@openmrs/esm-patient-common-lib 8.2.1-pre.5919 → 8.2.1-pre.5925
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,4 +1,11 @@
|
|
|
1
|
+
import { getPatientUuidFromStore } from './store/patient-chart-store';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated This function is now replaced with `getPatientUuidFromStore`. This function will be removed in upcoming releases.
|
|
5
|
+
* @returns {string} patientUuid
|
|
6
|
+
*/
|
|
1
7
|
export function getPatientUuidFromUrl(): string {
|
|
2
8
|
const match = /\/patient\/([a-zA-Z0-9\-]+)\/?/.exec(location.pathname);
|
|
3
|
-
|
|
9
|
+
const patientUuidFromUrl = match && match[1];
|
|
10
|
+
return patientUuidFromUrl || getPatientUuidFromStore();
|
|
4
11
|
}
|
package/src/index.ts
CHANGED
package/src/orders/postOrders.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { openmrsFetch, type OpenmrsResource, parseDate, restBaseUrl, type Visit } from '@openmrs/esm-framework';
|
|
2
|
-
import {
|
|
2
|
+
import { getPatientUuidFromStore } from '../store/patient-chart-store';
|
|
3
3
|
import { type OrderBasketStore, orderBasketStore } from './store';
|
|
4
4
|
import { type ExtractedOrderErrorObject, type OrderBasketItem, type OrderErrorObject, type OrderPost } from './types';
|
|
5
5
|
|
|
@@ -55,7 +55,7 @@ export async function postOrdersOnNewEncounter(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export async function postOrders(encounterUuid: string, abortController: AbortController) {
|
|
58
|
-
const patientUuid =
|
|
58
|
+
const patientUuid = getPatientUuidFromStore();
|
|
59
59
|
const { items, postDataPrepFunctions }: OrderBasketStore = orderBasketStore.getState();
|
|
60
60
|
const patientItems = items[patientUuid];
|
|
61
61
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useStoreWithActions } from '@openmrs/esm-framework';
|
|
2
2
|
import type { OrderBasketItem, PostDataPrepFunction } from './types';
|
|
3
|
-
import {
|
|
3
|
+
import { getPatientUuidFromStore } from '../store/patient-chart-store';
|
|
4
4
|
import { useEffect } from 'react';
|
|
5
5
|
import { type OrderBasketStore, orderBasketStore } from './store';
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ const orderBasketStoreActions = {
|
|
|
10
10
|
grouping: string,
|
|
11
11
|
value: Array<OrderBasketItem> | (() => Array<OrderBasketItem>),
|
|
12
12
|
) {
|
|
13
|
-
const patientUuid =
|
|
13
|
+
const patientUuid = getPatientUuidFromStore();
|
|
14
14
|
if (!Object.keys(state.postDataPrepFunctions).includes(grouping)) {
|
|
15
15
|
console.warn(`Programming error: You must register a postDataPrepFunction for grouping ${grouping} `);
|
|
16
16
|
}
|
|
@@ -35,7 +35,7 @@ const orderBasketStoreActions = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
function getOrderItems(items: OrderBasketStore['items'], grouping?: string | null): Array<OrderBasketItem> {
|
|
38
|
-
const patientUuid =
|
|
38
|
+
const patientUuid = getPatientUuidFromStore();
|
|
39
39
|
const patientItems = items?.[patientUuid] ?? {};
|
|
40
40
|
return grouping ? patientItems[grouping] ?? [] : Object.values(patientItems).flat();
|
|
41
41
|
}
|
|
@@ -46,7 +46,7 @@ export interface ClearOrdersOptions {
|
|
|
46
46
|
|
|
47
47
|
function clearOrders(options?: ClearOrdersOptions) {
|
|
48
48
|
const exceptThoseMatchingFcn = options?.exceptThoseMatching ?? (() => false);
|
|
49
|
-
const patientUuid =
|
|
49
|
+
const patientUuid = getPatientUuidFromStore();
|
|
50
50
|
const items = orderBasketStore.getState().items;
|
|
51
51
|
const patientItems = items[patientUuid] ?? {};
|
|
52
52
|
const newPatientItems = Object.fromEntries(
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createGlobalStore, useStore } from '@openmrs/esm-framework';
|
|
2
|
+
|
|
3
|
+
export interface PatientChartStore {
|
|
4
|
+
patientUuid: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const patientChartStoreName = 'patient-chart-global-store';
|
|
8
|
+
|
|
9
|
+
const patientChartStore = createGlobalStore<PatientChartStore>(patientChartStoreName, {
|
|
10
|
+
patientUuid: '',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This function returns the patient chart store.
|
|
15
|
+
*
|
|
16
|
+
* The patient chart store is used to store all global variables used in the patient chart.
|
|
17
|
+
* In the recent requirements, patient chart is now not only bound with `/patient/{patientUuid}/` path.
|
|
18
|
+
*/
|
|
19
|
+
export function getPatientChartStore() {
|
|
20
|
+
return patientChartStore;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function usePatientChartStore() {
|
|
24
|
+
return useStore(patientChartStore);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This function will get the patient UUID from either URL, or will look into the patient chart store.
|
|
29
|
+
* @returns {string} patientUuid
|
|
30
|
+
*/
|
|
31
|
+
export function getPatientUuidFromStore(): string {
|
|
32
|
+
return patientChartStore.getState()?.patientUuid;
|
|
33
|
+
}
|
package/src/workspaces.ts
CHANGED
|
@@ -4,18 +4,19 @@ import {
|
|
|
4
4
|
navigateAndLaunchWorkspace,
|
|
5
5
|
usePatient,
|
|
6
6
|
} from '@openmrs/esm-framework';
|
|
7
|
-
import {
|
|
7
|
+
import { getPatientUuidFromStore } from './store/patient-chart-store';
|
|
8
8
|
import { useSystemVisitSetting } from './useSystemVisitSetting';
|
|
9
9
|
import { useVisitOrOfflineVisit } from './offline/visit';
|
|
10
10
|
import { useCallback } from 'react';
|
|
11
11
|
import { launchStartVisitPrompt } from './launchStartVisitPrompt';
|
|
12
|
+
import { usePatientChartStore } from './store/patient-chart-store';
|
|
12
13
|
|
|
13
14
|
export interface DefaultPatientWorkspaceProps extends DefaultWorkspaceProps {
|
|
14
15
|
patientUuid: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export function launchPatientWorkspace(workspaceName: string, additionalProps?: object) {
|
|
18
|
-
const patientUuid =
|
|
19
|
+
const patientUuid = getPatientUuidFromStore();
|
|
19
20
|
launchWorkspace(workspaceName, {
|
|
20
21
|
patientUuid: patientUuid,
|
|
21
22
|
...additionalProps,
|
|
@@ -42,7 +43,7 @@ export function launchPatientChartWithWorkspaceOpen({
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export function useLaunchWorkspaceRequiringVisit<T extends object>(workspaceName: string) {
|
|
45
|
-
const { patientUuid } =
|
|
46
|
+
const { patientUuid } = usePatientChartStore();
|
|
46
47
|
const { systemVisitEnabled } = useSystemVisitSetting();
|
|
47
48
|
const { currentVisit } = useVisitOrOfflineVisit(patientUuid);
|
|
48
49
|
|