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

Location Popover & History Sheet #10540

Merged
merged 18 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
322cf9d
Location search fix
amjithtitus09 Feb 6, 2025
c783ce1
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Feb 6, 2025
340a975
Initial Commit
amjithtitus09 Feb 7, 2025
b25e067
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Feb 10, 2025
980aed1
Location History, Patient Name link
amjithtitus09 Feb 10, 2025
7af96b2
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Feb 10, 2025
37f0c32
Fix test - Patient details update
amjithtitus09 Feb 10, 2025
4a424ff
Merge branch 'develop' into encounter-overview-location
amjithtitus09 Feb 10, 2025
aba11be
Update src/components/Patient/PatientInfoCard.tsx
amjithtitus09 Feb 10, 2025
b199625
Update src/components/Location/LocationTree.tsx
amjithtitus09 Feb 10, 2025
85c838e
Update src/components/Location/LocationTree.tsx
amjithtitus09 Feb 10, 2025
3346a49
Converted to Recursion
amjithtitus09 Feb 10, 2025
39ef239
Merge branch 'encounter-overview-location' of https://github.com/ohcn…
amjithtitus09 Feb 10, 2025
c6fa906
Remove depth calculation
amjithtitus09 Feb 11, 2025
5819c06
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Feb 11, 2025
aba997f
Update the patient button in encounter page
bodhish Feb 11, 2025
ecaa675
Move location to the right, Add location button
amjithtitus09 Feb 11, 2025
32d5f72
Merge branch 'develop' of https://github.com/ohcnetwork/care_fe into …
amjithtitus09 Feb 11, 2025
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
8 changes: 4 additions & 4 deletions cypress/pageObject/Patients/PatientEncounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ export class PatientEncounter {
}

clickPatientDetailsButton() {
cy.verifyAndClickElement(
'[data-cy="patient-details-button"]',
"Patient Details",
);
cy.get('[data-cy="patient-details-button"]')
.filter(":visible")
.first()
.click();
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@
"location_created": "Location Created",
"location_details": "Location Details",
"location_form": "Location Form",
"location_history": "Location History",
"location_management": "Location Management",
"location_updated": "Location Updated",
"location_updated_successfully": "Location updated successfully",
Expand Down Expand Up @@ -2197,6 +2198,7 @@
"update_facility": "Update Facility",
"update_facility_middleware_success": "Facility middleware updated successfully",
"update_hospitalisation_details": "Update Hospitalisation Details",
"update_location": "Update Location",
"update_log": "Update Log",
"update_password": "Update Password",
"update_patient_details": "Update Patient Details",
Expand Down
49 changes: 49 additions & 0 deletions src/components/Location/LocationHistorySheet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useTranslation } from "react-i18next";

import { ScrollArea } from "@/components/ui/scroll-area";
import {
Sheet,
SheetContent,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet";

import { LocationHistory } from "@/types/emr/encounter";

import { LocationTree } from "./LocationTree";

interface LocationHistorySheetProps {
trigger: React.ReactNode;
history: LocationHistory[];
}

export function LocationHistorySheet({
trigger,
history,
}: LocationHistorySheetProps) {
const { t } = useTranslation();

return (
<Sheet>
<SheetTrigger asChild>{trigger}</SheetTrigger>
<SheetContent className="w-full sm:max-w-xl">
<SheetHeader className="px-1">
<SheetTitle>{t("location_history")}</SheetTitle>
</SheetHeader>
<ScrollArea className="h-[calc(100vh-8rem)] mt-6">
{history.map((item, index) => (
<div key={index}>
<LocationTree
location={item.location}
datetime={item.start_datetime}
isLatest={index === 0}
showTimeline
/>
</div>
))}
Comment on lines +35 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use stable keys for list items instead of array indices.

Using array indices as keys can lead to performance issues and bugs when items are reordered or removed.

-          {history.map((item, index) => (
-            <div key={index}>
+          {history.map((item) => (
+            <div key={`${item.location.id}_${item.start_datetime}`}>

Committable suggestion skipped: line range outside the PR's diff.

</ScrollArea>
</SheetContent>
</Sheet>
);
}
105 changes: 105 additions & 0 deletions src/components/Location/LocationTree.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { format } from "date-fns";
import React from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

import { LocationList } from "@/types/location/location";

interface LocationPathProps {
location: LocationList;
datetime?: string;
isLatest?: boolean;
showTimeline?: boolean;
}

interface LocationNodeProps {
location: LocationList;
isLast: boolean;
datetime?: string;
children?: React.ReactNode;
}

function LocationNode({
location,
isLast,
datetime,
children,
}: LocationNodeProps) {
if (!location.parent?.id) {
return (
<div className="flex flex-col gap-2">
<div className="flex items-center text-sm">
<span className="w-2 h-2 rounded-full bg-gray-400 mr-2" />
<span
className={isLast ? "font-semibold" : "text-gray-700 font-medium"}
>
{location.name}
</span>
</div>
{children}
{isLast && datetime && (
<div className="pl-6 flex items-center text-sm font-normal text-gray-700 italic">
{format(new Date(datetime), "MMM d, yyyy h:mm a")}
</div>
)}
</div>
);
}

return (
<LocationNode location={location.parent} isLast={false} datetime={datetime}>
<div className="flex flex-col gap-2 ml-6">
<div className="flex items-center text-sm">
<CareIcon
icon="l-corner-down-right"
className="w-4 h-4 mr-2 mb-1 text-gray-400"
/>
<span
className={isLast ? "font-semibold" : "text-gray-700 font-medium"}
>
{location.name}
</span>
</div>
{children}
{isLast && datetime && (
<div className="pl-6 flex items-center text-sm font-normal text-gray-700 italic">
{format(new Date(datetime), "MMM d, yyyy h:mm a")}
</div>
)}
</div>
</LocationNode>
);
}

export function LocationTree({
location,
datetime,
isLatest,
showTimeline = false,
}: LocationPathProps) {
return (
<div
className={`relative flex ${showTimeline ? "gap-8 pl-12" : ""} pt-0.5`}
>
{showTimeline && (
<div className="absolute left-0 top-0 bottom-0 flex flex-col items-center">
<div
className={`absolute w-px bg-gray-200 h-full ${isLatest ? "top-3" : "-top-3"}`}
/>
<div
className={`h-6 w-6 rounded-full ${isLatest ? "bg-green-100" : "bg-gray-100"} flex items-center justify-center z-10`}
>
<CareIcon
icon={isLatest ? "l-location-point" : "l-check"}
className={`h-4 w-4 ${isLatest ? "text-green-600" : "text-gray-600"}`}
/>
</div>
{!isLatest && <div className="flex-1 w-px bg-gray-200" />}
</div>
)}
<div className="flex flex-col gap-2">
<LocationNode location={location} isLast={true} datetime={datetime} />
</div>
</div>
);
}
106 changes: 86 additions & 20 deletions src/components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
Expand All @@ -30,6 +31,10 @@ import {
} from "@/components/ui/popover";

import { Avatar } from "@/components/Common/Avatar";
import { LocationHistorySheet } from "@/components/Location/LocationHistorySheet";
import { LocationTree } from "@/components/Location/LocationTree";

import useQuestionnaireOptions from "@/hooks/useQuestionnaireOptions";

import { PLUGIN_Component } from "@/PluginEngine";
import routes from "@/Utils/request/api";
Expand All @@ -50,6 +55,7 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
const { patient, encounter } = props;
const { t } = useTranslation();
const queryClient = useQueryClient();
const questionnaireOptions = useQuestionnaireOptions("encounter_actions");

const { mutate: updateEncounter } = useMutation({
mutationFn: mutate(routes.encounter.update, {
Expand Down Expand Up @@ -97,7 +103,18 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
className="mb-2 flex flex-col text-xl font-semibold capitalize lg:hidden"
id="patient-name-consultation"
>
{patient.name}
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}`}
className="text-gray-950 font-semibold flex items-start gap-0.5"
id="patient-details"
data-cy="patient-details-button"
>
{patient.name}
<CareIcon
icon="l-external-link-alt"
className="w-3 h-3 opacity-50 mt-1"
/>
</Link>
<div className="mt-[6px] text-sm font-semibold text-secondary-600">
{formatPatientAge(patient, true)} •{" "}
{t(`GENDER__${patient.gender}`)}
Expand All @@ -111,7 +128,18 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
className="hidden flex-row text-xl font-semibold capitalize lg:flex"
id="patient-name-consultation"
>
{patient.name}
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}`}
className="text-gray-950 font-semibold flex items-start gap-0.5"
id="patient-details"
data-cy="patient-details-button"
>
{patient.name}
<CareIcon
icon="l-external-link-alt"
className="w-3 h-3 opacity-50 mt-1"
/>
</Link>
<div className="ml-3 mr-2 mt-[6px] text-sm font-semibold text-secondary-600">
{formatPatientAge(patient, true)} •{" "}
{t(`GENDER__${patient.gender}`)}
Expand Down Expand Up @@ -208,31 +236,57 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
variant="outline"
title={`Current Location: ${props.encounter.current_location.name}`}
>
<Building className="w-4 h-4 text-blue-400" />
<CareIcon
icon="l-location-point"
className="h-4 w-4 text-green-600"
/>
{props.encounter.current_location.name}
<ChevronDown className="h-3 w-3 opacity-50" />
</Badge>
</div>
</PopoverTrigger>
<PopoverContent align={"start"} className="w-auto p-2">
<div className="space-y-2">
<h4 className="font-medium text-sm">
Current Location
</h4>
<p className="text-sm text-gray-700">
{props.encounter.current_location.name}
</p>
<p className="text-sm text-gray-500">
{props.encounter.current_location.description}
</p>
</div>
<Button variant="outline">
<Link
href={`/facility/${props.encounter.facility.id}/patient/${props.patient.id}/encounter/${props.encounter.id}/questionnaire/location_association`}
<div className="space-y-2 p-2 items-center">
<div className="flex items-center gap-8 justify-between">
<h4 className="font-medium text-sm">
{t("location")}
</h4>

<LocationHistorySheet
history={encounter.location_history}
trigger={
<div>
<CareIcon
icon="l-history"
className="w-4 h-4 text-gray-700"
/>
<Button
variant="link"
className="text-gray-950 underline pl-1 pr-0 font-semibold"
>
{t("history")}
</Button>
</div>
}
/>
</div>
<div className="border-b border-gray-200 my-2" />
<LocationTree
location={props.encounter.current_location}
/>
<div className="border-b border-dashed border-gray-200 my-2" />
<Button
variant="outline"
className="border-gray-400 w-full"
>
Move Patient
</Link>
</Button>
<Link
href={`/facility/${props.encounter.facility.id}/patient/${props.patient.id}/encounter/${props.encounter.id}/questionnaire/location_association`}
className="text-sm text-gray-950 font-semibold"
>
{t("update_location")}
</Link>
</Button>
</div>
</PopoverContent>
</Popover>
)}
Expand Down Expand Up @@ -372,6 +426,18 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{questionnaireOptions.map((option) => (
<DropdownMenuItem key={option.slug} asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
className="cursor-pointer text-gray-800"
data-cy="update-encounter-option"
>
{t(option.title)}
</Link>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add loading state for questionnaire options.

The dropdown menu should handle the loading state of questionnaire options to prevent potential UI flickers.

+const questionnaireOptions = useQuestionnaireOptions("encounter_actions");
+const isLoading = !questionnaireOptions?.length;

 <DropdownMenuContent align="end">
+  {isLoading ? (
+    <DropdownMenuItem disabled>
+      {t("loading_options")}
+    </DropdownMenuItem>
+  ) : (
     {questionnaireOptions.map((option) => (
       <DropdownMenuItem key={option.slug} asChild>
         <Link
           href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
           className="cursor-pointer text-gray-800"
           data-cy="update-encounter-option"
         >
           {t(option.title)}
         </Link>
       </DropdownMenuItem>
     ))}
+  )}
   <DropdownMenuSeparator />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{questionnaireOptions.map((option) => (
<DropdownMenuItem key={option.slug} asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
className="cursor-pointer text-gray-800"
data-cy="update-encounter-option"
>
{t(option.title)}
</Link>
</DropdownMenuItem>
))}
<DropdownMenuSeparator />
const questionnaireOptions = useQuestionnaireOptions("encounter_actions");
const isLoading = !questionnaireOptions?.length;
<DropdownMenuContent align="end">
{isLoading ? (
<DropdownMenuItem disabled>
{t("loading_options")}
</DropdownMenuItem>
) : (
questionnaireOptions.map((option) => (
<DropdownMenuItem key={option.slug} asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
className="cursor-pointer text-gray-800"
data-cy="update-encounter-option"
>
{t(option.title)}
</Link>
</DropdownMenuItem>
))
)}
<DropdownMenuSeparator />
</DropdownMenuContent>

<DropdownMenuLabel>{t("actions")}</DropdownMenuLabel>
<DropdownMenuItem onClick={handleMarkAsComplete}>
{t("mark_as_complete")}
Expand Down
8 changes: 0 additions & 8 deletions src/pages/Encounters/EncounterShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@ export const EncounterShow = (props: Props) => {
)}
</>
)} */}
<Link
href={`/facility/${facilityId}/patient/${encounterData.patient.id}`}
className="btn btn-primary m-1 w-full hover:text-white"
id="patient-details"
data-cy="patient-details-button"
>
{t("patient_details")}
</Link>
</div>
</nav>
<div className="mt-4 xl:mt-0 w-full border-b-2 border-secondary-200">
Expand Down
7 changes: 7 additions & 0 deletions src/types/emr/encounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ export type StatusHistory = {
history: History[];
};

export type LocationHistory = {
start_datetime: string;
location: LocationList;
status: string;
};

export interface Encounter {
id: string;
patient: Patient;
Expand All @@ -138,6 +144,7 @@ export interface Encounter {
status_history: StatusHistory;
organizations: FacilityOrganization[];
current_location: LocationList;
location_history: LocationHistory[];
}

export interface EncounterEditRequest {
Expand Down
1 change: 1 addition & 0 deletions src/types/location/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface LocationDetail extends LocationBase {
export interface LocationList extends LocationBase {
id: string;
has_children: boolean;
parent?: LocationList;
}

export interface LocationWrite extends LocationBase {
Expand Down
Loading