Skip to content

Commit 4105e21

Browse files
committed
Add careplan status changes
1 parent d5185d7 commit 4105e21

File tree

5 files changed

+173
-2
lines changed

5 files changed

+173
-2
lines changed

src/app/(dashboard)/patients/[id]/visits/page.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import { fetchData } from "./fetch";
3+
import Link from "next/link";
34

45
type Props = {
56
params: { id: string };
@@ -11,8 +12,9 @@ const Visits = async ({ params: { id } }: Props) => {
1112
<div className="container">
1213
<div className="flex flex-col gap-4 w-full">
1314
{data?.map((item) => (
14-
<div
15+
<Link
1516
key={item.id}
17+
href={`/visit/${item.id}`}
1618
className="card card-compact bg-base-100 shadow-xl w-full"
1719
>
1820
<div className="card-body">
@@ -26,7 +28,7 @@ const Visits = async ({ params: { id } }: Props) => {
2628
</div>
2729
<p>{item.period?.toString()}</p>
2830
</div>
29-
</div>
31+
</Link>
3032
))}
3133
</div>
3234
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use server";
2+
3+
import { fhirServer } from "@/lib/api/axios";
4+
import { CarePlanListItem, CarePlanStatus } from "./models";
5+
6+
export const fetchData = async (
7+
id: string
8+
): Promise<CarePlanListItem | null> => {
9+
try {
10+
const resource = (await fhirServer.get(`/CarePlan/${id}`)).data;
11+
return {
12+
id: resource.id ?? "",
13+
title: resource.title ?? "NA",
14+
status: resource.status ?? "NA",
15+
intent: resource.intent ?? "NA",
16+
period: resource.period?.start,
17+
visit:
18+
resource.category?.find(
19+
(e: any) =>
20+
e?.coding?.[0].system ==
21+
"https://d-tree.org/fhir/care-plan-visit-number"
22+
)?.coding?.[0].code ?? "NA",
23+
};
24+
} catch (error) {
25+
console.error(error);
26+
return null;
27+
}
28+
};
29+
30+
export const onCarePlanStatusChange = async (
31+
id: string,
32+
status: CarePlanStatus
33+
) => {
34+
try {
35+
const resource = (await fhirServer.get(`/CarePlan/${id}`)).data;
36+
await fhirServer.put(`/CarePlan/${id}`, {
37+
...resource,
38+
status: status,
39+
});
40+
} catch (error) {
41+
console.error(error);
42+
return null;
43+
}
44+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"use client";
2+
3+
import React from "react";
4+
import {
5+
Select,
6+
SelectContent,
7+
SelectItem,
8+
SelectTrigger,
9+
SelectValue,
10+
} from "@/components/ui/select";
11+
import { CarePlanListItem, CarePlanStatus, carePlanStatus } from "./models";
12+
import { Label } from "@/components/ui/label";
13+
import { Button } from "@/components/ui/button";
14+
15+
import { useRouter } from "next/navigation";
16+
17+
type Props = {
18+
id: string;
19+
data: CarePlanListItem | null;
20+
onCarePlanStatusChange: (
21+
id: string,
22+
status: CarePlanStatus
23+
) => Promise<null | undefined>;
24+
};
25+
26+
const Components = ({ data, id, onCarePlanStatusChange }: Props) => {
27+
const router = useRouter();
28+
const [status, setStatus] = React.useState<CarePlanStatus | null | undefined>(
29+
data?.status
30+
);
31+
const [loading, setLoading] = React.useState(false);
32+
return (
33+
<div className="space-y-2">
34+
<div className="flex flex-row gap-2 items-end">
35+
<Label>Status</Label>
36+
<Select
37+
onValueChange={(value) => setStatus(value as CarePlanStatus)}
38+
defaultValue={data?.status}
39+
>
40+
<SelectTrigger>
41+
<SelectValue placeholder="Select a verified email to display" />
42+
</SelectTrigger>
43+
<SelectContent>
44+
{carePlanStatus.map((status) => (
45+
<SelectItem key={status} value={status}>
46+
{status}
47+
</SelectItem>
48+
))}
49+
</SelectContent>
50+
</Select>
51+
{status !== data?.status && (
52+
<Button
53+
disabled={loading}
54+
onClick={async () => {
55+
if (status) {
56+
setLoading(true);
57+
await onCarePlanStatusChange(id, status);
58+
setLoading(false);
59+
window.location.reload();
60+
}
61+
}}
62+
>
63+
{loading ? "Saving..." : "Save"}
64+
</Button>
65+
)}
66+
</div>
67+
</div>
68+
);
69+
};
70+
71+
export default Components;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export interface CarePlanListItem {
2+
id: string;
3+
title: string;
4+
status: string;
5+
intent: string;
6+
period?: Date | string;
7+
visit: string;
8+
}
9+
10+
// draft | active | on-hold | revoked | completed | entered-in-error | unknown
11+
export const carePlanStatus = [
12+
"draft",
13+
"active",
14+
"on-hold",
15+
"revoked",
16+
"completed",
17+
"entered-in-error",
18+
"unknown",
19+
];
20+
21+
export type CarePlanStatus = (typeof carePlanStatus)[number];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react";
2+
import { fetchData, onCarePlanStatusChange } from "./action";
3+
import Components from "./component";
4+
5+
type Props = {
6+
params: { careplan: string };
7+
};
8+
9+
const Page = async ({ params: { careplan } }: Props) => {
10+
const data = await fetchData(careplan);
11+
return (
12+
<div className="container">
13+
<div>
14+
<h2>{data?.title}</h2>
15+
<div>
16+
<span>Visit {data?.visit}</span>
17+
<span>Status {data?.status}</span>
18+
<span>Intent {data?.intent}</span>
19+
</div>
20+
<p>{data?.period?.toString()}</p>
21+
</div>
22+
<div>
23+
<Components
24+
id={careplan}
25+
data={data}
26+
onCarePlanStatusChange={onCarePlanStatusChange}
27+
/>
28+
</div>
29+
</div>
30+
);
31+
};
32+
33+
export default Page;

0 commit comments

Comments
 (0)