Skip to content

Commit

Permalink
ft : add order model
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Oct 5, 2023
1 parent 05fdb0f commit 5923e31
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 84 deletions.
6 changes: 6 additions & 0 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ export const configSchema = {
_default: "159959AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
_description: "Concept UUID for laboratory specimen types",
},
laboratoryEncounterTypeUuid: {
_type: Type.String,
_default: "214e27a1-606a-4b1e-a96e-d736c87069d5",
_description: "Concept uuid for the laboratory tool encounter type.",
},
};

export type Config = {
laboratoryQueueConcept: string;
laboratoryLocationTag: string;
laboratorySpecimenTypeConcept: string;
laboratoryEncounterTypeUuid: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
import { Button, Tooltip } from "@carbon/react";
import { View } from "@carbon/react/icons";
import { launchPatientWorkspace } from "@openmrs/esm-patient-common-lib";
import { LaboratoryResponse } from "../laboratory-order.resource";

interface ViewLaboratoryItemActionMenuProps {
closeModal: () => void;
Expand Down
84 changes: 37 additions & 47 deletions src/patient-chart/laboratory-order.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import React, { useCallback, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { EmptyState } from "@ohri/openmrs-esm-ohri-commons-lib";
import styles from "./laboratory-order.scss";
import { useSession } from "@openmrs/esm-framework";
import {
formatDate,
parseDate,
usePagination,
useSession,
} from "@openmrs/esm-framework";
import {
DataTable,
DataTableSkeleton,
Expand All @@ -20,8 +25,10 @@ import {
Tag,
DataTableHeader,
Tile,
Pagination,
} from "@carbon/react";
import ViewLaboratoryItemActionMenu from "./laboratory-item/view-laboratory-item.component";
import { useLabOrders } from "./laboratory-order.resource";

interface LaboratoryOrderOverviewProps {
patientUuid: string;
Expand All @@ -40,44 +47,18 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
}) => {
const { t } = useTranslation();

const session = useSession();

// const { patientQueueEntries, isLoading } = usePatientQueuesList(
// session?.sessionLocation?.uuid,
// status
// );
const { labRequests, isLoading: loading } = useLabOrders(patientUuid);

const pageSizes = [10, 20, 30, 40, 50];
const [page, setPage] = useState(1);
const [currentPageSize, setPageSize] = useState(10);
const [nextOffSet, setNextOffSet] = useState(0);
const [isLoading, setIsLoading] = useState(false);

// const {
// goTo,
// results: paginatedQueueEntries,
// currentPage,
// } = usePagination(patientQueueEntries, currentPageSize);

const initialItems = useMemo(() => {
const items = [
{
id: 1,
encounterDate: "2023-04-01",
orders: ["Crag", "CBC", "MalariaRDT", "CD4", "RFT", "Unalysis"],
location: session.sessionLocation.display,
results: "tests returned",
},
{
id: 2,
encounterDate: "2023-04-05",
orders: ["Crag", "CBC", "CD4", "RFT", "Unalysis", "LFTs"],
location: session.sessionLocation.display,
results: "tests returned",
},
];
return items;
}, [session.sessionLocation.display]);
const {
goTo,
results: paginatedLabEntries,
currentPage,
} = usePagination(labRequests, currentPageSize);

let columns = [
{
Expand All @@ -92,8 +73,8 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
];

const [searchTerm, setSearchTerm] = useState("");
const [items, setItems] = useState(initialItems);
const [initialTests] = useState(initialItems);
const [items, setItems] = useState(paginatedLabEntries);
const [initialTests] = useState(paginatedLabEntries);

const handleChange = useCallback(
(val) => {
Expand All @@ -106,14 +87,15 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
items.map((item) => {
const newArray = item?.orders.filter(
(order) =>
order.toLowerCase().startsWith(searchText?.toLowerCase()) == true
order?.concept?.display
.toLowerCase()
.startsWith(searchText?.toLowerCase()) == true
);
if (newArray.length >= 1) {
filteredItems.push(item);
}
});

console.info(filteredItems);
setItems(filteredItems);
}
},
Expand Down Expand Up @@ -143,10 +125,18 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
};

const tableRows = useMemo(() => {
return items?.map((entry) => ({
return paginatedLabEntries?.map((entry) => ({
...entry,
encounterDate: {
content: <span>{entry.encounterDate}</span>,
content: (
<span>
{formatDate(parseDate(entry.encounterDatetime), {
time: false,
noToday: true,
mode: "wide",
})}
</span>
),
},
orders: {
content: (
Expand All @@ -160,18 +150,18 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
}}
role="tooltip"
>
{order}
{order?.concept?.display}
</Tag>
);
})}
</>
),
},
location: {
content: <span>{entry.location}</span>,
content: <span>{entry.location.display}</span>,
},
status: {
content: <span>{entry.results}</span>,
content: <span>--</span>,
},
actions: {
content: (
Expand All @@ -181,9 +171,9 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
),
},
}));
}, [items]);
}, [paginatedLabEntries]);

if (isLoading) {
if (loading) {
return <DataTableSkeleton role="progressbar" />;
}

Expand Down Expand Up @@ -264,13 +254,13 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
</Tile>
</div>
) : null}
{/* <Pagination
<Pagination
forwardText="Next page"
backwardText="Previous page"
page={currentPage}
pageSize={currentPageSize}
pageSizes={pageSizes}
totalItems={patientQueueEntries?.length}
totalItems={paginatedLabEntries?.length}
className={styles.pagination}
onChange={({ pageSize, page }) => {
if (pageSize !== currentPageSize) {
Expand All @@ -280,7 +270,7 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
goTo(page);
}
}}
/> */}
/>
</TableContainer>
)}
</DataTable>
Expand Down
95 changes: 90 additions & 5 deletions src/patient-chart/laboratory-order.resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openmrsFetch } from "@openmrs/esm-framework";
import { openmrsFetch, useConfig } from "@openmrs/esm-framework";
import useSWR from "swr";

export interface LaboratoryResponse {
Expand All @@ -14,7 +14,7 @@ export interface Result {
form: Form;
encounterType: EncounterType;
obs: Ob[];
orders: any[];
orders: Order[];
voided: boolean;
auditInfo: AuditInfo;
visit: Visit;
Expand Down Expand Up @@ -219,15 +219,100 @@ export interface Provider {
links: Link[];
}

export function useLabOrders(patientUuid: string, encounterTypeUuid: string) {
const apiUrl = `encounter?patient=${patientUuid}&encounterType=${encounterTypeUuid}&v=full`;
// order
export interface Order {
uuid: string;
orderNumber: string;
accessionNumber: any;
patient: Patient;
concept: Concept;
action: string;
careSetting: CareSetting;
previousOrder: any;
dateActivated: string;
scheduledDate: any;
dateStopped: any;
autoExpireDate: any;
encounter: Encounter;
orderer: Orderer;
orderReason: any;
orderReasonNonCoded: any;
orderType: OrderType;
urgency: string;
instructions: any;
commentToFulfiller: any;
display: string;
specimenSource: any;
laterality: any;
clinicalHistory: any;
frequency: any;
numberOfRepeats: any;
links: Link[];
type: string;
resourceVersion: string;
}

export interface Patient {
uuid: string;
display: string;
links: Link[];
}

export interface Link {
rel: string;
uri: string;
resourceAlias: string;
}

export interface Concept {
uuid: string;
display: string;
links: Link[];
}

export interface CareSetting {
uuid: string;
display: string;
links: Link[];
}

export interface Encounter {
uuid: string;
display: string;
links: Link[];
}

export interface Orderer {
uuid: string;
display: string;
links: Link[];
}

export interface OrderType {
uuid: string;
display: string;
name: string;
javaClassName: string;
retired: boolean;
description: string;
conceptClasses: any[];
parent: any;
links: Link[];
resourceVersion: string;
}

export function useLabOrders(patientUuid: string) {
const config = useConfig();
const { laboratoryEncounterTypeUuid } = config;

const apiUrl = `/ws/rest/v1/encounter?patient=${patientUuid}&encounterType=${laboratoryEncounterTypeUuid}&v=full`;
const { data, error, isLoading } = useSWR<
{ data: LaboratoryResponse },
Error
>(apiUrl, openmrsFetch);

return {
visitNumber: data.data.results,
labRequests: data?.data ? data?.data?.results : [],
isLoading,
isError: error,
};
Expand Down
17 changes: 11 additions & 6 deletions src/patient-chart/results-summary/results-summary.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ import {
import { Printer, MailAll, Edit } from "@carbon/react/icons";
import styles from "./results-summary.scss";
import TestsResults from "./test-results-table.component";
import { LaboratoryResponse } from "../laboratory-order.resource";

const ResultsSummary = () => {
interface ResultsSummaryProps {
labRequest: LaboratoryResponse;
}

const ResultsSummary: React.FC<ResultsSummaryProps> = () => {
const PrintButtonAction: React.FC = () => {
const handleButtonClick = (event: MouseEvent) => {
event.preventDefault();
Expand All @@ -58,7 +63,7 @@ const ResultsSummary = () => {
kind="ghost"
size="sm"
onClick={(e) => handleButtonClick(e)}
renderIcon={(props) => <Edit size={16} {...props} />}
renderIcon={(props) => <MailAll size={16} {...props} />}
>
{/* {children} */}
</Button>
Expand All @@ -74,7 +79,7 @@ const ResultsSummary = () => {
kind="ghost"
size="sm"
onClick={(e) => handleButtonClick(e)}
renderIcon={(props) => <MailAll size={16} {...props} />}
renderIcon={(props) => <Edit size={16} {...props} />}
>
{/* {children} */}
</Button>
Expand All @@ -92,9 +97,9 @@ const ResultsSummary = () => {
</div>
</section>
<section className={styles.section}>
<div>
<span>Date : </span>
<span> Ordered By :</span>
<div style={{ display: "flex", flexDirection: "column" }}>
<span style={{ margin: "5px" }}>Date : </span>
<span style={{ margin: "5px" }}> Ordered By :</span>
</div>
</section>
<section className={styles.section}>
Expand Down
Loading

0 comments on commit 5923e31

Please sign in to comment.