@openmrs/esm-fast-data-entry-app 1.0.1-pre.8 → 1.0.1-pre.82
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.
- package/README.md +21 -2
- package/dist/132.js +1 -0
- package/dist/168.js +1 -0
- package/dist/229.js +1 -0
- package/dist/247.js +1 -0
- package/dist/255.js +1 -0
- package/dist/294.js +2 -0
- package/dist/294.js.LICENSE.txt +9 -0
- package/dist/32.js +1 -0
- package/dist/327.js +1 -0
- package/dist/403.js +2 -0
- package/dist/403.js.LICENSE.txt +14 -0
- package/dist/553.js +2 -0
- package/dist/553.js.LICENSE.txt +14 -0
- package/dist/569.js +2 -0
- package/dist/569.js.LICENSE.txt +27 -0
- package/dist/574.js +1 -0
- package/dist/595.js +2 -0
- package/dist/595.js.LICENSE.txt +1 -0
- package/dist/617.js +1 -0
- package/dist/68.js +2 -0
- package/dist/68.js.LICENSE.txt +21 -0
- package/dist/74.js +1 -0
- package/dist/757.js +1 -0
- package/dist/776.js +1 -0
- package/dist/804.js +1 -0
- package/dist/820.js +1 -0
- package/dist/935.js +2 -0
- package/dist/935.js.LICENSE.txt +19 -0
- package/dist/main.js +1 -0
- package/dist/openmrs-esm-fast-data-entry-app.js +1 -1
- package/dist/openmrs-esm-fast-data-entry-app.js.buildmanifest.json +612 -0
- package/dist/openmrs-esm-fast-data-entry-app.old +1 -0
- package/package.json +9 -9
- package/src/CancelModal.tsx +48 -0
- package/src/CompleteModal.tsx +46 -0
- package/src/FormBootstrap.tsx +18 -3
- package/src/add-group-modal/AddGroupModal.tsx +80 -27
- package/src/add-group-modal/styles.scss +14 -4
- package/src/config-schema.ts +22 -0
- package/src/context/FormWorkflowContext.tsx +13 -1
- package/src/context/FormWorkflowReducer.ts +13 -3
- package/src/context/GroupFormWorkflowContext.tsx +41 -6
- package/src/context/GroupFormWorkflowReducer.ts +170 -12
- package/src/form-entry-workflow/FormEntryWorkflow.tsx +67 -101
- package/src/form-entry-workflow/styles.scss +2 -1
- package/src/forms-page/FormsPage.tsx +8 -3
- package/src/forms-page/forms-table/FormsTable.tsx +11 -5
- package/src/group-form-entry-workflow/GroupFormEntryWorkflow.tsx +13 -400
- package/src/group-form-entry-workflow/GroupSessionWorkspace.tsx +247 -0
- package/src/group-form-entry-workflow/SessionDetailsForm.tsx +122 -0
- package/src/group-form-entry-workflow/SessionMetaWorkspace.tsx +107 -0
- package/src/group-form-entry-workflow/attendance-table/AttendanceTable.tsx +105 -0
- package/src/group-form-entry-workflow/attendance-table/index.ts +1 -0
- package/src/group-form-entry-workflow/{group-banner/GroupBanner.test.tsx → group-display-header/GroupDisplayHeader.test.tsx} +2 -2
- package/src/group-form-entry-workflow/{group-banner/GroupBanner.tsx → group-display-header/GroupDisplayHeader.tsx} +23 -5
- package/src/group-form-entry-workflow/group-display-header/index.ts +3 -0
- package/src/group-form-entry-workflow/group-search/CompactGroupResults.tsx +61 -28
- package/src/group-form-entry-workflow/group-search/CompactGroupSearch.tsx +5 -0
- package/src/group-form-entry-workflow/group-search/GroupSearch.tsx +65 -8
- package/src/group-form-entry-workflow/group-search/group-search.scss +8 -6
- package/src/group-form-entry-workflow/group-search-header/GroupSearchHeader.tsx +11 -7
- package/src/group-form-entry-workflow/styles.scss +12 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useGetSystemSetting.ts +38 -0
- package/src/hooks/usePostEndpoint.ts +70 -0
- package/src/hooks/useSearchEndpoint.ts +120 -0
- package/src/hooks/useStartVisit.ts +92 -0
- package/src/patient-card/styles.scss +1 -0
- package/tools/i18next-parser.config.js +93 -0
- package/translations/en.json +27 -9
- package/translations/fr.json +50 -0
- package/.editorconfig +0 -12
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -10
- package/.husky/pre-push +0 -1
- package/.prettierignore +0 -14
- package/.yarn/plugins/@yarnpkg/plugin-version.cjs +0 -550
- package/.yarn/versions/7ee3eceb.yml +0 -0
- package/src/group-form-entry-workflow/group-banner/index.ts +0 -3
- package/src/group-form-entry-workflow/group-search/mock-group-data.ts +0 -79
- package/src/group-form-entry-workflow/group-search/useGroupSearch.ts +0 -14
- package/src/hooks/usePostCohort.ts +0 -18
- /package/src/group-form-entry-workflow/{group-banner → group-display-header}/styles.scss +0 -0
|
@@ -1,413 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
useStore,
|
|
5
|
-
} from "@openmrs/esm-framework";
|
|
6
|
-
import {
|
|
7
|
-
Button,
|
|
8
|
-
ComposedModal,
|
|
9
|
-
ModalBody,
|
|
10
|
-
ModalFooter,
|
|
11
|
-
ModalHeader,
|
|
12
|
-
Layer,
|
|
13
|
-
Tile,
|
|
14
|
-
TextInput,
|
|
15
|
-
TextArea,
|
|
16
|
-
DatePicker,
|
|
17
|
-
DatePickerInput,
|
|
18
|
-
} from "@carbon/react";
|
|
19
|
-
import React, { useContext, useEffect, useState } from "react";
|
|
20
|
-
import { useNavigate } from "react-router-dom";
|
|
21
|
-
import PatientCard from "../patient-card/PatientCard";
|
|
22
|
-
import GroupBanner from "./group-banner";
|
|
1
|
+
import { ExtensionSlot } from "@openmrs/esm-framework";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import GroupDisplayHeader from "./group-display-header";
|
|
23
4
|
import styles from "./styles.scss";
|
|
24
|
-
import {
|
|
25
|
-
import GroupFormWorkflowContext, {
|
|
26
|
-
GroupFormWorkflowProvider,
|
|
27
|
-
} from "../context/GroupFormWorkflowContext";
|
|
5
|
+
import { GroupFormWorkflowProvider } from "../context/GroupFormWorkflowContext";
|
|
28
6
|
import GroupSearchHeader from "./group-search-header";
|
|
29
|
-
import
|
|
30
|
-
|
|
31
|
-
FormProvider,
|
|
32
|
-
useForm,
|
|
33
|
-
useFormContext,
|
|
34
|
-
} from "react-hook-form";
|
|
35
|
-
import FormBootstrap from "../FormBootstrap";
|
|
36
|
-
|
|
37
|
-
const formStore = getGlobalStore("ampath-form-state");
|
|
38
|
-
|
|
39
|
-
const CancelModal = ({ open, setOpen }) => {
|
|
40
|
-
const { destroySession, closeSession } = useContext(GroupFormWorkflowContext);
|
|
41
|
-
const { t } = useTranslation();
|
|
42
|
-
const navigate = useNavigate();
|
|
43
|
-
|
|
44
|
-
const discard = async () => {
|
|
45
|
-
await destroySession();
|
|
46
|
-
setOpen(false);
|
|
47
|
-
navigate("../");
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const saveAndClose = async () => {
|
|
51
|
-
await closeSession();
|
|
52
|
-
setOpen(false);
|
|
53
|
-
navigate("../");
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<ComposedModal open={open}>
|
|
58
|
-
<ModalHeader>{t("areYouSure", "Are you sure?")}</ModalHeader>
|
|
59
|
-
<ModalBody>
|
|
60
|
-
{t(
|
|
61
|
-
"cancelExplanation",
|
|
62
|
-
"You will lose any unsaved changes on the current form. Do you want to discard the current session?"
|
|
63
|
-
)}
|
|
64
|
-
</ModalBody>
|
|
65
|
-
<ModalFooter>
|
|
66
|
-
<Button kind="secondary" onClick={() => setOpen(false)}>
|
|
67
|
-
{t("cancel", "Cancel")}
|
|
68
|
-
</Button>
|
|
69
|
-
<Button kind="danger" onClick={discard}>
|
|
70
|
-
{t("discard", "Discard")}
|
|
71
|
-
</Button>
|
|
72
|
-
<Button kind="primary" onClick={saveAndClose}>
|
|
73
|
-
{t("saveSession", "Save Session")}
|
|
74
|
-
</Button>
|
|
75
|
-
</ModalFooter>
|
|
76
|
-
</ComposedModal>
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const CompleteModal = ({ open, setOpen }) => {
|
|
81
|
-
const { submitForComplete } = useContext(GroupFormWorkflowContext);
|
|
82
|
-
const { t } = useTranslation();
|
|
83
|
-
|
|
84
|
-
const completeSession = () => {
|
|
85
|
-
submitForComplete();
|
|
86
|
-
setOpen(false);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<ComposedModal open={open}>
|
|
91
|
-
<ModalHeader>{t("areYouSure", "Are you sure?")}</ModalHeader>
|
|
92
|
-
<ModalBody>
|
|
93
|
-
{t(
|
|
94
|
-
"saveExplanation",
|
|
95
|
-
"Do you want to save the current form and exit the workflow?"
|
|
96
|
-
)}
|
|
97
|
-
</ModalBody>
|
|
98
|
-
<ModalFooter>
|
|
99
|
-
<Button kind="secondary" onClick={() => setOpen(false)}>
|
|
100
|
-
{t("cancel", "Cancel")}
|
|
101
|
-
</Button>
|
|
102
|
-
<Button kind="primary" onClick={completeSession}>
|
|
103
|
-
{t("complete", "Complete")}
|
|
104
|
-
</Button>
|
|
105
|
-
</ModalFooter>
|
|
106
|
-
</ComposedModal>
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const NewGroupWorkflowButtons = () => {
|
|
111
|
-
const { t } = useTranslation();
|
|
112
|
-
const { workflowState } = useContext(GroupFormWorkflowContext);
|
|
113
|
-
const [cancelModalOpen, setCancelModalOpen] = useState(false);
|
|
114
|
-
if (workflowState !== "NEW_GROUP_SESSION") return null;
|
|
115
|
-
|
|
116
|
-
return (
|
|
117
|
-
<>
|
|
118
|
-
<div className={styles.rightPanelActionButtons}>
|
|
119
|
-
<Button kind="secondary" type="submit">
|
|
120
|
-
{t("createNewSession", "Create New Session")}
|
|
121
|
-
</Button>
|
|
122
|
-
<Button
|
|
123
|
-
kind="tertiary"
|
|
124
|
-
onClick={() => {
|
|
125
|
-
setCancelModalOpen(true);
|
|
126
|
-
}}
|
|
127
|
-
>
|
|
128
|
-
{t("cancel", "Cancel")}
|
|
129
|
-
</Button>
|
|
130
|
-
</div>
|
|
131
|
-
<CancelModal open={cancelModalOpen} setOpen={setCancelModalOpen} />
|
|
132
|
-
</>
|
|
133
|
-
);
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const WorkflowNavigationButtons = () => {
|
|
137
|
-
const { activeFormUuid, submitForNext, patientUuids, activePatientUuid } =
|
|
138
|
-
useContext(GroupFormWorkflowContext);
|
|
139
|
-
const store = useStore(formStore);
|
|
140
|
-
const formState = store[activeFormUuid];
|
|
141
|
-
const navigationDisabled = formState !== "ready";
|
|
142
|
-
const [cancelModalOpen, setCancelModalOpen] = useState(false);
|
|
143
|
-
const [completeModalOpen, setCompleteModalOpen] = useState(false);
|
|
144
|
-
const { t } = useTranslation();
|
|
145
|
-
|
|
146
|
-
const isLastPatient =
|
|
147
|
-
activePatientUuid === patientUuids[patientUuids.length - 1];
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<>
|
|
151
|
-
<div className={styles.rightPanelActionButtons}>
|
|
152
|
-
<Button
|
|
153
|
-
kind="primary"
|
|
154
|
-
onClick={() => submitForNext()}
|
|
155
|
-
disabled={navigationDisabled}
|
|
156
|
-
>
|
|
157
|
-
{isLastPatient
|
|
158
|
-
? t("saveForm", "Save Form")
|
|
159
|
-
: t("nextPatient", "Next Patient")}
|
|
160
|
-
</Button>
|
|
161
|
-
<Button kind="secondary" onClick={() => setCompleteModalOpen(true)}>
|
|
162
|
-
{t("saveAndComplete", "Save & Complete")}
|
|
163
|
-
</Button>
|
|
164
|
-
<Button kind="tertiary" onClick={() => setCancelModalOpen(true)}>
|
|
165
|
-
{t("cancel", "Cancel")}
|
|
166
|
-
</Button>
|
|
167
|
-
</div>
|
|
168
|
-
<CancelModal open={cancelModalOpen} setOpen={setCancelModalOpen} />
|
|
169
|
-
<CompleteModal open={completeModalOpen} setOpen={setCompleteModalOpen} />
|
|
170
|
-
</>
|
|
171
|
-
);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const SessionDetails = () => {
|
|
175
|
-
const { t } = useTranslation();
|
|
176
|
-
const {
|
|
177
|
-
register,
|
|
178
|
-
formState: { errors },
|
|
179
|
-
control,
|
|
180
|
-
} = useFormContext();
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<div className={styles.formSection}>
|
|
184
|
-
<h4>{t("sessionDetails", "Session details")}</h4>
|
|
185
|
-
<div>
|
|
186
|
-
<p>
|
|
187
|
-
{t(
|
|
188
|
-
"allFieldsRequired",
|
|
189
|
-
"All fields are required unless marked optional"
|
|
190
|
-
)}
|
|
191
|
-
</p>
|
|
192
|
-
</div>
|
|
193
|
-
<Layer>
|
|
194
|
-
<Tile className={styles.formSectionTile}>
|
|
195
|
-
<Layer>
|
|
196
|
-
<div
|
|
197
|
-
style={{
|
|
198
|
-
display: "flex",
|
|
199
|
-
flexDirection: "column",
|
|
200
|
-
rowGap: "1.5rem",
|
|
201
|
-
}}
|
|
202
|
-
>
|
|
203
|
-
<TextInput
|
|
204
|
-
id="text"
|
|
205
|
-
type="text"
|
|
206
|
-
labelText={t("sessionName", "Session Name")}
|
|
207
|
-
{...register("sessionName", { required: true })}
|
|
208
|
-
invalid={errors.sessionName}
|
|
209
|
-
invalidText={"This field is required"}
|
|
210
|
-
/>
|
|
211
|
-
<TextInput
|
|
212
|
-
id="text"
|
|
213
|
-
type="text"
|
|
214
|
-
labelText={t("practitionerName", "Practitioner Name")}
|
|
215
|
-
{...register("practitionerName", { required: true })}
|
|
216
|
-
invalid={errors.practitionerName}
|
|
217
|
-
invalidText={"This field is required"}
|
|
218
|
-
/>
|
|
219
|
-
<Controller
|
|
220
|
-
name="sessionDate"
|
|
221
|
-
control={control}
|
|
222
|
-
rules={{ required: true }}
|
|
223
|
-
render={({ field }) => (
|
|
224
|
-
<DatePicker
|
|
225
|
-
datePickerType="single"
|
|
226
|
-
size="md"
|
|
227
|
-
maxDate={new Date()}
|
|
228
|
-
{...field}
|
|
229
|
-
>
|
|
230
|
-
<DatePickerInput
|
|
231
|
-
id="session-date"
|
|
232
|
-
labelText={t("sessionDate", "Session Date")}
|
|
233
|
-
placeholder="mm/dd/yyyy"
|
|
234
|
-
size="md"
|
|
235
|
-
invalid={errors.sessionDate}
|
|
236
|
-
invalidText={"This field is required"}
|
|
237
|
-
/>
|
|
238
|
-
</DatePicker>
|
|
239
|
-
)}
|
|
240
|
-
/>
|
|
241
|
-
<TextArea
|
|
242
|
-
id="text"
|
|
243
|
-
type="text"
|
|
244
|
-
labelText={t("sessionNotes", "Session Notes")}
|
|
245
|
-
{...register("sessionNotes", { required: true })}
|
|
246
|
-
invalid={errors.sessionNotes}
|
|
247
|
-
invalidText={"This field is required"}
|
|
248
|
-
/>
|
|
249
|
-
</div>
|
|
250
|
-
</Layer>
|
|
251
|
-
</Tile>
|
|
252
|
-
</Layer>
|
|
253
|
-
</div>
|
|
254
|
-
);
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const GroupIdField = () => {
|
|
258
|
-
const { t } = useTranslation();
|
|
259
|
-
const {
|
|
260
|
-
register,
|
|
261
|
-
formState: { errors },
|
|
262
|
-
setValue,
|
|
263
|
-
} = useFormContext();
|
|
264
|
-
const { activeGroupUuid } = useContext(GroupFormWorkflowContext);
|
|
265
|
-
|
|
266
|
-
useEffect(() => {
|
|
267
|
-
if (activeGroupUuid) setValue("groupUuid", activeGroupUuid);
|
|
268
|
-
}, [activeGroupUuid, setValue]);
|
|
269
|
-
|
|
270
|
-
return (
|
|
271
|
-
<>
|
|
272
|
-
<input
|
|
273
|
-
hidden
|
|
274
|
-
{...register("groupUuid", {
|
|
275
|
-
value: activeGroupUuid,
|
|
276
|
-
required: t("chooseGroupError", "Please choose a group."),
|
|
277
|
-
})}
|
|
278
|
-
/>
|
|
279
|
-
{errors.groupUuid && !activeGroupUuid && (
|
|
280
|
-
<div className={styles.formError}>
|
|
281
|
-
{errors.groupUuid.message as string}
|
|
282
|
-
</div>
|
|
283
|
-
)}
|
|
284
|
-
</>
|
|
285
|
-
);
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const SessionMetaWorkspace = () => {
|
|
289
|
-
const { t } = useTranslation();
|
|
290
|
-
const { setSessionMeta } = useContext(GroupFormWorkflowContext);
|
|
291
|
-
const methods = useForm();
|
|
292
|
-
|
|
293
|
-
const onSubmit = (data) => {
|
|
294
|
-
const { sessionDate, ...rest } = data;
|
|
295
|
-
setSessionMeta({ ...rest, sessionDate: sessionDate[0] });
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
return (
|
|
299
|
-
<FormProvider {...methods}>
|
|
300
|
-
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
301
|
-
<div className={styles.workspace}>
|
|
302
|
-
<div className={styles.formMainContent}>
|
|
303
|
-
<div className={styles.formContainer}>
|
|
304
|
-
<SessionDetails />
|
|
305
|
-
</div>
|
|
306
|
-
<div className={styles.rightPanel}>
|
|
307
|
-
<h4>{t("newGroupSession", "New Group Session")}</h4>
|
|
308
|
-
<GroupIdField />
|
|
309
|
-
<hr style={{ width: "100%" }} />
|
|
310
|
-
<NewGroupWorkflowButtons />
|
|
311
|
-
</div>
|
|
312
|
-
</div>
|
|
313
|
-
</div>
|
|
314
|
-
</form>
|
|
315
|
-
</FormProvider>
|
|
316
|
-
);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
const GroupSessionWorkspace = () => {
|
|
320
|
-
const { t } = useTranslation();
|
|
321
|
-
const {
|
|
322
|
-
patientUuids,
|
|
323
|
-
activePatientUuid,
|
|
324
|
-
editEncounter,
|
|
325
|
-
encounters,
|
|
326
|
-
activeEncounterUuid,
|
|
327
|
-
activeFormUuid,
|
|
328
|
-
saveEncounter,
|
|
329
|
-
// activeSessionMeta,
|
|
330
|
-
} = useContext(GroupFormWorkflowContext);
|
|
331
|
-
|
|
332
|
-
// const handleEncounterCreate = (payload: Record<string, unknown>) => {
|
|
333
|
-
// console.log("payload", payload);
|
|
334
|
-
// Object.entries(activeSessionMeta).forEach((key, value) => {
|
|
335
|
-
// payload[key as unknown as string] = value;
|
|
336
|
-
// });
|
|
337
|
-
// };
|
|
338
|
-
|
|
339
|
-
const handlePostResponse = (encounter) => {
|
|
340
|
-
if (encounter && encounter.uuid) {
|
|
341
|
-
saveEncounter(encounter.uuid);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
return (
|
|
346
|
-
<div className={styles.workspace}>
|
|
347
|
-
<div className={styles.formMainContent}>
|
|
348
|
-
<div className={styles.formContainer}>
|
|
349
|
-
<FormBootstrap
|
|
350
|
-
patientUuid={activePatientUuid}
|
|
351
|
-
encounterUuid={activeEncounterUuid}
|
|
352
|
-
{...{
|
|
353
|
-
formUuid: activeFormUuid,
|
|
354
|
-
handlePostResponse,
|
|
355
|
-
// handleEncounterCreate,
|
|
356
|
-
}}
|
|
357
|
-
/>
|
|
358
|
-
</div>
|
|
359
|
-
<div className={styles.rightPanel}>
|
|
360
|
-
<h4>{t("formsFilled", "Forms filled")}</h4>
|
|
361
|
-
<div className={styles.patientCardsSection}>
|
|
362
|
-
{patientUuids?.map((patientUuid) => (
|
|
363
|
-
<PatientCard
|
|
364
|
-
key={patientUuid}
|
|
365
|
-
{...{
|
|
366
|
-
patientUuid,
|
|
367
|
-
activePatientUuid,
|
|
368
|
-
editEncounter,
|
|
369
|
-
encounters,
|
|
370
|
-
}}
|
|
371
|
-
/>
|
|
372
|
-
))}
|
|
373
|
-
</div>
|
|
374
|
-
<WorkflowNavigationButtons />
|
|
375
|
-
</div>
|
|
376
|
-
</div>
|
|
377
|
-
</div>
|
|
378
|
-
);
|
|
379
|
-
};
|
|
7
|
+
import SessionMetaWorkspace from "./SessionMetaWorkspace";
|
|
8
|
+
import GroupSessionWorkspace from "./GroupSessionWorkspace";
|
|
380
9
|
|
|
381
10
|
const GroupFormEntryWorkflow = () => {
|
|
382
|
-
const { workflowState } = useContext(GroupFormWorkflowContext);
|
|
383
|
-
|
|
384
11
|
return (
|
|
385
|
-
|
|
12
|
+
<GroupFormWorkflowProvider>
|
|
386
13
|
<div className={styles.breadcrumbsContainer}>
|
|
387
14
|
<ExtensionSlot extensionSlotName="breadcrumbs-slot" />
|
|
388
15
|
</div>
|
|
389
16
|
<GroupSearchHeader />
|
|
390
|
-
<
|
|
391
|
-
{
|
|
392
|
-
<
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
)}
|
|
396
|
-
{["EDIT_FORM"].includes(workflowState) && (
|
|
397
|
-
<div className={styles.workspaceWrapper}>
|
|
398
|
-
<GroupSessionWorkspace />
|
|
399
|
-
</div>
|
|
400
|
-
)}
|
|
401
|
-
</>
|
|
402
|
-
);
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
const GroupFormEntryWorkflowWrapper = () => {
|
|
406
|
-
return (
|
|
407
|
-
<GroupFormWorkflowProvider>
|
|
408
|
-
<GroupFormEntryWorkflow />
|
|
17
|
+
<GroupDisplayHeader />
|
|
18
|
+
<div className={styles.workspaceWrapper}>
|
|
19
|
+
<SessionMetaWorkspace />
|
|
20
|
+
<GroupSessionWorkspace />
|
|
21
|
+
</div>
|
|
409
22
|
</GroupFormWorkflowProvider>
|
|
410
23
|
);
|
|
411
24
|
};
|
|
412
25
|
|
|
413
|
-
export default
|
|
26
|
+
export default GroupFormEntryWorkflow;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getGlobalStore,
|
|
3
|
+
useConfig,
|
|
4
|
+
useSession,
|
|
5
|
+
useStore,
|
|
6
|
+
} from "@openmrs/esm-framework";
|
|
7
|
+
import { Button } from "@carbon/react";
|
|
8
|
+
import React, { useCallback, useContext, useEffect, useState } from "react";
|
|
9
|
+
import PatientCard from "../patient-card/PatientCard";
|
|
10
|
+
import styles from "./styles.scss";
|
|
11
|
+
import { useTranslation } from "react-i18next";
|
|
12
|
+
import GroupFormWorkflowContext from "../context/GroupFormWorkflowContext";
|
|
13
|
+
import FormBootstrap from "../FormBootstrap";
|
|
14
|
+
import useStartVisit from "../hooks/useStartVisit";
|
|
15
|
+
import CompleteModal from "../CompleteModal";
|
|
16
|
+
import CancelModal from "../CancelModal";
|
|
17
|
+
|
|
18
|
+
const formStore = getGlobalStore("ampath-form-state");
|
|
19
|
+
|
|
20
|
+
const WorkflowNavigationButtons = () => {
|
|
21
|
+
const context = useContext(GroupFormWorkflowContext);
|
|
22
|
+
const {
|
|
23
|
+
activeFormUuid,
|
|
24
|
+
submitForNext,
|
|
25
|
+
patientUuids,
|
|
26
|
+
activePatientUuid,
|
|
27
|
+
workflowState,
|
|
28
|
+
} = context;
|
|
29
|
+
const store = useStore(formStore);
|
|
30
|
+
const formState = store[activeFormUuid];
|
|
31
|
+
const navigationDisabled =
|
|
32
|
+
(formState !== "ready" || workflowState !== "EDIT_FORM") &&
|
|
33
|
+
formState !== "readyWithValidationErrors";
|
|
34
|
+
const [cancelModalOpen, setCancelModalOpen] = useState(false);
|
|
35
|
+
const [completeModalOpen, setCompleteModalOpen] = useState(false);
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
|
|
38
|
+
const isLastPatient =
|
|
39
|
+
activePatientUuid === patientUuids[patientUuids.length - 1];
|
|
40
|
+
|
|
41
|
+
const handleClickNext = () => {
|
|
42
|
+
if (
|
|
43
|
+
workflowState === "EDIT_FORM" ||
|
|
44
|
+
formState === "readyWithValidationErrors"
|
|
45
|
+
) {
|
|
46
|
+
submitForNext();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<>
|
|
52
|
+
<div className={styles.rightPanelActionButtons}>
|
|
53
|
+
<Button
|
|
54
|
+
kind="primary"
|
|
55
|
+
onClick={handleClickNext}
|
|
56
|
+
disabled={navigationDisabled}
|
|
57
|
+
>
|
|
58
|
+
{isLastPatient
|
|
59
|
+
? t("saveForm", "Save Form")
|
|
60
|
+
: t("nextPatient", "Next Patient")}
|
|
61
|
+
</Button>
|
|
62
|
+
<Button kind="secondary" onClick={() => setCompleteModalOpen(true)}>
|
|
63
|
+
{t("saveAndComplete", "Save & Complete")}
|
|
64
|
+
</Button>
|
|
65
|
+
<Button kind="tertiary" onClick={() => setCancelModalOpen(true)}>
|
|
66
|
+
{t("cancel", "Cancel")}
|
|
67
|
+
</Button>
|
|
68
|
+
</div>
|
|
69
|
+
<CancelModal
|
|
70
|
+
open={cancelModalOpen}
|
|
71
|
+
setOpen={setCancelModalOpen}
|
|
72
|
+
context={context}
|
|
73
|
+
/>
|
|
74
|
+
<CompleteModal
|
|
75
|
+
open={completeModalOpen}
|
|
76
|
+
setOpen={setCompleteModalOpen}
|
|
77
|
+
context={context}
|
|
78
|
+
validateFirst={false}
|
|
79
|
+
/>
|
|
80
|
+
</>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const GroupSessionWorkspace = () => {
|
|
85
|
+
const { groupSessionConcepts } = useConfig();
|
|
86
|
+
const { t } = useTranslation();
|
|
87
|
+
const {
|
|
88
|
+
patientUuids,
|
|
89
|
+
activePatientUuid,
|
|
90
|
+
encounters,
|
|
91
|
+
activeEncounterUuid,
|
|
92
|
+
activeVisitUuid,
|
|
93
|
+
activeFormUuid,
|
|
94
|
+
saveEncounter,
|
|
95
|
+
activeSessionMeta,
|
|
96
|
+
groupVisitTypeUuid,
|
|
97
|
+
updateVisitUuid,
|
|
98
|
+
submitForNext,
|
|
99
|
+
workflowState,
|
|
100
|
+
} = useContext(GroupFormWorkflowContext);
|
|
101
|
+
|
|
102
|
+
const { sessionLocation } = useSession();
|
|
103
|
+
const [encounter, setEncounter] = useState(null);
|
|
104
|
+
const [visit, setVisit] = useState(null);
|
|
105
|
+
|
|
106
|
+
const {
|
|
107
|
+
saveVisit,
|
|
108
|
+
updateEncounter,
|
|
109
|
+
success: visitSaveSuccess,
|
|
110
|
+
} = useStartVisit({
|
|
111
|
+
showSuccessNotification: false,
|
|
112
|
+
showErrorNotification: true,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// 0. user clicks "next patient" in WorkflowNavigationButtons
|
|
116
|
+
// which triggers submitForNext() if workflowState === "EDIT_FORM"
|
|
117
|
+
|
|
118
|
+
// 1. save the new visit uuid and start form submission
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (
|
|
121
|
+
visitSaveSuccess &&
|
|
122
|
+
visitSaveSuccess.data.patient.uuid === activePatientUuid
|
|
123
|
+
) {
|
|
124
|
+
setVisit(visitSaveSuccess.data);
|
|
125
|
+
// Update visit UUID on workflow
|
|
126
|
+
updateVisitUuid(visitSaveSuccess.data.uuid);
|
|
127
|
+
}
|
|
128
|
+
}, [
|
|
129
|
+
visitSaveSuccess,
|
|
130
|
+
updateVisitUuid,
|
|
131
|
+
activeVisitUuid,
|
|
132
|
+
activePatientUuid,
|
|
133
|
+
visit,
|
|
134
|
+
setVisit,
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
// 2. If there's no active visit, trigger the creation of a new one
|
|
138
|
+
const handleEncounterCreate = useCallback(
|
|
139
|
+
(payload) => {
|
|
140
|
+
// Create a visit with the same date as the encounter being saved
|
|
141
|
+
if (!activeVisitUuid) {
|
|
142
|
+
saveVisit({
|
|
143
|
+
patientUuid: activePatientUuid,
|
|
144
|
+
startDatetime: activeSessionMeta.sessionDate,
|
|
145
|
+
stopDatetime: activeSessionMeta.sessionDate,
|
|
146
|
+
visitType: groupVisitTypeUuid,
|
|
147
|
+
location: sessionLocation?.uuid,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const obsTime = new Date(activeSessionMeta.sessionDate);
|
|
151
|
+
payload.obs.forEach((item, index) => {
|
|
152
|
+
payload.obs[index] = {
|
|
153
|
+
...item,
|
|
154
|
+
groupMembers: item.groupMembers?.map((mem) => ({
|
|
155
|
+
...mem,
|
|
156
|
+
obsDatetime: obsTime.toISOString(),
|
|
157
|
+
})),
|
|
158
|
+
obsDatetime: obsTime.toISOString(),
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
// If this is a newly created encounter and visit, add session concepts to encounter payload.
|
|
162
|
+
if (!activeVisitUuid) {
|
|
163
|
+
Object.entries(groupSessionConcepts).forEach(([field, uuid]) => {
|
|
164
|
+
payload.obs.push({
|
|
165
|
+
concept: uuid,
|
|
166
|
+
value: activeSessionMeta?.[field],
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
payload.location = sessionLocation?.uuid;
|
|
171
|
+
payload.encounterDatetime = obsTime.toISOString();
|
|
172
|
+
},
|
|
173
|
+
[
|
|
174
|
+
activePatientUuid,
|
|
175
|
+
activeVisitUuid,
|
|
176
|
+
activeSessionMeta,
|
|
177
|
+
groupSessionConcepts,
|
|
178
|
+
groupVisitTypeUuid,
|
|
179
|
+
saveVisit,
|
|
180
|
+
sessionLocation,
|
|
181
|
+
]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
// 3. Update encounter so that it belongs to the created visit
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (encounter && visit && encounter.patient?.uuid === visit.patient?.uuid) {
|
|
187
|
+
updateEncounter({ uuid: encounter.uuid, visit: visit.uuid });
|
|
188
|
+
}
|
|
189
|
+
}, [encounter, updateEncounter, visit]);
|
|
190
|
+
|
|
191
|
+
// 4. Once form has been posted, save the new encounter uuid so we can edit it later
|
|
192
|
+
const handlePostResponse = useCallback(
|
|
193
|
+
(encounter) => {
|
|
194
|
+
if (encounter && encounter.uuid) {
|
|
195
|
+
saveEncounter(encounter.uuid);
|
|
196
|
+
setEncounter(encounter);
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
[saveEncounter]
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const switchPatient = useCallback(
|
|
203
|
+
(patientUuid) => {
|
|
204
|
+
submitForNext(patientUuid);
|
|
205
|
+
},
|
|
206
|
+
[submitForNext]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (workflowState === "NEW_GROUP_SESSION") return null;
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<div className={styles.workspace}>
|
|
213
|
+
<div className={styles.formMainContent}>
|
|
214
|
+
<div className={styles.formContainer}>
|
|
215
|
+
<FormBootstrap
|
|
216
|
+
patientUuid={activePatientUuid}
|
|
217
|
+
encounterUuid={activeEncounterUuid}
|
|
218
|
+
{...{
|
|
219
|
+
formUuid: activeFormUuid,
|
|
220
|
+
handlePostResponse,
|
|
221
|
+
handleEncounterCreate,
|
|
222
|
+
}}
|
|
223
|
+
/>
|
|
224
|
+
</div>
|
|
225
|
+
<div className={styles.rightPanel}>
|
|
226
|
+
<h4>{t("formsFilled", "Forms filled")}</h4>
|
|
227
|
+
<div className={styles.patientCardsSection}>
|
|
228
|
+
{patientUuids?.map((patientUuid) => (
|
|
229
|
+
<PatientCard
|
|
230
|
+
key={patientUuid}
|
|
231
|
+
{...{
|
|
232
|
+
patientUuid,
|
|
233
|
+
activePatientUuid,
|
|
234
|
+
editEncounter: switchPatient,
|
|
235
|
+
encounters,
|
|
236
|
+
}}
|
|
237
|
+
/>
|
|
238
|
+
))}
|
|
239
|
+
</div>
|
|
240
|
+
<WorkflowNavigationButtons />
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
export default GroupSessionWorkspace;
|