Skip to content

Commit

Permalink
O3-2061 Pass active visit attributes as default in visit related form…
Browse files Browse the repository at this point in the history
… fields (openmrs#30)
  • Loading branch information
CynthiaKamau authored and eudson committed Apr 21, 2023
1 parent 52aff38 commit 680d6d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
19 changes: 19 additions & 0 deletions __mocks__/visit.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const mockVisit =
{
uuid: '15dd49ba-4283-472f-bce3-05401f85c0d3',
patient: {
uuid: '5a4e7a05-e275-4c14-acab-cb86f3e16353',
display: '102EWH - Test Patient Registration',
},
visitType: {
uuid: '7b0f5697-27e3-40c4-8bae-f4049abfb4ed',
display: 'Facility Visit',
},
location: {
uuid: '7fdfa2cb-bc95-405a-88c6-32b7673c0453',
display: 'Laboratory',
},
startDatetime: '2020-07-28T10:29:00.000+0000',
stopDatetime: '2020-07-29T10:29:00.000+0000',
encounters: [],
}
12 changes: 10 additions & 2 deletions src/components/encounter/ohri-encounter-form.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { SessionLocation, useLayoutType } from '@openmrs/esm-framework';
import { SessionLocation, useLayoutType, Visit } from '@openmrs/esm-framework';
import { ConceptFalse, ConceptTrue } from '../../constants';
import { OHRIFormContext } from '../../ohri-form-context';
import { getHandler, getValidator } from '../../registry/registry';
Expand Down Expand Up @@ -35,6 +35,7 @@ interface OHRIEncounterFormProps {
encounterDate: Date;
provider: string;
location: SessionLocation;
visit?: Visit;
values: Record<string, any>;
isCollapsed: boolean;
sessionMode: SessionMode;
Expand All @@ -57,6 +58,7 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
encounterDate,
provider,
location,
visit,
values,
isCollapsed,
sessionMode,
Expand Down Expand Up @@ -92,6 +94,7 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
sessionMode: sessionMode || (form?.encounter ? 'edit' : 'enter'),
date: encounterDate,
form: form,
visit: visit,
}),
[encounter, encounterDate, form?.encounter, location, patient, previousEncounter, sessionMode],
);
Expand Down Expand Up @@ -381,7 +384,10 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
];
encounterForSubmission['form'] = {
uuid: encounterContext?.form?.uuid,
};
},
encounterForSubmission['visit'] = {
uuid: visit?.uuid
}
}
encounterForSubmission['obs'] = obsForSubmission;
} else {
Expand All @@ -400,6 +406,7 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
form: {
uuid: encounterContext?.form?.uuid,
},
visit: visit?.uuid,
};
}

Expand Down Expand Up @@ -562,6 +569,7 @@ export const OHRIEncounterForm: React.FC<OHRIEncounterFormProps> = ({
encounterDate={encounterDate}
provider={provider}
location={location}
visit={visit}
values={values}
isCollapsed={isCollapsed}
sessionMode={sessionMode}
Expand Down
3 changes: 3 additions & 0 deletions src/ohri-form.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import {
findSelectInput,
findTextOrDateInput,
} from './utils/test-utils';
import { mockVisit } from '../__mocks__/visit.mock';

//////////////////////////////////////////
////// Base setup
//////////////////////////////////////////

const patientUUID = '8673ee4f-e2ab-4077-ba55-4980f408773e';
const visit = mockVisit
const mockOpenmrsFetch = jest.fn();
const formsResourcePath = when((url: string) => url.includes('/ws/rest/v1/form/'));
const clobdataResourcePath = when((url: string) => url.includes('/ws/rest/v1/clobdata/'));
Expand Down Expand Up @@ -298,6 +300,7 @@ describe('OHRI Forms:', () => {
formUUID={formUUID}
patientUUID={patientUUID}
formSessionIntent={intent}
visit={visit}
/>,
);
});
Expand Down
4 changes: 4 additions & 0 deletions src/ohri-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
detach,
registerExtension,
attach,
Visit,
} from '@openmrs/esm-framework';
import LinearLoader from './components/loaders/linear-loader.component';
import LoadingIcon from './components/loaders/loading.component';
Expand All @@ -32,6 +33,7 @@ interface OHRIFormProps {
formUUID?: string;
formJson?: OHRIFormSchema;
encounterUUID?: string;
visit?: Visit;
formSessionIntent?: string;
onSubmit?: () => void;
onCancel?: () => void;
Expand Down Expand Up @@ -76,6 +78,7 @@ const OHRIForm: React.FC<OHRIFormProps> = ({
formUUID,
patientUUID,
encounterUUID,
visit,
mode,
onSubmit,
onCancel,
Expand Down Expand Up @@ -281,6 +284,7 @@ const OHRIForm: React.FC<OHRIFormProps> = ({
encounterDate={encDate}
provider={currentProvider}
location={location}
visit={visit}
values={props.values}
isCollapsed={collapsed}
sessionMode={sessionMode}
Expand Down

0 comments on commit 680d6d7

Please sign in to comment.