-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group patient states by Program (#294)
- Loading branch information
1 parent
d47607c
commit c690eab
Showing
2 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { type PatientProgram, type FormField } from '../../types'; | ||
import { EncounterFormManager } from './encounter-form-manager'; | ||
|
||
describe('EncounterFormManager', () => { | ||
describe('preparePatientPrograms', () => { | ||
const fields: FormField[] = [ | ||
{ | ||
label: 'State 1', | ||
type: 'programState', | ||
questionOptions: { rendering: 'select', programUuid: 'program-1-uuid' }, | ||
meta: { submission: { newValue: { state: 'state-1' } } }, | ||
id: 'state_1', | ||
}, | ||
{ | ||
label: 'State 2', | ||
type: 'programState', | ||
questionOptions: { rendering: 'select', programUuid: 'program-1-uuid' }, | ||
meta: { submission: { newValue: { state: 'state-2' } } }, | ||
id: 'state_2', | ||
}, | ||
{ | ||
label: 'State 3', | ||
type: 'programState', | ||
questionOptions: { rendering: 'select', programUuid: 'program-2-uuid' }, | ||
meta: { submission: { newValue: { state: 'state-3' } } }, | ||
id: 'state_3', | ||
}, | ||
]; | ||
|
||
it('should group program states by program', () => { | ||
const patient = { id: 'patient-1' } as fhir.Patient; | ||
const currentPatientPrograms = [ | ||
{ | ||
program: { | ||
uuid: 'program-1-uuid', | ||
}, | ||
uuid: 'existing-enrollment-1-uuid', | ||
}, | ||
{ | ||
program: { | ||
uuid: 'program-2-uuid', | ||
}, | ||
uuid: 'existing-enrollment-2-uuid', | ||
}, | ||
] as Array<PatientProgram>; | ||
|
||
const result = EncounterFormManager.preparePatientPrograms(fields, patient, currentPatientPrograms); | ||
expect(result).toEqual([ | ||
{ | ||
uuid: 'existing-enrollment-1-uuid', | ||
states: [{ state: 'state-1' }, { state: 'state-2' }], | ||
}, | ||
{ | ||
uuid: 'existing-enrollment-2-uuid', | ||
states: [{ state: 'state-3' }], | ||
}, | ||
]); | ||
}); | ||
|
||
it('should enroll in a new program if none exists', () => { | ||
const patient = { id: 'patient-1' } as fhir.Patient; | ||
const result = EncounterFormManager.preparePatientPrograms([fields[0]], patient, []); | ||
expect(result).toEqual([ | ||
{ | ||
patient: 'patient-1', | ||
program: 'program-1-uuid', | ||
states: [{ state: 'state-1' }], | ||
dateEnrolled: expect.any(String), | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters