@ampath/esm-dispensing-app 1.10.0-next.1
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/.editorconfig +12 -0
- package/.eslintignore +2 -0
- package/.eslintrc +80 -0
- package/.husky/pre-commit +7 -0
- package/.husky/pre-push +6 -0
- package/.prettierignore +12 -0
- package/.tx/config +11 -0
- package/.yarn/versions/1c40b9b6.yml +0 -0
- package/.yarn/versions/ff162597.yml +0 -0
- package/LICENSE +401 -0
- package/README.md +124 -0
- package/__mocks__/react-i18next.js +51 -0
- package/dist/1043.js +1 -0
- package/dist/1043.js.map +1 -0
- package/dist/1119.js +1 -0
- package/dist/1197.js +1 -0
- package/dist/2146.js +1 -0
- package/dist/2177.js +2 -0
- package/dist/2177.js.LICENSE.txt +9 -0
- package/dist/2177.js.map +1 -0
- package/dist/2690.js +1 -0
- package/dist/2890.js +2 -0
- package/dist/2890.js.LICENSE.txt +14 -0
- package/dist/2890.js.map +1 -0
- package/dist/2898.js +1 -0
- package/dist/2898.js.map +1 -0
- package/dist/3041.js +1 -0
- package/dist/3041.js.map +1 -0
- package/dist/3099.js +1 -0
- package/dist/3184.js +2 -0
- package/dist/3184.js.LICENSE.txt +14 -0
- package/dist/3184.js.map +1 -0
- package/dist/3568.js +1 -0
- package/dist/3568.js.map +1 -0
- package/dist/3584.js +1 -0
- package/dist/4055.js +1 -0
- package/dist/4099.js +1 -0
- package/dist/4099.js.map +1 -0
- package/dist/4132.js +1 -0
- package/dist/4225.js +1 -0
- package/dist/4225.js.map +1 -0
- package/dist/4300.js +1 -0
- package/dist/4335.js +1 -0
- package/dist/4353.js +1 -0
- package/dist/4353.js.map +1 -0
- package/dist/439.js +1 -0
- package/dist/4618.js +1 -0
- package/dist/4652.js +1 -0
- package/dist/4944.js +1 -0
- package/dist/5173.js +1 -0
- package/dist/5241.js +1 -0
- package/dist/5422.js +1 -0
- package/dist/5422.js.map +1 -0
- package/dist/5442.js +1 -0
- package/dist/5661.js +1 -0
- package/dist/5897.js +1 -0
- package/dist/5897.js.map +1 -0
- package/dist/6022.js +1 -0
- package/dist/609.js +1 -0
- package/dist/609.js.map +1 -0
- package/dist/6468.js +1 -0
- package/dist/6540.js +2 -0
- package/dist/6540.js.LICENSE.txt +9 -0
- package/dist/6540.js.map +1 -0
- package/dist/6589.js +1 -0
- package/dist/6606.js +1 -0
- package/dist/6606.js.map +1 -0
- package/dist/6679.js +1 -0
- package/dist/6825.js +1 -0
- package/dist/6825.js.map +1 -0
- package/dist/6840.js +1 -0
- package/dist/6841.js +1 -0
- package/dist/6841.js.map +1 -0
- package/dist/6859.js +1 -0
- package/dist/7097.js +1 -0
- package/dist/7159.js +1 -0
- package/dist/723.js +1 -0
- package/dist/7240.js +1 -0
- package/dist/7240.js.map +1 -0
- package/dist/7255.js +1 -0
- package/dist/7255.js.map +1 -0
- package/dist/7617.js +1 -0
- package/dist/795.js +1 -0
- package/dist/8163.js +1 -0
- package/dist/8349.js +1 -0
- package/dist/8371.js +1 -0
- package/dist/8569.js +2 -0
- package/dist/8569.js.LICENSE.txt +41 -0
- package/dist/8569.js.map +1 -0
- package/dist/8600.js +1 -0
- package/dist/8600.js.map +1 -0
- package/dist/8618.js +1 -0
- package/dist/8885.js +1 -0
- package/dist/8885.js.map +1 -0
- package/dist/890.js +1 -0
- package/dist/9214.js +1 -0
- package/dist/9538.js +1 -0
- package/dist/9569.js +1 -0
- package/dist/961.js +2 -0
- package/dist/961.js.LICENSE.txt +19 -0
- package/dist/961.js.map +1 -0
- package/dist/963.js +1 -0
- package/dist/963.js.map +1 -0
- package/dist/986.js +1 -0
- package/dist/9879.js +1 -0
- package/dist/9895.js +1 -0
- package/dist/9900.js +1 -0
- package/dist/9913.js +1 -0
- package/dist/main.js +2 -0
- package/dist/main.js.LICENSE.txt +51 -0
- package/dist/main.js.map +1 -0
- package/dist/openmrs-esm-dispensing-app.js +1 -0
- package/dist/openmrs-esm-dispensing-app.js.buildmanifest.json +1645 -0
- package/dist/openmrs-esm-dispensing-app.js.map +1 -0
- package/dist/routes.json +1 -0
- package/e2e/README.md +119 -0
- package/e2e/commands/drug-order-operations.ts +43 -0
- package/e2e/commands/encounter-operations.ts +60 -0
- package/e2e/commands/index.ts +5 -0
- package/e2e/commands/patient-operations.ts +109 -0
- package/e2e/commands/provider-operations.ts +9 -0
- package/e2e/commands/types/index.ts +157 -0
- package/e2e/commands/visit-operations.ts +38 -0
- package/e2e/core/global-setup.ts +32 -0
- package/e2e/core/index.ts +1 -0
- package/e2e/core/test.ts +31 -0
- package/e2e/fixtures/api.ts +27 -0
- package/e2e/fixtures/index.ts +1 -0
- package/e2e/pages/dispensing-page.ts +9 -0
- package/e2e/pages/index.ts +1 -0
- package/e2e/specs/active-prescriptions.spec.ts +72 -0
- package/e2e/specs/close-prescription.spec.ts +71 -0
- package/e2e/specs/dispense-medication.spec.ts +71 -0
- package/e2e/specs/pause-prescription.spec.ts +72 -0
- package/e2e/support/github/Dockerfile +34 -0
- package/e2e/support/github/docker-compose.yml +24 -0
- package/e2e/support/github/run-e2e-docker-env.sh +42 -0
- package/e2e/types/index.ts +157 -0
- package/example.env +7 -0
- package/jest.config.js +24 -0
- package/package.json +110 -0
- package/playwright.config.ts +36 -0
- package/prettier.config.js +8 -0
- package/src/components/action-buttons.component.tsx +87 -0
- package/src/components/action-buttons.scss +16 -0
- package/src/components/action-buttons.test.tsx +217 -0
- package/src/components/medication-card.component.tsx +37 -0
- package/src/components/medication-card.scss +20 -0
- package/src/components/medication-card.test.tsx +36 -0
- package/src/components/medication-dispense-review.scss +108 -0
- package/src/components/medication-event.component.tsx +96 -0
- package/src/components/medication-event.scss +44 -0
- package/src/components/medication-event.test.tsx +212 -0
- package/src/components/prescription-actions/close-action-button.component.tsx +50 -0
- package/src/components/prescription-actions/dispense-action-button.component.tsx +57 -0
- package/src/components/prescription-actions/pause-action-button.component.tsx +49 -0
- package/src/conditions/conditions.component.tsx +118 -0
- package/src/conditions/conditions.resource.ts +100 -0
- package/src/conditions/conditions.scss +26 -0
- package/src/conditions/conditions.test.tsx +200 -0
- package/src/config-schema.ts +192 -0
- package/src/constants.ts +22 -0
- package/src/dashboard/dispensing-dashboard-link.component.tsx +36 -0
- package/src/dashboard/dispensing-dashboard.component.tsx +36 -0
- package/src/declarations.d.ts +2 -0
- package/src/diagnoses/diagnoses.component.tsx +111 -0
- package/src/diagnoses/diagnoses.resource.ts +30 -0
- package/src/diagnoses/diagnoses.scss +31 -0
- package/src/dispensing-link.component.tsx +9 -0
- package/src/dispensing-tiles/dispensing-tile.component.tsx +42 -0
- package/src/dispensing-tiles/dispensing-tile.scss +43 -0
- package/src/dispensing-tiles/dispensing-tiles.component.tsx +39 -0
- package/src/dispensing-tiles/dispensing-tiles.resource.tsx +30 -0
- package/src/dispensing-tiles/dispensing-tiles.scss +11 -0
- package/src/dispensing.component.tsx +31 -0
- package/src/dispensing.scss +5 -0
- package/src/dispensing.test.tsx +9 -0
- package/src/fill-prescription/fill-prescription-button.component.tsx +103 -0
- package/src/fill-prescription/fill-prescription-button.scss +8 -0
- package/src/fill-prescription/on-prescription-filled.modal.tsx +140 -0
- package/src/fill-prescription/on-prescription-filled.scss +7 -0
- package/src/forms/close-dispense-form.workspace.tsx +194 -0
- package/src/forms/dispense-form.workspace.test.tsx +334 -0
- package/src/forms/dispense-form.workspace.tsx +324 -0
- package/src/forms/forms.scss +152 -0
- package/src/forms/medication-dispense-review.component.tsx +649 -0
- package/src/forms/medication-dispense-review.test.tsx +158 -0
- package/src/forms/pause-dispense-form.workspace.tsx +196 -0
- package/src/forms/stock-dispense/stock-dispense.component.tsx +126 -0
- package/src/forms/stock-dispense/stock.resource.tsx +67 -0
- package/src/history/delete-confirm.modal.tsx +35 -0
- package/src/history/history-and-comments.component.tsx +338 -0
- package/src/history/history-and-comments.scss +54 -0
- package/src/index.ts +57 -0
- package/src/location/location.resource.test.tsx +108 -0
- package/src/location/location.resource.tsx +32 -0
- package/src/medication/medication.resource.test.tsx +156 -0
- package/src/medication/medication.resource.tsx +45 -0
- package/src/medication-dispense/medication-dispense.resource.test.tsx +243 -0
- package/src/medication-dispense/medication-dispense.resource.tsx +178 -0
- package/src/medication-request/medication-request.resource.test.tsx +1333 -0
- package/src/medication-request/medication-request.resource.tsx +257 -0
- package/src/patient/patient-info-cell.component.tsx +26 -0
- package/src/patient/patient.resources.ts +14 -0
- package/src/pharmacy-header/pharmacy-header.component.tsx +35 -0
- package/src/pharmacy-header/pharmacy-header.scss +55 -0
- package/src/pharmacy-header/pharmacy-illustration.component.tsx +30 -0
- package/src/prescriptions/patient-search-tab-panel.component.tsx +58 -0
- package/src/prescriptions/patient-search-tab-panel.scss +26 -0
- package/src/prescriptions/prescription-actions.component.tsx +24 -0
- package/src/prescriptions/prescription-actions.scss +14 -0
- package/src/prescriptions/prescription-details.component.tsx +152 -0
- package/src/prescriptions/prescription-details.scss +87 -0
- package/src/prescriptions/prescription-details.test.tsx +267 -0
- package/src/prescriptions/prescription-expanded.component.tsx +58 -0
- package/src/prescriptions/prescription-expanded.scss +56 -0
- package/src/prescriptions/prescription-tab-lists.component.tsx +70 -0
- package/src/prescriptions/prescription-tab-panel.component.tsx +83 -0
- package/src/prescriptions/prescriptions-table.component.tsx +189 -0
- package/src/prescriptions/prescriptions.scss +152 -0
- package/src/print-prescription/prescription-print-action.component.tsx +30 -0
- package/src/print-prescription/prescription-print-preview.modal.tsx +92 -0
- package/src/print-prescription/prescription-printout.component.tsx +154 -0
- package/src/print-prescription/print-prescription.scss +75 -0
- package/src/print-prescription/printable-prescriptions.component.tsx +57 -0
- package/src/routes.json +137 -0
- package/src/types.ts +530 -0
- package/src/utils.test.ts +2947 -0
- package/src/utils.ts +637 -0
- package/tools/i18next-parser.config.js +89 -0
- package/tools/setup-tests.ts +8 -0
- package/tools/update-openmrs-deps.mjs +42 -0
- package/translations/am.json +133 -0
- package/translations/ar.json +133 -0
- package/translations/ar_SY.json +133 -0
- package/translations/bn.json +133 -0
- package/translations/cs.json +133 -0
- package/translations/de.json +133 -0
- package/translations/en.json +133 -0
- package/translations/en_US.json +133 -0
- package/translations/es.json +133 -0
- package/translations/es_MX.json +133 -0
- package/translations/fr.json +133 -0
- package/translations/he.json +133 -0
- package/translations/hi.json +133 -0
- package/translations/hi_IN.json +133 -0
- package/translations/id.json +133 -0
- package/translations/it.json +133 -0
- package/translations/ka.json +133 -0
- package/translations/km.json +133 -0
- package/translations/ku.json +133 -0
- package/translations/ky.json +133 -0
- package/translations/lg.json +133 -0
- package/translations/ne.json +133 -0
- package/translations/pl.json +133 -0
- package/translations/pt.json +133 -0
- package/translations/pt_BR.json +133 -0
- package/translations/qu.json +133 -0
- package/translations/ro_RO.json +133 -0
- package/translations/ru_RU.json +133 -0
- package/translations/si.json +133 -0
- package/translations/sq.json +133 -0
- package/translations/sw.json +133 -0
- package/translations/sw_KE.json +133 -0
- package/translations/tr.json +133 -0
- package/translations/tr_TR.json +133 -0
- package/translations/uk.json +133 -0
- package/translations/uz.json +133 -0
- package/translations/uz@Latn.json +133 -0
- package/translations/uz_UZ.json +133 -0
- package/translations/vi.json +133 -0
- package/translations/zh.json +133 -0
- package/translations/zh_CN.json +133 -0
- package/translations/zh_TW.json +133 -0
- package/tsconfig.json +23 -0
- package/turbo.json +41 -0
- package/webpack.config.js +1 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { Button, Checkbox, Form, FormLabel, InlineLoading } from '@carbon/react';
|
|
4
|
+
import {
|
|
5
|
+
ExtensionSlot,
|
|
6
|
+
getCoreTranslation,
|
|
7
|
+
showSnackbar,
|
|
8
|
+
useConfig,
|
|
9
|
+
usePatient,
|
|
10
|
+
Workspace2,
|
|
11
|
+
type Workspace2DefinitionProps,
|
|
12
|
+
} from '@openmrs/esm-framework';
|
|
13
|
+
import {
|
|
14
|
+
type MedicationDispense,
|
|
15
|
+
MedicationDispenseStatus,
|
|
16
|
+
type MedicationRequestBundle,
|
|
17
|
+
type InventoryItem,
|
|
18
|
+
MedicationRequestFulfillerStatus,
|
|
19
|
+
} from '../types';
|
|
20
|
+
import {
|
|
21
|
+
calculateIsFreeTextDosage,
|
|
22
|
+
computeNewFulfillerStatusAfterDispenseEvent,
|
|
23
|
+
getDosageInstruction,
|
|
24
|
+
getFulfillerStatus,
|
|
25
|
+
getUuidFromReference,
|
|
26
|
+
markEncounterAsStale,
|
|
27
|
+
revalidate,
|
|
28
|
+
} from '../utils';
|
|
29
|
+
import { type PharmacyConfig } from '../config-schema';
|
|
30
|
+
import { createStockDispenseRequestPayload, sendStockDispenseRequest } from './stock-dispense/stock.resource';
|
|
31
|
+
import { saveMedicationDispense } from '../medication-dispense/medication-dispense.resource';
|
|
32
|
+
import { updateMedicationRequestFulfillerStatus } from '../medication-request/medication-request.resource';
|
|
33
|
+
import MedicationDispenseReview from './medication-dispense-review.component';
|
|
34
|
+
import StockDispense from './stock-dispense/stock-dispense.component';
|
|
35
|
+
import styles from './forms.scss';
|
|
36
|
+
|
|
37
|
+
type DispenseFormProps = {
|
|
38
|
+
medicationDispense: MedicationDispense;
|
|
39
|
+
medicationRequestBundle: MedicationRequestBundle;
|
|
40
|
+
mode: 'enter' | 'edit';
|
|
41
|
+
patientUuid?: string;
|
|
42
|
+
encounterUuid: string;
|
|
43
|
+
quantityRemaining: number;
|
|
44
|
+
quantityDispensed: number;
|
|
45
|
+
customWorkspaceTitle?: string;
|
|
46
|
+
onWorkspaceClosed?(): void;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const DispenseForm: React.FC<Workspace2DefinitionProps<DispenseFormProps, {}, {}>> = ({
|
|
50
|
+
workspaceProps: {
|
|
51
|
+
medicationDispense,
|
|
52
|
+
medicationRequestBundle,
|
|
53
|
+
mode,
|
|
54
|
+
patientUuid,
|
|
55
|
+
encounterUuid,
|
|
56
|
+
quantityRemaining,
|
|
57
|
+
quantityDispensed,
|
|
58
|
+
customWorkspaceTitle,
|
|
59
|
+
onWorkspaceClosed,
|
|
60
|
+
},
|
|
61
|
+
closeWorkspace,
|
|
62
|
+
}) => {
|
|
63
|
+
const { t } = useTranslation();
|
|
64
|
+
const { patient, isLoading } = usePatient(patientUuid);
|
|
65
|
+
const config = useConfig<PharmacyConfig>();
|
|
66
|
+
|
|
67
|
+
// Keep track of inventory item
|
|
68
|
+
const [inventoryItem, setInventoryItem] = useState<InventoryItem>();
|
|
69
|
+
|
|
70
|
+
// Keep track of medication dispense payload
|
|
71
|
+
const [medicationDispensePayload, setMedicationDispensePayload] = useState<MedicationDispense>();
|
|
72
|
+
|
|
73
|
+
// to prevent duplicate submits
|
|
74
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
75
|
+
|
|
76
|
+
const [shouldCompleteOrder, setShouldCompleteOrder] = useState(false);
|
|
77
|
+
|
|
78
|
+
const [isFreeTextDosage, setIsFreeTextDosage] = useState(() => {
|
|
79
|
+
const dosageInstruction = getDosageInstruction(medicationDispense?.dosageInstruction);
|
|
80
|
+
return dosageInstruction ? calculateIsFreeTextDosage(dosageInstruction) : false;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Submit medication dispense form
|
|
84
|
+
const handleSubmit = () => {
|
|
85
|
+
if (!isSubmitting) {
|
|
86
|
+
setIsSubmitting(true);
|
|
87
|
+
const abortController = new AbortController();
|
|
88
|
+
markEncounterAsStale(encounterUuid);
|
|
89
|
+
saveMedicationDispense(medicationDispensePayload, MedicationDispenseStatus.completed, abortController)
|
|
90
|
+
.then((response) => {
|
|
91
|
+
if (response.ok) {
|
|
92
|
+
if (config.completeOrderWithThisDispense && shouldCompleteOrder) {
|
|
93
|
+
return updateMedicationRequestFulfillerStatus(
|
|
94
|
+
getUuidFromReference(
|
|
95
|
+
medicationDispensePayload.authorizingPrescription[0].reference, // assumes authorizing prescription exist
|
|
96
|
+
),
|
|
97
|
+
MedicationRequestFulfillerStatus.completed,
|
|
98
|
+
).then(() => response);
|
|
99
|
+
}
|
|
100
|
+
const newFulfillerStatus = computeNewFulfillerStatusAfterDispenseEvent(
|
|
101
|
+
medicationDispensePayload,
|
|
102
|
+
medicationRequestBundle,
|
|
103
|
+
config.dispenseBehavior.restrictTotalQuantityDispensed,
|
|
104
|
+
);
|
|
105
|
+
if (getFulfillerStatus(medicationRequestBundle.request) !== newFulfillerStatus) {
|
|
106
|
+
return updateMedicationRequestFulfillerStatus(
|
|
107
|
+
getUuidFromReference(
|
|
108
|
+
medicationDispensePayload.authorizingPrescription[0].reference, // assumes authorizing prescription exist
|
|
109
|
+
),
|
|
110
|
+
newFulfillerStatus,
|
|
111
|
+
).then(() => response);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return response;
|
|
115
|
+
})
|
|
116
|
+
.then((response) => {
|
|
117
|
+
const { status } = response;
|
|
118
|
+
if (config.enableStockDispense && (status === 201 || status === 200)) {
|
|
119
|
+
const stockDispenseRequestPayload = createStockDispenseRequestPayload(
|
|
120
|
+
inventoryItem,
|
|
121
|
+
patientUuid,
|
|
122
|
+
encounterUuid,
|
|
123
|
+
medicationDispensePayload,
|
|
124
|
+
);
|
|
125
|
+
sendStockDispenseRequest(stockDispenseRequestPayload, abortController).then(
|
|
126
|
+
() => {
|
|
127
|
+
showSnackbar({
|
|
128
|
+
title: t('stockDispensed', 'Stock dispensed'),
|
|
129
|
+
kind: 'success',
|
|
130
|
+
subtitle: t('stockDispensedSuccessfully', 'Stock dispensed successfully and batch level updated.'),
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
(error) => {
|
|
134
|
+
showSnackbar({
|
|
135
|
+
title: 'Stock dispense error',
|
|
136
|
+
kind: 'error',
|
|
137
|
+
subtitle: error?.message,
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return response;
|
|
143
|
+
})
|
|
144
|
+
.then(
|
|
145
|
+
(response) => {
|
|
146
|
+
const { status } = response;
|
|
147
|
+
if (config.completeOrderWithThisDispense && shouldCompleteOrder && response?.data?.status === 'completed') {
|
|
148
|
+
showSnackbar({
|
|
149
|
+
title: t('prescriptionCompleted', 'Prescription completed'),
|
|
150
|
+
kind: 'success',
|
|
151
|
+
subtitle: t(
|
|
152
|
+
'prescriptionCompletedSuccessfully',
|
|
153
|
+
'Medication dispensed and prescription marked as completed',
|
|
154
|
+
),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (status === 201 || status === 200) {
|
|
158
|
+
revalidate(encounterUuid);
|
|
159
|
+
showSnackbar({
|
|
160
|
+
kind: 'success',
|
|
161
|
+
subtitle: t('medicationListUpdated', 'Medication dispense list has been updated.'),
|
|
162
|
+
title: t(
|
|
163
|
+
mode === 'enter' ? 'medicationDispensed' : 'medicationDispenseUpdated',
|
|
164
|
+
mode === 'enter'
|
|
165
|
+
? 'Medication successfully dispensed.'
|
|
166
|
+
: 'Medication dispense record successfully updated.',
|
|
167
|
+
),
|
|
168
|
+
});
|
|
169
|
+
closeWorkspace({ discardUnsavedChanges: true });
|
|
170
|
+
setIsSubmitting(false);
|
|
171
|
+
onWorkspaceClosed?.();
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
(error) => {
|
|
175
|
+
showSnackbar({
|
|
176
|
+
kind: 'error',
|
|
177
|
+
title: t(
|
|
178
|
+
mode === 'enter' ? 'medicationDispenseError' : 'medicationDispenseUpdatedError',
|
|
179
|
+
mode === 'enter' ? 'Error dispensing medication.' : 'Error updating dispense record',
|
|
180
|
+
),
|
|
181
|
+
subtitle: error?.message,
|
|
182
|
+
});
|
|
183
|
+
setIsSubmitting(false);
|
|
184
|
+
},
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const updateMedicationDispense = useCallback((medicationDispenseUpdate: Partial<MedicationDispense>) => {
|
|
190
|
+
setMedicationDispensePayload((prevState) => ({
|
|
191
|
+
...prevState,
|
|
192
|
+
...medicationDispenseUpdate,
|
|
193
|
+
}));
|
|
194
|
+
}, []);
|
|
195
|
+
|
|
196
|
+
// whether or not the form is valid and ready to submit
|
|
197
|
+
const isValid = useMemo(() => {
|
|
198
|
+
if (!medicationDispensePayload) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const anyCodedDosage =
|
|
202
|
+
medicationDispensePayload.dosageInstruction[0]?.doseAndRate[0]?.doseQuantity?.value ||
|
|
203
|
+
medicationDispensePayload.dosageInstruction[0]?.doseAndRate[0]?.doseQuantity?.code ||
|
|
204
|
+
medicationDispensePayload.dosageInstruction[0]?.route?.coding[0]?.code ||
|
|
205
|
+
medicationDispensePayload.dosageInstruction[0]?.timing?.code?.coding[0].code;
|
|
206
|
+
|
|
207
|
+
const allCodedDosage =
|
|
208
|
+
medicationDispensePayload.dosageInstruction[0]?.doseAndRate[0]?.doseQuantity?.value &&
|
|
209
|
+
medicationDispensePayload.dosageInstruction[0]?.doseAndRate[0]?.doseQuantity?.code &&
|
|
210
|
+
medicationDispensePayload.dosageInstruction[0]?.route?.coding[0]?.code &&
|
|
211
|
+
medicationDispensePayload.dosageInstruction[0]?.timing?.code?.coding[0].code;
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
medicationDispensePayload.performer &&
|
|
215
|
+
medicationDispensePayload.performer[0]?.actor.reference &&
|
|
216
|
+
medicationDispensePayload.quantity?.value &&
|
|
217
|
+
(!quantityRemaining || medicationDispensePayload?.quantity?.value <= quantityRemaining) &&
|
|
218
|
+
medicationDispensePayload.quantity?.code &&
|
|
219
|
+
((allCodedDosage && !isFreeTextDosage) ||
|
|
220
|
+
(!anyCodedDosage && isFreeTextDosage && medicationDispensePayload.dosageInstruction[0]?.text)) &&
|
|
221
|
+
(!medicationDispensePayload.substitution.wasSubstituted ||
|
|
222
|
+
(medicationDispensePayload.substitution.reason[0]?.coding[0].code &&
|
|
223
|
+
medicationDispensePayload.substitution.type?.coding[0].code))
|
|
224
|
+
);
|
|
225
|
+
}, [isFreeTextDosage, medicationDispensePayload, quantityRemaining]);
|
|
226
|
+
|
|
227
|
+
// initialize the internal dispense payload with the dispenses passed in as props
|
|
228
|
+
useEffect(() => setMedicationDispensePayload(medicationDispense), [medicationDispense]);
|
|
229
|
+
|
|
230
|
+
// Auto-default "Complete Order With This Dispense" checkbox for orders with no refills
|
|
231
|
+
useEffect(() => {
|
|
232
|
+
// Only auto-default in 'enter' mode when creating a new dispense
|
|
233
|
+
if (mode === 'enter' && medicationRequestBundle?.request?.dispenseRequest) {
|
|
234
|
+
const numberOfRepeatsAllowed = medicationRequestBundle.request.dispenseRequest.numberOfRepeatsAllowed;
|
|
235
|
+
// Default to true if order doesn't support refills
|
|
236
|
+
if (numberOfRepeatsAllowed === 0 || numberOfRepeatsAllowed === null || numberOfRepeatsAllowed === undefined) {
|
|
237
|
+
setShouldCompleteOrder(true);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}, [medicationRequestBundle, mode]);
|
|
241
|
+
|
|
242
|
+
const isButtonDisabled = (config.enableStockDispense ? !inventoryItem : false) || !isValid || isSubmitting;
|
|
243
|
+
|
|
244
|
+
const bannerState = useMemo(() => {
|
|
245
|
+
if (patient) {
|
|
246
|
+
return {
|
|
247
|
+
patient,
|
|
248
|
+
patientUuid,
|
|
249
|
+
hideActionsOverflow: true,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}, [patient, patientUuid]);
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<Workspace2 title={customWorkspaceTitle ?? t('dispensePrescription', 'Dispense prescription')}>
|
|
256
|
+
<Form className={styles.formWrapper}>
|
|
257
|
+
<div>
|
|
258
|
+
{isLoading && (
|
|
259
|
+
<InlineLoading
|
|
260
|
+
className={styles.bannerLoading}
|
|
261
|
+
iconDescription="Loading"
|
|
262
|
+
description="Loading banner"
|
|
263
|
+
status="active"
|
|
264
|
+
/>
|
|
265
|
+
)}
|
|
266
|
+
{patient && <ExtensionSlot name="patient-header-slot" state={bannerState} />}
|
|
267
|
+
<section className={styles.formGroup}>
|
|
268
|
+
<FormLabel>
|
|
269
|
+
{config.dispenseBehavior.allowModifyingPrescription
|
|
270
|
+
? t('drugHelpText', 'You may edit the formulation and quantity dispensed here')
|
|
271
|
+
: t('drugHelpTextNoEdit', 'You may edit quantity dispensed here')}
|
|
272
|
+
</FormLabel>
|
|
273
|
+
{medicationDispensePayload ? (
|
|
274
|
+
<div>
|
|
275
|
+
<MedicationDispenseReview
|
|
276
|
+
medicationDispense={medicationDispensePayload}
|
|
277
|
+
updateMedicationDispense={updateMedicationDispense}
|
|
278
|
+
isFreeTextDosage={isFreeTextDosage}
|
|
279
|
+
setIsFreeTextDosage={setIsFreeTextDosage}
|
|
280
|
+
quantityRemaining={quantityRemaining}
|
|
281
|
+
quantityDispensed={quantityDispensed}
|
|
282
|
+
/>
|
|
283
|
+
{config.completeOrderWithThisDispense && mode === 'enter' && !medicationDispense?.id && (
|
|
284
|
+
<Checkbox
|
|
285
|
+
id="complete-order-with-this-dispense"
|
|
286
|
+
labelText={t('completeOrderWithThisDispense', 'Complete order with this dispense')}
|
|
287
|
+
checked={shouldCompleteOrder}
|
|
288
|
+
onChange={(_, { checked }) => setShouldCompleteOrder(checked)}
|
|
289
|
+
/>
|
|
290
|
+
)}
|
|
291
|
+
{config.enableStockDispense && (
|
|
292
|
+
<StockDispense
|
|
293
|
+
inventoryItem={inventoryItem}
|
|
294
|
+
medicationDispense={medicationDispense}
|
|
295
|
+
updateInventoryItem={setInventoryItem}
|
|
296
|
+
/>
|
|
297
|
+
)}
|
|
298
|
+
</div>
|
|
299
|
+
) : null}
|
|
300
|
+
</section>
|
|
301
|
+
</div>
|
|
302
|
+
<section className={styles.buttonGroup}>
|
|
303
|
+
<Button
|
|
304
|
+
disabled={isSubmitting}
|
|
305
|
+
onClick={() => {
|
|
306
|
+
closeWorkspace();
|
|
307
|
+
onWorkspaceClosed?.();
|
|
308
|
+
}}
|
|
309
|
+
kind="secondary">
|
|
310
|
+
{getCoreTranslation('cancel', 'Cancel')}
|
|
311
|
+
</Button>
|
|
312
|
+
<Button disabled={isButtonDisabled} onClick={handleSubmit}>
|
|
313
|
+
{t(
|
|
314
|
+
mode === 'enter' ? 'dispensePrescription' : 'saveChanges',
|
|
315
|
+
mode === 'enter' ? 'Dispense prescription' : 'Save changes',
|
|
316
|
+
)}
|
|
317
|
+
</Button>
|
|
318
|
+
</section>
|
|
319
|
+
</Form>
|
|
320
|
+
</Workspace2>
|
|
321
|
+
);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
export default DispenseForm;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
@use '@carbon/colors';
|
|
2
|
+
@use '@carbon/layout';
|
|
3
|
+
@use '@carbon/type';
|
|
4
|
+
@use '@openmrs/esm-styleguide/src/vars' as *;
|
|
5
|
+
|
|
6
|
+
.productiveHeading02 {
|
|
7
|
+
color: $color-gray-70;
|
|
8
|
+
@include type.type-style('heading-02');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.formWrapper {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
height: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:global(.omrs-breakpoint-lt-desktop) .formWrapper {
|
|
19
|
+
background-color: $openmrs-background-grey;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:global(.omrs-breakpoint-gt-tablet) .formWrapper {
|
|
23
|
+
background-color: $ui-02;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.formGroup {
|
|
27
|
+
margin-bottom: layout.$spacing-02;
|
|
28
|
+
padding: layout.$spacing-05;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.bannerLoading {
|
|
32
|
+
width: 100%;
|
|
33
|
+
display: flex;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.patientInfo {
|
|
38
|
+
position: sticky;
|
|
39
|
+
z-index: 1000;
|
|
40
|
+
background-color: $ui-02;
|
|
41
|
+
top: layout.$spacing-09;
|
|
42
|
+
overflow-y: auto;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.dateTimeContainer {
|
|
46
|
+
display: flex;
|
|
47
|
+
margin: layout.$spacing-05 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.timePickersContainer,
|
|
51
|
+
.frequencyAndDay {
|
|
52
|
+
display: flex;
|
|
53
|
+
|
|
54
|
+
> div {
|
|
55
|
+
margin-right: layout.$spacing-03;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.datePickerControl {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
|
|
63
|
+
> div {
|
|
64
|
+
margin-bottom: layout.$spacing-05;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.buttonGroup {
|
|
69
|
+
display: flex;
|
|
70
|
+
position: sticky;
|
|
71
|
+
bottom: 0;
|
|
72
|
+
width: 100%;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
:global(.omrs-breakpoint-lt-desktop) .buttonGroup {
|
|
76
|
+
padding: layout.$spacing-05 layout.$spacing-06;
|
|
77
|
+
background-color: $ui-02;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.buttonGroup button {
|
|
81
|
+
max-width: none;
|
|
82
|
+
width: 50%;
|
|
83
|
+
height: layout.$spacing-10;
|
|
84
|
+
align-items: flex-start;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.contentSwitcherWrapper {
|
|
88
|
+
display: flex;
|
|
89
|
+
width: fit-content;
|
|
90
|
+
justify-content: flex-end;
|
|
91
|
+
align-items: center;
|
|
92
|
+
width: 60%;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.contentSwitcherWrapper > div > button {
|
|
96
|
+
background-color: $ui-02;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.contentSwitcherWrapper > div button:first-child {
|
|
100
|
+
border-top: 1px solid colors.$blue-30;
|
|
101
|
+
border-bottom: 1px solid colors.$blue-30;
|
|
102
|
+
border-left: 1px solid colors.$blue-30;
|
|
103
|
+
border-right: none;
|
|
104
|
+
border-radius: layout.$spacing-02 0 0px layout.$spacing-02;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.contentSwitcherWrapper > div button:last-child {
|
|
108
|
+
border-top: 1px solid colors.$blue-30;
|
|
109
|
+
border-bottom: 1px solid colors.$blue-30;
|
|
110
|
+
border-right: 1px solid colors.$blue-30;
|
|
111
|
+
border-left: none;
|
|
112
|
+
border-radius: 0px layout.$spacing-02 layout.$spacing-02 0px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.contentSwitcherWrapper > div > button[aria-selected='true'],
|
|
116
|
+
.contentSwitcherWrapper > div > button[aria-selected='true']:first-child {
|
|
117
|
+
background-color: $color-blue-10;
|
|
118
|
+
color: $color-blue-60-2;
|
|
119
|
+
border-color: $color-blue-60-2;
|
|
120
|
+
border-right: 1px solid $color-blue-60-2;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.contentSwitcherWrapper > div > button[aria-selected='true'],
|
|
124
|
+
.contentSwitcherWrapper > div > button[aria-selected='true']:last-child {
|
|
125
|
+
background-color: $color-blue-10;
|
|
126
|
+
color: $color-blue-60-2;
|
|
127
|
+
border-color: $color-blue-60-2;
|
|
128
|
+
border-left: 1px solid $color-blue-60-2;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.contentSwitcherWrapper > div > button[aria-selected='true']:focus {
|
|
132
|
+
box-shadow: none;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.reviewContainer {
|
|
136
|
+
margin: 0.8rem 0 0 0 !important;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// copied from .sectionHeader of drug-order-form.scss
|
|
140
|
+
.prescriptionFormSectionHeader {
|
|
141
|
+
@include type.type-style('heading-01');
|
|
142
|
+
margin-bottom: layout.$spacing-05;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// copied from .field of drug-order-form.scss
|
|
146
|
+
.prescriptionFormField {
|
|
147
|
+
margin-bottom: layout.$spacing-05;
|
|
148
|
+
|
|
149
|
+
:global(.cds--label) {
|
|
150
|
+
vertical-align: middle;
|
|
151
|
+
}
|
|
152
|
+
}
|