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

Add tests ordered and referred date filter #9

Merged
merged 10 commits into from
Jun 26, 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"devDependencies": {
"@ohri/openmrs-esm-ohri-commons-lib": "next",
"@openmrs/esm-extensions": "next",
"@openmrs/esm-framework": "^5.5.1-pre.1704",
"@openmrs/esm-framework": "^5.6.0",
"@openmrs/esm-patient-common-lib": "next",
"@openmrs/esm-react-utils": "next",
"@openmrs/esm-styleguide": "next",
Expand Down Expand Up @@ -96,7 +96,7 @@
"jest-cli": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"lerna": "^5.6.1",
"openmrs": "^5.5.1-pre.1704",
"openmrs": "^5.6.1-pre.1930",
"plotly.js": "^2.24.3",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
Expand Down
7 changes: 3 additions & 4 deletions src/completed-list/completed-list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
DataTableSkeleton,
} from "@carbon/react";
import styles from "./completed-list.scss";
import { getStatusColor } from "../utils/functions";
import dayjs from "dayjs";
import { getStatusColor, useOrderDate } from "../utils/functions";

interface CompletedListProps {
fulfillerStatus: string;
Expand All @@ -35,11 +34,11 @@ interface CompletedListProps {
const CompletedList: React.FC<CompletedListProps> = ({ fulfillerStatus }) => {
const { t } = useTranslation();

const today = dayjs(new Date()).format("YYYY-MM-DD");
const { currentOrdersDate } = useOrderDate();

const { data: completedOrderList, isLoading } = useGetOrdersWorklist(
fulfillerStatus,
today
currentOrdersDate
);

const pageSizes = [10, 20, 30, 40, 50];
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const moduleName = "@openmrs/esm-laboratory-app";

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";
36 changes: 29 additions & 7 deletions src/header/laboratory-header.component.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import React from "react";
import React, { useRef } from "react";
import { useTranslation } from "react-i18next";
import { Calendar, Location } from "@carbon/react/icons";
import { useSession, formatDate } from "@openmrs/esm-framework";
import { Location } from "@carbon/react/icons";
import { useSession } from "@openmrs/esm-framework";
import LaboratoryIllustration from "./laboratory-illustration.component";
import styles from "./laboratory-header.scss";
import { DatePicker, DatePickerInput } from "@carbon/react";
import dayjs from "dayjs";
import { changeStartDate, useOrderDate } from "../utils/functions";

export const LaboratoryHeader: React.FC = () => {
const { t } = useTranslation();
const datePickerRef = useRef(null);

const userSession = useSession();
const userLocation = userSession?.sessionLocation?.display;

const { currentOrdersDate } = useOrderDate();

return (
<div className={styles.header}>
<div className={styles["left-justified-items"]}>
Expand All @@ -23,10 +30,25 @@ export const LaboratoryHeader: React.FC = () => {
<Location size={16} />
<span className={styles.value}>{userLocation}</span>
<span className={styles.middot}>&middot;</span>
<Calendar size={16} />
<span className={styles.value}>
{formatDate(new Date(), { mode: "standard" })}
</span>
<DatePicker
onChange={([date]) => changeStartDate(new Date(date))}
ref={datePickerRef}
dateFormat="Y-m-d"
datePickerType="single"
>
<DatePickerInput
style={{
backgroundColor: "transparent",
border: "none",
maxWidth: "10rem",
}}
id="date-picker-calendar-id"
placeholder="YYYY-MM-DD"
labelText=""
type="text"
value={dayjs(currentOrdersDate).format("YYYY-MM-DD")}
/>
</DatePicker>
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/lab-tabs/referred-tab.component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import { EmptyState } from "@openmrs/esm-patient-common-lib";
import ReferredOrdersList from "../referred-orders/referred-orders.component";

const ReferredComponent = () => {
Expand Down
1 change: 0 additions & 1 deletion src/lab-tabs/work-list-tab.component.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import WorkList from "../work-list/work-list.component";
import styles from "../queue-list/laboratory-queue.scss";

const WorkListComponent = () => {
return (
Expand Down
7 changes: 3 additions & 4 deletions src/lab-tiles/completed-tile.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import React from "react";
import { useTranslation } from "react-i18next";
import SummaryTile from "../summary-tiles/summary-tile.component";
import { useLabTestsStats } from "../summary-tiles/laboratory-summary.resource";
import dayjs from "dayjs";
import { useOrderDate } from "../utils/functions";

const ApprovedTileComponent = () => {
const { t } = useTranslation();

const today = dayjs(new Date()).format("YYYY-MM-DD");

const { data } = useLabTestsStats("COMPLETED", today);
const { currentOrdersDate } = useOrderDate();
const { data } = useLabTestsStats("COMPLETED", currentOrdersDate);

return (
<SummaryTile
Expand Down
8 changes: 6 additions & 2 deletions src/lab-tiles/referred-tile.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ import React from "react";
import { useTranslation } from "react-i18next";
import SummaryTile from "../summary-tiles/summary-tile.component";
import { useLabTestsStats } from "../summary-tiles/laboratory-summary.resource";
import { useOrderDate } from "../utils/functions";
import { REFERINSTRUCTIONS } from "../constants";

const ReferredTileComponent = () => {
const { t } = useTranslation();

const { data } = useLabTestsStats("");
const { currentOrdersDate } = useOrderDate();

const { data } = useLabTestsStats("", currentOrdersDate);

const filteredData = data?.filter(
(item) =>
item?.fulfillerStatus === "IN_PROGRESS" &&
item?.accessionNumber !== null &&
item?.dateStopped === null &&
item?.instructions === "REFER TO cphl"
item?.instructions === REFERINSTRUCTIONS
);

return (
Expand Down
5 changes: 4 additions & 1 deletion src/lab-tiles/rejected-tile.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import React from "react";
import { useTranslation } from "react-i18next";
import SummaryTile from "../summary-tiles/summary-tile.component";
import { useLabTestsStats } from "../summary-tiles/laboratory-summary.resource";
import { useOrderDate } from "../utils/functions";

const RejectedTileComponent = () => {
const { t } = useTranslation();

const { data } = useLabTestsStats("");
const { currentOrdersDate } = useOrderDate();

const { data } = useLabTestsStats("", currentOrdersDate);

const filteredData = data?.filter(
(item) => item?.fulfillerStatus === "DECLINED"
Expand Down
7 changes: 4 additions & 3 deletions src/lab-tiles/tests-ordered-tile.component.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { useTranslation } from "react-i18next";
import SummaryTile from "../summary-tiles/summary-tile.component";
import dayjs from "dayjs";
import { useGetOrdersWorklist } from "../work-list/work-list.resource";
import { useOrderDate } from "../utils/functions";

const TestsOrderedTileComponent = () => {
const { t } = useTranslation();
const today = dayjs(new Date()).format("YYYY-MM-DD");
const { data } = useGetOrdersWorklist("", today);

const { currentOrdersDate } = useOrderDate();
const { data } = useGetOrdersWorklist("", currentOrdersDate);

const filteredData = data?.filter(
(item) =>
Expand Down
9 changes: 5 additions & 4 deletions src/lab-tiles/worklist-tile.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ import React from "react";
import { useTranslation } from "react-i18next";
import SummaryTile from "../summary-tiles/summary-tile.component";
import { useLabTestsStats } from "../summary-tiles/laboratory-summary.resource";
import dayjs from "dayjs";
import { useOrderDate } from "../utils/functions";
import { REFERINSTRUCTIONS } from "../constants";

const WorklistTileComponent = () => {
const { t } = useTranslation();
const today = dayjs(new Date()).format("YYYY-MM-DD");
const { currentOrdersDate } = useOrderDate();

const { data } = useLabTestsStats("IN_PROGRESS", today);
const { data } = useLabTestsStats("IN_PROGRESS", currentOrdersDate);

const filteredData = data?.filter(
(item) =>
item?.fulfillerStatus === "IN_PROGRESS" &&
item?.accessionNumber !== null &&
item?.dateStopped === null &&
item?.instructions !== "REFER TO cphl"
item?.instructions !== REFERINSTRUCTIONS
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,25 @@ const LaboratoryActiveTestOrderResults: React.FC<

const sortedLabRequests = useMemo(() => {
return [...items]
?.filter(
(item) =>
(item?.encounterType?.uuid === laboratoryEncounterTypeUuid ||
item?.encounterType?.uuid === artCardEncounterTypeUuid) &&
item.orders.filter(
(order) => order.orderType === laboratoryOrderTypeUuid
)
)
?.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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
launchPatientWorkspace,
} from "@openmrs/esm-patient-common-lib";
import { mutate } from "swr";
import { REFERINSTRUCTIONS } from "../../constants";

interface LaboratoryOrderReferalResultsProps {
patientUuid: string;
Expand Down Expand Up @@ -111,16 +112,26 @@ const LaboratoryOrderReferalResults: React.FC<

const sortedLabRequests = useMemo(() => {
return [...items]
?.filter(
(item) =>
(item?.encounterType?.uuid === laboratoryEncounterTypeUuid ||
item?.encounterType?.uuid === artCardEncounterTypeUuid) &&
item?.orders?.filter(
(order) =>
order?.instructions === "REFER TO cphl" ||
order.orderType === laboratoryOrderTypeUuid
)
)
?.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(
(order) =>
order?.orderType?.uuid === laboratoryOrderTypeUuid &&
order?.orderType?.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7" &&
order?.instructions === REFERINSTRUCTIONS
);

// 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);
Expand Down Expand Up @@ -281,7 +292,8 @@ const LaboratoryOrderReferalResults: React.FC<
(order?.action === "NEW" ||
order?.action === "REVISE" ||
order?.action === "DISCONTINUE") &&
order.dateStopped === null
order.dateStopped === null &&
order.instructions === REFERINSTRUCTIONS
) {
return (
<Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,25 @@ const LaboratoryPastTestOrderResults: React.FC<

const sortedLabRequests = useMemo(() => {
return [...items]
?.filter(
(item) =>
(item?.encounterType?.uuid === laboratoryEncounterTypeUuid ||
item?.encounterType?.uuid === artCardEncounterTypeUuid) &&
item.orders.filter(
(order) => order.orderType === laboratoryOrderTypeUuid
)
)
?.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);
Expand Down
23 changes: 13 additions & 10 deletions src/patient-chart/patient-laboratory-order-results.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,20 @@ export function usePatientLaboratoryOrders(filter: LaboratoryOrderFilter) {
Error
>(apiUrl, openmrsFetch, { refreshInterval: 3000 });

const filteredItems = data?.data?.results
? data.data.results
.map((item) => ({
...item,
orders: item.orders.filter(
(order) =>
order?.orderType?.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7"
),
}))
.filter((item) => item.orders.length > 0)
: [];

return {
items: data?.data
? data?.data?.results.filter(
(item) =>
item?.orders.length !== 0 &&
item.orders.filter(
(item) =>
item?.orderType?.uuid !== "131168f4-15f5-102d-96e4-000c29c2a5d7"
)
)
: [],
items: filteredItems,
isLoading,
isError: error,
};
Expand Down
Loading
Loading