Skip to content

Commit

Permalink
Merge branch 'develop' into camera_error_fix_1
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh-D-2004 authored Mar 7, 2025
2 parents ac0c657 + 0837b8d commit 8440f02
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 156 deletions.
202 changes: 202 additions & 0 deletions src/components/Encounter/EncounterActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { Link } from "raviger";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";

import { cn } from "@/lib/utils";

import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button, buttonVariants } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";

import { PLUGIN_Component } from "@/PluginEngine";
import routes from "@/Utils/request/api";
import mutate from "@/Utils/request/mutate";
import { Encounter, completedEncounterStatus } from "@/types/emr/encounter";

interface EncounterActionsProps {
encounter: Encounter;
variant?: "default" | "outline" | "ghost";
size?: "default" | "sm" | "lg" | "icon";
disableButtons?: boolean;
className?: string;
layout?: "dropdown" | "standalone";
}

export default function EncounterActions({
encounter,
variant = "outline",
size = "default",
disableButtons = false,
className,
layout = "standalone",
}: EncounterActionsProps) {
const { t } = useTranslation();
const queryClient = useQueryClient();

const { mutate: updateEncounter } = useMutation({
mutationFn: mutate(routes.encounter.update, {
pathParams: { id: encounter.id },
}),
onSuccess: () => {
toast.success(t("encounter_marked_as_complete"));
queryClient.invalidateQueries({ queryKey: ["encounter", encounter.id] });
},
onError: () => {
toast.error(t("error_updating_encounter"));
},
});

const handleMarkAsComplete = () => {
updateEncounter({
...encounter,
status: "completed",
organizations: encounter.organizations.map((org) => org.id),
patient: encounter.patient.id,
encounter_class: encounter.encounter_class,
period: encounter.period,
hospitalization: encounter.hospitalization,
priority: encounter.priority,
external_identifier: encounter.external_identifier,
facility: encounter.facility.id,
});
};

if (completedEncounterStatus.includes(encounter.status) || disableButtons) {
return null;
}

const ActionItems = () => {
if (layout === "dropdown") {
return (
<>
<DropdownMenuItem asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}/encounter/${encounter.id}/treatment_summary`}
>
{t("treatment_summary")}
</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}/encounter/${encounter.id}/files/discharge_summary`}
>
{t("discharge_summary")}
</Link>
</DropdownMenuItem>
<AlertDialog>
<AlertDialogTrigger asChild>
<DropdownMenuItem onSelect={(e) => e.preventDefault()}>
{t("mark_as_complete")}
</DropdownMenuItem>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t("mark_as_complete")}</AlertDialogTitle>
<AlertDialogDescription>
{t("mark_encounter_as_complete_confirmation")}
</AlertDialogDescription>
</AlertDialogHeader>

<PLUGIN_Component
__name="PatientInfoCardMarkAsComplete"
encounter={encounter}
/>

<AlertDialogFooter>
<AlertDialogCancel>{t("cancel")}</AlertDialogCancel>
<AlertDialogAction
className={cn(buttonVariants({ variant: "primary" }))}
onClick={handleMarkAsComplete}
data-cy="mark-encounter-as-complete"
>
{t("mark_as_complete")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
}

return (
<div className={cn("space-y-2", className)}>
<Button
variant={variant}
size={size}
className="w-full justify-start"
asChild
>
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}/encounter/${encounter.id}/treatment_summary`}
>
{t("treatment_summary")}
</Link>
</Button>
<Button
variant={variant}
size={size}
className="w-full justify-start"
asChild
>
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}/encounter/${encounter.id}/files/discharge_summary`}
>
{t("discharge_summary")}
</Link>
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant={variant}
size={size}
className="w-full justify-start"
>
{t("mark_as_complete")}
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t("mark_as_complete")}</AlertDialogTitle>
<AlertDialogDescription>
{t("mark_encounter_as_complete_confirmation")}
</AlertDialogDescription>
</AlertDialogHeader>

<PLUGIN_Component
__name="PatientInfoCardMarkAsComplete"
encounter={encounter}
/>

<AlertDialogFooter>
<AlertDialogCancel>{t("cancel")}</AlertDialogCancel>
<AlertDialogAction
className={cn(buttonVariants({ variant: "primary" }))}
onClick={handleMarkAsComplete}
data-cy="mark-encounter-as-complete"
>
{t("mark_as_complete")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<PLUGIN_Component
__name="PatientInfoCardActions"
encounter={encounter}
/>
</div>
);
};

return ActionItems();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useQuery } from "@tanstack/react-query";
import { t } from "i18next";
import { Link, useQueryParams } from "raviger";
import { useQueryParams } from "raviger";
import { Trans, useTranslation } from "react-i18next";

import { cn } from "@/lib/utils";

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

import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";

Expand Down Expand Up @@ -297,8 +294,8 @@ function ResponseCard({
}

export default function QuestionnaireResponsesList({
encounter,
patientId,
facilityId,
isPrintPreview = false,
onlyUnstructured,
}: Props) {
Expand All @@ -314,8 +311,9 @@ export default function QuestionnaireResponsesList({
limit: RESULTS_PER_PAGE_LIMIT,
offset: ((qParams.page ?? 1) - 1) * RESULTS_PER_PAGE_LIMIT,
}),
encounter: encounter?.id,
only_unstructured: onlyUnstructured,
subject_type: "patient",
subject_type: encounter ? "encounter" : "patient",
},
maxPages: isPrintPreview ? undefined : 1,
pageSize: isPrintPreview ? 100 : RESULTS_PER_PAGE_LIMIT,
Expand All @@ -325,23 +323,6 @@ export default function QuestionnaireResponsesList({
return (
<div className="mt-4 gap-4">
<div className="max-w-full">
<div className="flex justify-between items-center mb-4">
<div className="mr-4 text-xl font-bold text-secondary-900">
{t("updates")}
</div>
<Button asChild variant="outline_primary">
<Link
href={
facilityId
? `/facility/${facilityId}/patient/${patientId}/questionnaire`
: `/patient/${patientId}/questionnaire`
}
>
<CareIcon icon="l-plus" className="mr-2" />
{t("add_patient_updates")}
</Link>
</Button>
</div>
{isLoading ? (
<div className="grid gap-5">
<CardListSkeleton count={RESULTS_PER_PAGE_LIMIT} />
Expand Down
10 changes: 10 additions & 0 deletions src/components/Facility/ConsultationDetails/QuickAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CareIcon from "@/CAREUI/icons/CareIcon";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";

import EncounterActions from "@/components/Encounter/EncounterActions";
import LinkDepartmentsSheet from "@/components/Patient/LinkDepartmentsSheet";

import useQuestionnaireOptions from "@/hooks/useQuestionnaireOptions";
Expand Down Expand Up @@ -44,6 +45,15 @@ export default function QuickAccess({ encounter }: QuickAccessProps) {
</section>
)}

{/* Encounter Actions */}
<section>
<h3 className="text-lg font-medium text-gray-950 mb-1">
{t("actions")}
</h3>

<EncounterActions encounter={encounter} />
</section>

{/* Departments and Teams */}
<section>
<div className="items-center justify-between mb-3">
Expand Down
4 changes: 2 additions & 2 deletions src/components/Patient/PatientDetailsTab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import QuestionnaireResponsesList from "@/components/Facility/ConsultationDetails/QuestionnaireResponsesList";
import EncounterHistory from "@/components/Patient/PatientDetailsTab//EncounterHistory";
import { HealthProfileSummary } from "@/components/Patient/PatientDetailsTab//HealthProfileSummary";
import { Demography } from "@/components/Patient/PatientDetailsTab/Demography";
Expand All @@ -9,6 +8,7 @@ import { Appointments } from "./Appointments";
import { PatientFilesTab } from "./PatientFiles";
import { PatientUsers } from "./PatientUsers";
import { ResourceRequests } from "./ResourceRequests";
import { Updates } from "./patientUpdates";

export interface PatientProps {
facilityId?: string;
Expand All @@ -35,7 +35,7 @@ export const patientTabs = [
},
{
route: "updates",
component: QuestionnaireResponsesList,
component: Updates,
},
{
route: "resource_requests",
Expand Down
36 changes: 36 additions & 0 deletions src/components/Patient/PatientDetailsTab/patientUpdates.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Link } from "raviger";
import { useTranslation } from "react-i18next";

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

import { Button } from "@/components/ui/button";

import QuestionnaireResponsesList from "@/components/Facility/ConsultationDetails/QuestionnaireResponsesList";

import { PatientProps } from ".";

export const Updates = (props: PatientProps) => {
const { patientId, facilityId } = props;
const { t } = useTranslation();

return (
<div className="mt-4 px-3 md:px-0">
<div className="flex justify-between items-center mb-4">
<h2 className="text-2xl font-semibold leading-tight">{t("updates")}</h2>
<Button asChild variant="outline_primary">
<Link
href={
facilityId
? `/facility/${facilityId}/patient/${patientId}/questionnaire`
: `/patient/${patientId}/questionnaire`
}
>
<CareIcon icon="l-plus" className="mr-2" />
{t("add_patient_updates")}
</Link>
</Button>
</div>
<QuestionnaireResponsesList patientId={patientId} />
</div>
);
};
Loading

0 comments on commit 8440f02

Please sign in to comment.