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, Input, OnDestroy } from '@angular/core';
import { GridElement } from '../../models/uiModels';
import * as _ from 'lodash';
import { QueryParams, Immunization } from '../../models/patientModels';
import { AppState } from '../../models/state';
import { Store } from '@ngrx/store';
import * as patientActions from '../../actions/patient.action';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ImmunizationComponent } from '../immunization/immunization.component';

@Component({
selector: 'app-immunizations',
templateUrl: './immunizations.component.html',
styleUrls: ['./immunizations.component.css']
})
export class ImmunizationsComponent implements OnInit, OnDestroy {

/**
* local data store for immunization data, error info and the datatable to display
*/
_immunizations = {
data: [],
err: '',
dataTable: []
};

/**
* input property for current querystring parameters
*/
@Input()
queryParams: QueryParams;

/**
* input property of immunization for display. In format {data: Immunization[], err: string }
* @description When input array changes, clear the data table & repopulate
*/
@Input()
set immunizations(immunizations: {data: Immunization[], err: string}) {
this._immunizations.data = immunizations.data;
this._immunizations.err = immunizations.err;
this._immunizations.dataTable = [];

if (immunizations.data) { this.generateDataTable(); }
}

/**
* property defines the data elements, headers & tooltips to display on the grid
*/
dataDef: Array<GridElement> = [
{ header: 'Name (of immunization)', key: 'name', tooltip: 'Name of immunization given to the patient at the encounter.'},
{ header: 'Administration Date/Time', key: 'administered', format: 'date', tooltip: 'Date/Time the immunization was administered.' },
{ header: 'Reaction', key: 'reaction', tooltip: 'The reaction that may have been observed because of the immunization given.' },
{ header: 'Facility',
key: 'facility.stationNumber',
tooltip: 'Station number of facility where immunization was administered.', dataTooltipKey: 'facility.siteName'
}
];


constructor(private _store: Store<AppState>, private modalService: NgbModal) { }


/**
* On init, subscribe to the app state's session info to get the user's 'local' facility.
*/
ngOnInit() {
// this.subSession = this._store.select(state => state.session).subscribe(session => this.session = session);
}

/**
* try to clean up after ourselves
*/
ngOnDestroy() {
// if (this.subSession) { this.subSession.unsubscribe(); }
}

/**
* used by template to display dataDef's header text for a field.
* @param itm - Field name to get the display text for
*/
displayText(itm: string) {
return _.find(this.dataDef, (elem) => elem.key === itm ).header;
}

/**
* creates local dataTable array from the immunization data, applying local filters and
* sorting it.
*/
generateDataTable() {

this._immunizations.dataTable = [];

// push the data into the data table
this._immunizations.data.forEach((itm, idx) => {

this._immunizations.dataTable.push({
name: itm.name,
administered: itm.administered,
reaction: itm.reaction,
'facility.stationNumber': (itm.facility) ? itm.facility.stationNumber : '',
'facility.siteName': (itm.facility) ? itm.facility.siteName : '',
dataIndex: idx
});
});

}

/**
* Method for displaying detailed Immunization record in a modal popup
* @param dataTableRecord the Immunization record to display
*/
viewDetail(dataTableRecord: any) {
const immunizationModal = this.modalService.open(ImmunizationComponent, {size: 'lg'});
immunizationModal.componentInstance.data = {...this._immunizations.data[dataTableRecord.dataIndex]};
}

/**
* Paging events bubble up from grid component. updating the store here triggers a requery
* @param action string in [prev, next, number]
*/
changePage(action: any) {

const newParams = JSON.parse(JSON.stringify(this.queryParams));
switch (action) {
case 'next':
newParams.page++;
break;
case 'prev':
if (newParams.page > 1) { newParams.page--; }
break;
default:
if (Number.isInteger(action)) { newParams.page = action; }
}

this._store.dispatch(new patientActions.SetQueryParameters({element: 'immunizations', params: JSON.parse(JSON.stringify(newParams)) }));

}

sync(params: QueryParams) {

const newParams = JSON.parse(JSON.stringify(this.queryParams));
newParams.filter = JSON.parse(JSON.stringify(params.filter));
newParams.sort = JSON.parse(JSON.stringify(params.sort));
newParams.size = params.size;
newParams.page = 1;
this._store.dispatch(new patientActions.SetQueryParameters({element: 'immunizations', params: JSON.parse(JSON.stringify(newParams)) }));

}

resetAndSync() {
this._store.dispatch(new patientActions.ResetQueryParameters({element: 'immunizations'}));
}

}