-
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.
- Loading branch information
1 parent
6f36300
commit 2415c6d
Showing
8 changed files
with
140 additions
and
0 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 OpenmrsResource } from '@openmrs/esm-framework'; | ||
import { type FormFieldValueAdapter, type FormProcessorContextProps } from '..'; | ||
import { type FormContextProps } from '../provider/form-provider'; | ||
import { type FormField } from '../types'; | ||
import { clearSubmission, gracefullySetSubmission } from '../utils/common-utils'; | ||
|
||
export let assignedEncounterDiagnosisIds: string[] = []; | ||
|
||
export const EncounterDiagnosisAdapter: FormFieldValueAdapter = { | ||
transformFieldValue: function (field: FormField, value: any, context: FormContextProps) { | ||
if (context.sessionMode == 'edit' && field.meta?.previousValue?.uuid) { | ||
return editDiagnosis(value, field, context.currentProvider.uuid); | ||
} | ||
const newValue = constructNewDiagnosis(value, field, context.currentProvider.uuid); | ||
gracefullySetSubmission(field, newValue, null); | ||
return newValue; | ||
}, | ||
getInitialValue: function ( | ||
field: FormField, | ||
sourceObject: OpenmrsResource, | ||
context: FormProcessorContextProps, | ||
): Promise<any> { | ||
// if (context.encounter?.diagnoses?.length > 0) { | ||
// assignedEncounterDiagnosisIds.push(encounter.diagnoses[0].diagnosis.coded.uuid); | ||
// return encounter.diagnoses[0].diagnosis.coded.uuid; | ||
// } else { | ||
// return; | ||
// } | ||
return; | ||
}, | ||
getPreviousValue: function ( | ||
field: FormField, | ||
sourceObject: OpenmrsResource, | ||
context: FormProcessorContextProps, | ||
): Promise<any> { | ||
return null; | ||
}, | ||
getDisplayValue: (field: FormField, value: any) => { | ||
field.questionOptions; | ||
return field.questionOptions.answers?.find((option) => option.concept == value)?.label || value; | ||
}, | ||
tearDown: function (): void { | ||
assignedEncounterDiagnosisIds = []; | ||
}, | ||
}; | ||
|
||
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 | ||
}; | ||
}; | ||
|
||
function editDiagnosis(newEncounterDiagnosis: any, field: FormField, EncounterDiagnosiser: string) { | ||
if (newEncounterDiagnosis === field.meta.previousValue?.concept?.uuid) { | ||
clearSubmission(field); | ||
return null; | ||
} | ||
const voided = { | ||
uuid: field.meta.previousValue?.uuid, | ||
voided: true, | ||
}; | ||
gracefullySetSubmission(field, constructNewDiagnosis(newEncounterDiagnosis, field, null), voided); | ||
return field.meta.submission.newValue || null; | ||
} |
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