diff --git a/src/patient-chart/laboratory-active-test-order/laboratory-active-test-order-results.component.tsx b/src/patient-chart/laboratory-active-test-order/laboratory-active-test-order-results.component.tsx index a3309965..18443848 100644 --- a/src/patient-chart/laboratory-active-test-order/laboratory-active-test-order-results.component.tsx +++ b/src/patient-chart/laboratory-active-test-order/laboratory-active-test-order-results.component.tsx @@ -81,6 +81,7 @@ const LaboratoryActiveTestOrderResults: React.FC< enableSendingLabTestsByEmail, laboratoryEncounterTypeUuid, artCardEncounterTypeUuid, + laboratoryOrderTypeUuid, } = useConfig(); const displayText = t( @@ -103,15 +104,23 @@ const LaboratoryActiveTestOrderResults: React.FC< return [...items] ?.filter( (item) => - item?.encounterType?.uuid === laboratoryEncounterTypeUuid || - item?.encounterType?.uuid === artCardEncounterTypeUuid + (item?.encounterType?.uuid === laboratoryEncounterTypeUuid || + item?.encounterType?.uuid === artCardEncounterTypeUuid) && + item.orders.filter( + (order) => order.orderType === laboratoryOrderTypeUuid + ) ) ?.sort((a, b) => { const dateA = new Date(a.encounterDatetime); const dateB = new Date(b.encounterDatetime); return dateB.getTime() - dateA.getTime(); }); - }, [artCardEncounterTypeUuid, items, laboratoryEncounterTypeUuid]); + }, [ + artCardEncounterTypeUuid, + items, + laboratoryEncounterTypeUuid, + laboratoryOrderTypeUuid, + ]); const [searchTerm, setSearchTerm] = useState(""); const [laboratoryOrders, setLaboratoryOrders] = useState(sortedLabRequests); diff --git a/src/patient-chart/laboratory-order-referals/laboratory-order-referals.component.tsx b/src/patient-chart/laboratory-order-referals/laboratory-order-referals.component.tsx index 3e6ac986..bf0b9f01 100644 --- a/src/patient-chart/laboratory-order-referals/laboratory-order-referals.component.tsx +++ b/src/patient-chart/laboratory-order-referals/laboratory-order-referals.component.tsx @@ -84,6 +84,7 @@ const LaboratoryOrderReferalResults: React.FC< enableSendingLabTestsByEmail, laboratoryEncounterTypeUuid, artCardEncounterTypeUuid, + laboratoryOrderTypeUuid, } = useConfig(); const displayText = t( @@ -114,14 +115,23 @@ const LaboratoryOrderReferalResults: React.FC< (item) => (item?.encounterType?.uuid === laboratoryEncounterTypeUuid || item?.encounterType?.uuid === artCardEncounterTypeUuid) && - item?.orders?.filter((item) => item?.instructions === "REFER TO cphl") + item?.orders?.filter( + (order) => + order?.instructions === "REFER TO cphl" || + order.orderType === laboratoryOrderTypeUuid + ) ) ?.sort((a, b) => { const dateA = new Date(a.encounterDatetime); const dateB = new Date(b.encounterDatetime); return dateB.getTime() - dateA.getTime(); }); - }, [artCardEncounterTypeUuid, items, laboratoryEncounterTypeUuid]); + }, [ + artCardEncounterTypeUuid, + items, + laboratoryEncounterTypeUuid, + laboratoryOrderTypeUuid, + ]); const [searchTerm, setSearchTerm] = useState(""); const [laboratoryOrders, setLaboratoryOrders] = useState(sortedLabRequests); diff --git a/src/patient-chart/laboratory-past-test/laboratory-past-test-order-results.component.tsx b/src/patient-chart/laboratory-past-test/laboratory-past-test-order-results.component.tsx index 16d06bcd..adc66e01 100644 --- a/src/patient-chart/laboratory-past-test/laboratory-past-test-order-results.component.tsx +++ b/src/patient-chart/laboratory-past-test/laboratory-past-test-order-results.component.tsx @@ -78,6 +78,7 @@ const LaboratoryPastTestOrderResults: React.FC< enableSendingLabTestsByEmail, laboratoryEncounterTypeUuid, artCardEncounterTypeUuid, + laboratoryOrderTypeUuid, } = useConfig(); const displayText = t( @@ -98,15 +99,23 @@ const LaboratoryPastTestOrderResults: React.FC< return [...items] ?.filter( (item) => - item?.encounterType?.uuid === laboratoryEncounterTypeUuid || - item?.encounterType?.uuid === artCardEncounterTypeUuid + (item?.encounterType?.uuid === laboratoryEncounterTypeUuid || + item?.encounterType?.uuid === artCardEncounterTypeUuid) && + item.orders.filter( + (order) => order.orderType === laboratoryOrderTypeUuid + ) ) ?.sort((a, b) => { const dateA = new Date(a.encounterDatetime); const dateB = new Date(b.encounterDatetime); return dateB.getTime() - dateA.getTime(); }); - }, [artCardEncounterTypeUuid, items, laboratoryEncounterTypeUuid]); + }, [ + artCardEncounterTypeUuid, + items, + laboratoryEncounterTypeUuid, + laboratoryOrderTypeUuid, + ]); const [searchTerm, setSearchTerm] = useState(""); const [laboratoryOrders, setLaboratoryOrders] = useState(sortedLabRequests); diff --git a/src/referred-orders/referred-orders.component.tsx b/src/referred-orders/referred-orders.component.tsx index 3e36c8be..cb9aa11b 100644 --- a/src/referred-orders/referred-orders.component.tsx +++ b/src/referred-orders/referred-orders.component.tsx @@ -55,16 +55,17 @@ const ReferredOrdersList: React.FC = () => { { id: 1, header: t("orderNumber", "Order Number"), key: "orderNumber" }, { id: 2, header: t("patient", "Patient"), key: "patient" }, + { id: 3, header: t("artNumber", "Art Number"), key: "artNumber" }, { - id: 3, + id: 4, header: t("accessionNumber", "Accession Number"), key: "accessionNumber", }, - { id: 4, header: t("test", "Test"), key: "test" }, - { id: 5, header: t("status", "Status"), key: "status" }, - { id: 6, header: t("orderer", "Ordered By"), key: "orderer" }, - { id: 7, header: t("urgency", "Urgency"), key: "urgency" }, + { id: 5, header: t("test", "Test"), key: "test" }, + { id: 6, header: t("status", "Status"), key: "status" }, + { id: 7, header: t("orderer", "Ordered By"), key: "orderer" }, + { id: 8, header: t("urgency", "Urgency"), key: "urgency" }, ]; const tableRows = useMemo(() => { return paginatedReferredOrderEntries.map((entry, index) => ({ @@ -78,6 +79,10 @@ const ReferredOrdersList: React.FC = () => { {entry?.patient?.display.split("-")[1]} ), + artNumber: entry.patient?.identifiers.find( + (item) => + item?.identifierType?.uuid === "e1731641-30ab-102d-86b0-7a5022ba4115" + ).display, orderNumber: entry?.orderNumber, accessionNumber: entry?.accessionNumber, test: entry?.concept?.display, diff --git a/src/reject-order/reject-order-dialog.component.tsx b/src/reject-order/reject-order-dialog.component.tsx index 3a9f4e75..0d2d7387 100644 --- a/src/reject-order/reject-order-dialog.component.tsx +++ b/src/reject-order/reject-order-dialog.component.tsx @@ -2,25 +2,18 @@ import React, { useState } from "react"; import { Button, - ContentSwitcher, Form, ModalBody, ModalFooter, ModalHeader, - Select, - SelectItem, - Switch, TextArea, - Grid, - Checkbox, - TextInput, - IconButton, } from "@carbon/react"; import { useTranslation } from "react-i18next"; import styles from "./reject-order-dialog.scss"; import { Result } from "../work-list/work-list.resource"; import { RejectOrder } from "./reject-order-dialog.resource"; import { showNotification, showSnackbar } from "@openmrs/esm-framework"; +import { extractErrorMessagesFromResponse } from "../utils/functions"; interface RejectOrderDialogProps { order: Result; @@ -39,7 +32,7 @@ const RejectOrderDialog: React.FC = ({ event.preventDefault(); const payload = { - fulfillerStatus: "EXCEPTION", // Todo changed to Declined when UgEMR module is upgraded to 2.6.1 + fulfillerStatus: "DECLINED", // Todo changed to Declined when UgEMR module is upgraded to 2.6.1 fulfillerComment: notes, }; RejectOrder(order.uuid, payload).then( @@ -55,12 +48,14 @@ const RejectOrderDialog: React.FC = ({ }); closeModal(); }, - (err) => { + (error) => { + const errorMessages = extractErrorMessagesFromResponse(error); + showNotification({ title: t(`errorRejecting order', 'Error Rejecting a order`), kind: "error", critical: true, - description: err?.message, + description: errorMessages.join(", "), }); } ); diff --git a/src/reject-order/rejected-tests-list.component.tsx b/src/reject-order/rejected-tests-list.component.tsx index 965dc14a..928437eb 100644 --- a/src/reject-order/rejected-tests-list.component.tsx +++ b/src/reject-order/rejected-tests-list.component.tsx @@ -28,7 +28,7 @@ const RejectedTestsList: React.FC = () => { const { data: pickedOrderList, isLoading } = useGetOrdersWorklist(""); const data = pickedOrderList.filter( - (item) => item?.fulfillerStatus === "EXCEPTION" || item?.action === "REVISE" + (item) => item?.fulfillerStatus === "DECLINED" ); const pageSizes = [10, 20, 30, 40, 50]; @@ -44,12 +44,19 @@ const RejectedTestsList: React.FC = () => { { id: 0, header: t("date", "Date"), key: "date" }, { id: 1, header: t("orderNumber", "Order Number"), key: "orderNumber" }, - { id: 2, header: t("patient", "Patient"), key: "patient" }, - { id: 3, header: t("test", "Test"), key: "test" }, - { id: 4, header: t("orderer", "Ordered By"), key: "orderer" }, - { id: 5, header: t("urgency", "Urgency"), key: "urgency" }, { - id: 6, + id: 2, + header: t("accessionNumber", "Accession Number"), + key: "accessionNumber", + }, + { id: 3, header: t("patient", "Patient"), key: "patient" }, + { id: 4, header: t("artNumber", "Art Number"), key: "artNumber" }, + + { id: 5, header: t("test", "Test"), key: "test" }, + { id: 6, header: t("orderer", "Ordered By"), key: "orderer" }, + { id: 7, header: t("urgency", "Urgency"), key: "urgency" }, + { + id: 8, header: t("fulfillerComment", "Reason for Rejection"), key: "fulfillerComment", }, @@ -65,6 +72,10 @@ const RejectedTestsList: React.FC = () => { ), patient: entry?.patient?.display.split("-")[1], + artNumber: entry.patient?.identifiers.find( + (item) => + item?.identifierType?.uuid === "e1731641-30ab-102d-86b0-7a5022ba4115" + ).display, orderNumber: entry?.orderNumber, accessionNumber: entry?.accessionNumber, test: entry?.concept?.display, diff --git a/src/review-list/dialog/review-item.component.tsx b/src/review-list/dialog/review-item.component.tsx index d1a08956..96149f11 100644 --- a/src/review-list/dialog/review-item.component.tsx +++ b/src/review-list/dialog/review-item.component.tsx @@ -17,6 +17,7 @@ import { useGetConceptById } from "../../patient-chart/results-summary/results-s import { ApproverOrder } from "./review-item.resource"; import { showNotification, showSnackbar } from "@openmrs/esm-framework"; import { Result } from "../../work-list/work-list.resource"; +import { extractErrorMessagesFromResponse } from "../../utils/functions"; interface ReviewItemDialogProps { encounterUuid: string; @@ -43,9 +44,9 @@ const ReviewItem: React.FC = ({ const testsOrder = useMemo(() => { return encounter?.obs?.filter( - (item) => item?.order?.display === orderItem?.display + (item) => item?.order?.display === "Test Order" ); - }, [encounter?.obs, orderItem?.display]); + }, [encounter?.obs]); const filteredGroupedResults = useMemo(() => { let groupedResults = []; @@ -74,12 +75,14 @@ const ReviewItem: React.FC = ({ }); closeModal(); }, - (err) => { + (error) => { + const errorMessages = extractErrorMessagesFromResponse(error); + showNotification({ title: t(`errorApproving order', 'Error Approving a order`), kind: "error", critical: true, - description: err?.message, + description: errorMessages.join(", "), }); } ); diff --git a/src/tests-ordered/lab-dialogs/add-to-worklist-dialog.component.tsx b/src/tests-ordered/lab-dialogs/add-to-worklist-dialog.component.tsx index 43bd8c08..7df68832 100644 --- a/src/tests-ordered/lab-dialogs/add-to-worklist-dialog.component.tsx +++ b/src/tests-ordered/lab-dialogs/add-to-worklist-dialog.component.tsx @@ -26,6 +26,7 @@ import { useSpecimenTypes, } from "./add-to-worklist-dialog.resource"; import { Order } from "../../types/patient-queues"; +import { extractErrorMessagesFromResponse } from "../../utils/functions"; interface AddToWorklistDialogProps { queueId; @@ -85,11 +86,13 @@ const AddToWorklistDialog: React.FC = ({ closeModal(); }, (error) => { + const errorMessages = extractErrorMessagesFromResponse(error); + showNotification({ title: t(`errorPicking an order', 'Error Picking an Order`), kind: "error", critical: true, - description: error?.message, + description: errorMessages.join(", "), }); } ); @@ -115,12 +118,14 @@ const AddToWorklistDialog: React.FC = ({ ), }); }, - (err) => { + (error) => { + const errorMessages = extractErrorMessagesFromResponse(error); + showNotification({ title: t(`errorGeneratingId', 'Error Generating Sample Id`), kind: "error", critical: true, - description: err?.message, + description: errorMessages.join(", "), }); } ); diff --git a/src/tests-ordered/tests-ordered-list.component.tsx b/src/tests-ordered/tests-ordered-list.component.tsx index 89ff6053..8d618b3b 100644 --- a/src/tests-ordered/tests-ordered-list.component.tsx +++ b/src/tests-ordered/tests-ordered-list.component.tsx @@ -58,10 +58,11 @@ const TestsOrderedList: React.FC = () => { { id: 1, header: t("orderNumber", "Order Number"), key: "orderNumber" }, { id: 2, header: t("patient", "Patient"), key: "patient" }, - { id: 3, header: t("test", "Test"), key: "test" }, - { id: 4, header: t("orderer", "Ordered By"), key: "orderer" }, - { id: 5, header: t("urgency", "Urgency"), key: "urgency" }, - { id: 6, header: t("actions", "Actions"), key: "actions" }, + { id: 3, header: t("artNumber", "Art Number"), key: "artNumber" }, + { id: 4, header: t("test", "Test"), key: "test" }, + { id: 5, header: t("orderer", "Ordered By"), key: "orderer" }, + { id: 6, header: t("urgency", "Urgency"), key: "urgency" }, + { id: 7, header: t("actions", "Actions"), key: "actions" }, ]; const tableRows = useMemo(() => { @@ -74,6 +75,10 @@ const TestsOrderedList: React.FC = () => { ), patient: entry?.patient?.display.split("-")[1], + artNumber: entry.patient?.identifiers.find( + (item) => + item?.identifierType?.uuid === "e1731641-30ab-102d-86b0-7a5022ba4115" + ).display, orderNumber: entry?.orderNumber, test: entry?.concept?.display, action: entry?.action, diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 3b101307..a80e08bf 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -273,3 +273,13 @@ export function OrderTagStyle(order: any) { }; } } + +export function extractErrorMessagesFromResponse(errorObject) { + const fieldErrors = errorObject?.responseBody?.error?.fieldErrors; + if (!fieldErrors) { + return [errorObject?.responseBody?.error?.message ?? errorObject?.message]; + } + return Object.values(fieldErrors).flatMap((errors: Array) => + errors.map((error) => error.message) + ); +} diff --git a/src/work-list/work-list.resource.ts b/src/work-list/work-list.resource.ts index 0a6954ea..c067f728 100644 --- a/src/work-list/work-list.resource.ts +++ b/src/work-list/work-list.resource.ts @@ -5,125 +5,93 @@ import useSWR, { mutate } from "swr"; export interface Result { uuid: string; orderNumber: string; - accessionNumber: string; - patient: Patient; + accessionNumber?: string; + instructions?: string; + careSetting: CareSetting; + encounter: Encounter; + fulfillerComment?: string; + orderType: OrderType; concept: Concept; action: string; - careSetting: CareSetting; - previousOrder: PreviousOrder; + dateStopped?: string; + fulfillerStatus: string; dateActivated: string; - scheduledDate: any; - dateStopped: any; - autoExpireDate: any; - encounter: Encounter; orderer: Orderer; - orderReason: any; - orderReasonNonCoded: any; - orderType: OrderType; urgency: string; - instructions: string; - commentToFulfiller: any; - display: string; - auditInfo: AuditInfo; - fulfillerStatus: string; - fulfillerComment: any; - specimenSource: SpecimenSource; - laterality: any; - clinicalHistory: any; - frequency: any; - numberOfRepeats: any; - links: Link[]; - type: string; - resourceVersion: string; + patient: Patient2; } -export interface Patient { +export interface CareSetting { uuid: string; - display: string; - links: Link[]; } -export interface Link { - rel: string; - uri: string; - resourceAlias: string; +export interface Encounter { + uuid: string; + obs: Ob[]; } -export interface Concept { +export interface Ob { + order?: Order; +} + +export interface Order { uuid: string; display: string; - links: Link[]; + patient: Patient; } -export interface CareSetting { +export interface Patient { uuid: string; - name: string; - description: string; - retired: boolean; - careSettingType: string; display: string; - links: Link[]; - resourceVersion: string; } -export interface PreviousOrder { - uuid: string; +export interface OrderType { display: string; - links: Link[]; - type: string; } -export interface Encounter { - uuid: string; +export interface Concept { display: string; - links: Link[]; + uuid: string; } export interface Orderer { - uuid: string; display: string; - links: Link[]; } -export interface OrderType { +export interface Patient2 { uuid: string; + names: Name[]; display: string; - name: string; - javaClassName: string; - retired: boolean; - description: string; - conceptClasses: any[]; - parent: any; - links: Link[]; - resourceVersion: string; + gender: string; + birthdate: string; + identifiers: Identifier[]; } -export interface AuditInfo { - creator: Creator; - dateCreated: string; - changedBy: any; - dateChanged: any; +export interface Name { + display: string; } -export interface Creator { +export interface Identifier { + voided: boolean; + preferred: boolean; uuid: string; display: string; - links: Link[]; + identifierType: IdentifierType; } -export interface SpecimenSource { +export interface IdentifierType { uuid: string; - display: string; - links: Link[]; } export function useGetOrdersWorklist(fulfillerStatus: string, date?: string) { const { laboratoryOrderTypeUuid } = useConfig(); + const customRepresentation = + "v=custom:(uuid,orderNumber,accessionNumber,instructions,careSetting:(uuid),encounter:(uuid,obs:(order:(uuid,display,patient:(uuid,display)))),fulfillerComment,orderType:(display),concept:(display,uuid),action,dateStopped,fulfillerStatus,dateActivated,orderer:(display),urgency,patient:(uuid,names:(display),display,gender,birthdate,identifiers:(voided,preferred,uuid,display,identifierType:(uuid))))"; const orderTypeQuery = laboratoryOrderTypeUuid !== "" ? `orderTypes=${laboratoryOrderTypeUuid}` : ""; - let apiUrl = `${restBaseUrl}/order?${orderTypeQuery}&fulfillerStatus=${fulfillerStatus}&v=full`; + let apiUrl = `${restBaseUrl}/order?${orderTypeQuery}&fulfillerStatus=${fulfillerStatus}&${customRepresentation}`; if (date) { apiUrl += `&activatedOnOrAfterDate=${date}`; }