Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) O3-3373: Add ability to mark fulfiller status as completed when saving test results #74

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CompletedLabRequestsTable: React.FC = () => {
return (
<OrdersDataTable
fulfillerStatus="COMPLETED"
excludeColumns={["actions"]}
excludeColumns={["actions", "action"]}
excludeCanceledAndDiscontinuedOrders={false}
/>
);
Expand Down
92 changes: 68 additions & 24 deletions src/results/result-form.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { useTranslation } from "react-i18next";
import { closeOverlay } from "../components/overlay/store";
import {
ExtensionSlot,
restBaseUrl,
showNotification,
showSnackbar,
useConfig,
useLayoutType,
usePatient,
} from "@openmrs/esm-framework";
Expand All @@ -18,6 +20,9 @@ import ResultFormField from "./result-form-field.component";
import { useForm } from "react-hook-form";
import { Order } from "@openmrs/esm-patient-common-lib";
import Loader from "../components/loader/loader.component";
import { setFulfillerStatus } from "../laboratory-resource";
import { mutate } from "swr";
import { Config } from "../config-schema";

interface ResultFormProps {
patientUuid: string;
Expand All @@ -26,6 +31,7 @@ interface ResultFormProps {

const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
const { t } = useTranslation();
const { laboratoryOrderTypeUuid } = useConfig<Config>();
const {
control,
register,
Expand Down Expand Up @@ -123,30 +129,68 @@ const ResultForm: React.FC<ResultFormProps> = ({ order, patientUuid }) => {
order.encounter.uuid,
obsPayload,
orderDiscontinuationPayload
).then(
() => {
showSnackbar({
isLowContrast: true,
title: t("updateEncounter", "Update lab results"),
kind: "success",
subtitle: t(
"generateSuccessfully",
"You have successfully updated test results"
),
});
closeOverlay();
},
(err) => {
showNotification({
title: t(
`errorUpdatingEncounter', 'Error occurred while updating test results`
),
kind: "error",
critical: true,
description: err?.message,
});
}
);
)
.then(
(resp) => {
showSnackbar({
isLowContrast: true,
title: t("updateEncounter", "Update lab results"),
kind: "success",
subtitle: t(
"generateSuccessfully",
"You have successfully updated test results"
),
});
return resp;
},
(err) => {
showNotification({
title: t(
`errorUpdatingEncounter', 'Error occurred while updating test results`
),
kind: "error",
critical: true,
description: err?.message,
});
}
)
.then((resp) => {
const abortController = new AbortController();
setFulfillerStatus(order.uuid, "COMPLETED", abortController).then(
() => {
showSnackbar({
isLowContrast: true,
title: t("markOrderFulfillStatus", "Test order completed"),
kind: "success",
subtitle: t(
"testOrderCompletedSuccessfully",
"You have successfully completed the test order"
),
});
mutate(
(key) =>
typeof key === "string" &&
key.startsWith(
`${restBaseUrl}/order?orderTypes=${laboratoryOrderTypeUuid}`
),
undefined,
{ revalidate: true }
);
closeOverlay();
},
(err) => {
showNotification({
title: t(
`errorMarkingOrderFulfillStatus`,
"Error occurred while marking order fulfill status"
),
kind: "error",
critical: true,
description: err?.message,
});
}
);
});
};
if (isLoadingPatient || isLoadingConcepts) {
return <Loader />;
Expand Down
Loading