Skip to content

Commit

Permalink
ft : encouter api call
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Oct 6, 2023
1 parent 5923e31 commit bba3b1c
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 154 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"dependencies": {
"@carbon/react": "^1.14.0",
"lodash-es": "^4.17.21"
"lodash-es": "^4.17.21",
"react-to-print": "^2.14.15"
},
"peerDependencies": {
"@openmrs/esm-framework": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { showModal, useSession } from "@openmrs/esm-framework";
import React, { useCallback } from "react";
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;
encounterUuid: string;
}

const ViewLaboratoryItemActionMenu: React.FC<
ViewLaboratoryItemActionMenuProps
> = () => {
> = ({ encounterUuid }) => {
const { t } = useTranslation();

const handleClick = useCallback(
() =>
launchPatientWorkspace("results-summary", {
workspaceTitle: `Results Summary Form`,
encounterUuid,
}),
[]
[encounterUuid]
);

return (
Expand Down
290 changes: 290 additions & 0 deletions src/patient-chart/laboratory-item/view-laboratory-item.resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
import { openmrsFetch } from "@openmrs/esm-framework";
import useSWR from "swr";

export interface EncounterResponse {
uuid: string;
display: string;
encounterDatetime: string;
patient: Patient;
location: Location;
form: Form;
encounterType: EncounterType2;
obs: Ob[];
orders: Order[];
voided: boolean;
auditInfo: AuditInfo;
visit: Visit;
encounterProviders: any[];
diagnoses: any[];
links: Link[];
resourceVersion: string;
}

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

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

export interface Location {
uuid: string;
display: string;
name: string;
description: any;
address1: any;
address2: any;
cityVillage: any;
stateProvince: any;
country: string;
postalCode: any;
latitude: any;
longitude: any;
countyDistrict: any;
address3: any;
address4: any;
address5: any;
address6: any;
tags: Tag[];
parentLocation: ParentLocation;
childLocations: ChildLocation[];
retired: boolean;
attributes: any[];
address7: any;
address8: any;
address9: any;
address10: any;
address11: any;
address12: any;
address13: any;
address14: any;
address15: any;
links: Link[];
resourceVersion: string;
}

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

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

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

export interface Form {
uuid: string;
display: string;
name: string;
description: string;
encounterType: EncounterType;
version: string;
build: any;
published: boolean;
formFields: any[];
retired: boolean;
resources: Resource[];
links: Link[];
resourceVersion: string;
}

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

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

export interface EncounterType2 {
uuid: string;
display: string;
name: string;
description: string;
retired: boolean;
links: Link[];
resourceVersion: string;
}

export interface Ob {
uuid: string;
display: string;
concept: Concept;
person: Person;
obsDatetime: string;
accessionNumber: any;
obsGroup: any;
valueCodedName: any;
groupMembers: any;
comment: any;
location: Location2;
order: any;
encounter: Encounter;
voided: boolean;
value: any;
valueModifier: any;
formFieldPath: string;
formFieldNamespace: string;
links: Link[];
resourceVersion: string;
}

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

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

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

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

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 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 interface AuditInfo {
creator: Creator;
dateCreated: string;
changedBy: any;
dateChanged: any;
}

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

export interface Visit {
uuid: string;
display: string;
patient: Patient;
visitType: VisitType;
indication: any;
location: Location;
startDatetime: string;
stopDatetime: any;
encounters: Encounter[];
attributes: any[];
voided: boolean;
links: Link[];
resourceVersion: string;
}

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

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

export function useGetEncounterById(encounterUuid: string) {
const apiUrl = `/ws/rest/v1/encounter/${encounterUuid}?v=full`;
const { data, error, isLoading } = useSWR<{ data: EncounterResponse }, Error>(
apiUrl,
openmrsFetch
);

return {
encounter: data?.data,
isLoading,
isError: error,
};
}
25 changes: 8 additions & 17 deletions src/patient-chart/laboratory-order.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ 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 {
formatDate,
parseDate,
usePagination,
useSession,
} from "@openmrs/esm-framework";
import { usePagination, useSession } from "@openmrs/esm-framework";
import {
DataTable,
DataTableSkeleton,
Expand Down Expand Up @@ -85,7 +80,7 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
} else {
let filteredItems = [];
items.map((item) => {
const newArray = item?.orders.filter(
const newArray = item?.orders?.filter(
(order) =>
order?.concept?.display
.toLowerCase()
Expand Down Expand Up @@ -127,16 +122,9 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
const tableRows = useMemo(() => {
return paginatedLabEntries?.map((entry) => ({
...entry,
id: entry.uuid,
encounterDate: {
content: (
<span>
{formatDate(parseDate(entry.encounterDatetime), {
time: false,
noToday: true,
mode: "wide",
})}
</span>
),
content: <span>{entry.encounterDatetime}</span>,
},
orders: {
content: (
Expand Down Expand Up @@ -166,7 +154,10 @@ const LaboratoryOrder: React.FC<LaboratoryOrderOverviewProps> = ({
actions: {
content: (
<>
<ViewLaboratoryItemActionMenu closeModal={() => true} />
<ViewLaboratoryItemActionMenu
closeModal={() => true}
encounterUuid={entry.uuid}
/>
</>
),
},
Expand Down
Loading

0 comments on commit bba3b1c

Please sign in to comment.