diff --git a/__mocks__/visit.mock.ts b/__mocks__/visit.mock.ts new file mode 100644 index 000000000..a0dcb7d81 --- /dev/null +++ b/__mocks__/visit.mock.ts @@ -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: [], +} \ No newline at end of file diff --git a/src/components/encounter/ohri-encounter-form.tsx b/src/components/encounter/ohri-encounter-form.tsx index a53c584f4..9715a930c 100644 --- a/src/components/encounter/ohri-encounter-form.tsx +++ b/src/components/encounter/ohri-encounter-form.tsx @@ -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'; @@ -35,6 +35,7 @@ interface OHRIEncounterFormProps { encounterDate: Date; provider: string; location: SessionLocation; + visit?: Visit; values: Record; isCollapsed: boolean; sessionMode: SessionMode; @@ -57,6 +58,7 @@ export const OHRIEncounterForm: React.FC = ({ encounterDate, provider, location, + visit, values, isCollapsed, sessionMode, @@ -92,6 +94,7 @@ export const OHRIEncounterForm: React.FC = ({ sessionMode: sessionMode || (form?.encounter ? 'edit' : 'enter'), date: encounterDate, form: form, + visit: visit, }), [encounter, encounterDate, form?.encounter, location, patient, previousEncounter, sessionMode], ); @@ -381,7 +384,10 @@ export const OHRIEncounterForm: React.FC = ({ ]; encounterForSubmission['form'] = { uuid: encounterContext?.form?.uuid, - }; + }, + encounterForSubmission['visit'] = { + uuid: visit?.uuid + } } encounterForSubmission['obs'] = obsForSubmission; } else { @@ -400,6 +406,7 @@ export const OHRIEncounterForm: React.FC = ({ form: { uuid: encounterContext?.form?.uuid, }, + visit: visit?.uuid, }; } @@ -564,6 +571,7 @@ export const OHRIEncounterForm: React.FC = ({ encounterDate={encounterDate} provider={provider} location={location} + visit={visit} values={values} isCollapsed={isCollapsed} sessionMode={sessionMode} diff --git a/src/ohri-form.component.test.tsx b/src/ohri-form.component.test.tsx index 6f9a81db5..337d5cd3f 100644 --- a/src/ohri-form.component.test.tsx +++ b/src/ohri-form.component.test.tsx @@ -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/')); @@ -298,6 +300,7 @@ describe('OHRI Forms:', () => { formUUID={formUUID} patientUUID={patientUUID} formSessionIntent={intent} + visit={visit} />, ); }); diff --git a/src/ohri-form.component.tsx b/src/ohri-form.component.tsx index 80533ced2..9879db2b8 100644 --- a/src/ohri-form.component.tsx +++ b/src/ohri-form.component.tsx @@ -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'; @@ -32,6 +33,7 @@ interface OHRIFormProps { formUUID?: string; formJson?: OHRIFormSchema; encounterUUID?: string; + visit?: Visit; formSessionIntent?: string; onSubmit?: () => void; onCancel?: () => void; @@ -76,6 +78,7 @@ const OHRIForm: React.FC = ({ formUUID, patientUUID, encounterUUID, + visit, mode, onSubmit, onCancel, @@ -281,6 +284,7 @@ const OHRIForm: React.FC = ({ encounterDate={encDate} provider={currentProvider} location={location} + visit={visit} values={props.values} isCollapsed={collapsed} sessionMode={sessionMode}