Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Nov 20, 2024
1 parent 619f2df commit 1b338c3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/adapters/encounter-diagnoses-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ export const EncounterDiagnosesAdapter: FormFieldValueAdapter = {
sourceObject: OpenmrsResource,
context: FormProcessorContextProps,
): Promise<any> {
const availableDiagnoses = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
const matchedDiagnoses = availableDiagnoses.diagnoses.find(
const encounter = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
const matchedDiagnosis = encounter.diagnoses.find(
(diagnosis) => diagnosis.formFieldPath === `rfe-forms-${field.id}`,
);

if (matchedDiagnoses) {
field.meta = { ...(field.meta || {}), previousValue: matchedDiagnoses };
if (!assignedDiagnosesIds.includes(matchedDiagnoses.diagnosis?.coded?.uuid)) {
assignedDiagnosesIds.push(matchedDiagnoses.diagnosis?.coded?.uuid);
if (matchedDiagnosis) {
field.meta = { ...(field.meta || {}), previousValue: matchedDiagnosis };
if (!assignedDiagnosesIds.includes(matchedDiagnosis.diagnosis?.coded?.uuid)) {
assignedDiagnosesIds.push(matchedDiagnosis.diagnosis?.coded?.uuid);
}
return matchedDiagnoses.diagnosis?.coded.uuid;
return matchedDiagnosis.diagnosis?.coded.uuid;
}
return null;
},
Expand Down Expand Up @@ -67,7 +67,7 @@ const constructNewDiagnosis = (value: any, field: FormField, patientUuid: string
};

function editDiagnosis(newEncounterDiagnosis: any, field: FormField) {
if (newEncounterDiagnosis === field.meta.previousValue?.concept?.uuid) {
if (newEncounterDiagnosis === field.meta.previousValue?.diagnosis?.coded?.uuid) {
clearSubmission(field);
return null;
}
Expand Down
36 changes: 36 additions & 0 deletions src/adapters/encounter-diagnoses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const field = {
submission: {
newValue: null,
},
previousValue: null,
},
validators: [
{
Expand Down Expand Up @@ -163,4 +164,39 @@ describe('EncounterDiagnosesAdapter', () => {
it('should execute tearDown without issues', () => {
expect(() => EncounterDiagnosesAdapter.tearDown()).not.toThrow();
});

it('should edit a diagnosis value', () => {
formContext.sessionMode = 'edit';

const value = '128138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
field.meta.previousValue = {
uuid: '0e20bb67-5d7f-41e0-96a1-751efc21a96f',
certainty: 'CONFIRMED',
condition: null,
formFieldPath: 'rfe-forms-DiagNosIS_1',
formFieldNamespace: 'rfe-forms',
display: 'Schistosoma Mansonii Infection',
rank: 1,
voided: false,
diagnosis: {
coded: {
uuid: '127133AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'Schistosoma Mansonii Infection',
},
},
};
EncounterDiagnosesAdapter.transformFieldValue(field, value, formContext);
expect(field.meta.submission.newValue).toEqual({
patient: null,
condition: null,
diagnosis: {
coded: '128138AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
},
certainty: 'CONFIRMED',
rank: 1,
formFieldPath: 'rfe-forms-DiagNosIS',
formFieldNamespace: 'rfe-forms',
});
expect(field.meta.submission.voidedValue).toEqual({ uuid: '0e20bb67-5d7f-41e0-96a1-751efc21a96f', voided: true });
});
});
14 changes: 7 additions & 7 deletions src/processors/encounter/encounter-form-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ export class EncounterFormProcessor extends FormProcessor {
// save encounter
try {
const { data: savedEncounter } = await saveEncounter(abortController, encounter, encounter.uuid);
const saveOrders = savedEncounter.orders.map((order) => order.orderNumber);
const saveDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
if (saveOrders.length) {
const savedOrders = savedEncounter.orders.map((order) => order.orderNumber);
const savedDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
if (savedOrders.length) {
showSnackbar({
title: translateFn('ordersSaved', 'Order(s) saved successfully'),
subtitle: saveOrders.join(', '),
subtitle: savedOrders.join(', '),
kind: 'success',
isLowContrast: true,
});
}
// handle diagnoses
if (saveDiagnoses.length) {
if (savedDiagnoses.length) {
showSnackbar({
title: translateFn('diagnosisSaved', 'Diagnosis(s) saved successfully'),
subtitle: saveDiagnoses.join(', '),
title: translateFn('diagnosisSaved', 'Diagnosis(es) saved successfully'),
subtitle: savedDiagnoses.join(', '),
kind: 'success',
isLowContrast: true,
});
Expand Down

0 comments on commit 1b338c3

Please sign in to comment.