From d1fbce808ce78fc0daa61aba2a601f8ecf09a09a Mon Sep 17 00:00:00 2001 From: Donald Kibet Date: Wed, 5 Jun 2024 20:27:21 +0300 Subject: [PATCH] (feat) O3-3373: Add ability to mark fulfiller status as completed when saving test results --- ...completed-lab-requests-table.extension.tsx | 2 +- src/results/result-form.component.tsx | 92 ++++++++++++++----- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/src/lab-tabs/data-table-extensions/completed-lab-requests-table.extension.tsx b/src/lab-tabs/data-table-extensions/completed-lab-requests-table.extension.tsx index e690b47d..3ca20cd9 100644 --- a/src/lab-tabs/data-table-extensions/completed-lab-requests-table.extension.tsx +++ b/src/lab-tabs/data-table-extensions/completed-lab-requests-table.extension.tsx @@ -5,7 +5,7 @@ const CompletedLabRequestsTable: React.FC = () => { return ( ); diff --git a/src/results/result-form.component.tsx b/src/results/result-form.component.tsx index 40d39cf1..ce944b13 100644 --- a/src/results/result-form.component.tsx +++ b/src/results/result-form.component.tsx @@ -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"; @@ -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; @@ -26,6 +31,7 @@ interface ResultFormProps { const ResultForm: React.FC = ({ order, patientUuid }) => { const { t } = useTranslation(); + const { laboratoryOrderTypeUuid } = useConfig(); const { control, register, @@ -123,30 +129,68 @@ const ResultForm: React.FC = ({ 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 ;