-
Notifications
You must be signed in to change notification settings - Fork 248
/
Copy pathform-entry-interop.ts
42 lines (40 loc) · 1.38 KB
/
form-entry-interop.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { navigate, type Visit } from '@openmrs/esm-framework';
import { type HtmlFormEntryForm } from './config-schema';
import isEmpty from 'lodash-es/isEmpty';
import { launchPatientWorkspace, launchStartVisitPrompt } from '@openmrs/esm-patient-common-lib';
export function launchFormEntryOrHtmlForms(
currentVisit: Visit | undefined,
formUuid: string,
patient: fhir.Patient,
htmlFormEntryForms: Array<HtmlFormEntryForm>,
encounterUuid?: string,
formName?: string,
mutateForms?: () => void,
) {
if (currentVisit) {
const htmlForm = htmlFormEntryForms.find((form) => form.formUuid === formUuid);
if (isEmpty(htmlForm)) {
launchFormEntry(formUuid, patient.id, encounterUuid, formName, mutateForms, currentVisit);
} else {
navigate({
to: `\${openmrsBase}/htmlformentryui/htmlform/${htmlForm.formUiPage}.page?patientId=${patient.id}&visitId=${currentVisit.uuid}&definitionUiResource=${htmlForm.formUiResource}&returnUrl=${window.location.href}`,
});
}
} else {
launchStartVisitPrompt();
}
}
export function launchFormEntry(
formUuid: string,
patientUuid: string,
encounterUuid?: string,
formName?: string,
mutateForm?: () => void,
currentVisit?: Visit,
) {
launchPatientWorkspace('patient-form-entry-workspace', {
workspaceTitle: formName,
mutateForm,
formInfo: { encounterUuid, formUuid, visit: currentVisit },
});
}