Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
import { Component, OnInit } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { QueryParams, AppointmentExt, ProgressNote, PatientIdentity } from '../../models/patientModels';
import { GridElement } from '../../models/uiModels';
import * as _ from 'lodash';
import { Store, select } from '@ngrx/store';
import { AppState } from '../../models/state';
import * as patientActions from '../../actions/patient.action';
@Component({
selector: 'app-appointments',
templateUrl: './appointments.component.html',
styleUrls: ['./appointments.component.css']
})
export class AppointmentsComponent implements OnInit {
patientIdentity: PatientIdentity;
_appt: {
data?: AppointmentExt[];
err?: string;
queryDate?: Date;
future?: any;
custom?: any;
params?: QueryParams;
} = {};
filterForm = {
startDate: null,
endDate: new Date(),
facility: null,
error: {},
changed: false
};
gridParams = {sort: {'appointmentDate': 'desc'}};
showFutureAppointments = true;
set params(incoming: QueryParams) {
this._appt.params = incoming;
this.filterForm.startDate = (incoming && incoming.filter.appointmentDate) ? new Date(incoming.filter.appointmentDate.value) : null;
}
set appointments(incoming: any) {
if (incoming) {
this._appt.data = incoming.data;
this._appt.err = incoming.err;
this._appt.queryDate = incoming.queryDate;
this._appt.future = this.setFutureTable(incoming.data);
this._appt.custom = this.setCustomTable(incoming.data);
}
}
// for printing list of appointments & list type
printing = {
list: [],
type: ''
};
/**
* grid definition for future appointment table
*/
futureApptDef: Array<GridElement> = [
{ header: 'Date/Time', key: 'appointmentDate', format: 'date', tooltip: 'The date/time of the appointment.'},
{ header: 'Clinic', key: 'location.name', tooltip: 'Hospital Location where appointment/visit will take place.' },
{ header: 'Specialty', key: 'location.specialty', tooltip: 'Treating specialty assigned to a specific location; \
specialties within services (i.e. neurosurgery, alcohol/drug rehabilitation, dermatology)' },
{ header: 'Provider', key: 'provider', tooltip: 'A default provider assigned to the clinic.'},
{ header: 'Facility',
key: 'location.facility.stationNumber',
tooltip: 'The station number of the facility for the patient appointment.',
dataTooltipKey: 'location.facility.siteName'
}
];
/**
* grid definition for custom appointment table
*/
customApptDef: Array<GridElement> = [
{ header: 'Date/Time', key: 'appointmentDate', tooltip: 'The date/time of the appointment.', dataTooltipKey: 'noshow'},
{ header: 'Clinic', key: 'location.name', tooltip: 'Hospital Location where appointment/visit will take place.' },
{ header: 'Specialty', key: 'location.specialty', tooltip: 'Treating specialty assigned to a specific location; \
specialties within services (i.e. neurosurgery, alcohol/drug rehabilitation, dermatology)' },
{ header: 'Provider', key: 'provider', tooltip: 'A default provider assigned to the clinic.'},
{ header: 'Facility',
key: 'location.facility.stationNumber',
tooltip: 'The station number of the facility for the patient appointment.',
dataTooltipKey: 'location.facility.siteName'
}
];
constructor(private _store: Store<AppState>, public activeModal: NgbActiveModal) {
// subscribe to appointments, appointment parameters and patientID in data store...
this._store.pipe(select(state => state.patient.selectedPatient.params.appointments)).subscribe(params => this.params = params);
this._store.pipe(select(state => state.patient.selectedPatient.data.appointments)).subscribe(data => this.appointments = data);
this._store.pipe(select(state => state.patient.selectedPatient.data.identity)).subscribe(data => this.patientIdentity = data);
}
ngOnInit() {
}
/**
* pull out future appointments from the list
* @param data full appointment list
*/
setFutureTable(data: AppointmentExt[]) {
const retVal = [];
const Today = new Date();
data.forEach((itm, idx) => {
if (new Date(itm.appointmentDate) > Today) {
retVal.push({
appointmentDate: itm.appointmentDate,
'location.name': (itm.location) ? itm.location.name : '',
'location.specialty': (itm.location) ? itm.location.specialty : '',
provider: itm.provider,
'location.facility.stationNumber': (itm.location && itm.location.facility)
? itm.location.facility.stationNumber : '',
'location.facility.siteName': (itm.location && itm.location.facility)
? itm.location.facility.siteName : '',
dataIndex: idx
});
}
});
return retVal;
}
/**
* pull out appointments that meet the current filter criteria from the list
* @param data full appointment list
*/
setCustomTable(data: AppointmentExt[]) {
// if they have an end date specified, set it here w/hours at 23:59:59 so we capture everything during the day
// when we do a comparison...
const endDate = (this.filterForm.endDate) ? new Date(this.filterForm.endDate) : null;
if (endDate) { endDate.setHours(23, 59, 59); }
const retVal = [];
data.forEach((itm, idx) => {
const dt = new Date(itm.appointmentDate);
if ((!this.filterForm.startDate || this.filterForm.startDate <= dt) &&
(!endDate || endDate >= dt) &&
(!this.filterForm.facility || this.filterForm.facility.toString() === itm.location.facility.stationNumber.toString())) {
// format the date as a string & append indicator if it's a no-show
const dateText = ('0' + (dt.getMonth() + 1)).slice(-2) + '/' + ('0' + dt.getDate()).slice(-2) + '/' +
dt.getFullYear() + ' ' + ('0' + dt.getHours()).slice(-2) + ':' + ('0' + dt.getMinutes()).slice(-2) +
((itm.status && itm.status === 'noshow') ? ' [no-show]' : '');
const newItem = {
appointmentDate: dateText,
'location.name': (itm.location) ? itm.location.name : '',
'location.specialty': (itm.location) ? itm.location.specialty : '',
provider: itm.provider,
'location.facility.stationNumber': (itm.location && itm.location.facility)
? itm.location.facility.stationNumber : '',
'location.facility.siteName': (itm.location && itm.location.facility)
? itm.location.facility.siteName : '',
dataIndex: idx
};
// add noshow property to the row for applicable items, for the grid component's data-tooltip display
if (itm.status && itm.status === 'noshow') { newItem['noshow'] = 'This indicates that the appointment status was a no-show.'; }
retVal.push(newItem);
}
});
return retVal;
}
/**
* closes the current modal window
*/
cancel() {
this.activeModal.close();
}
/**
* returns list of current form errors in custom list query
*/
getErrorList() {
let retVal = '';
_.map(this.filterForm.error, (itm) => { retVal += ' ' + itm; });
return retVal;
}
/**
* Triggered on change of date-picker element
* @param newVal new value sent from date element
* @param field which date field we're working with...
*/
changeDate(newVal: any, field: string) {
if (newVal === 'error') {
this.filterForm.error[field] = '*Invalid ' + field + ' date. ';
} else {
delete this.filterForm.error[field];
(field === 'start') ? this.filterForm.startDate = newVal : this.filterForm.endDate = newVal;
if (this.filterForm.startDate && this.filterForm.endDate &&
this.filterForm.startDate > this.filterForm.endDate) {
this.filterForm.error['range'] = '*Start date is after end date. ';
} else {
delete this.filterForm.error['range'];
}
}
}
/**
* requery data
*/
changeFilter() {
if (Object.keys(this.filterForm.error).length > 0 ) { return; }
// for appointments, we're only sending a start date & do all other filtering locally
const newParams = JSON.parse(JSON.stringify(this._appt.params));
if (this.filterForm.startDate) {
newParams.filter['appointmentDate'].value = new Date(this.filterForm.startDate).toISOString();
} else {
delete newParams.filter['appointmentDate'];
}
this._store.dispatch(new patientActions.SetQueryParameters({element: 'appointments', params: JSON.parse(JSON.stringify(newParams)) }));
}
/**
* set filters back to initial values
*/
resetFilter() {
this.filterForm.facility = null;
this.filterForm.endDate = new Date();
this._store.dispatch(new patientActions.ResetQueryParameters({element: 'appointments'}));
}
/**
* Grabs the given element, inserts it into a popup & triggers the browser print dialog, on
* cancel/print, it closes the popup
* @param contentID element ID to print
* @param listType whether this is for the custom list or the future list
*/
printComponent(contentID, listType) {
if (listType === 'custom') {
this.printing.list = this._appt.custom;
this.printing.type = 'custom';
} else {
this.printing.list = this._appt.future;
this.printing.type = 'future';
}
setTimeout(() => {
const content = document.getElementById(contentID);
const printWindow = window.open('', 'Appointments', 'width=850,height=750,toolbar=0,scrollbars=0,status=0');
printWindow.document.write(content.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}, 10);
}
getMaskedSSN(ssn: string) {
if (ssn && ssn.match(/^\d{3}-\d{2}-\d{4}$/)) {
return '***-**-' + ssn.slice(-4);
} else {
return '***-**-****';
}
}
}