@openmrs/esm-patient-common-lib 11.3.1-pre.9641 → 11.3.1-pre.9645
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/package.json +1 -1
- package/src/orders/postOrders.ts +44 -40
- package/src/orders/types/order.ts +7 -2
- package/src/orders/useOrders.ts +5 -2
- package/src/workspaces.ts +1 -1
package/package.json
CHANGED
package/src/orders/postOrders.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Concept,
|
|
3
|
+
type Encounter,
|
|
3
4
|
openmrsFetch,
|
|
4
5
|
type OpenmrsResource,
|
|
5
6
|
parseDate,
|
|
@@ -7,20 +8,28 @@ import {
|
|
|
7
8
|
type Visit,
|
|
8
9
|
} from '@openmrs/esm-framework';
|
|
9
10
|
import { type OrderBasketStore, orderBasketStore } from './store';
|
|
10
|
-
import type {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
OrderPost
|
|
17
|
-
|
|
11
|
+
import type { ExtractedOrderErrorObject, Order, OrderBasketItem, OrderErrorObject, OrderPost } from './types';
|
|
12
|
+
|
|
13
|
+
function getOrdersPayloadFromOrderBasket(patientUuid: string, ordererUuid: string) {
|
|
14
|
+
const { items, postDataPrepFunctions }: OrderBasketStore = orderBasketStore.getState();
|
|
15
|
+
const patientItems = items[patientUuid];
|
|
16
|
+
|
|
17
|
+
const orders: Array<OrderPost> = [];
|
|
18
|
+
Object.entries(patientItems).forEach(([grouping, groupOrders]) => {
|
|
19
|
+
groupOrders.forEach((order) => {
|
|
20
|
+
orders.push(postDataPrepFunctions[grouping](order, patientUuid, null, ordererUuid));
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return orders;
|
|
25
|
+
}
|
|
18
26
|
|
|
19
27
|
export async function postOrdersOnNewEncounter(
|
|
20
28
|
patientUuid: string,
|
|
21
29
|
orderEncounterType: string,
|
|
22
30
|
currentVisit: Visit | null,
|
|
23
|
-
|
|
31
|
+
orderLocationUuid: string,
|
|
32
|
+
ordererUuid: string,
|
|
24
33
|
abortController?: AbortController,
|
|
25
34
|
|
|
26
35
|
/**
|
|
@@ -29,34 +38,19 @@ export async function postOrdersOnNewEncounter(
|
|
|
29
38
|
*/
|
|
30
39
|
encounterDate?: Date,
|
|
31
40
|
) {
|
|
32
|
-
const now = new Date();
|
|
33
|
-
const visitStartDate = parseDate(currentVisit?.startDatetime);
|
|
34
|
-
const visitEndDate = parseDate(currentVisit?.stopDatetime);
|
|
35
41
|
if (!encounterDate) {
|
|
36
|
-
if (
|
|
37
|
-
encounterDate =
|
|
42
|
+
if (currentVisit?.stopDatetime) {
|
|
43
|
+
encounterDate = parseDate(currentVisit.startDatetime);
|
|
38
44
|
} else {
|
|
39
|
-
|
|
40
|
-
'postOrdersOnNewEncounter received an active visit that is not currently active. This is a programming error. Attempting to place the order using the visit start date.',
|
|
41
|
-
);
|
|
42
|
-
encounterDate = visitStartDate;
|
|
45
|
+
encounterDate = new Date();
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
const
|
|
47
|
-
const patientItems = items[patientUuid];
|
|
48
|
-
|
|
49
|
-
const orders: Array<DrugOrderPost | TestOrderPost> = [];
|
|
50
|
-
|
|
51
|
-
Object.entries(patientItems).forEach(([grouping, groupOrders]) => {
|
|
52
|
-
groupOrders.forEach((order) => {
|
|
53
|
-
orders.push(postDataPrepFunctions[grouping](order, patientUuid, null));
|
|
54
|
-
});
|
|
55
|
-
});
|
|
49
|
+
const orders = getOrdersPayloadFromOrderBasket(patientUuid, ordererUuid);
|
|
56
50
|
|
|
57
51
|
const encounterPostData: EncounterPost = {
|
|
58
52
|
patient: patientUuid,
|
|
59
|
-
location:
|
|
53
|
+
location: orderLocationUuid,
|
|
60
54
|
encounterType: orderEncounterType,
|
|
61
55
|
encounterDatetime: encounterDate,
|
|
62
56
|
visit: currentVisit?.uuid,
|
|
@@ -82,21 +76,27 @@ export interface EncounterPost {
|
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
export async function postEncounter(encounterPostData: EncounterPost, abortController?: AbortController) {
|
|
85
|
-
return openmrsFetch<
|
|
79
|
+
return openmrsFetch<Encounter>(`${restBaseUrl}/encounter`, {
|
|
86
80
|
headers: {
|
|
87
81
|
'Content-Type': 'application/json',
|
|
88
82
|
},
|
|
89
83
|
method: 'POST',
|
|
90
84
|
body: encounterPostData,
|
|
91
85
|
signal: abortController?.signal,
|
|
92
|
-
}).then((res) => res?.data
|
|
86
|
+
}).then((res) => res?.data);
|
|
93
87
|
}
|
|
94
88
|
|
|
95
|
-
export async function postOrders(
|
|
89
|
+
export async function postOrders(
|
|
90
|
+
patientUuid: string,
|
|
91
|
+
encounterUuid: string,
|
|
92
|
+
abortController: AbortController,
|
|
93
|
+
ordererUuid: string,
|
|
94
|
+
) {
|
|
96
95
|
const { items, postDataPrepFunctions }: OrderBasketStore = orderBasketStore.getState();
|
|
97
96
|
const patientItems = items[patientUuid];
|
|
98
97
|
|
|
99
98
|
const erroredItems: Array<OrderBasketItem> = [];
|
|
99
|
+
const postedOrders: Array<Order> = [];
|
|
100
100
|
for (let grouping in patientItems) {
|
|
101
101
|
const orders = patientItems[grouping];
|
|
102
102
|
for (let i = 0; i < orders.length; i++) {
|
|
@@ -108,20 +108,24 @@ export async function postOrders(patientUuid: string, encounterUuid: string, abo
|
|
|
108
108
|
continue;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
await postOrder(dataPrepFn(order, patientUuid, encounterUuid), abortController)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
await postOrder(dataPrepFn(order, patientUuid, encounterUuid, ordererUuid), abortController)
|
|
112
|
+
.then((response) => {
|
|
113
|
+
postedOrders.push(response.data);
|
|
114
|
+
})
|
|
115
|
+
.catch((error) => {
|
|
116
|
+
erroredItems.push({
|
|
117
|
+
...order,
|
|
118
|
+
orderError: error,
|
|
119
|
+
extractedOrderError: extractErrorDetails(error),
|
|
120
|
+
});
|
|
116
121
|
});
|
|
117
|
-
});
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
|
-
return erroredItems;
|
|
124
|
+
return { postedOrders, erroredItems };
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
export function postOrder(body: OrderPost, abortController?: AbortController) {
|
|
124
|
-
return openmrsFetch(`${restBaseUrl}/order`, {
|
|
128
|
+
return openmrsFetch<Order>(`${restBaseUrl}/order`, {
|
|
125
129
|
method: 'POST',
|
|
126
130
|
signal: abortController?.signal,
|
|
127
131
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -47,8 +47,6 @@ export interface OrderBasketItem {
|
|
|
47
47
|
action: OrderAction;
|
|
48
48
|
display: string;
|
|
49
49
|
uuid?: string;
|
|
50
|
-
orderer?: string;
|
|
51
|
-
careSetting?: string;
|
|
52
50
|
orderError?: Error & {
|
|
53
51
|
responseBody?: {
|
|
54
52
|
error?: {
|
|
@@ -211,10 +209,15 @@ export interface OrderType {
|
|
|
211
209
|
|
|
212
210
|
export type FulfillerStatus = 'RECEIVED' | 'IN_PROGRESS' | 'EXCEPTION' | 'ON_HOLD' | 'DECLINED' | 'COMPLETED';
|
|
213
211
|
|
|
212
|
+
/**
|
|
213
|
+
* A function type that converts a OrderBasketItem into
|
|
214
|
+
* a POST order payload
|
|
215
|
+
*/
|
|
214
216
|
export type PostDataPrepFunction = (
|
|
215
217
|
order: OrderBasketItem,
|
|
216
218
|
patientUuid: string,
|
|
217
219
|
encounterUuid: string | null,
|
|
220
|
+
orderingProviderUuid: string,
|
|
218
221
|
) => OrderPost;
|
|
219
222
|
|
|
220
223
|
export interface OrderBasketExtensionProps {
|
|
@@ -308,6 +311,7 @@ export interface TestOrderBasketItem extends OrderBasketItem {
|
|
|
308
311
|
|
|
309
312
|
export interface OrderBasketWindowProps {
|
|
310
313
|
encounterUuid: string;
|
|
314
|
+
onOrderBasketSubmitted?: (encounterUuid: string, postedOrders: Array<Order>) => void;
|
|
311
315
|
}
|
|
312
316
|
|
|
313
317
|
export interface ExportedOrderBasketWindowProps {
|
|
@@ -319,4 +323,5 @@ export interface ExportedOrderBasketWindowProps {
|
|
|
319
323
|
patientUuid: string;
|
|
320
324
|
visitContext: Visit;
|
|
321
325
|
mutateVisitContext: () => void;
|
|
326
|
+
onOrderBasketSubmitted?: (encounterUuid: string, postedOrders: Array<Order>) => void;
|
|
322
327
|
}
|
package/src/orders/useOrders.ts
CHANGED
|
@@ -15,6 +15,9 @@ export const drugCustomRepresentation =
|
|
|
15
15
|
'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' +
|
|
16
16
|
'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)';
|
|
17
17
|
|
|
18
|
+
export const orderCustomRepresentation =
|
|
19
|
+
'custom:(uuid,display,orderNumber,accessionNumber,patient,concept,action,careSetting,previousOrder,dateActivated,scheduledDate,dateStopped,autoExpireDate,encounter:(uuid,display,visit),orderer:ref,orderReason,orderReasonNonCoded,orderType,urgency,instructions,commentToFulfiller)';
|
|
20
|
+
|
|
18
21
|
export function usePatientOrders(
|
|
19
22
|
patientUuid: string,
|
|
20
23
|
status?: Status,
|
|
@@ -25,8 +28,8 @@ export function usePatientOrders(
|
|
|
25
28
|
const { mutate } = useSWRConfig();
|
|
26
29
|
const baseOrdersUrl =
|
|
27
30
|
startDate && endDate
|
|
28
|
-
? `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v
|
|
29
|
-
: `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v
|
|
31
|
+
? `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v=${orderCustomRepresentation}&activatedOnOrAfterDate=${startDate}&activatedOnOrBeforeDate=${endDate}&excludeDiscontinueOrders=true`
|
|
32
|
+
: `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v=${orderCustomRepresentation}&status=${status}&excludeDiscontinueOrders=true`;
|
|
30
33
|
const ordersUrl = orderType ? `${baseOrdersUrl}&orderTypes=${orderType}` : baseOrdersUrl;
|
|
31
34
|
|
|
32
35
|
const { data, error, isLoading, isValidating } = useSWR<FetchResponse<PatientOrderFetchResponse>, Error>(
|
package/src/workspaces.ts
CHANGED
|
@@ -47,7 +47,7 @@ export function useLaunchWorkspaceRequiringVisit<T extends object>(patientUuid:
|
|
|
47
47
|
(workspaceProps?: T, windowProps?: any, groupProps?: any) => {
|
|
48
48
|
startVisitIfNeeded().then((didStartVisit) => {
|
|
49
49
|
if (didStartVisit) {
|
|
50
|
-
launchWorkspace2(workspaceName, workspaceProps, windowProps);
|
|
50
|
+
launchWorkspace2(workspaceName, workspaceProps, windowProps, groupProps);
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
},
|