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 { Store, select } from '@ngrx/store';
import { AppState } from '../../models/state';
import * as patientActions from '../../actions/patient.action';

import { PatientIdentity } from '../../models/patientModels';
import { ISubscription } from 'rxjs/Subscription';

/**
* Component to display current patient queue and provide selection/deletion capability
*/
@Component({
selector: 'app-patient-queue',
templateUrl: './patient-queue.component.html',
styleUrls: ['./patient-queue.component.css']
})

export class PatientQueueComponent implements OnInit {

/**
* current patient queue
*/
patientQueue: PatientIdentity[];
/**
* currently selected patient
*/
selectedPatient: PatientIdentity;

/**
* subscription to ngrx-store's patientqueue & selectedpatient observables
*/
subPatient: ISubscription;

/**
*
* @param _store ngrx-store containing application state
*/
constructor(private _store: Store<AppState>) { }

/**
* on initialization, subscribe to ngrx-store's patient observable and
* select the first patient in the queue
*/
ngOnInit() {

this.subPatient = this._store.pipe(select(state => state.patient)).subscribe(patient => {
this.patientQueue = patient.patientQueue;
this.selectedPatient = patient.selectedPatient.data.identity;
});

// Select the first patient by default
if (this.patientQueue && this.patientQueue.length > 0) { this.selectPatient(this.patientQueue[0]); }

}

/**
* dispatch change in selected patient to the ngrx-store
* @param patient identity of the patient to select
*/
selectPatient(patient: PatientIdentity) {
this._store.dispatch(new patientActions.SelectPatient(patient));
}

/**
* dispatch removal of a patient from the queue in the ngrx-store
* @param patient identity of patient to remove from queue
*/
removePatient(patient: PatientIdentity) {
this._store.dispatch(new patientActions.RemFromPatientQueue(patient));
}

/**
* dispatch clearing of entire patient queue in ngrx-store
*/
clearQueue() {
this._store.dispatch(new patientActions.ClearPatientQueue());
}

}