Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O3-2061: Introduce visit as an optional parameter to the form-engine #30

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -564,6 +571,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