Skip to content

Commit

Permalink
Fix view orders in patient chart (#10)
Browse files Browse the repository at this point in the history
Fix view orders in patient chart (#10)
  • Loading branch information
jabahum authored Jun 26, 2024
1 parent d62dd31 commit 87c6b44
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export const LABORATARORY_ENCOUNTER_TYPE =
"cbf01392-ca29-11e9-a32f-2a2ae2dbcce4";
export const TEST_ORDER_ENCOUNTER_TYPE = "dca07f4a-30ab-102d-86b0-7a5022ba4115";
export const omrsDateFormat = "YYYY-MM-DD";
export const REFERINSTRUCTIONS = "REFER TO cphl";
export const REFERINSTRUCTIONS = "REFER TO CPHL";
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,12 @@ const LaboratoryActiveTestOrderResults: React.FC<
const [currentPageSize, setPageSize] = useState(10);

const sortedLabRequests = useMemo(() => {
return [...items]
?.filter((item) => {
const { encounterType, orders } = item || {};
const { uuid: encounterTypeUuid } = encounterType || {};

// Check if the encounterType UUID matches either of the specified UUIDs
const isMatchingEncounterType =
encounterTypeUuid === laboratoryEncounterTypeUuid ||
encounterTypeUuid === artCardEncounterTypeUuid;

// Filter orders to only include those with the matching orderType UUID
const matchingOrders = orders?.filter(
({ orderType }) =>
orderType?.uuid === laboratoryOrderTypeUuid &&
orderType?.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7"
);

// Return the item only if it has matching encounterType and at least one matching order
return isMatchingEncounterType && matchingOrders?.length > 0;
})
?.sort((a, b) => {
const dateA = new Date(a.encounterDatetime);
const dateB = new Date(b.encounterDatetime);
return dateB.getTime() - dateA.getTime();
});
}, [
artCardEncounterTypeUuid,
items,
laboratoryEncounterTypeUuid,
laboratoryOrderTypeUuid,
]);
return [...items]?.sort((a, b) => {
const dateA = new Date(a.encounterDatetime);
const dateB = new Date(b.encounterDatetime);
return dateB.getTime() - dateA.getTime();
});
}, [items]);

const [searchTerm, setSearchTerm] = useState("");
const [laboratoryOrders, setLaboratoryOrders] = useState(sortedLabRequests);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,21 @@ const LaboratoryOrderReferalResults: React.FC<
const { uuid: encounterTypeUuid } = encounterType || {};

// Check if the encounterType UUID matches either of the specified UUIDs
const isMatchingEncounterType =
encounterTypeUuid === laboratoryEncounterTypeUuid ||
encounterTypeUuid === artCardEncounterTypeUuid;

// Filter orders to only include those with the matching orderType UUID
const matchingOrders = orders?.filter(
(order) =>
order?.orderType?.uuid === laboratoryOrderTypeUuid &&
order?.orderType?.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7" &&
order?.instructions === REFERINSTRUCTIONS
(order) => order?.instructions === REFERINSTRUCTIONS
);

// Return the item only if it has matching encounterType and at least one matching order
return isMatchingEncounterType && matchingOrders?.length > 0;
return matchingOrders?.length > 0;
})
?.sort((a, b) => {
const dateA = new Date(a.encounterDatetime);
const dateB = new Date(b.encounterDatetime);
return dateB.getTime() - dateA.getTime();
});
}, [
artCardEncounterTypeUuid,
items,
laboratoryEncounterTypeUuid,
laboratoryOrderTypeUuid,
]);
}, [items]);

const [searchTerm, setSearchTerm] = useState("");
const [laboratoryOrders, setLaboratoryOrders] = useState(sortedLabRequests);
Expand Down Expand Up @@ -292,7 +281,6 @@ const LaboratoryOrderReferalResults: React.FC<
(order?.action === "NEW" ||
order?.action === "REVISE" ||
order?.action === "DISCONTINUE") &&
order.dateStopped === null &&
order.instructions === REFERINSTRUCTIONS
) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ const LaboratoryPastTestOrderResults: React.FC<
> = ({ patientUuid }) => {
const { t } = useTranslation();

const {
enableSendingLabTestsByEmail,
laboratoryEncounterTypeUuid,
artCardEncounterTypeUuid,
laboratoryOrderTypeUuid,
} = useConfig();
const { enableSendingLabTestsByEmail, laboratoryEncounterTypeUuid } =
useConfig();

const displayText = t(
"pastLaboratoryTestsDisplayTextTitle",
Expand All @@ -96,37 +92,12 @@ const LaboratoryPastTestOrderResults: React.FC<
const [currentPageSize, setPageSize] = useState(10);

const sortedLabRequests = useMemo(() => {
return [...items]
?.filter((item) => {
const { encounterType, orders } = item || {};
const { uuid: encounterTypeUuid } = encounterType || {};

// Check if the encounterType UUID matches either of the specified UUIDs
const isMatchingEncounterType =
encounterTypeUuid === laboratoryEncounterTypeUuid ||
encounterTypeUuid === artCardEncounterTypeUuid;

// Filter orders to only include those with the matching orderType UUID
const matchingOrders = orders?.filter(
({ orderType }) =>
orderType?.uuid === laboratoryOrderTypeUuid &&
orderType.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7"
);

// Return the item only if it has matching encounterType and at least one matching order
return isMatchingEncounterType && matchingOrders?.length > 0;
})
?.sort((a, b) => {
const dateA = new Date(a.encounterDatetime);
const dateB = new Date(b.encounterDatetime);
return dateB.getTime() - dateA.getTime();
});
}, [
artCardEncounterTypeUuid,
items,
laboratoryEncounterTypeUuid,
laboratoryOrderTypeUuid,
]);
return [...items]?.sort((a, b) => {
const dateA = new Date(a.encounterDatetime);
const dateB = new Date(b.encounterDatetime);
return dateB.getTime() - dateA.getTime();
});
}, [items]);

const [searchTerm, setSearchTerm] = useState("");
const [laboratoryOrders, setLaboratoryOrders] = useState(sortedLabRequests);
Expand Down
10 changes: 6 additions & 4 deletions src/patient-chart/patient-laboratory-order-results.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export interface Order {
orderReasonNonCoded: any;
orderType: OrderType;
urgency: string;
instructions: any;
instructions: string;
commentToFulfiller: any;
display: string;
specimenSource: any;
Expand Down Expand Up @@ -445,21 +445,23 @@ export function toQueryParams<T extends ResourceFilterCriteria>(

export function usePatientLaboratoryOrders(filter: LaboratoryOrderFilter) {
const config = useConfig();
const { laboratoryEncounterTypeUuid } = config;
const { laboratoryEncounterTypeUuid, laboratoryOrderTypeUuid } = config;

const apiUrl = `${restBaseUrl}/encounter?patient=${filter.patientUuid}&encounterType=${laboratoryEncounterTypeUuid}&v=${filter.v}&totalCount=true`;
const { data, error, isLoading } = useSWR<
{ data: LaboratoryResponse },
Error
>(apiUrl, openmrsFetch, { refreshInterval: 3000 });
>(apiUrl, openmrsFetch);

const filteredItems = data?.data?.results
? data.data.results
.map((item) => ({
...item,
orders: item.orders.filter(
(order) =>
order?.orderType?.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7"
order?.orderType?.uuid !==
"131168f4-15f5-102d-96e4-000c29c2a5d7" &&
order.orderType?.uuid === laboratoryOrderTypeUuid
),
}))
.filter((item) => item.orders.length > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Renew } from "@carbon/react/icons";
import {
GenerateSpecimenId,
UpdateOrder,
extractCapitalLetters,
extractLetters,
useReferralLocations,
useSpecimenTypes,
} from "./add-to-worklist-dialog.resource";
Expand Down Expand Up @@ -69,7 +69,7 @@ const AddToWorklistDialog: React.FC<AddToWorklistDialogProps> = ({
specimenSourceId: specimenType,
unProcessedOrders: "",
patientQueueId: queueId,
referenceLab: extractCapitalLetters(selectedReferral).toLowerCase(),
referenceLab: preferred ? extractLetters(selectedReferral) : "",
};

UpdateOrder(order.uuid, body).then(
Expand Down Expand Up @@ -142,7 +142,7 @@ const AddToWorklistDialog: React.FC<AddToWorklistDialogProps> = ({
<Form onSubmit={pickLabRequestQueue}>
<ModalHeader
closeModal={closeModal}
title={t("pickRequest", `Test : ${order?.display}`)}
title={t("pickRequest", `Test : ${order?.concept?.display}`)}
/>
<ModalBody>
<div className={styles.modalBody}>
Expand Down
15 changes: 12 additions & 3 deletions src/tests-ordered/lab-dialogs/add-to-worklist-dialog.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,23 @@ export async function GetOrderByUuid(uuid: string) {
});
}

export function extractCapitalLetters(statement: string): string {
export function extractLetters(
statement: string,
extractUppercase: boolean = true
): string {
const words = statement.split(" ");
let result = "";

for (const word of words) {
for (const char of word) {
if (char >= "A" && char <= "Z") {
result += char;
if (extractUppercase) {
if (char >= "A" && char <= "Z") {
result += char;
}
} else {
if (char >= "a" && char <= "z") {
result += char;
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/types/patient-queues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Concept } from "../work-list/work-list.resource";

export interface PatientQueue {
uuid: string;
creator: {
Expand Down Expand Up @@ -174,6 +176,7 @@ export interface Order {
display: string;
links: Link[];
type: string;
concept: Concept;
}

export interface Visit {
Expand Down

0 comments on commit 87c6b44

Please sign in to comment.