@openmrs/esm-dispensing-app 1.9.2-pre.916 → 1.9.2-pre.917
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/.turbo/cache/3b64a05e375c386d-meta.json +1 -0
- package/.turbo/cache/3b64a05e375c386d.tar.zst +0 -0
- package/.turbo/turbo-build.log +4 -4
- package/dist/1282.js +1 -1
- package/dist/1282.js.map +1 -1
- package/dist/4099.js +1 -1
- package/dist/4099.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-dispensing-app.js.buildmanifest.json +11 -11
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/forms/dispense-form.workspace.tsx +14 -16
- package/src/forms/medication-dispense-review.component.tsx +34 -87
- package/src/forms/medication-dispense-review.test.tsx +1 -1
- package/src/medication-dispense/medication-dispense.resource.tsx +11 -9
- package/src/medication-request/medication-request.resource.test.tsx +4 -0
- package/src/medication-request/medication-request.resource.tsx +35 -35
- package/src/types.ts +1 -1
- package/.turbo/cache/73ee20738420f8cc-meta.json +0 -1
- package/.turbo/cache/73ee20738420f8cc.tar.zst +0 -0
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
"auxiliaryFiles": [
|
|
166
166
|
"963.js.map"
|
|
167
167
|
],
|
|
168
|
-
"hash": "
|
|
168
|
+
"hash": "e2990b60a266c12b",
|
|
169
169
|
"childrenByOrder": {}
|
|
170
170
|
},
|
|
171
171
|
{
|
|
@@ -263,9 +263,9 @@
|
|
|
263
263
|
"initial": false,
|
|
264
264
|
"entry": false,
|
|
265
265
|
"recorded": false,
|
|
266
|
-
"size":
|
|
266
|
+
"size": 357574,
|
|
267
267
|
"sizes": {
|
|
268
|
-
"javascript":
|
|
268
|
+
"javascript": 357574
|
|
269
269
|
},
|
|
270
270
|
"names": [],
|
|
271
271
|
"idHints": [],
|
|
@@ -278,7 +278,7 @@
|
|
|
278
278
|
"auxiliaryFiles": [
|
|
279
279
|
"1282.js.map"
|
|
280
280
|
],
|
|
281
|
-
"hash": "
|
|
281
|
+
"hash": "9cbbd1f9410dd461",
|
|
282
282
|
"childrenByOrder": {}
|
|
283
283
|
},
|
|
284
284
|
{
|
|
@@ -585,9 +585,9 @@
|
|
|
585
585
|
"initial": false,
|
|
586
586
|
"entry": false,
|
|
587
587
|
"recorded": false,
|
|
588
|
-
"size":
|
|
588
|
+
"size": 113788,
|
|
589
589
|
"sizes": {
|
|
590
|
-
"javascript":
|
|
590
|
+
"javascript": 113788
|
|
591
591
|
},
|
|
592
592
|
"names": [],
|
|
593
593
|
"idHints": [],
|
|
@@ -601,7 +601,7 @@
|
|
|
601
601
|
"auxiliaryFiles": [
|
|
602
602
|
"4099.js.map"
|
|
603
603
|
],
|
|
604
|
-
"hash": "
|
|
604
|
+
"hash": "85b1f1b8aa599cea",
|
|
605
605
|
"childrenByOrder": {}
|
|
606
606
|
},
|
|
607
607
|
{
|
|
@@ -1125,7 +1125,7 @@
|
|
|
1125
1125
|
"auxiliaryFiles": [
|
|
1126
1126
|
"6841.js.map"
|
|
1127
1127
|
],
|
|
1128
|
-
"hash": "
|
|
1128
|
+
"hash": "0b514e092eae0f75",
|
|
1129
1129
|
"childrenByOrder": {}
|
|
1130
1130
|
},
|
|
1131
1131
|
{
|
|
@@ -1416,10 +1416,10 @@
|
|
|
1416
1416
|
"initial": true,
|
|
1417
1417
|
"entry": true,
|
|
1418
1418
|
"recorded": false,
|
|
1419
|
-
"size":
|
|
1419
|
+
"size": 3410192,
|
|
1420
1420
|
"sizes": {
|
|
1421
1421
|
"consume-shared": 210,
|
|
1422
|
-
"javascript":
|
|
1422
|
+
"javascript": 3387297,
|
|
1423
1423
|
"share-init": 378,
|
|
1424
1424
|
"runtime": 22307
|
|
1425
1425
|
},
|
|
@@ -1436,7 +1436,7 @@
|
|
|
1436
1436
|
"auxiliaryFiles": [
|
|
1437
1437
|
"main.js.map"
|
|
1438
1438
|
],
|
|
1439
|
-
"hash": "
|
|
1439
|
+
"hash": "61fedd7ee00eee3a",
|
|
1440
1440
|
"childrenByOrder": {}
|
|
1441
1441
|
},
|
|
1442
1442
|
{
|
package/dist/routes.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.2.0"},"pages":[{"component":"dispensing","route":"dispensing","online":true,"offline":true}],"extensions":[{"name":"dispensing-link","slot":"app-menu-slot","component":"dispensingLink","online":true,"offline":true},{"name":"patient-diagnoses","component":"patientDiagnoses","slot":"dispensing-condition-and-diagnoses","online":true,"offline":true},{"name":"patient-conditions","component":"patientConditions","slot":"dispensing-condition-and-diagnoses","online":true,"offline":true},{"name":"dispensing-dashboard","slot":"dispensing-dashboard-slot","component":"dispensingDashboard","online":true,"offline":true},{"name":"dispensing-dashboard-link","component":"dispensingDashboardLink","meta":{"name":"dispensing","slot":"dispensing-dashboard-slot","title":"Dispensing"}},{"name":"dispense-action-button","slot":"prescription-action-button-slot","component":"dispenseActionButton"},{"name":"pause-action-button","slot":"prescription-action-button-slot","component":"pauseActionButton"},{"name":"close-action-button","slot":"prescription-action-button-slot","component":"closeActionButton"}],"workspaces":[{"name":"close-dispense-workspace","component":"closeDispenseWorkspace","type":"dispense","title":"Close prescription"},{"name":"pause-dispense-workspace","component":"pauseDispenseWorkspace","type":"dispense","title":"Pause prescription"},{"name":"dispense-workspace","component":"dispenseWorkspace","type":"dispense","title":"Dispense prescription","width":"wider"}],"modals":[{"name":"prescription-print-preview-modal","component":"printPrescriptionPreviewModal"},{"name":"delete-confirm-modal","component":"deleteConfirmModal"}],"version":"1.9.2-pre.
|
|
1
|
+
{"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.2.0"},"pages":[{"component":"dispensing","route":"dispensing","online":true,"offline":true}],"extensions":[{"name":"dispensing-link","slot":"app-menu-slot","component":"dispensingLink","online":true,"offline":true},{"name":"patient-diagnoses","component":"patientDiagnoses","slot":"dispensing-condition-and-diagnoses","online":true,"offline":true},{"name":"patient-conditions","component":"patientConditions","slot":"dispensing-condition-and-diagnoses","online":true,"offline":true},{"name":"dispensing-dashboard","slot":"dispensing-dashboard-slot","component":"dispensingDashboard","online":true,"offline":true},{"name":"dispensing-dashboard-link","component":"dispensingDashboardLink","meta":{"name":"dispensing","slot":"dispensing-dashboard-slot","title":"Dispensing"}},{"name":"dispense-action-button","slot":"prescription-action-button-slot","component":"dispenseActionButton"},{"name":"pause-action-button","slot":"prescription-action-button-slot","component":"pauseActionButton"},{"name":"close-action-button","slot":"prescription-action-button-slot","component":"closeActionButton"}],"workspaces":[{"name":"close-dispense-workspace","component":"closeDispenseWorkspace","type":"dispense","title":"Close prescription"},{"name":"pause-dispense-workspace","component":"pauseDispenseWorkspace","type":"dispense","title":"Pause prescription"},{"name":"dispense-workspace","component":"dispenseWorkspace","type":"dispense","title":"Dispense prescription","width":"wider"}],"modals":[{"name":"prescription-print-preview-modal","component":"printPrescriptionPreviewModal"},{"name":"delete-confirm-modal","component":"deleteConfirmModal"}],"version":"1.9.2-pre.917"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import { Button, Checkbox, Form, FormLabel, InlineLoading } from '@carbon/react';
|
|
4
4
|
import {
|
|
@@ -62,9 +62,6 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
|
|
|
62
62
|
// Keep track of medication dispense payload
|
|
63
63
|
const [medicationDispensePayload, setMedicationDispensePayload] = useState<MedicationDispense>();
|
|
64
64
|
|
|
65
|
-
// whether or not the form is valid and ready to submit
|
|
66
|
-
const [isValid, setIsValid] = useState(false);
|
|
67
|
-
|
|
68
65
|
// to prevent duplicate submits
|
|
69
66
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
70
67
|
|
|
@@ -175,8 +172,16 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
|
|
|
175
172
|
}
|
|
176
173
|
};
|
|
177
174
|
|
|
178
|
-
const
|
|
179
|
-
|
|
175
|
+
const updateMedicationDispense = useCallback((medicationDispenseUpdate: Partial<MedicationDispense>) => {
|
|
176
|
+
setMedicationDispensePayload((prevState) => ({
|
|
177
|
+
...prevState,
|
|
178
|
+
...medicationDispenseUpdate,
|
|
179
|
+
}));
|
|
180
|
+
}, []);
|
|
181
|
+
|
|
182
|
+
// whether or not the form is valid and ready to submit
|
|
183
|
+
const isValid = useMemo(() => {
|
|
184
|
+
return (
|
|
180
185
|
medicationDispensePayload &&
|
|
181
186
|
medicationDispensePayload.performer &&
|
|
182
187
|
medicationDispensePayload.performer[0]?.actor.reference &&
|
|
@@ -190,19 +195,12 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
|
|
|
190
195
|
(!medicationDispensePayload.substitution.wasSubstituted ||
|
|
191
196
|
(medicationDispensePayload.substitution.reason[0]?.coding[0].code &&
|
|
192
197
|
medicationDispensePayload.substitution.type?.coding[0].code))
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
} else {
|
|
196
|
-
setIsValid(false);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
198
|
+
);
|
|
199
|
+
}, [medicationDispensePayload, quantityRemaining]);
|
|
199
200
|
|
|
200
201
|
// initialize the internal dispense payload with the dispenses passed in as props
|
|
201
202
|
useEffect(() => setMedicationDispensePayload(medicationDispense), [medicationDispense]);
|
|
202
203
|
|
|
203
|
-
// check is valid on any changes
|
|
204
|
-
useEffect(checkIsValid, [medicationDispensePayload, quantityRemaining, inventoryItem]);
|
|
205
|
-
|
|
206
204
|
const isButtonDisabled = (config.enableStockDispense ? !inventoryItem : false) || !isValid || isSubmitting;
|
|
207
205
|
|
|
208
206
|
const bannerState = useMemo(() => {
|
|
@@ -240,7 +238,7 @@ const DispenseForm: React.FC<DispenseFormProps> = ({
|
|
|
240
238
|
<div>
|
|
241
239
|
<MedicationDispenseReview
|
|
242
240
|
medicationDispense={medicationDispensePayload}
|
|
243
|
-
updateMedicationDispense={
|
|
241
|
+
updateMedicationDispense={updateMedicationDispense}
|
|
244
242
|
quantityRemaining={quantityRemaining}
|
|
245
243
|
quantityDispensed={quantityDispensed}
|
|
246
244
|
/>
|
|
@@ -7,6 +7,7 @@ import { getConceptCodingUuid, getMedicationReferenceOrCodeableConcept, getOpenM
|
|
|
7
7
|
import { useMedicationCodeableConcept, useMedicationFormulations } from '../medication/medication.resource';
|
|
8
8
|
import { useMedicationRequest, usePrescriptionDetails } from '../medication-request/medication-request.resource';
|
|
9
9
|
import {
|
|
10
|
+
blankSubstitution,
|
|
10
11
|
useOrderConfig,
|
|
11
12
|
useProviders,
|
|
12
13
|
useSubstitutionReasonValueSet,
|
|
@@ -20,7 +21,7 @@ import styles from '../components/medication-dispense-review.scss';
|
|
|
20
21
|
|
|
21
22
|
interface MedicationDispenseReviewProps {
|
|
22
23
|
medicationDispense: MedicationDispense;
|
|
23
|
-
updateMedicationDispense:
|
|
24
|
+
updateMedicationDispense(updates: Partial<MedicationDispense>);
|
|
24
25
|
quantityRemaining: number;
|
|
25
26
|
quantityDispensed: number;
|
|
26
27
|
}
|
|
@@ -35,15 +36,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
35
36
|
const config = useConfig<PharmacyConfig>();
|
|
36
37
|
const session = useSession();
|
|
37
38
|
const [isEditingFormulation, setIsEditingFormulation] = useState(false);
|
|
38
|
-
const [isSubstitution, setIsSubstitution] = useState(false);
|
|
39
|
-
// Dosing Unit eg Tablets
|
|
40
|
-
const [drugDosingUnits, setDrugDosingUnits] = useState([]);
|
|
41
|
-
// Dispensing Unit eg Tablets
|
|
42
|
-
const [drugDispensingUnits, setDrugDispensingUnits] = useState([]);
|
|
43
|
-
// Route eg Oral
|
|
44
|
-
const [drugRoutes, setDrugRoutes] = useState([]);
|
|
45
|
-
// Frequency eg Twice daily
|
|
46
|
-
const [orderFrequencies, setOrderFrequencies] = useState([]);
|
|
47
39
|
// type of substitution question
|
|
48
40
|
const [substitutionTypes, setSubstitutionTypes] = useState([]);
|
|
49
41
|
// reason for substitution question
|
|
@@ -72,41 +64,21 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
72
64
|
// we fetch this just to get the prescription date
|
|
73
65
|
const { prescriptionDate } = usePrescriptionDetails(medicationRequest ? medicationRequest.encounter.reference : null);
|
|
74
66
|
|
|
75
|
-
|
|
67
|
+
const { drugRoutes, drugDosingUnits, drugDispensingUnits, orderFrequencies } = useMemo(() => {
|
|
76
68
|
if (orderConfigObject) {
|
|
77
|
-
//
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
orderConfigObject.
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
orderConfigObject.drugDosingUnits.forEach(
|
|
89
|
-
(x) => availableDosingUnits.includes(x.uuid) || otherDosingUnits.push({ id: x.uuid, text: x.display }),
|
|
90
|
-
);
|
|
91
|
-
setDrugDosingUnits([...drugDosingUnits, ...otherDosingUnits]);
|
|
92
|
-
|
|
93
|
-
// sync dispensing unit options with what's defined in the order config
|
|
94
|
-
const availableDispensingUnits = drugDispensingUnits.map((x) => x.id);
|
|
95
|
-
const otherDispensingUnits = [];
|
|
96
|
-
orderConfigObject.drugDispensingUnits.forEach(
|
|
97
|
-
(x) => availableDispensingUnits.includes(x.uuid) || otherDispensingUnits.push({ id: x.uuid, text: x.display }),
|
|
98
|
-
);
|
|
99
|
-
setDrugDispensingUnits([...drugDispensingUnits, ...otherDispensingUnits]);
|
|
100
|
-
|
|
101
|
-
// sync order frequency options with order config
|
|
102
|
-
const availableFrequencies = orderFrequencies.map((x) => x.id);
|
|
103
|
-
const otherFrequencyOptions = [];
|
|
104
|
-
orderConfigObject.orderFrequencies.forEach(
|
|
105
|
-
(x) => availableFrequencies.includes(x.uuid) || otherFrequencyOptions.push({ id: x.uuid, text: x.display }),
|
|
106
|
-
);
|
|
107
|
-
setOrderFrequencies([...orderFrequencies, ...otherFrequencyOptions]);
|
|
69
|
+
// Dosing Unit eg Tablets
|
|
70
|
+
const drugRoutes = orderConfigObject.drugRoutes.map((x) => ({ id: x.uuid, text: x.display }));
|
|
71
|
+
// Dispensing Unit eg Tablets
|
|
72
|
+
const drugDosingUnits = orderConfigObject.drugDosingUnits.map((x) => ({ id: x.uuid, text: x.display }));
|
|
73
|
+
// Route eg Oral
|
|
74
|
+
const drugDispensingUnits = orderConfigObject.drugDispensingUnits.map((x) => ({ id: x.uuid, text: x.display }));
|
|
75
|
+
// Frequency eg Twice daily
|
|
76
|
+
const orderFrequencies = orderConfigObject.orderFrequencies.map((x) => ({ id: x.uuid, text: x.display }));
|
|
77
|
+
return { drugRoutes, drugDosingUnits, drugDispensingUnits, orderFrequencies };
|
|
78
|
+
} else {
|
|
79
|
+
return { drugRoutes: [], drugDosingUnits: [], drugDispensingUnits: [], orderFrequencies: [] };
|
|
108
80
|
}
|
|
109
|
-
}, [
|
|
81
|
+
}, [orderConfigObject]);
|
|
110
82
|
|
|
111
83
|
useEffect(() => {
|
|
112
84
|
const substitutionTypeOptions = [];
|
|
@@ -164,36 +136,25 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
164
136
|
);
|
|
165
137
|
|
|
166
138
|
// check to see if the current dispense would be a substitution, and update accordingly
|
|
139
|
+
const isSubstitution =
|
|
140
|
+
medicationRequest?.medicationReference?.reference &&
|
|
141
|
+
medicationDispense?.medicationReference?.reference &&
|
|
142
|
+
medicationRequest.medicationReference.reference != medicationDispense.medicationReference.reference;
|
|
143
|
+
|
|
144
|
+
const { substitution } = medicationDispense;
|
|
167
145
|
useEffect(() => {
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
updateMedicationDispense({
|
|
175
|
-
...medicationDispense,
|
|
176
|
-
substitution: {
|
|
177
|
-
...medicationDispense.substitution,
|
|
178
|
-
wasSubstituted: true,
|
|
179
|
-
},
|
|
180
|
-
});
|
|
146
|
+
if (isSubstitution) {
|
|
147
|
+
// make sure that the value substitution.wasSubstituted exists and is truthy
|
|
148
|
+
if (!substitution.wasSubstituted) {
|
|
149
|
+
const newSubstitution = { ...substitution, wasSubstituted: true };
|
|
150
|
+
updateMedicationDispense({ substitution: newSubstitution });
|
|
151
|
+
}
|
|
181
152
|
} else {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
substitution: {
|
|
186
|
-
wasSubstituted: false,
|
|
187
|
-
reason: [
|
|
188
|
-
{
|
|
189
|
-
coding: [{ code: null }],
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
type: { coding: [{ code: null }] },
|
|
193
|
-
},
|
|
194
|
-
});
|
|
153
|
+
if (substitution != blankSubstitution) {
|
|
154
|
+
updateMedicationDispense({ substitution: blankSubstitution });
|
|
155
|
+
}
|
|
195
156
|
}
|
|
196
|
-
}, [
|
|
157
|
+
}, [isSubstitution, substitution, updateMedicationDispense]);
|
|
197
158
|
|
|
198
159
|
useEffect(() => {
|
|
199
160
|
setUserCanModify(session?.user && userHasAccess(PRIVILEGE_CREATE_DISPENSE_MODIFY_DETAILS, session.user));
|
|
@@ -211,11 +172,9 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
211
172
|
}
|
|
212
173
|
: undefined;
|
|
213
174
|
}, [medicationDispense?.performer, providers, session?.currentProvider?.uuid, session?.user?.person?.display]);
|
|
214
|
-
|
|
215
175
|
useEffect(() => {
|
|
216
176
|
if (initialDispenser?.uuid) {
|
|
217
177
|
updateMedicationDispense({
|
|
218
|
-
...medicationDispense,
|
|
219
178
|
performer: [
|
|
220
179
|
{
|
|
221
180
|
actor: {
|
|
@@ -225,7 +184,7 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
225
184
|
],
|
|
226
185
|
});
|
|
227
186
|
}
|
|
228
|
-
}, [initialDispenser,
|
|
187
|
+
}, [initialDispenser, updateMedicationDispense]);
|
|
229
188
|
|
|
230
189
|
return (
|
|
231
190
|
<div className={styles.medicationDispenseReviewContainer}>
|
|
@@ -251,7 +210,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
251
210
|
onChange={({ selectedItem }) => {
|
|
252
211
|
const typedItem = selectedItem as Medication;
|
|
253
212
|
updateMedicationDispense({
|
|
254
|
-
...medicationDispense,
|
|
255
213
|
medicationCodeableConcept: undefined,
|
|
256
214
|
medicationReference: {
|
|
257
215
|
reference: 'Medication/' + typedItem?.id,
|
|
@@ -279,7 +237,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
279
237
|
}}
|
|
280
238
|
onChange={({ selectedItem }) => {
|
|
281
239
|
updateMedicationDispense({
|
|
282
|
-
...medicationDispense,
|
|
283
240
|
substitution: {
|
|
284
241
|
...medicationDispense.substitution,
|
|
285
242
|
type: {
|
|
@@ -312,7 +269,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
312
269
|
}}
|
|
313
270
|
onChange={({ selectedItem }) => {
|
|
314
271
|
updateMedicationDispense({
|
|
315
|
-
...medicationDispense,
|
|
316
272
|
substitution: {
|
|
317
273
|
...medicationDispense.substitution,
|
|
318
274
|
reason: [
|
|
@@ -362,10 +318,9 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
362
318
|
max={config.dispenseBehavior.restrictTotalQuantityDispensed ? quantityRemaining : undefined}
|
|
363
319
|
onChange={(event, state) => {
|
|
364
320
|
updateMedicationDispense({
|
|
365
|
-
...medicationDispense,
|
|
366
321
|
quantity: {
|
|
367
322
|
...medicationDispense.quantity,
|
|
368
|
-
value: state.value ? parseFloat(state.value.toString()) :
|
|
323
|
+
value: state.value ? parseFloat(state.value.toString()) : 0,
|
|
369
324
|
},
|
|
370
325
|
});
|
|
371
326
|
}}
|
|
@@ -383,7 +338,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
383
338
|
}}
|
|
384
339
|
onChange={({ selectedItem }) => {
|
|
385
340
|
updateMedicationDispense({
|
|
386
|
-
...medicationDispense,
|
|
387
341
|
// note that we specifically recreate doseQuantity to overwrite any unit or system properties that may have been set
|
|
388
342
|
quantity: {
|
|
389
343
|
value: medicationDispense.quantity.value,
|
|
@@ -408,7 +362,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
408
362
|
value={medicationDispense.dosageInstruction[0].doseAndRate[0].doseQuantity.value}
|
|
409
363
|
onChange={(event, state) => {
|
|
410
364
|
updateMedicationDispense({
|
|
411
|
-
...medicationDispense,
|
|
412
365
|
dosageInstruction: [
|
|
413
366
|
{
|
|
414
367
|
...medicationDispense.dosageInstruction[0],
|
|
@@ -417,7 +370,7 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
417
370
|
...medicationDispense.dosageInstruction[0].doseAndRate[0],
|
|
418
371
|
doseQuantity: {
|
|
419
372
|
...medicationDispense.dosageInstruction[0].doseAndRate[0].doseQuantity,
|
|
420
|
-
value: state.value ? parseFloat(state.value.toString()) :
|
|
373
|
+
value: state.value ? parseFloat(state.value.toString()) : 0,
|
|
421
374
|
},
|
|
422
375
|
},
|
|
423
376
|
],
|
|
@@ -440,7 +393,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
440
393
|
}}
|
|
441
394
|
onChange={({ selectedItem }) => {
|
|
442
395
|
updateMedicationDispense({
|
|
443
|
-
...medicationDispense,
|
|
444
396
|
dosageInstruction: [
|
|
445
397
|
{
|
|
446
398
|
...medicationDispense.dosageInstruction[0],
|
|
@@ -474,7 +426,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
474
426
|
itemToString={(item) => item?.text}
|
|
475
427
|
onChange={({ selectedItem }) => {
|
|
476
428
|
updateMedicationDispense({
|
|
477
|
-
...medicationDispense,
|
|
478
429
|
dosageInstruction: [
|
|
479
430
|
{
|
|
480
431
|
...medicationDispense.dosageInstruction[0],
|
|
@@ -507,7 +458,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
507
458
|
itemToString={(item) => item?.text}
|
|
508
459
|
onChange={({ selectedItem }) => {
|
|
509
460
|
updateMedicationDispense({
|
|
510
|
-
...medicationDispense,
|
|
511
461
|
dosageInstruction: [
|
|
512
462
|
{
|
|
513
463
|
...medicationDispense.dosageInstruction[0],
|
|
@@ -535,7 +485,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
535
485
|
maxLength={65535}
|
|
536
486
|
onChange={(e) => {
|
|
537
487
|
updateMedicationDispense({
|
|
538
|
-
...medicationDispense,
|
|
539
488
|
dosageInstruction: [
|
|
540
489
|
{
|
|
541
490
|
...medicationDispense.dosageInstruction[0],
|
|
@@ -555,7 +504,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
555
504
|
const currentDate = medicationDispense.whenHandedOver ? dayjs(medicationDispense.whenHandedOver) : null;
|
|
556
505
|
const selectedDate = dayjs(input);
|
|
557
506
|
updateMedicationDispense({
|
|
558
|
-
...medicationDispense,
|
|
559
507
|
whenHandedOver: currentDate?.isSame(selectedDate, 'day')
|
|
560
508
|
? currentDate.toISOString()
|
|
561
509
|
: selectedDate.toISOString(), // to preserve any time component, only update if the day actually changes
|
|
@@ -570,7 +518,6 @@ const MedicationDispenseReview: React.FC<MedicationDispenseReviewProps> = ({
|
|
|
570
518
|
initialSelectedItem={initialDispenser}
|
|
571
519
|
onChange={({ selectedItem }) => {
|
|
572
520
|
updateMedicationDispense({
|
|
573
|
-
...medicationDispense,
|
|
574
521
|
performer: [
|
|
575
522
|
{
|
|
576
523
|
actor: {
|
|
@@ -166,16 +166,18 @@ export function initiateMedicationDispenseBody(
|
|
|
166
166
|
],
|
|
167
167
|
},
|
|
168
168
|
],
|
|
169
|
-
substitution:
|
|
170
|
-
wasSubstituted: false,
|
|
171
|
-
reason: [
|
|
172
|
-
{
|
|
173
|
-
coding: [{ code: null }],
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
type: { coding: [{ code: null }] },
|
|
177
|
-
},
|
|
169
|
+
substitution: blankSubstitution,
|
|
178
170
|
};
|
|
179
171
|
}
|
|
180
172
|
return medicationDispense;
|
|
181
173
|
}
|
|
174
|
+
|
|
175
|
+
export const blankSubstitution = {
|
|
176
|
+
wasSubstituted: false,
|
|
177
|
+
reason: [
|
|
178
|
+
{
|
|
179
|
+
coding: [{ code: null }],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
type: { coding: [{ code: null }] },
|
|
183
|
+
};
|
|
@@ -13,6 +13,10 @@ import { JSON_MERGE_PATH_MIME_TYPE, OPENMRS_FHIR_EXT_REQUEST_FULFILLER_STATUS }
|
|
|
13
13
|
|
|
14
14
|
jest.mocked(openmrsFetch);
|
|
15
15
|
jest.mock('swr');
|
|
16
|
+
jest.mock('react', () => ({
|
|
17
|
+
...jest.requireActual('react'),
|
|
18
|
+
useMemo: jest.fn((fn) => fn()),
|
|
19
|
+
}));
|
|
16
20
|
|
|
17
21
|
describe('Medication Request Resource Test', () => {
|
|
18
22
|
test('usePrescriptionsTable should call active endpoint and proper date based on expiration period if status parameter is active', () => {
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from '../utils';
|
|
24
24
|
import dayjs from 'dayjs';
|
|
25
25
|
import { JSON_MERGE_PATH_MIME_TYPE, OPENMRS_FHIR_EXT_REQUEST_FULFILLER_STATUS } from '../constants';
|
|
26
|
+
import { useMemo } from 'react';
|
|
26
27
|
|
|
27
28
|
export function usePrescriptionsTable(
|
|
28
29
|
loadData: boolean,
|
|
@@ -127,54 +128,53 @@ function buildPrescriptionsTableRow(
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
export function usePrescriptionDetails(encounterUuid: string, refreshInterval = null) {
|
|
130
|
-
const
|
|
131
|
-
let prescriptionDate: Date;
|
|
132
|
-
let isLoading = true;
|
|
133
|
-
|
|
134
|
-
const { data, error } = useSWR<{ data: MedicationRequestResponse }, Error>(
|
|
131
|
+
const { data, ...rest } = useSWR<{ data: MedicationRequestResponse }, Error>(
|
|
135
132
|
getPrescriptionDetailsEndpoint(encounterUuid),
|
|
136
133
|
openmrsFetch,
|
|
137
134
|
{ refreshInterval: refreshInterval },
|
|
138
135
|
);
|
|
139
136
|
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.map((entry) => entry.resource as Encounter);
|
|
146
|
-
|
|
147
|
-
if (encounter) {
|
|
148
|
-
// by definition of the request (search by encounter) there should be one and only one encounter
|
|
149
|
-
prescriptionDate = parseDate(encounter[0]?.period.start);
|
|
137
|
+
const { medicationRequestBundles, prescriptionDate } = useMemo(() => {
|
|
138
|
+
const medicationRequestBundles: Array<MedicationRequestBundle> = [];
|
|
139
|
+
let prescriptionDate: Date;
|
|
140
|
+
if (data) {
|
|
141
|
+
const results = data?.data.entry;
|
|
150
142
|
|
|
151
|
-
const
|
|
152
|
-
?.filter((entry) => entry?.resource?.resourceType == '
|
|
153
|
-
.map((entry) => entry.resource as
|
|
154
|
-
|
|
155
|
-
const medicationDispenses = results
|
|
156
|
-
?.filter((entry) => entry?.resource?.resourceType == 'MedicationDispense')
|
|
157
|
-
.map((entry) => entry.resource as MedicationDispense)
|
|
158
|
-
.sort(sortMedicationDispensesByWhenHandedOver);
|
|
143
|
+
const encounter = results
|
|
144
|
+
?.filter((entry) => entry?.resource?.resourceType == 'Encounter')
|
|
145
|
+
.map((entry) => entry.resource as Encounter);
|
|
159
146
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
|
|
147
|
+
if (encounter) {
|
|
148
|
+
// by definition of the request (search by encounter) there should be one and only one encounter
|
|
149
|
+
prescriptionDate = parseDate(encounter[0]?.period.start);
|
|
150
|
+
|
|
151
|
+
const medicationRequests = results
|
|
152
|
+
?.filter((entry) => entry?.resource?.resourceType == 'MedicationRequest')
|
|
153
|
+
.map((entry) => entry.resource as MedicationRequest);
|
|
154
|
+
|
|
155
|
+
const medicationDispenses = results
|
|
156
|
+
?.filter((entry) => entry?.resource?.resourceType == 'MedicationDispense')
|
|
157
|
+
.map((entry) => entry.resource as MedicationDispense)
|
|
158
|
+
.sort(sortMedicationDispensesByWhenHandedOver);
|
|
159
|
+
|
|
160
|
+
medicationRequests.every((medicationRequest) =>
|
|
161
|
+
medicationRequestBundles.push({
|
|
162
|
+
request: medicationRequest,
|
|
163
|
+
dispenses: getAssociatedMedicationDispenses(medicationRequest, medicationDispenses).sort(
|
|
164
|
+
sortMedicationDispensesByWhenHandedOver,
|
|
165
|
+
),
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
168
169
|
}
|
|
169
|
-
}
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
return { medicationRequestBundles, prescriptionDate };
|
|
172
|
+
}, [data]);
|
|
172
173
|
|
|
173
174
|
return {
|
|
174
175
|
medicationRequestBundles,
|
|
175
176
|
prescriptionDate,
|
|
176
|
-
|
|
177
|
-
isLoading,
|
|
177
|
+
...rest,
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
|
package/src/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"hash":"73ee20738420f8cc","duration":44568}
|
|
Binary file
|