-
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.
- Loading branch information
1 parent
2f9b75f
commit 089214e
Showing
9 changed files
with
210 additions
and
24 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
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,166 @@ | ||
import { type FormContextProps } from '../provider/form-provider'; | ||
import { type FormField } from '../types'; | ||
import { EncounterDiagnosesAdapter } from './encounter-diagnoses-adapter'; | ||
|
||
const formContext = { | ||
methods: null, | ||
workspaceLayout: 'maximized', | ||
isSubmitting: false, | ||
patient: { | ||
id: '833db896-c1f0-11eb-8529-0242ac130003', | ||
}, | ||
formJson: null, | ||
visit: null, | ||
sessionMode: 'enter', | ||
sessionDate: new Date(), | ||
location: { | ||
uuid: '41e6e516-c1f0-11eb-8529-0242ac130003', | ||
}, | ||
currentProvider: null, | ||
layoutType: 'small-desktop', | ||
domainObjectValue: { | ||
uuid: '873455da-3ec4-453c-b565-7c1fe35426be', | ||
obs: [], | ||
diagnoses: [], | ||
}, | ||
previousDomainObjectValue: null, | ||
processor: null, | ||
formFields: [], | ||
formFieldAdapters: null, | ||
formFieldValidators: null, | ||
customDependencies: { | ||
patientPrograms: [], | ||
}, | ||
getFormField: jest.fn(), | ||
addFormField: jest.fn(), | ||
updateFormField: jest.fn(), | ||
removeFormField: () => {}, | ||
addInvalidField: jest.fn(), | ||
removeInvalidField: jest.fn(), | ||
setInvalidFields: jest.fn(), | ||
setForm: jest.fn(), | ||
} as FormContextProps; | ||
|
||
const field = { | ||
label: 'Test Diagnosis', | ||
id: 'DiagNosIS', | ||
type: 'diagnosis', | ||
questionOptions: { | ||
rendering: 'repeating', | ||
rank: 1, | ||
datasource: { | ||
name: 'problem_datasource', | ||
config: { | ||
class: [ | ||
'8d4918b0-c2cc-11de-8d13-0010c6dffd0f', | ||
'8d492954-c2cc-11de-8d13-0010c6dffd0f', | ||
'8d492b2a-c2cc-11de-8d13-0010c6dffd0f', | ||
], | ||
}, | ||
}, | ||
}, | ||
meta: { | ||
submission: { | ||
newValue: null, | ||
}, | ||
}, | ||
validators: [ | ||
{ | ||
type: 'form_field', | ||
}, | ||
{ | ||
type: 'default_value', | ||
}, | ||
], | ||
isHidden: false, | ||
isRequired: false, | ||
isDisabled: false, | ||
} as FormField; | ||
|
||
const diagnoses = [ | ||
{ | ||
uuid: '8d975f9e-e9e6-452f-be7c-0e87c047f056', | ||
diagnosis: { | ||
coded: { | ||
uuid: '127133AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
display: 'Schistosoma Mansonii Infection', | ||
links: [], | ||
}, | ||
}, | ||
condition: null, | ||
encounter: { | ||
uuid: '9a4b06bd-d655-414f-b9ce-69e940c337ce', | ||
}, | ||
certainty: 'CONFIRMED', | ||
rank: 1, | ||
voided: false, | ||
display: 'Schistosoma Mansonii Infection', | ||
patient: { | ||
uuid: '00affa97-0010-417c-87f5-de48362de915', | ||
display: '1000VKV - Bett Tett', | ||
}, | ||
formFieldNamespace: 'rfe-forms', | ||
formFieldPath: 'rfe-forms-DiagNosIS_1', | ||
links: [], | ||
resourceVersion: '1.8', | ||
}, | ||
{ | ||
uuid: 'b2d0e95b-d2f6-49d1-a477-acc7026edbd7', | ||
diagnosis: { | ||
coded: { | ||
uuid: '137329AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
display: 'Infection due to Entamoeba Histolytica', | ||
links: [], | ||
}, | ||
}, | ||
condition: null, | ||
encounter: { | ||
uuid: '9a4b06bd-d655-414f-b9ce-69e940c337ce', | ||
}, | ||
certainty: 'CONFIRMED', | ||
rank: 1, | ||
voided: false, | ||
display: 'Infection due to Entamoeba Histolytica', | ||
patient: { | ||
uuid: '00affa97-0010-417c-87f5-de48362de915', | ||
display: '1000VKV - Bett Tett', | ||
}, | ||
formFieldNamespace: 'rfe-forms', | ||
formFieldPath: 'rfe-forms-DiagNosIS', | ||
links: [], | ||
resourceVersion: '1.8', | ||
}, | ||
]; | ||
|
||
describe('EncounterDiagnosesAdapter', () => { | ||
it('should should handle submission of a diagnosis field', async () => { | ||
const value = '127133AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; | ||
EncounterDiagnosesAdapter.transformFieldValue(field, value, formContext); | ||
expect(field.meta.submission.newValue).toEqual({ | ||
patient: '833db896-c1f0-11eb-8529-0242ac130003', | ||
condition: null, | ||
diagnosis: { | ||
coded: '127133AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', | ||
}, | ||
certainty: 'CONFIRMED', | ||
rank: 1, | ||
formFieldPath: 'rfe-forms-DiagNosIS', | ||
formFieldNamespace: 'rfe-forms', | ||
}); | ||
}); | ||
|
||
it('should get initial value for the diagnosis', async () => { | ||
formContext.domainObjectValue.diagnoses.push(...diagnoses); | ||
const program = await EncounterDiagnosesAdapter.getInitialValue(field, null, formContext); | ||
expect(program).toEqual('137329AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'); | ||
}); | ||
|
||
it('should return null for getPreviousValue', async () => { | ||
const previousValue = await EncounterDiagnosesAdapter.getPreviousValue(field, null, formContext); | ||
expect(previousValue).toBeNull(); | ||
}); | ||
|
||
it('should execute tearDown without issues', () => { | ||
expect(() => EncounterDiagnosesAdapter.tearDown()).not.toThrow(); | ||
}); | ||
}); |
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
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
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
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
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
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
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