Skip to content

Commit

Permalink
add test orders display
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Jul 10, 2024
1 parent c3c5641 commit 542b6e6
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/ordered-orders/tests-ordered-list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,26 @@ import {
TableExpandHeader,
TableExpandRow,
TableExpandedRow,
ExpandedRowView,
} from "@carbon/react";

import { useTranslation } from "react-i18next";
import {
ErrorState,
useConfig,
useLayoutType,
useLocations,
usePagination,
useSession,
} from "@openmrs/esm-framework";
import styles from "./tests-ordered.scss";
import { usePatientQueuesList } from "./tests-ordered-list.resource";

import { formatWaitTime, trimVisitNumber } from "../utils/functions";
import TestOrder from "../patient-orders/patient-test-orders.component";
import TestOrders from "../patient-test-orders/patient-test-orders.component";

const TestsOrderedList: React.FC = () => {
const { t } = useTranslation();
const session = useSession();
const isTablet = useLayoutType() === "tablet";

const { excludePatientIdentifierCodeTypes } = useConfig();
const locations = useLocations();

const { patientQueueEntries, isLoading, isError, mutate } =
usePatientQueuesList(
Expand Down Expand Up @@ -88,6 +85,8 @@ const TestsOrderedList: React.FC = () => {
const tableRows = useMemo(() => {
return paginatedQueueEntries?.map((entry) => ({
...entry,
id: entry.uuid,
patientUuid: entry.patientUuid,
visitId: {
content: <span>{trimVisitNumber(entry.visitNumber)}</span>,
},
Expand All @@ -101,7 +100,8 @@ const TestsOrderedList: React.FC = () => {
content: <span>{entry?.patientAge}</span>,
},
orderedFrom: {
content: <span>{entry?.locationFrom}</span>,
content: locations.find((loc) => loc.uuid === entry?.locationFrom)
?.display,
},
waitTime: {
content: <span> {formatWaitTime(entry.waitTime, t)}</span>,
Expand Down Expand Up @@ -144,7 +144,7 @@ const TestsOrderedList: React.FC = () => {
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => {
{rows.map((row, index) => {
return (
<React.Fragment key={row.id}>
<TableExpandRow {...getRowProps({ row })} key={row.id}>
Expand All @@ -155,7 +155,7 @@ const TestsOrderedList: React.FC = () => {
))}
</TableExpandRow>
<TableExpandedRow colSpan={headers.length + 1}>
{/* <TestOrder testOrder={row} /> */}
<TestOrders patientUuid={tableRows[index].patientUuid} />
</TableExpandedRow>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,32 @@ import {
} from "@carbon/react";

import { useTranslation } from "react-i18next";
import { useLayoutType } from "@openmrs/esm-framework";
import { useConfig, useLayoutType } from "@openmrs/esm-framework";
import {
useLabEncounter,
useOrderConceptByUuid,
} from "./patient-test-orders.resource";
usePatientLabEnounters,
} from "./patient-test-obs.resource";
import { Order } from "@openmrs/esm-patient-common-lib";
import styles from "./patient-test-orders.scss";

interface TestOrderProps {
testOrder: Order;
testOrder?: Order;
patientUuid: string;
}

const TestOrder: React.FC<TestOrderProps> = ({ testOrder }) => {
const TestObs: React.FC<TestOrderProps> = ({ testOrder, patientUuid }) => {
const { t } = useTranslation();
const isTablet = useLayoutType() === "tablet";
const { laboratoryEncounterTypeUuid } = useConfig();

console.log("testOrder" + patientUuid);

Check failure on line 35 in src/patient-test-obs/patient-test-obs.component.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

const { concept, isLoading: isLoadingTestConcepts } = useOrderConceptByUuid(
testOrder.concept.uuid
testOrder?.concept?.uuid
);
const { encounter, isLoading: isLoadingResult } = useLabEncounter(
testOrder.encounter.uuid
testOrder?.encounter?.uuid
);

const tableHeaders: Array<{ key: string; header: string }> = [
Expand Down Expand Up @@ -151,4 +156,4 @@ const TestOrder: React.FC<TestOrderProps> = ({ testOrder }) => {
);
};

export default TestOrder;
export default TestObs;
192 changes: 192 additions & 0 deletions src/patient-test-obs/patient-test-obs.resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import useSWR from "swr";
import {
type OpenmrsResource,
openmrsFetch,
restBaseUrl,
type FetchResponse,
type Visit,
} from "@openmrs/esm-framework";
import { type Order } from "@openmrs/esm-patient-common-lib";

const labEncounterRepresentation =
"custom:(uuid,encounterDatetime,encounterType,location:(uuid,name)," +
"patient:(uuid,display),encounterProviders:(uuid,provider:(uuid,name))," +
"orders," +
"obs:(uuid,obsDatetime,voided,groupMembers,formFieldNamespace,formFieldPath,order:(uuid,display),concept:(uuid,name:(uuid,name))," +
"value:(uuid,display,name:(uuid,name),names:(uuid,conceptNameType,name))))";
const labConceptRepresentation =
"custom:(uuid,display,name,datatype,set,answers,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units," +
"setMembers:(uuid,display,answers,datatype,hiNormal,hiAbsolute,hiCritical,lowNormal,lowAbsolute,lowCritical,units))";
const conceptObsRepresentation =
"custom:(uuid,display,concept:(uuid,display),groupMembers,value)";

export interface Encounter {
uuid: string;
encounterDatetime: string;
encounterProviders: Array<{
uuid: string;
display: string;
encounterRole: {
uuid: string;
display: string;
};
provider: {
uuid: string;
person: {
uuid: string;
display: string;
};
};
}>;
encounterType: {
uuid: string;
display: string;
};
visit?: Visit;
obs: Array<Observation>;
orders: Array<Order>;
diagnoses: Array<Diagnosis>;
patient: OpenmrsResource;
location: OpenmrsResource;
}

export interface Observation {
uuid: string;
display: string;
concept: {
uuid: string;
display: string;
};
obsGroup: any;
obsDatetime: string;
groupMembers?: Array<Observation>;
value: {
uuid: string;
display: string;
};
location: OpenmrsResource;
order: Order;
status: string;
}

export interface Diagnosis {
uuid: string;
display: string;
diagnosis: {
coded?: {
uuid: string;
display?: string;
};
nonCoded?: string;
};
certainty: string;
rank: number;
}

export interface LabOrderConcept {
uuid: string;
display: string;
name?: ConceptName;
datatype: Datatype;
set: boolean;
version: string;
retired: boolean;
descriptions: Array<Description>;
mappings?: Array<Mapping>;
answers?: Array<OpenmrsResource>;
setMembers?: Array<LabOrderConcept>;
hiNormal?: number;
hiAbsolute?: number;
hiCritical?: number;
lowNormal?: number;
lowAbsolute?: number;
lowCritical?: number;
units?: string;
}

export interface ConceptName {
display: string;
uuid: string;
name: string;
locale: string;
localePreferred: boolean;
conceptNameType: string;
}

export interface Datatype {
uuid: string;
display: string;
name: string;
description: string;
hl7Abbreviation: string;
retired: boolean;
resourceVersion: string;
}

export interface Description {
display: string;
uuid: string;
description: string;
locale: string;
resourceVersion: string;
}

export interface Mapping {
display: string;
uuid: string;
conceptReferenceTerm: OpenmrsResource;
conceptMapType: OpenmrsResource;
resourceVersion: string;
}

export function useOrderConceptByUuid(uuid: string) {
const apiUrl = `${restBaseUrl}/concept/${uuid}?v=${labConceptRepresentation}`;

const { data, error, isLoading, isValidating, mutate } = useSWR<
{ data: LabOrderConcept },
Error
>(apiUrl, openmrsFetch);
return {
concept: data?.data,
isLoading,
error,
isValidating,
mutate,
};
}

export function useLabEncounter(encounterUuid: string) {
const apiUrl = `${restBaseUrl}/encounter/${encounterUuid}?v=${labEncounterRepresentation}`;

const { data, error, isLoading, isValidating, mutate } = useSWR<
FetchResponse<Encounter>,
Error
>(apiUrl, openmrsFetch);

return {
encounter: data?.data,
isLoading,
isError: error,
isValidating,
mutate,
};
}

export function usePatientLabEnounters(
patientUuid: string,
encounterTypeUuid: string
) {
const apiUrl = `${restBaseUrl}/encounter?patient=${patientUuid}&encounterType=${encounterTypeUuid}&v=${labEncounterRepresentation}`;
const { data, error, isLoading, isValidating, mutate } = useSWR<
FetchResponse<Array<Encounter>>,
Error
>(apiUrl, openmrsFetch);

return {
encounters: data?.data,
isLoading,
isError: error,
isValidating,
mutate,
};
}
File renamed without changes.
Loading

0 comments on commit 542b6e6

Please sign in to comment.