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, OnDestroy } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { AppState } from '../../models/state';
import { ISubscription } from 'rxjs/Subscription';
import {Patient, PatientQueryParams, AllergyExt} from '../../models/patientModels';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { AllergyComponent } from '../allergy/allergy.component';
import * as _ from 'lodash';
/** Component for displaying an individual patient's information */
@Component({
selector: 'app-patient-detail',
templateUrl: './patient-detail.component.html',
styleUrls: ['./patient-detail.component.css']
})
export class PatientDetailComponent implements OnInit, OnDestroy {
isCollapsed = false;
showFullDemographics = false;
/**
* The patient data for display
*/
patient: {
data: Patient;
params: PatientQueryParams;
};
patientAllergyCount = 0;
_allergyMap: Map<string, Array<AllergyExt>>;
/**
* subscription for patient data observable
*/
subPatient: ISubscription;
/**
*
* @param _store ngrx-store containing application state
* @param modalService ng-bootstrap modal for displaying messages to the user
*/
constructor(private _store: Store<AppState>, private modalService: NgbModal) { }
/**
* Initialize the component by subscribing to the ngrx-store's selectedPatient and user preferences
*/
ngOnInit() {
this.subPatient = this._store
.pipe(select(state => state.patient.selectedPatient))
.subscribe(data => {
this.patient = data;
this.constAllergyMap();
this.patientAllergyCount = this.allergyRecordCount();
});
}
// this._store.pipe(select(state => state.patient.selectedPatient.params)).subscribe(params => this.patientParams = params);
/**
* clean up subscriptions on exit
*/
ngOnDestroy() {
this.subPatient.unsubscribe();
}
/**
* method to trigger display of a detailed allergy record
* @param allergies Array of allergy records to display in modal component
*/
viewAllergy(allergies: Array<AllergyExt>) {
const allergyModal = this.modalService.open(AllergyComponent, {size: 'lg', windowClass: 'record-popup'});
allergyModal.componentInstance.data = allergies;
}
/**
* constructs an internal Allergy Map Object used for the Patient Detail Allergy banner.
* @param data an Array of AllergyExt objects for the patient.
*/
private constAllergyMap() {
const map = new Map();
if (this.patient.data && this.patient.data.allergies) {
for (const allergy of this.patient.data.allergies.data) {
if (allergy.gmrAllergy && allergy.status === 'active') {
const k = allergy.gmrAllergy;
if (map.has(k)) {
map.get(k).push(allergy);
} else {
map.set(k, [allergy]);
}
}
}
// @ts-ignore
this._allergyMap = new Map([...map.entries()].sort());
}
}
/**
* Returns an Array of gmrAllergy strings for a given gmrAllergy for the patient.
*/
getGmrAllergies() {
let rtn = null;
if (this._allergyMap != null) {
rtn = Array.from( this._allergyMap.keys() );
}
return rtn;
}
/**
* Returns the number of allergy records for a given gmsAllergy.
* @param key the gmrAllergy key.
*/
getNumAllergy(key) {
return this._allergyMap.get(key).length;
}
/**
* Returns the Array of Allergy records for the given gmrAllergy key.
* @param key the gmrAllergy key.
*/
getAllergies(key): Array<AllergyExt> {
return this._allergyMap.get(key);
}
/**
* count up the total number of allergy assessment & ACTIVE allergy records...
*/
allergyRecordCount(): number {
if (this.patient.data && this.patient.data.allergies && this.patient.data.allergies.data &&
this.patient.data.allergies.data.length > 0 ) {
return (_.reduce(this.patient.data.allergies.data, (sum, itm) => {
return (!itm.gmrAllergy || itm.status.toLowerCase().match('active')) ? sum + 1 : sum;
}, 0));
} else {
return 0;
}
}
/**
* Returns whether or not any vitalSummary type has data. For toggling disabled on Vital tab header
*/
hasVitals() {
if (!this.patient.data || !this.patient.data.vitalSummary) { return false; }
let hasData = false;
const keys = Object.keys(this.patient.data.vitalSummary);
for (let i = 0; i < keys.length; i++) {
if (this.patient.data.vitalSummary[keys[i]].data.name) {
hasData = true;
break;
}
}
return hasData;
}
}