@openmrs/esm-patient-common-lib 11.3.1-patch.9508 → 11.3.1-pre.10003

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,152 +0,0 @@
1
- import { launchWorkspace } from '@openmrs/esm-framework';
2
- import { type Form, type HtmlFormEntryForm } from './types';
3
- import { launchStartVisitPrompt } from './launchStartVisitPrompt';
4
-
5
- export const clinicalFormsWorkspace = 'clinical-forms-workspace';
6
- export const formEntryWorkspace = 'patient-form-entry-workspace';
7
- export const htmlFormEntryWorkspace = 'patient-html-form-entry-workspace';
8
-
9
- const formEngineResourceName = 'formEngine';
10
- const htmlformentryFormEngine = 'htmlformentry';
11
- const uiStyleResourceName = 'uiStyle';
12
- const uiStyleSimple = 'simple';
13
-
14
- export function launchFormEntryOrHtmlForms(
15
- htmlFormEntryForms: Array<HtmlFormEntryForm>,
16
- patientUuid: string,
17
- form: Form,
18
- visitUuid?: string,
19
- encounterUuid?: string,
20
- visitTypeUuid?: string,
21
- visitStartDatetime?: string,
22
- visitStopDatetime?: string,
23
- mutateForms?: () => void,
24
- clinicalFormsWorkspaceName = clinicalFormsWorkspace,
25
- formEntryWorkspaceName = formEntryWorkspace,
26
- htmlFormEntryWorkspaceName = htmlFormEntryWorkspace,
27
- ) {
28
- if (visitUuid) {
29
- const { uuid: formUuid, display, name } = form ?? {};
30
- const formName = display ?? name ?? '--';
31
-
32
- const htmlForm = toHtmlForm(form, htmlFormEntryForms);
33
- if (htmlForm) {
34
- launchHtmlFormEntry(patientUuid, formName, encounterUuid, visitUuid, htmlForm, htmlFormEntryWorkspaceName);
35
- } else {
36
- launchFormEntry(
37
- formUuid,
38
- patientUuid,
39
- encounterUuid,
40
- formName,
41
- visitUuid,
42
- visitTypeUuid,
43
- visitStartDatetime,
44
- visitStopDatetime,
45
- htmlForm,
46
- mutateForms,
47
- clinicalFormsWorkspaceName,
48
- formEntryWorkspaceName,
49
- );
50
- }
51
- } else {
52
- launchStartVisitPrompt();
53
- }
54
- }
55
-
56
- export function launchFormEntry(
57
- formUuid: string,
58
- patientUuid: string,
59
- encounterUuid?: string,
60
- formName?: string,
61
- visitUuid?: string,
62
- visitTypeUuid?: string,
63
- visitStartDatetime?: string,
64
- visitStopDatetime?: string,
65
- htmlForm?: HtmlFormEntryForm,
66
- mutateForm?: () => void,
67
- clinicalFormsWorkspaceName = clinicalFormsWorkspace,
68
- formEntryWorkspaceName = formEntryWorkspace,
69
- ) {
70
- launchWorkspace(formEntryWorkspaceName, {
71
- workspaceTitle: formName,
72
- clinicalFormsWorkspaceName,
73
- formEntryWorkspaceName,
74
- patientUuid,
75
- mutateForm,
76
- formInfo: {
77
- encounterUuid,
78
- formUuid,
79
- patientUuid,
80
- visitTypeUuid: visitTypeUuid,
81
- visitUuid: visitUuid,
82
- visitStartDatetime,
83
- visitStopDatetime,
84
- htmlForm,
85
- },
86
- });
87
- }
88
-
89
- export function launchHtmlFormEntry(
90
- patientUuid: string,
91
- formName: string,
92
- encounterUuid: string,
93
- visitUuid: string,
94
- htmlForm: HtmlFormEntryForm,
95
- workspaceName = htmlFormEntryWorkspace,
96
- ) {
97
- launchWorkspace(workspaceName, {
98
- workspaceTitle: formName,
99
- patientUuid,
100
- formInfo: {
101
- encounterUuid,
102
- visitUuid,
103
- htmlForm,
104
- },
105
- });
106
- }
107
-
108
- /**
109
- * For a given form , check if it is an HTML form. If it is, return the HtmlFormEntryForm object,
110
- * otherwise return null
111
- * @param form
112
- * @param htmlFormEntryForms A list of HTML forms configured in @esm-patient-forms-app's config
113
- *
114
- * @returns
115
- */
116
- function toHtmlForm(form: Form, htmlFormEntryForms: Array<HtmlFormEntryForm>): HtmlFormEntryForm {
117
- const isHtmlForm =
118
- htmlFormEntryForms?.some((hfeForm) => hfeForm.formUuid === form.uuid) ||
119
- form.resources?.some((resource) => {
120
- return resource.name === formEngineResourceName && resource.valueReference === htmlformentryFormEngine;
121
- });
122
- if (isHtmlForm) {
123
- const hfeForm = htmlFormEntryForms?.find((f) => f.formUuid === form.uuid);
124
- const simple = form.resources?.some((r) => r.name === uiStyleResourceName && r.valueReference === uiStyleSimple);
125
-
126
- return {
127
- formUuid: form.uuid,
128
- formName: hfeForm?.formName ?? form.display ?? form.name,
129
- formUiResource: hfeForm?.formUiResource,
130
- formUiPage: hfeForm?.formUiPage ?? (simple ? 'enterHtmlFormWithSimpleUi' : 'enterHtmlFormWithStandardUi'),
131
- formEditUiPage: hfeForm?.formEditUiPage ?? (simple ? 'editHtmlFormWithSimpleUi' : 'editHtmlFormWithStandardUi'),
132
- };
133
- } else {
134
- return null;
135
- }
136
- }
137
-
138
- /**
139
- * Given a list of forms and a list of HtmlFormEntryForm objects from configuration, return a List of HtmlFormEntryForm
140
- * returned forms either
141
- * a) have a form resource with a name of `formEngine` and a value of `htmlformentry, or
142
- * b) have an entry in the HtmlFormEntryForm array for a given form uuid
143
- * The HtmlFormEntryForm configuration provides a means to override the name and rendering mode of a given form
144
- * @param allForms
145
- * @param htmlFormEntryForms
146
- */
147
- export function mapFormsToHtmlFormEntryForms(
148
- allForms: Array<Form>,
149
- htmlFormEntryForms: Array<HtmlFormEntryForm>,
150
- ): Array<HtmlFormEntryForm> {
151
- return allForms?.map((form) => toHtmlForm(form, htmlFormEntryForms))?.filter((form) => form !== null);
152
- }