@openmrs/esm-patient-common-lib 11.3.1-pre.8993 → 11.3.1-pre.8999
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 +42 -10
- package/src/orders/useOrderBasket.ts +2 -2
package/package.json
CHANGED
package/src/orders/postOrders.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type Concept,
|
|
3
|
+
openmrsFetch,
|
|
4
|
+
type OpenmrsResource,
|
|
5
|
+
parseDate,
|
|
6
|
+
restBaseUrl,
|
|
7
|
+
type Visit,
|
|
8
|
+
} from '@openmrs/esm-framework';
|
|
2
9
|
import { type OrderBasketStore, orderBasketStore } from './store';
|
|
3
10
|
import type {
|
|
4
11
|
DrugOrderPost,
|
|
@@ -15,18 +22,25 @@ export async function postOrdersOnNewEncounter(
|
|
|
15
22
|
currentVisit: Visit | null,
|
|
16
23
|
sessionLocationUuid: string,
|
|
17
24
|
abortController?: AbortController,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* If not specified, the encounterDate will either be set to
|
|
28
|
+
* `now` if currentVisit is active, or the start of the visit
|
|
29
|
+
*/
|
|
30
|
+
encounterDate?: Date,
|
|
18
31
|
) {
|
|
19
32
|
const now = new Date();
|
|
20
33
|
const visitStartDate = parseDate(currentVisit?.startDatetime);
|
|
21
34
|
const visitEndDate = parseDate(currentVisit?.stopDatetime);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
if (!encounterDate) {
|
|
36
|
+
if (!currentVisit || (visitStartDate < now && (!visitEndDate || visitEndDate > now))) {
|
|
37
|
+
encounterDate = now;
|
|
38
|
+
} else {
|
|
39
|
+
console.warn(
|
|
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;
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
45
|
|
|
32
46
|
const { items, postDataPrepFunctions }: OrderBasketStore = orderBasketStore.getState();
|
|
@@ -40,7 +54,7 @@ export async function postOrdersOnNewEncounter(
|
|
|
40
54
|
});
|
|
41
55
|
});
|
|
42
56
|
|
|
43
|
-
const encounterPostData = {
|
|
57
|
+
const encounterPostData: EncounterPost = {
|
|
44
58
|
patient: patientUuid,
|
|
45
59
|
location: sessionLocationUuid,
|
|
46
60
|
encounterType: orderEncounterType,
|
|
@@ -50,6 +64,24 @@ export async function postOrdersOnNewEncounter(
|
|
|
50
64
|
orders,
|
|
51
65
|
};
|
|
52
66
|
|
|
67
|
+
return postEncounter(encounterPostData, abortController);
|
|
68
|
+
}
|
|
69
|
+
interface ObsPayload {
|
|
70
|
+
concept: Concept | string;
|
|
71
|
+
value?: string | OpenmrsResource;
|
|
72
|
+
groupMembers?: Array<ObsPayload>;
|
|
73
|
+
}
|
|
74
|
+
export interface EncounterPost {
|
|
75
|
+
patient: string;
|
|
76
|
+
location: string;
|
|
77
|
+
encounterType: string;
|
|
78
|
+
encounterDatetime: Date;
|
|
79
|
+
visit?: string;
|
|
80
|
+
obs: ObsPayload[];
|
|
81
|
+
orders: OrderPost[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function postEncounter(encounterPostData: EncounterPost, abortController?: AbortController) {
|
|
53
85
|
return openmrsFetch<OpenmrsResource>(`${restBaseUrl}/encounter`, {
|
|
54
86
|
headers: {
|
|
55
87
|
'Content-Type': 'application/json',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useStoreWithActions } from '@openmrs/esm-framework';
|
|
1
|
+
import { type Actions, useStoreWithActions } from '@openmrs/esm-framework';
|
|
2
2
|
import type { OrderBasketItem, PostDataPrepFunction } from './types';
|
|
3
3
|
import { getPatientUuidFromStore } from '../store/patient-chart-store';
|
|
4
4
|
import { useEffect } from 'react';
|
|
@@ -32,7 +32,7 @@ const orderBasketStoreActions = {
|
|
|
32
32
|
},
|
|
33
33
|
};
|
|
34
34
|
},
|
|
35
|
-
}
|
|
35
|
+
} satisfies Actions<OrderBasketStore>;
|
|
36
36
|
|
|
37
37
|
function getOrderItems(items: OrderBasketStore['items'], grouping?: string | null): Array<OrderBasketItem> {
|
|
38
38
|
const patientUuid = getPatientUuidFromStore();
|