@openmrs/esm-patient-common-lib 7.0.2-pre.3846 → 7.0.2-pre.3855

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-patient-common-lib",
3
- "version": "7.0.2-pre.3846",
3
+ "version": "7.0.2-pre.3855",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Library for common patient chart components",
6
6
  "browser": "dist/openmrs-esm-patient-common-lib.js",
@@ -38,5 +38,5 @@
38
38
  "react": "18.x",
39
39
  "single-spa": "6.x"
40
40
  },
41
- "gitHead": "8167490f458ef62f39503f71acf0593964c39b08"
41
+ "gitHead": "24d36b0f125ad2a5220058375f232e6ad029a3b9"
42
42
  }
@@ -1,7 +1,9 @@
1
1
  import { type OpenmrsResource } from '@openmrs/esm-framework';
2
2
 
3
+ export type OrderAction = 'NEW' | 'REVISE' | 'DISCONTINUE' | 'RENEW';
4
+
3
5
  export interface OrderBasketItem {
4
- action: 'NEW' | 'REVISE' | 'DISCONTINUE' | 'RENEW' | undefined;
6
+ action?: OrderAction;
5
7
  display: string;
6
8
  uuid?: string;
7
9
  orderer?: string;
@@ -19,7 +21,7 @@ export interface OrderBasketItem {
19
21
  }
20
22
 
21
23
  export interface OrderPost {
22
- action?: 'NEW' | 'REVISE' | 'DISCONTINUE';
24
+ action?: OrderAction;
23
25
  patient?: string;
24
26
  careSetting?: string;
25
27
  orderer?: string;
@@ -53,7 +55,7 @@ export interface PatientOrderFetchResponse {
53
55
 
54
56
  export interface Order {
55
57
  uuid: string;
56
- action: string;
58
+ action: OrderAction;
57
59
  asNeeded: boolean;
58
60
  asNeededCondition?: string;
59
61
  autoExpireDate: string;
@@ -122,6 +124,7 @@ export interface Order {
122
124
  clinicalHistory: string;
123
125
  numberOfRepeats: string;
124
126
  type: string;
127
+ labReferenceNumber?: string;
125
128
  }
126
129
 
127
130
  export interface OrderTypeFetchResponse {
@@ -145,3 +148,39 @@ export interface Drug {
145
148
  }
146
149
 
147
150
  export type PostDataPrepFunction = (order: OrderBasketItem, patientUuid: string, encounterUuid: string) => OrderPost;
151
+
152
+ // Adopted from @openmrs/esm-patient-medications-app package. We should consider maintaining a single shared types file
153
+ export interface DrugOrderBasketItem extends OrderBasketItem {
154
+ drug: Drug;
155
+ unit: any;
156
+ commonMedicationName: string;
157
+ dosage: number;
158
+ frequency: any;
159
+ route: any;
160
+ quantityUnits: any;
161
+ patientInstructions: string;
162
+ asNeeded: boolean;
163
+ asNeededCondition: string;
164
+ startDate: Date | string;
165
+ durationUnit: any;
166
+ duration: number | null;
167
+ pillsDispensed: number;
168
+ numRefills: number;
169
+ indication: string;
170
+ isFreeTextDosage: boolean;
171
+ freeTextDosage: string;
172
+ previousOrder?: string;
173
+ template?: any;
174
+ }
175
+
176
+ export interface LabOrderBasketItem extends OrderBasketItem {
177
+ testType?: {
178
+ label: string;
179
+ conceptUuid: string;
180
+ };
181
+ labReferenceNumber?: string;
182
+ urgency?: string;
183
+ instructions?: string;
184
+ previousOrder?: string;
185
+ orderReason?: string;
186
+ }
@@ -1,12 +1,21 @@
1
- import useSWR, { mutate } from 'swr';
1
+ import useSWR, { useSWRConfig } from 'swr';
2
2
  import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
3
3
  import { useCallback, useMemo } from 'react';
4
4
  import { type OrderTypeFetchResponse, type PatientOrderFetchResponse } from '@openmrs/esm-patient-common-lib';
5
5
 
6
6
  export const careSettingUuid = '6f0c9a92-6f24-11e3-af88-005056821db0';
7
7
 
8
- export function usePatientOrders(patientUuid: string, status: 'ACTIVE' | 'any', orderType?: string) {
9
- const baseOrdersUrl = `${restBaseUrl}/order?v=full&patient=${patientUuid}&careSetting=${careSettingUuid}&status=${status}`;
8
+ export const drugCustomRepresentation =
9
+ 'custom:(uuid,dosingType,orderNumber,accessionNumber,' +
10
+ 'patient:ref,action,careSetting:ref,previousOrder:ref,dateActivated,scheduledDate,dateStopped,autoExpireDate,' +
11
+ 'orderType:ref,encounter:ref,orderer:(uuid,display,person:(display)),orderReason,orderReasonNonCoded,orderType,urgency,instructions,' +
12
+ 'commentToFulfiller,drug:(uuid,display,strength,dosageForm:(display,uuid),concept),dose,doseUnits:ref,' +
13
+ 'frequency:ref,asNeeded,asNeededCondition,quantity,quantityUnits:ref,numRefills,dosingInstructions,' +
14
+ 'duration,durationUnits:ref,route:ref,brandName,dispenseAsWritten)';
15
+
16
+ export function usePatientOrders(patientUuid: string, status?: 'ACTIVE' | 'any', orderType?: string) {
17
+ const { mutate } = useSWRConfig();
18
+ const baseOrdersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v=full&status=${status}`;
10
19
  const ordersUrl = orderType ? `${baseOrdersUrl}&orderType=${orderType}` : baseOrdersUrl;
11
20
 
12
21
  const { data, error, isLoading, isValidating } = useSWR<FetchResponse<PatientOrderFetchResponse>, Error>(
@@ -15,7 +24,10 @@ export function usePatientOrders(patientUuid: string, status: 'ACTIVE' | 'any',
15
24
  );
16
25
 
17
26
  const mutateOrders = useCallback(
18
- () => mutate((key) => typeof key === 'string' && key.startsWith(`${restBaseUrl}/order?patient=${patientUuid}`)),
27
+ () =>
28
+ mutate((key) => {
29
+ return typeof key === 'string' && key.startsWith(`${restBaseUrl}/order?patient=${patientUuid}`);
30
+ }, data),
19
31
  [patientUuid],
20
32
  );
21
33
 
@@ -50,3 +62,7 @@ export function useOrderTypes() {
50
62
  isValidating,
51
63
  };
52
64
  }
65
+
66
+ export function getDrugOrderByUuid(orderUuid: string) {
67
+ return openmrsFetch(`${restBaseUrl}/order/${orderUuid}?v=${drugCustomRepresentation}`);
68
+ }