-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) O3-3316 Add support for encounter diagnosis
- Loading branch information
1 parent
c690eab
commit b959145
Showing
7 changed files
with
137 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { gracefullySetSubmission } from '../utils/common-utils'; | ||
import { type EncounterContext, type FormField, type OpenmrsEncounter, type SubmissionHandler } from '..'; | ||
|
||
export const EncounterDiagnosisHandler: SubmissionHandler = { | ||
handleFieldSubmission: (field: FormField, value: any, context: EncounterContext) => { | ||
const newValue = constructNewDiagnosis(value, field, context.patient.id); | ||
gracefullySetSubmission(field, newValue, null); | ||
return newValue; | ||
}, | ||
getInitialValue: ( | ||
encounter: OpenmrsEncounter, | ||
field: FormField, | ||
allFormFields: Array<FormField>, | ||
context: EncounterContext, | ||
) => { | ||
if (encounter?.diagnoses?.length > 0) { | ||
if(field.questionOptions.rank === 1) { | ||
return encounter.diagnoses.find((entry) => entry.voided === false && field.questionOptions.rank === entry.rank)?.diagnosis | ||
?.coded?.uuid; | ||
} else { | ||
return encounter.diagnoses.find((entry) => entry.voided === false && field.questionOptions.rank !== entry.rank)?.diagnosis | ||
?.coded?.uuid; | ||
} | ||
} else { | ||
return; | ||
} | ||
}, | ||
|
||
getDisplayValue: (field: FormField, value: any) => { | ||
return value; | ||
}, | ||
getPreviousValue: (field: FormField, encounter: OpenmrsEncounter, allFormFields: Array<FormField>) => { | ||
return null; | ||
} | ||
}; | ||
|
||
const constructNewDiagnosis = (value: any, field: FormField, patientUuid: string) => { | ||
if (!value) { | ||
return null; | ||
} | ||
return { | ||
patient: patientUuid, | ||
condition: null, | ||
diagnosis: { | ||
coded: value, | ||
}, | ||
certainty: 'CONFIRMED', | ||
rank: field.questionOptions.rank, // rank 1 denotes a diagnosis is primary, else secondary | ||
}; | ||
}; |
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