Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Sep 26, 2024
1 parent 2f9b75f commit bc33d5d
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/adapters/encounter-diagnosis-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export const EncounterDiagnosisAdapter: FormFieldValueAdapter = {
context: FormProcessorContextProps,
): Promise<any> {
const availableDiagnoses = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
const matchedDiagnosis = availableDiagnoses.diagnoses?.find(
const matchedDiagnoses = availableDiagnoses.diagnoses?.find(
(diagnosis) => diagnosis.formFieldPath === `rfe-forms-${field.id}`,
);
if (matchedDiagnosis) {
field.meta = { ...(field.meta || {}), previousValue: matchedDiagnosis };
assignedEncounterDiagnosisIds.push(matchedDiagnosis.diagnosis?.coded?.uuid);
if (matchedDiagnoses) {
field.meta = { ...(field.meta || {}), previousValue: matchedDiagnoses };
assignedEncounterDiagnosisIds.push(matchedDiagnoses.diagnosis?.coded?.uuid);

return matchedDiagnosis.diagnosis?.coded.uuid;
return matchedDiagnoses.diagnosis?.coded.uuid;
}
return null;
},
Expand Down
1 change: 1 addition & 0 deletions src/adapters/orders-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const OrdersAdapter: FormFieldValueAdapter = {
}
const newValue = constructNewOrder(value, field, context.currentProvider.uuid);
gracefullySetSubmission(field, newValue, null);

return newValue;
},
getInitialValue: function (
Expand Down
106 changes: 105 additions & 1 deletion src/hooks/useEncounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,109 @@ export function useEncounter(formJson: FormSchema) {
}
}, [formJson.encounter]);

return { encounter: encounter, error, isLoading };
const mockEncounter = {
uuid: 'ba7829e5-4097-4fda-adfe-ec97682b7c2a',
encounterDatetime: '2024-09-26T06:59:41.000+0000',
encounterType: {
uuid: '0e8230ce-bd1d-43f5-a863-cf44344fa4b0',
name: 'Adult Visit',
description: 'Encounter for adult visit form',
},
location: {
uuid: 'b309447b-2b0b-4f2c-869b-fdae85f193f1',
name: 'Registration Desk',
},
patient: {
uuid: '89efb55a-4f24-4206-9939-6d28c25d5791',
display: '100017F - Kajiando Test',
},
encounterProviders: [
{
uuid: '923f6fab-9337-488f-a751-e4f6a0c645af',
provider: {
uuid: 'bc450226-4138-40b7-ad88-9c98df687738',
name: 'Super User',
},
encounterRole: {
uuid: '8cb3a399-d18b-4b62-aefb-5a0f948a3809',
name: 'Clinician',
},
},
],
orders: [
{
uuid: '5a11d1bb-12e5-49a2-909e-bf0511cd1738',
display: 'Congestion',
concept: {
uuid: '30e2da8f-34ca-4c93-94c8-d429f22d381c',
display: 'Congestion',
},
voided: false,
},
{
uuid: 'b260e5f7-5da4-447e-a70c-dd55860d0654',
display: 'tos',
concept: {
uuid: '143264AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'tos',
},
voided: false,
},
],
diagnoses: [
{
uuid: '9cc2e254-1b34-4ef7-b11a-06d86ef41e17',
certainty: 'CONFIRMED',
condition: null,
formFieldPath: 'rfe-forms-DiagNosIS_1',
formFieldNamespace: 'rfe-forms',
display: 'Immunocompromised state',
rank: 1,
voided: false,
diagnosis: {
coded: {
uuid: '156753AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'Immunocompromised state',
},
},
},
{
uuid: '0ace7a3e-dab6-4a00-935c-2d516a00271f',
certainty: 'CONFIRMED',
condition: null,
formFieldPath: 'rfe-forms-DiagNosIS',
formFieldNamespace: 'rfe-forms',
display: 'Cigarette smoker',
rank: 1,
voided: false,
diagnosis: {
coded: {
uuid: '155600AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
display: 'Cigarette smoker',
},
},
},
],
obs: [
{
uuid: '7a216892-dd63-40b3-ba54-1ee60d2e2989',
obsDatetime: '2024-09-26T06:59:41.000+0000',
comment: null,
voided: false,
groupMembers: null,
formFieldNamespace: 'rfe-forms',
formFieldPath: 'rfe-forms-visitType',
concept: {
uuid: '160632AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
name: {
uuid: '06d5da31-4437-35aa-a533-7973b5358c3e',
name: 'Free text general',
},
},
value: 'Test here',
},
],
};

return { encounter: mockEncounter, error, isLoading };
}
6 changes: 3 additions & 3 deletions src/processors/encounter/encounter-form-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class EncounterFormProcessor extends FormProcessor {
try {
const { data: savedEncounter } = await saveEncounter(abortController, encounter, encounter.uuid);
const saveOrders = savedEncounter.orders.map((order) => order.orderNumber);
const saveDiagnosis = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
const saveDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
if (saveOrders.length) {
showSnackbar({
title: translateFn('ordersSaved', 'Order(s) saved successfully'),
Expand All @@ -176,10 +176,10 @@ export class EncounterFormProcessor extends FormProcessor {
});
}
// handle diagnoses
if (saveDiagnosis.length) {
if (saveDiagnoses.length) {
showSnackbar({
title: translateFn('diagnosisSaved', 'Diagnosis(s) saved successfully'),
subtitle: saveDiagnosis.join(', '),
subtitle: saveDiagnoses.join(', '),
kind: 'success',
isLowContrast: true,
});
Expand Down
11 changes: 5 additions & 6 deletions src/processors/encounter/encounter-processor-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function prepareEncounter(
const obsForSubmission = [];
prepareObs(obsForSubmission, formFields);
const ordersForSubmission = prepareOrders(formFields);
const diagnosisForSubmission = prepareDiagnosis(formFields);
const diagnosesForSubmission = prepareDiagnosis(formFields);
let encounterForSubmission: OpenmrsEncounter = {};

if (encounter) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export function prepareEncounter(
}
encounterForSubmission.obs = obsForSubmission;
encounterForSubmission.orders = ordersForSubmission;
encounterForSubmission.diagnoses = diagnosisForSubmission;
encounterForSubmission.diagnoses = diagnosesForSubmission;
} else {
encounterForSubmission = {
patient: patient.id,
Expand All @@ -78,7 +78,7 @@ export function prepareEncounter(
},
visit: visit?.uuid,
orders: ordersForSubmission,
diagnoses: diagnosisForSubmission,
diagnoses: diagnosesForSubmission,
};
}
return encounterForSubmission;
Expand Down Expand Up @@ -306,13 +306,12 @@ export async function hydrateRepeatField(
}

//handle diagnoses
const unMappedDiagnosis = encounter.diagnoses.filter((diagnosis) => {
const unMappedDiagnoses = encounter.diagnoses.filter((diagnosis) => {
return !assignedEncounterDiagnosisIds.includes(diagnosis.diagnosis.coded.uuid);
});

if (field.type === 'diagnosis') {
return Promise.all(
unMappedDiagnosis
unMappedDiagnoses
.filter((diagnosis) => !diagnosis.voided)
.map(async (diagnosis) => {
const clone = cloneRepeatField(field, diagnosis, counter++);
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/default-schema-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function transformByType(question: FormField) {
: question.questionOptions.rendering;
break;
case 'diagnosis':
handleDiagnosesDataSource(question);
handleDiagnosis(question);
break;
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ function handleQuestionsWithObsComments(sectionQuestions: Array<FormField>): Arr
return augmentedQuestions;
}

function handleDiagnosesDataSource(question: FormField) {
function handleDiagnosis(question: FormField) {
if ('dataSource' in question.questionOptions && question.questionOptions['dataSource'] === 'diagnoses') {
question.questionOptions.datasource = {
name: 'problem_datasource',
Expand Down

0 comments on commit bc33d5d

Please sign in to comment.