@openmrs/esm-stock-management-app 1.0.1-pre.350 → 1.0.1-pre.357
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/304.js +2 -0
- package/dist/304.js.map +1 -0
- package/dist/969.js +1 -0
- package/dist/969.js.map +1 -0
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-stock-management-app.js +1 -1
- package/dist/openmrs-esm-stock-management-app.js.buildmanifest.json +41 -41
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/stock-batch/stock-batch.resource.ts +7 -5
- package/src/stock-items/add-stock-item/stock-item-rules/stock-rules.resource.ts +7 -5
- package/src/stock-items/stock-items.resource.ts +23 -19
- package/src/stock-items/types.ts +79 -0
- package/src/stock-locations/add-locations-form.component.tsx +74 -0
- package/src/stock-locations/location-admin-form.component.tsx +164 -0
- package/src/stock-locations/stock-locations-table.component.tsx +33 -10
- package/src/stock-locations/stock-locations-table.resource.tsx +67 -12
- package/src/stock-locations/stock-locations-table.scss +3 -0
- package/src/stock-lookups/stock-lookups.resource.ts +15 -15
- package/src/stock-operations/add-stock-operation/add-stock-operation.component.tsx +10 -5
- package/src/stock-operations/stock-operations.resource.ts +18 -14
- package/src/stock-sources/stock-sources.resource.ts +5 -5
- package/src/stock-user-role-scopes/stock-user-role-scopes.resource.ts +5 -5
- package/dist/500.js +0 -2
- package/dist/500.js.map +0 -1
- package/dist/842.js +0 -1
- package/dist/842.js.map +0 -1
- /package/dist/{500.js.LICENSE.txt → 304.js.LICENSE.txt} +0 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
import React, { useState } from "react";
|
2
|
+
import { z } from "zod";
|
3
|
+
import { useForm, Controller } from "react-hook-form";
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
5
|
+
import {
|
6
|
+
Button,
|
7
|
+
ComposedModal,
|
8
|
+
FormGroup,
|
9
|
+
ModalBody,
|
10
|
+
ModalFooter,
|
11
|
+
ModalHeader,
|
12
|
+
Stack,
|
13
|
+
TextInput,
|
14
|
+
InlineNotification,
|
15
|
+
FilterableMultiSelect,
|
16
|
+
InlineLoading,
|
17
|
+
} from "@carbon/react";
|
18
|
+
import { useTranslation } from "react-i18next";
|
19
|
+
import { locationData } from "../stock-items/types";
|
20
|
+
import styles from "./stock-locations-table.scss";
|
21
|
+
import { useLocationTags } from "./stock-locations-table.resource";
|
22
|
+
|
23
|
+
const LocationAdministrationSchema = z.object({
|
24
|
+
name: z.string().max(255),
|
25
|
+
});
|
26
|
+
|
27
|
+
interface LocationAdministrationFormProps {
|
28
|
+
showModal: boolean;
|
29
|
+
onModalChange: (showModal: boolean) => void;
|
30
|
+
handleCreateQuestion?: (formData: locationData) => void;
|
31
|
+
handleDeleteBedTag?: () => void;
|
32
|
+
headerTitle: string;
|
33
|
+
initialData: locationData;
|
34
|
+
}
|
35
|
+
|
36
|
+
interface ErrorType {
|
37
|
+
message: string;
|
38
|
+
}
|
39
|
+
|
40
|
+
const LocationAdministrationForm: React.FC<LocationAdministrationFormProps> = ({
|
41
|
+
showModal,
|
42
|
+
onModalChange,
|
43
|
+
handleCreateQuestion,
|
44
|
+
headerTitle,
|
45
|
+
initialData,
|
46
|
+
}) => {
|
47
|
+
const { t } = useTranslation();
|
48
|
+
|
49
|
+
const [showErrorNotification, setShowErrorNotification] = useState(false);
|
50
|
+
const [formStateError, setFormStateError] = useState("");
|
51
|
+
|
52
|
+
// Location tag types
|
53
|
+
const { locationTagList: Tags, loading: loadingRoles } = useLocationTags();
|
54
|
+
|
55
|
+
const {
|
56
|
+
handleSubmit,
|
57
|
+
control,
|
58
|
+
getValues,
|
59
|
+
formState: { isDirty },
|
60
|
+
} = useForm<locationData>({
|
61
|
+
mode: "all",
|
62
|
+
resolver: zodResolver(LocationAdministrationSchema),
|
63
|
+
defaultValues: {
|
64
|
+
name: initialData.name || "",
|
65
|
+
tags: initialData.tags || [],
|
66
|
+
},
|
67
|
+
});
|
68
|
+
|
69
|
+
const onSubmit = (formData: locationData) => {
|
70
|
+
const formDataFormSubmission = getValues();
|
71
|
+
const locationTagsUuid =
|
72
|
+
formDataFormSubmission?.tags?.["selectedItems"]?.map((tag) => tag.uuid) ??
|
73
|
+
[];
|
74
|
+
|
75
|
+
const payload = {
|
76
|
+
name: formDataFormSubmission.name,
|
77
|
+
tags: locationTagsUuid,
|
78
|
+
};
|
79
|
+
const result = LocationAdministrationSchema.safeParse(formData);
|
80
|
+
if (result.success) {
|
81
|
+
setShowErrorNotification(false);
|
82
|
+
handleCreateQuestion(payload);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
|
86
|
+
const onError = (error: { [key: string]: ErrorType }) => {
|
87
|
+
setFormStateError(Object.entries(error)[0][1].message);
|
88
|
+
setShowErrorNotification(true);
|
89
|
+
};
|
90
|
+
|
91
|
+
return (
|
92
|
+
<ComposedModal
|
93
|
+
open={showModal}
|
94
|
+
onClose={() => onModalChange(false)}
|
95
|
+
preventCloseOnClickOutside
|
96
|
+
size={"md"}
|
97
|
+
>
|
98
|
+
<ModalHeader title={headerTitle} />
|
99
|
+
<form onSubmit={handleSubmit(onSubmit, onError)}>
|
100
|
+
<ModalBody hasScrollingContent>
|
101
|
+
<Stack gap={3}>
|
102
|
+
<FormGroup legendText={""}>
|
103
|
+
<Controller
|
104
|
+
name="name"
|
105
|
+
control={control}
|
106
|
+
rules={{ required: true }}
|
107
|
+
render={({ field, fieldState }) => (
|
108
|
+
<>
|
109
|
+
<TextInput
|
110
|
+
id="location"
|
111
|
+
labelText={t("location", "Location Name")}
|
112
|
+
placeholder={t("locationPlaceholder", "Add a location")}
|
113
|
+
invalidText={fieldState.error?.message}
|
114
|
+
{...field}
|
115
|
+
/>
|
116
|
+
</>
|
117
|
+
)}
|
118
|
+
/>
|
119
|
+
<div className={styles.loaderContainer}>
|
120
|
+
<Controller
|
121
|
+
name="tags"
|
122
|
+
control={control}
|
123
|
+
render={({ field, fieldState }) => (
|
124
|
+
<FilterableMultiSelect
|
125
|
+
id="tag"
|
126
|
+
titleText="Select tag(s)"
|
127
|
+
helperText="This is helper text"
|
128
|
+
items={Tags ?? []}
|
129
|
+
{...field}
|
130
|
+
itemToString={(item) => (item ? item.display : "")}
|
131
|
+
selectionFeedback="top-after-reopen"
|
132
|
+
/>
|
133
|
+
)}
|
134
|
+
/>
|
135
|
+
</div>
|
136
|
+
</FormGroup>
|
137
|
+
|
138
|
+
{showErrorNotification && (
|
139
|
+
<InlineNotification
|
140
|
+
lowContrast
|
141
|
+
title={t("error", "Error")}
|
142
|
+
style={{ minWidth: "100%", margin: "0rem", padding: "0rem" }}
|
143
|
+
role="alert"
|
144
|
+
kind="error"
|
145
|
+
subtitle={t("pleaseFillField", formStateError) + "."}
|
146
|
+
onClose={() => setShowErrorNotification(false)}
|
147
|
+
/>
|
148
|
+
)}
|
149
|
+
</Stack>
|
150
|
+
</ModalBody>
|
151
|
+
<ModalFooter>
|
152
|
+
<Button onClick={() => onModalChange(false)} kind="secondary">
|
153
|
+
{t("cancel", "Cancel")}
|
154
|
+
</Button>
|
155
|
+
<Button disabled={!isDirty} type="submit">
|
156
|
+
<span>{t("save", "Save")}</span>
|
157
|
+
</Button>
|
158
|
+
</ModalFooter>
|
159
|
+
</form>
|
160
|
+
</ComposedModal>
|
161
|
+
);
|
162
|
+
};
|
163
|
+
|
164
|
+
export default LocationAdministrationForm;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React from "react";
|
1
|
+
import React, { useMemo, useState } from "react";
|
2
2
|
import { useStockLocationPages } from "./stock-locations-table.resource";
|
3
3
|
import {
|
4
4
|
Button,
|
@@ -12,6 +12,9 @@ import styles from "../stock-items/stock-items-table.scss";
|
|
12
12
|
import { ResourceRepresentation } from "../core/api/api";
|
13
13
|
import DataList from "../core/components/table/table.component";
|
14
14
|
import { useTranslation } from "react-i18next";
|
15
|
+
import { mutate } from "swr";
|
16
|
+
import NewLocationForm from "./add-locations-form.component";
|
17
|
+
import { Add } from "@carbon/react/icons";
|
15
18
|
|
16
19
|
interface StockLocationsTableProps {
|
17
20
|
status?: string;
|
@@ -20,20 +23,29 @@ interface StockLocationsTableProps {
|
|
20
23
|
const StockLocationsItems: React.FC<StockLocationsTableProps> = () => {
|
21
24
|
const { t } = useTranslation();
|
22
25
|
|
23
|
-
const
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
const [showLocationModal, setAddLocationModal] = useState(false);
|
27
|
+
|
28
|
+
const { tableHeaders, tableRows, items, isLoading } = useStockLocationPages({
|
29
|
+
v: ResourceRepresentation.Full,
|
30
|
+
});
|
27
31
|
|
28
32
|
const handleRefresh = () => {
|
29
33
|
// search.refetch()
|
30
34
|
};
|
31
35
|
|
32
|
-
const
|
33
|
-
|
36
|
+
const createStockLocation = () => {
|
37
|
+
{
|
38
|
+
showLocationModal ? (
|
39
|
+
<NewLocationForm
|
40
|
+
onModalChange={setAddLocationModal}
|
41
|
+
showModal={showLocationModal}
|
42
|
+
mutate={mutate}
|
43
|
+
/>
|
44
|
+
) : null;
|
45
|
+
}
|
34
46
|
};
|
35
47
|
|
36
|
-
if (
|
48
|
+
if (isLoading) {
|
37
49
|
return <DataTableSkeleton role="progressbar" />;
|
38
50
|
}
|
39
51
|
|
@@ -48,8 +60,19 @@ const StockLocationsItems: React.FC<StockLocationsTableProps> = () => {
|
|
48
60
|
Refresh
|
49
61
|
</TableToolbarAction>
|
50
62
|
</TableToolbarMenu>
|
51
|
-
|
52
|
-
|
63
|
+
{showLocationModal ? (
|
64
|
+
<NewLocationForm
|
65
|
+
onModalChange={setAddLocationModal}
|
66
|
+
showModal={showLocationModal}
|
67
|
+
mutate={mutate}
|
68
|
+
/>
|
69
|
+
) : null}
|
70
|
+
<Button
|
71
|
+
kind="ghost"
|
72
|
+
renderIcon={(props) => <Add size={16} {...props} />}
|
73
|
+
onClick={() => setAddLocationModal(true)}
|
74
|
+
>
|
75
|
+
{t("createLocation", "Create Location")}
|
53
76
|
</Button>
|
54
77
|
</>
|
55
78
|
)}
|
@@ -1,12 +1,22 @@
|
|
1
1
|
import { StockOperationFilter } from "../stock-operations/stock-operations.resource";
|
2
2
|
import { useMemo, useState } from "react";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
FetchResponse,
|
5
|
+
openmrsFetch,
|
6
|
+
restBaseUrl,
|
7
|
+
showToast,
|
8
|
+
usePagination,
|
9
|
+
} from "@openmrs/esm-framework";
|
4
10
|
import { useTranslation } from "react-i18next";
|
5
|
-
import {
|
11
|
+
import {
|
12
|
+
useStockLocations,
|
13
|
+
useStockTagLocations,
|
14
|
+
} from "../stock-lookups/stock-lookups.resource";
|
15
|
+
import useSWR from "swr";
|
16
|
+
import { extractErrorMessagesFromResponse } from "../constants";
|
6
17
|
|
7
18
|
export function useStockLocationPages(filter: StockOperationFilter) {
|
8
|
-
const {
|
9
|
-
useStockLocations(filter);
|
19
|
+
const { stockLocations, error, isLoading } = useStockTagLocations();
|
10
20
|
|
11
21
|
const pageSizes = [10, 20, 30, 40, 50];
|
12
22
|
const [currentPageSize, setPageSize] = useState(10);
|
@@ -15,7 +25,7 @@ export function useStockLocationPages(filter: StockOperationFilter) {
|
|
15
25
|
goTo,
|
16
26
|
results: paginatedQueueEntries,
|
17
27
|
currentPage,
|
18
|
-
} = usePagination(
|
28
|
+
} = usePagination(stockLocations, currentPageSize);
|
19
29
|
|
20
30
|
const { t } = useTranslation();
|
21
31
|
|
@@ -46,28 +56,73 @@ export function useStockLocationPages(filter: StockOperationFilter) {
|
|
46
56
|
);
|
47
57
|
|
48
58
|
const tableRows = useMemo(() => {
|
49
|
-
return
|
59
|
+
return stockLocations.map((location) => ({
|
50
60
|
id: location?.uuid,
|
51
61
|
key: `key-${location?.uuid}`,
|
52
62
|
uuid: `${location?.uuid}`,
|
53
63
|
name: `${location?.name}`,
|
54
|
-
tags:
|
64
|
+
tags:
|
65
|
+
location?.meta.tag
|
66
|
+
?.filter((tag) => tag.code !== "SUBSETTED")
|
67
|
+
.map((p) => p.code)
|
68
|
+
?.join(", ") ?? "",
|
55
69
|
childLocations:
|
56
70
|
location?.childLocations?.map((p) => p.display)?.join(", ") ?? "",
|
57
71
|
}));
|
58
|
-
}, [
|
59
|
-
|
72
|
+
}, [stockLocations]);
|
60
73
|
return {
|
61
|
-
items:
|
74
|
+
items: stockLocations,
|
62
75
|
currentPage,
|
63
76
|
currentPageSize,
|
64
77
|
paginatedQueueEntries,
|
65
78
|
goTo,
|
66
79
|
pageSizes,
|
67
|
-
|
68
|
-
|
80
|
+
isLoading,
|
81
|
+
error,
|
69
82
|
setPageSize,
|
70
83
|
tableHeaders,
|
71
84
|
tableRows,
|
72
85
|
};
|
73
86
|
}
|
87
|
+
|
88
|
+
export const useLocationTags = () => {
|
89
|
+
const url = `${restBaseUrl}/locationtag/`;
|
90
|
+
|
91
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
92
|
+
const { data, error, isLoading, isValidating, mutate } = useSWR<
|
93
|
+
{ data },
|
94
|
+
Error
|
95
|
+
>(url, openmrsFetch);
|
96
|
+
const results = data?.data?.results ? data?.data?.results : [];
|
97
|
+
return {
|
98
|
+
locationTagList: results,
|
99
|
+
loading: isLoading,
|
100
|
+
mutate,
|
101
|
+
};
|
102
|
+
};
|
103
|
+
interface LocationName {
|
104
|
+
name: string;
|
105
|
+
}
|
106
|
+
export async function saveLocation({
|
107
|
+
locationPayload,
|
108
|
+
}): Promise<FetchResponse<LocationName>> {
|
109
|
+
try {
|
110
|
+
const response: FetchResponse = await openmrsFetch(
|
111
|
+
`${restBaseUrl}/location/`,
|
112
|
+
{
|
113
|
+
method: "POST",
|
114
|
+
headers: { "Content-Type": "application/json" },
|
115
|
+
body: locationPayload,
|
116
|
+
}
|
117
|
+
);
|
118
|
+
return response;
|
119
|
+
} catch (error) {
|
120
|
+
const errorMessages = extractErrorMessagesFromResponse(error);
|
121
|
+
showToast({
|
122
|
+
description: errorMessages.join(", "),
|
123
|
+
title: "Error on saving form",
|
124
|
+
kind: "error",
|
125
|
+
critical: true,
|
126
|
+
});
|
127
|
+
}
|
128
|
+
}
|
@@ -41,7 +41,7 @@ interface FHIRResponse {
|
|
41
41
|
|
42
42
|
// getLocations
|
43
43
|
export function useStockLocations(filter: LocationFilterCriteria) {
|
44
|
-
const apiUrl =
|
44
|
+
const apiUrl = `${restBaseUrl}/location${toQueryParams(filter, false)}`;
|
45
45
|
const { data, error, isLoading } = useSWR<
|
46
46
|
{
|
47
47
|
data: PageableResult<OpenMRSLocation>;
|
@@ -76,7 +76,7 @@ export function useStockTagLocations() {
|
|
76
76
|
|
77
77
|
// getLocationWithIdByUuid
|
78
78
|
export function useLocationWithIdByUuid(id: string) {
|
79
|
-
const apiUrl =
|
79
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/location/${id}`;
|
80
80
|
const { data, error, isLoading } = useSWR<
|
81
81
|
{
|
82
82
|
data: PageableResult<OpenMRSLocation>;
|
@@ -92,7 +92,7 @@ export function useLocationWithIdByUuid(id: string) {
|
|
92
92
|
|
93
93
|
// deleteLocation
|
94
94
|
export function deleteLocation(id: string) {
|
95
|
-
const apiUrl =
|
95
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/location/${id}`;
|
96
96
|
const abortController = new AbortController();
|
97
97
|
return openmrsFetch(apiUrl, {
|
98
98
|
method: "DELETE",
|
@@ -105,7 +105,7 @@ export function deleteLocation(id: string) {
|
|
105
105
|
|
106
106
|
// getLocationTags
|
107
107
|
export function useLocationTags(q: string) {
|
108
|
-
const apiUrl =
|
108
|
+
const apiUrl = `${restBaseUrl}/locationtag?v=default${
|
109
109
|
q && q.length > 0 ? "&q=" + encodeURIComponent(q) : ""
|
110
110
|
}`;
|
111
111
|
const { data, error, isLoading } = useSWR<
|
@@ -123,7 +123,7 @@ export function useLocationTags(q: string) {
|
|
123
123
|
|
124
124
|
// getRoles
|
125
125
|
export function useRoles(filter: ResourceFilterCriteria) {
|
126
|
-
const apiUrl =
|
126
|
+
const apiUrl = `${restBaseUrl}/role${toQueryParams(filter)}`;
|
127
127
|
const { data, error, isLoading } = useSWR<
|
128
128
|
{
|
129
129
|
data: PageableResult<Role>;
|
@@ -139,7 +139,7 @@ export function useRoles(filter: ResourceFilterCriteria) {
|
|
139
139
|
|
140
140
|
// getStockOperationTypes
|
141
141
|
export function useStockOperationTypes() {
|
142
|
-
const apiUrl =
|
142
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationtype?v=default`;
|
143
143
|
const { data, isLoading, error } = useSWR<
|
144
144
|
{
|
145
145
|
data: PageableResult<StockOperationType>;
|
@@ -156,13 +156,13 @@ export function useStockOperationTypes() {
|
|
156
156
|
export function getStockOperationTypes(): Promise<
|
157
157
|
FetchResponse<PageableResult<StockOperationType>>
|
158
158
|
> {
|
159
|
-
const apiUrl =
|
159
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationtype?v=default`;
|
160
160
|
return openmrsFetch(apiUrl);
|
161
161
|
}
|
162
162
|
|
163
163
|
// getUsers
|
164
164
|
export function useUsers(filter: UserFilterCriteria) {
|
165
|
-
const apiUrl =
|
165
|
+
const apiUrl = `${restBaseUrl}/user${toQueryParams(filter)}`;
|
166
166
|
const { data, error, isLoading } = useSWR<
|
167
167
|
{
|
168
168
|
data: PageableResult<User>;
|
@@ -178,7 +178,7 @@ export function useUsers(filter: UserFilterCriteria) {
|
|
178
178
|
|
179
179
|
// getUser
|
180
180
|
export function useUser(id: string) {
|
181
|
-
const apiUrl =
|
181
|
+
const apiUrl = `${restBaseUrl}/user${id}`;
|
182
182
|
const { data, error, isLoading } = useSWR<
|
183
183
|
{
|
184
184
|
data: User;
|
@@ -193,7 +193,7 @@ export function useUser(id: string) {
|
|
193
193
|
}
|
194
194
|
|
195
195
|
export function useConcept(conceptUuid: string) {
|
196
|
-
const apiUrl =
|
196
|
+
const apiUrl = `${restBaseUrl}/concept/${conceptUuid}`;
|
197
197
|
const { data, error, isLoading } = useSWR<
|
198
198
|
{
|
199
199
|
data: Concept;
|
@@ -209,7 +209,7 @@ export function useConcept(conceptUuid: string) {
|
|
209
209
|
|
210
210
|
// getParties
|
211
211
|
export function useParties() {
|
212
|
-
const apiUrl =
|
212
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/party?v=default`;
|
213
213
|
const { data, error, isLoading } = useSWR<
|
214
214
|
{
|
215
215
|
data: PageableResult<Party>;
|
@@ -224,13 +224,13 @@ export function useParties() {
|
|
224
224
|
}
|
225
225
|
|
226
226
|
export function getParties(): Promise<FetchResponse<PageableResult<Party>>> {
|
227
|
-
const apiUrl =
|
227
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/party?v=default`;
|
228
228
|
return openmrsFetch(apiUrl);
|
229
229
|
}
|
230
230
|
|
231
231
|
// getDrugs
|
232
232
|
export function useDrugs(filter: DrugFilterCriteria) {
|
233
|
-
const apiUrl =
|
233
|
+
const apiUrl = `${restBaseUrl}/drug${toQueryParams(filter)}`;
|
234
234
|
const { data, error, isLoading } = useSWR<
|
235
235
|
{
|
236
236
|
data: PageableResult<Drug>;
|
@@ -246,7 +246,7 @@ export function useDrugs(filter: DrugFilterCriteria) {
|
|
246
246
|
|
247
247
|
// getConcepts
|
248
248
|
export function useConcepts(filter: ConceptFilterCriteria) {
|
249
|
-
const apiUrl =
|
249
|
+
const apiUrl = `${restBaseUrl}/concept${toQueryParams(filter)}`;
|
250
250
|
const { data, error, isLoading } = useSWR<
|
251
251
|
{
|
252
252
|
data: PageableResult<Concept>;
|
@@ -262,7 +262,7 @@ export function useConcepts(filter: ConceptFilterCriteria) {
|
|
262
262
|
|
263
263
|
// getPatients
|
264
264
|
export function usePatients(filter: ConceptFilterCriteria) {
|
265
|
-
const apiUrl =
|
265
|
+
const apiUrl = `${restBaseUrl}/patient${toQueryParams(filter)}`;
|
266
266
|
const { data, error, isLoading } = useSWR<
|
267
267
|
{
|
268
268
|
data: PageableResult<Patient>;
|
@@ -22,7 +22,12 @@ import StockOperationApproveDispatchButton from "../stock-operations-dialog/stoc
|
|
22
22
|
import StockOperationCompleteDispatchButton from "../stock-operations-dialog/stock-operations-completed-dispatch-button.component";
|
23
23
|
import StockOperationIssueStockButton from "../stock-operations-dialog/stock-operations-issue-stock-button.component";
|
24
24
|
import { StockOperation } from "./stock-operation-context/useStockOperationContext";
|
25
|
-
import {
|
25
|
+
import {
|
26
|
+
formatDate,
|
27
|
+
parseDate,
|
28
|
+
showSnackbar,
|
29
|
+
showToast,
|
30
|
+
} from "@openmrs/esm-framework";
|
26
31
|
import {
|
27
32
|
OperationType,
|
28
33
|
StockOperationType,
|
@@ -43,12 +48,12 @@ const AddStockOperation: React.FC<AddStockOperationProps> = (props) => {
|
|
43
48
|
if (isLoading) return <AccordionSkeleton />;
|
44
49
|
if (isError) {
|
45
50
|
closeOverlay();
|
46
|
-
|
51
|
+
showSnackbar({
|
47
52
|
kind: "error",
|
48
53
|
title: t("error", "Error"),
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
subtitle: t("errorLoadingStockOperation", "Error loading stock item"),
|
55
|
+
timeoutInMs: 5000,
|
56
|
+
isLowContrast: true,
|
52
57
|
});
|
53
58
|
return;
|
54
59
|
}
|
@@ -1,4 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
FetchResponse,
|
3
|
+
openmrsFetch,
|
4
|
+
restBaseUrl,
|
5
|
+
} from "@openmrs/esm-framework";
|
2
6
|
import useSWR from "swr";
|
3
7
|
import { ResourceFilterCriteria, toQueryParams } from "../core/api/api";
|
4
8
|
import { PageableResult } from "../core/api/types/PageableResult";
|
@@ -34,7 +38,7 @@ export interface StockItemInventoryFilter extends ResourceFilterCriteria {
|
|
34
38
|
|
35
39
|
// getStockOperations
|
36
40
|
export function useStockOperations(filter: StockOperationFilter) {
|
37
|
-
const apiUrl =
|
41
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation${toQueryParams(
|
38
42
|
filter
|
39
43
|
)}`;
|
40
44
|
const { data, error, isLoading } = useSWR<
|
@@ -51,7 +55,7 @@ export function useStockOperations(filter: StockOperationFilter) {
|
|
51
55
|
|
52
56
|
// getStockOperationLinks
|
53
57
|
export function useStockOperationLinks(filter: string) {
|
54
|
-
const apiUrl =
|
58
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationlink?v=default&q=${filter}`;
|
55
59
|
const { data, error, isLoading } = useSWR<
|
56
60
|
{ data: PageableResult<StockOperationLinkDTO> },
|
57
61
|
Error
|
@@ -65,7 +69,7 @@ export function useStockOperationLinks(filter: string) {
|
|
65
69
|
|
66
70
|
// getStockOperation
|
67
71
|
export function useStockOperation(id: string) {
|
68
|
-
const apiUrl =
|
72
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${id}`;
|
69
73
|
const { data, error, isLoading } = useSWR<{ data: StockOperationDTO }, Error>(
|
70
74
|
apiUrl,
|
71
75
|
openmrsFetch
|
@@ -79,14 +83,14 @@ export function useStockOperation(id: string) {
|
|
79
83
|
export function getStockOperation(
|
80
84
|
id: string
|
81
85
|
): Promise<FetchResponse<StockOperationDTO>> {
|
82
|
-
const apiUrl =
|
86
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${id}?v=full`;
|
83
87
|
|
84
88
|
return openmrsFetch(apiUrl);
|
85
89
|
}
|
86
90
|
|
87
91
|
// getStockOperationAndItems
|
88
92
|
export function useStockOperationAndItems(id: string) {
|
89
|
-
const apiUrl =
|
93
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${id}?v=full`;
|
90
94
|
const { data, error, isLoading } = useSWR<{ data: StockOperationDTO }, Error>(
|
91
95
|
apiUrl,
|
92
96
|
openmrsFetch
|
@@ -108,7 +112,7 @@ export function deleteStockOperations(ids: string[]) {
|
|
108
112
|
if (otherIds.length > 0) {
|
109
113
|
otherIds = "?ids=" + otherIds;
|
110
114
|
}
|
111
|
-
const apiUrl =
|
115
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${ids[0]}${otherIds}`;
|
112
116
|
const abortController = new AbortController();
|
113
117
|
return openmrsFetch(apiUrl, {
|
114
118
|
method: "DELETE",
|
@@ -121,7 +125,7 @@ export function deleteStockOperations(ids: string[]) {
|
|
121
125
|
|
122
126
|
// deleteStockOperationItem
|
123
127
|
export function deleteStockOperationItem(id: string) {
|
124
|
-
const apiUrl =
|
128
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationitem/${id}`;
|
125
129
|
const abortController = new AbortController();
|
126
130
|
return openmrsFetch(apiUrl, {
|
127
131
|
method: "DELETE",
|
@@ -134,7 +138,7 @@ export function deleteStockOperationItem(id: string) {
|
|
134
138
|
|
135
139
|
// createStockOperation
|
136
140
|
export function createStockOperation(item: StockOperationDTO) {
|
137
|
-
const apiUrl =
|
141
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation`;
|
138
142
|
const abortController = new AbortController();
|
139
143
|
return openmrsFetch(apiUrl, {
|
140
144
|
method: "POST",
|
@@ -148,7 +152,7 @@ export function createStockOperation(item: StockOperationDTO) {
|
|
148
152
|
|
149
153
|
// updateStockOperation
|
150
154
|
export function updateStockOperation(item: StockOperationDTO) {
|
151
|
-
const apiUrl =
|
155
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperation/${item.uuid}`;
|
152
156
|
const abortController = new AbortController();
|
153
157
|
return openmrsFetch(apiUrl, {
|
154
158
|
method: "POST",
|
@@ -162,7 +166,7 @@ export function updateStockOperation(item: StockOperationDTO) {
|
|
162
166
|
|
163
167
|
// executeStockOperationAction
|
164
168
|
export function executeStockOperationAction(item: StopOperationAction) {
|
165
|
-
const apiUrl =
|
169
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationaction`;
|
166
170
|
const abortController = new AbortController();
|
167
171
|
return openmrsFetch(apiUrl, {
|
168
172
|
method: "POST",
|
@@ -179,7 +183,7 @@ export function updateStockOperationBatchNumbers(
|
|
179
183
|
item: StockOperationDTO,
|
180
184
|
uuid: string
|
181
185
|
) {
|
182
|
-
const apiUrl =
|
186
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationbatchnumbers/${uuid}`;
|
183
187
|
const abortController = new AbortController();
|
184
188
|
return openmrsFetch(apiUrl, {
|
185
189
|
method: "POST",
|
@@ -193,7 +197,7 @@ export function updateStockOperationBatchNumbers(
|
|
193
197
|
|
194
198
|
// get stock operation itemcosts
|
195
199
|
export function getStockOperationItemsCost(filter: StockOperationFilter) {
|
196
|
-
const apiUrl =
|
200
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockoperationitemcost?v=default&stockOperationUuid=${filter}`;
|
197
201
|
const abortController = new AbortController();
|
198
202
|
return openmrsFetch(apiUrl, {
|
199
203
|
method: "GET",
|
@@ -205,7 +209,7 @@ export function getStockOperationItemsCost(filter: StockOperationFilter) {
|
|
205
209
|
}
|
206
210
|
// get stockiteminvoentory
|
207
211
|
export function getStockItemInventory(filter: StockItemInventoryFilter) {
|
208
|
-
const apiUrl =
|
212
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stockiteminventory${toQueryParams(
|
209
213
|
filter
|
210
214
|
)}`;
|
211
215
|
const abortController = new AbortController();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { openmrsFetch } from "@openmrs/esm-framework";
|
1
|
+
import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework";
|
2
2
|
import { ResourceFilterCriteria, toQueryParams } from "../core/api/api";
|
3
3
|
import useSWR from "swr";
|
4
4
|
import { PageableResult } from "../core/api/types/PageableResult";
|
@@ -10,7 +10,7 @@ export interface StockSourceFilter extends ResourceFilterCriteria {
|
|
10
10
|
|
11
11
|
// getStockSources
|
12
12
|
export function useStockSources(filter: StockSourceFilter) {
|
13
|
-
const apiUrl =
|
13
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stocksource${toQueryParams(
|
14
14
|
filter
|
15
15
|
)}`;
|
16
16
|
|
@@ -28,7 +28,7 @@ export function useStockSources(filter: StockSourceFilter) {
|
|
28
28
|
|
29
29
|
// getStockSource
|
30
30
|
export function useStockSource(id: string) {
|
31
|
-
const apiUrl =
|
31
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stocksource/${id}`;
|
32
32
|
const { data, error, isLoading } = useSWR<{ data: StockSource }, Error>(
|
33
33
|
apiUrl,
|
34
34
|
openmrsFetch
|
@@ -50,7 +50,7 @@ export function deleteStockSource(ids: string[]) {
|
|
50
50
|
if (otherIds.length > 0) {
|
51
51
|
otherIds = "?ids=" + otherIds;
|
52
52
|
}
|
53
|
-
const apiUrl =
|
53
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stocksource/${ids[0]}${otherIds}`;
|
54
54
|
const abortController = new AbortController();
|
55
55
|
return openmrsFetch(apiUrl, {
|
56
56
|
method: "DELETE",
|
@@ -65,7 +65,7 @@ export function deleteStockSource(ids: string[]) {
|
|
65
65
|
export function createOrUpdateStockSource(item: StockSource) {
|
66
66
|
const isNew = item.uuid != null;
|
67
67
|
|
68
|
-
const apiUrl =
|
68
|
+
const apiUrl = `${restBaseUrl}/stockmanagement/stocksource${
|
69
69
|
isNew ? "/" + item.uuid : ""
|
70
70
|
}`;
|
71
71
|
const abortController = new AbortController();
|