@openmrs/esm-stock-management-app 1.0.1-pre.469 → 1.0.1-pre.473

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,10 +86,10 @@
86
86
  "initial": true,
87
87
  "entry": true,
88
88
  "recorded": false,
89
- "size": 4770073,
89
+ "size": 4770791,
90
90
  "sizes": {
91
91
  "consume-shared": 252,
92
- "javascript": 4748124,
92
+ "javascript": 4748842,
93
93
  "share-init": 252,
94
94
  "runtime": 21445
95
95
  },
@@ -106,7 +106,7 @@
106
106
  "auxiliaryFiles": [
107
107
  "main.js.map"
108
108
  ],
109
- "hash": "4584f840c7b06eb6",
109
+ "hash": "137fc6c0e5d30a79",
110
110
  "childrenByOrder": {}
111
111
  },
112
112
  {
@@ -138,9 +138,9 @@
138
138
  "initial": false,
139
139
  "entry": false,
140
140
  "recorded": false,
141
- "size": 1098361,
141
+ "size": 1099079,
142
142
  "sizes": {
143
- "javascript": 1098151,
143
+ "javascript": 1098869,
144
144
  "consume-shared": 210
145
145
  },
146
146
  "names": [],
@@ -154,7 +154,7 @@
154
154
  "auxiliaryFiles": [
155
155
  "474.js.map"
156
156
  ],
157
- "hash": "3d31f10ff5724cc8",
157
+ "hash": "0f9bb5a017f33892",
158
158
  "childrenByOrder": {}
159
159
  },
160
160
  {
package/dist/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"extensions":[{"name":"stock-nav-menu","slot":"stock-sidebar-slot","component":"stockNavMenu","online":true,"offline":true},{"name":"overview-db-link","slot":"stock-page-dashboard-slot","component":"stockOverviewLink","meta":{"name":"overview","slot":"overview-dashboard-slot","title":"overview"},"order":0,"online":true,"offline":true},{"name":"stock-overview-db","slot":"overview-dashboard-slot","component":"stockOverview"},{"name":"operations-db-link","slot":"stock-page-dashboard-slot","component":"stockOperationsLink","meta":{"name":"operations","slot":"operations-dashboard-slot","title":"operations"},"order":2,"online":true,"offline":true},{"name":"stock-operations-db","slot":"operations-dashboard-slot","component":"stockOperations"},{"name":"items-db-link","slot":"stock-page-dashboard-slot","component":"stockItemsLink","meta":{"name":"items","slot":"items-dashboard-slot","title":"items"},"order":1,"online":true,"offline":true},{"name":"stock-items-db","slot":"items-dashboard-slot","component":"stockItems"},{"name":"user-scopes-db-link","slot":"stock-page-dashboard-slot","component":"stockUserScopesLink","meta":{"name":"user-scopes","slot":"user-scopes-dashboard-slot","title":"user-scopes"},"order":3,"online":true,"offline":true},{"name":"stock-user-scopes-db","slot":"user-scopes-dashboard-slot","component":"stockUserScopes"},{"name":"sources-db-link","slot":"stock-page-dashboard-slot","component":"stockSourcesLink","meta":{"name":"sources","slot":"sources-dashboard-slot","title":"Sources"},"order":2,"online":true,"offline":true},{"name":"stock-sources-db","slot":"sources-dashboard-slot","component":"stockSources"},{"name":"locations-db-link","slot":"stock-page-dashboard-slot","component":"stockLocationsLink","meta":{"name":"locations","slot":"locations-dashboard-slot","title":"Locations"},"order":4,"online":true,"offline":true},{"name":"stock-locations-db","slot":"locations-dashboard-slot","component":"stockLocations"},{"name":"reports-db-link","slot":"stock-page-dashboard-slot","component":"stockReportsLink","meta":{"name":"reports","slot":"reports-dashboard-slot","title":"Reports"},"order":5,"online":true,"offline":true},{"name":"stock-reports-db","slot":"reports-dashboard-slot","component":"stockReports"},{"name":"settings-db-link","slot":"stock-page-dashboard-slot","component":"stockSettingsLink","meta":{"name":"settings","slot":"settings-dashboard-slot","title":"Settings"},"order":6,"online":true,"offline":true},{"name":"stock-settings-db","slot":"settings-dashboard-slot","component":"stockSettings"},{"name":"stock-management-admin-card-link","slot":"system-admin-page-card-link-slot","component":"stockManagementAdminCardLink"},{"name":"stock-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.469"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.24.0"},"extensions":[{"name":"stock-nav-menu","slot":"stock-sidebar-slot","component":"stockNavMenu","online":true,"offline":true},{"name":"overview-db-link","slot":"stock-page-dashboard-slot","component":"stockOverviewLink","meta":{"name":"overview","slot":"overview-dashboard-slot","title":"overview"},"order":0,"online":true,"offline":true},{"name":"stock-overview-db","slot":"overview-dashboard-slot","component":"stockOverview"},{"name":"operations-db-link","slot":"stock-page-dashboard-slot","component":"stockOperationsLink","meta":{"name":"operations","slot":"operations-dashboard-slot","title":"operations"},"order":2,"online":true,"offline":true},{"name":"stock-operations-db","slot":"operations-dashboard-slot","component":"stockOperations"},{"name":"items-db-link","slot":"stock-page-dashboard-slot","component":"stockItemsLink","meta":{"name":"items","slot":"items-dashboard-slot","title":"items"},"order":1,"online":true,"offline":true},{"name":"stock-items-db","slot":"items-dashboard-slot","component":"stockItems"},{"name":"user-scopes-db-link","slot":"stock-page-dashboard-slot","component":"stockUserScopesLink","meta":{"name":"user-scopes","slot":"user-scopes-dashboard-slot","title":"user-scopes"},"order":3,"online":true,"offline":true},{"name":"stock-user-scopes-db","slot":"user-scopes-dashboard-slot","component":"stockUserScopes"},{"name":"sources-db-link","slot":"stock-page-dashboard-slot","component":"stockSourcesLink","meta":{"name":"sources","slot":"sources-dashboard-slot","title":"Sources"},"order":2,"online":true,"offline":true},{"name":"stock-sources-db","slot":"sources-dashboard-slot","component":"stockSources"},{"name":"locations-db-link","slot":"stock-page-dashboard-slot","component":"stockLocationsLink","meta":{"name":"locations","slot":"locations-dashboard-slot","title":"Locations"},"order":4,"online":true,"offline":true},{"name":"stock-locations-db","slot":"locations-dashboard-slot","component":"stockLocations"},{"name":"reports-db-link","slot":"stock-page-dashboard-slot","component":"stockReportsLink","meta":{"name":"reports","slot":"reports-dashboard-slot","title":"Reports"},"order":5,"online":true,"offline":true},{"name":"stock-reports-db","slot":"reports-dashboard-slot","component":"stockReports"},{"name":"settings-db-link","slot":"stock-page-dashboard-slot","component":"stockSettingsLink","meta":{"name":"settings","slot":"settings-dashboard-slot","title":"Settings"},"order":6,"online":true,"offline":true},{"name":"stock-settings-db","slot":"settings-dashboard-slot","component":"stockSettings"},{"name":"stock-management-admin-card-link","slot":"system-admin-page-card-link-slot","component":"stockManagementAdminCardLink"},{"name":"stock-operation-dialog","component":"stockOperationDialog"},{"name":"import-bulk-stock-items","component":"importBulkStockItemsDialog"},{"name":"delete-stock-modal","component":"deleteStockModal"},{"name":"delete-stock-user-scope-modal","component":"deleteUserScopeModal"},{"name":"stock-management-app-menu-item","component":"stockManagementAppMenuItem","slot":"app-menu-item-slot","meta":{"name":" Stock Management"}},{"name":"delete-stock-rule-modal","component":"deleteStockRuleModal"},{"name":"delete-packaging-unit-modal","component":"deletePackagingUnitModal"},{"name":"delete-packaging-unit-button","component":"deletePackagingUnitButton"}],"pages":[{"component":"root","route":"stock-management"}],"version":"1.0.1-pre.473"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-stock-management-app",
3
- "version": "1.0.1-pre.469",
3
+ "version": "1.0.1-pre.473",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Stock management microfrontend for OpenMRS 3.x",
6
6
  "browser": "dist/openmrs-esm-stock-management-app.js",
@@ -22,6 +22,7 @@ import { Drug } from "../core/api/types/concept/Drug";
22
22
  import { Patient } from "../core/api/types/identity/Patient";
23
23
  import { useMemo } from "react";
24
24
  import { uniqBy } from "lodash-es";
25
+ import { UserRoleScope } from "../core/api/types/identity/UserRoleScope";
25
26
 
26
27
  export type PatientFilterCriteria = ResourceFilterCriteria;
27
28
 
@@ -304,3 +305,9 @@ export const useUserRoles = () => {
304
305
  error,
305
306
  };
306
307
  };
308
+ export function getUserRoleScopes(): Promise<
309
+ FetchResponse<PageableResult<UserRoleScope>>
310
+ > {
311
+ const apiUrl = `${restBaseUrl}/stockmanagement/userrolescope`;
312
+ return openmrsFetch(apiUrl);
313
+ }
@@ -23,8 +23,10 @@ import {
23
23
  import {
24
24
  getParties,
25
25
  getStockOperationTypes,
26
+ getUserRoleScopes,
26
27
  } from "../../stock-lookups/stock-lookups.resource";
27
28
  import { Party } from "../../core/api/types/Party";
29
+ import { getCurrentUser } from "@openmrs/esm-framework";
28
30
 
29
31
  export async function initializeNewStockOperation(
30
32
  currentStockOperationType: StockOperationType,
@@ -36,7 +38,15 @@ export async function initializeNewStockOperation(
36
38
  const isNew = !!stockOperation;
37
39
  const newItemsToCopy: StockOperationItemDTO[] = [];
38
40
  const showQuantityRequested = false;
39
-
41
+ const currentUserUuid = await new Promise((resolve, reject) => {
42
+ getCurrentUser().subscribe({
43
+ next: (user) => {
44
+ const userUuid = user?.user?.uuid;
45
+ resolve(userUuid);
46
+ },
47
+ error: (err) => reject(err),
48
+ });
49
+ });
40
50
  let operationTypes = stockOperationTypes;
41
51
  const canIssueStock =
42
52
  stockOperation?.permission?.isRequisitionAndCanIssueStock ?? false;
@@ -68,69 +78,27 @@ export async function initializeNewStockOperation(
68
78
  operationTypeUuid: currentStockOperationType?.uuid,
69
79
  operationType: currentStockOperationType?.operationType,
70
80
  });
71
-
72
- if (
73
- currentStockOperationType.operationType ==
74
- OperationType.STOCK_ISSUE_OPERATION_TYPE
75
- ) {
76
- // requisition = urlQueryParams?.get("requisition");
77
- // if (requisition) {
78
- // const response = await getStockOperation(requisition);
79
- // if (!response.ok) {
80
- // return;
81
- // }
82
- //
83
- // const requisitionStockOperation = response.data;
84
- //
85
- // if (
86
- // !requisitionStockOperation.responsiblePersonUuid &&
87
- // requisitionStockOperation.responsiblePersonOther
88
- // ) {
89
- // requisitionStockOperation.responsiblePersonUuid = "Other";
90
- // }
91
- //
92
- // if (
93
- // requisitionStockOperation &&
94
- // requisitionStockOperation.stockOperationItems
95
- // ) {
96
- // let hasQtyRequested = false;
97
- // requisitionStockOperation.stockOperationItems.forEach((si) => {
98
- // if (si.quantity && si.stockItemPackagingUOMName) {
99
- // hasQtyRequested = true;
100
- // }
101
- //
102
- // const itemId = `new-item-${getStockOperationUniqueId()}`;
103
- // si.id = itemId;
104
- // si.uuid = itemId;
105
- // newItemsToCopy.push({
106
- // ...si,
107
- // quantityRequested: si.quantity,
108
- // quantityRequestedPackagingUOMUuid: si.stockItemPackagingUOMUuid,
109
- // quantityRequestedPackagingUOMName: si.stockItemPackagingUOMName,
110
- // });
111
- // });
112
- // if (hasQtyRequested) {
113
- // showQuantityRequested = true;
114
- // }
115
- // }
116
- // newItemsToCopy.push({ uuid: `new-item-1`, id: `new-item-1` });
117
- // model.destinationUuid = requisitionStockOperation.sourceUuid;
118
- // model.destinationName = requisitionStockOperation.sourceName;
119
- // model.responsiblePersonUuid =
120
- // requisitionStockOperation.responsiblePersonUuid;
121
- // model.responsiblePersonOther =
122
- // requisitionStockOperation.responsiblePersonOther;
123
- // model.responsiblePersonFamilyName =
124
- // requisitionStockOperation.responsiblePersonFamilyName;
125
- // model.responsiblePersonGivenName =
126
- // requisitionStockOperation.responsiblePersonGivenName;
127
- // model.remarks = requisitionStockOperation.remarks;
128
- // }
129
- }
130
81
  const partyList = await getParties();
82
+ const userRoleScopes = await getUserRoleScopes();
83
+ const currentUserRoleScope = userRoleScopes.data?.results?.filter(
84
+ (role) => role.userUuid === currentUserUuid
85
+ );
86
+ const userRoleScopeLocations = [
87
+ ...new Set(
88
+ currentUserRoleScope.flatMap((role) =>
89
+ role?.locations?.map((l) => l.locationUuid)
90
+ )
91
+ ),
92
+ ];
93
+
131
94
  if (!partyList.ok) throw Error("Error loading parties");
95
+ const filteredPartyList = partyList.data?.results?.filter(
96
+ (party) =>
97
+ userRoleScopeLocations.includes(party.locationUuid) ||
98
+ party.stockSourceUuid !== null
99
+ );
132
100
 
133
- sourcePartyList = partyList?.data?.results?.filter(
101
+ sourcePartyList = filteredPartyList?.filter(
134
102
  (p) =>
135
103
  (p.locationUuid &&
136
104
  currentStockOperationType?.sourceType === LocationTypeLocation &&