diff --git a/aidbox-forms-smart-launch-2/src/app/(authorized)/public-library/questionnaires/page.tsx b/aidbox-forms-smart-launch-2/src/app/(authorized)/public-library/questionnaires/page.tsx new file mode 100644 index 0000000..5b5f821 --- /dev/null +++ b/aidbox-forms-smart-launch-2/src/app/(authorized)/public-library/questionnaires/page.tsx @@ -0,0 +1,133 @@ +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { PageHeader } from "@/components/page-header"; +import { PageSizeSelect } from "@/components/page-size-select"; +import Link from "next/link"; +import { Search } from "lucide-react"; +import { Pager } from "@/components/pager"; +import { Bundle, Questionnaire } from "fhir/r4"; +import { isDefined } from "@/lib/utils"; +import { decidePageSize } from "@/lib/server/utils"; +import ky from "ky"; + +interface PageProps { + searchParams: Promise<{ + page?: string; + title?: string; + pageSize?: string; + }>; +} + +export default async function PublicLibraryPage({ searchParams }: PageProps) { + const publicLibrary = ky.extend({ + prefixUrl: "https://form-builder.aidbox.app", + }); + const params = await searchParams; + + const pageSize = await decidePageSize(params.pageSize); + const page = Number(params.page) || 1; + const title = params.title || ""; + + const response = await publicLibrary + .get("fhir/Questionnaire", { + searchParams: { + _count: pageSize, + _page: page, + ...(title && { "title:contains": title }), + }, + }) + .json>(); + + const resources = + response.entry?.map((entry) => entry.resource)?.filter(isDefined) || []; + + const total = response.total || 0; + const totalPages = Math.ceil(total / pageSize); + + return ( + <> + +
+
+
+
+ + +
+ + {title && ( + + )} +
+
+ +
+ + + + Title + Status + Date + Actions + + + + {resources.map((resource) => ( + + {resource.title} + {resource.status} + {resource.date} + + + + + ))} + {!resources.length && ( + + + No questionnaires found + + + )} + +
+
+ +
+
+ {total ? ( +
{`Showing ${ + (page - 1) * pageSize + 1 + }-${Math.min( + page * pageSize, + total, + )} of ${total} practitioners`}
+ ) : null} + +
+ +
+
+ + ); +} diff --git a/aidbox-forms-smart-launch-2/src/components/app-menu.tsx b/aidbox-forms-smart-launch-2/src/components/app-menu.tsx index f5b9b6c..663a616 100644 --- a/aidbox-forms-smart-launch-2/src/components/app-menu.tsx +++ b/aidbox-forms-smart-launch-2/src/components/app-menu.tsx @@ -4,6 +4,8 @@ import * as React from "react"; import { FileQuestion, LayoutDashboard, + Library, + LucideIcon, SquareMenu, UserCog, Users, @@ -11,57 +13,113 @@ import { import { usePathname } from "next/navigation"; import { + SidebarGroup, + SidebarGroupContent, + SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem, + SidebarMenuSub, + SidebarMenuSubButton, + SidebarMenuSubItem, } from "@/components/ui/sidebar"; import Link from "next/link"; -const data = { - navMain: [ - { - title: "Dashboard", - href: "/dashboard", - icon: LayoutDashboard, - }, - { - title: "Patients", - href: "/patients", - icon: Users, - }, - { - title: "Practitioners", - href: "/practitioners", - icon: UserCog, - }, - { - title: "Questionnaires", - href: "/questionnaires", - icon: FileQuestion, - }, - { - title: "Questionnaire Responses", - href: "/questionnaire-responses", - icon: SquareMenu, - }, - ], -}; +const data: { + label?: string; + children: { + icon: LucideIcon; + href: string; + title: string; + children?: { + icon: LucideIcon; + href: string; + title: string; + }[]; + }[]; +}[] = [ + { + children: [ + { + title: "Dashboard", + href: "/dashboard", + icon: LayoutDashboard, + }, + { + title: "Patients", + href: "/patients", + icon: Users, + }, + { + title: "Practitioners", + href: "/practitioners", + icon: UserCog, + }, + { + title: "Questionnaires", + href: "/questionnaires", + icon: FileQuestion, + }, + { + title: "Questionnaire Responses", + href: "/questionnaire-responses", + icon: SquareMenu, + }, + ], + }, + { + label: "Public Library", + children: [ + { + title: "Questionnaires", + href: "/public-library/questionnaires", + icon: Library, + }, + ], + }, +]; export function AppMenu() { const pathname = usePathname(); return ( - - {data.navMain.map((item) => ( - - - - - {item.title} - - - + <> + {data.map((group, index) => ( + + {group.label && {group.label}} + + + {group.children.map((item) => ( + + + + + {item.title} + + + {item.children && ( + + {item.children.map((child) => ( + + + + + {child.title} + + + + ))} + + )} + + ))} + + + ))} - + ); } diff --git a/aidbox-forms-smart-launch-2/src/components/app-sidebar.tsx b/aidbox-forms-smart-launch-2/src/components/app-sidebar.tsx index 3bb4707..c62864c 100644 --- a/aidbox-forms-smart-launch-2/src/components/app-sidebar.tsx +++ b/aidbox-forms-smart-launch-2/src/components/app-sidebar.tsx @@ -5,7 +5,6 @@ import { Sidebar, SidebarContent, SidebarFooter, - SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuButton, @@ -43,9 +42,7 @@ export function AppSidebar({ ...props }: React.ComponentProps) { - - - + diff --git a/aidbox-forms-smart-launch/src/hooks/use-client.jsx b/aidbox-forms-smart-launch/src/hooks/use-client.jsx index e1b635c..2454190 100644 --- a/aidbox-forms-smart-launch/src/hooks/use-client.jsx +++ b/aidbox-forms-smart-launch/src/hooks/use-client.jsx @@ -20,19 +20,10 @@ export const defaultScope = [ "patient/QuestionnaireResponse.crus", // Request create, read, update access to QuestionnaireResponse resource ]; -const brokenUrl = "https://form-builder.aidbox.app"; const correctUrl = "https://form-builder.aidbox.app/fhir"; export const publicBuilderClient = client(correctUrl); -export const fixPotentialBrokenUrl = (url) => { - if (url.startsWith(brokenUrl) && !url.startsWith(correctUrl)) { - return url.replace(brokenUrl, correctUrl); - } - - return url; -}; - const clientContext = createContext(null); export const authorize = (options) => { diff --git a/aidbox-forms-smart-launch/src/lib/utils.js b/aidbox-forms-smart-launch/src/lib/utils.js index 0002312..e72f1d1 100644 --- a/aidbox-forms-smart-launch/src/lib/utils.js +++ b/aidbox-forms-smart-launch/src/lib/utils.js @@ -1,9 +1,6 @@ import { clsx } from "clsx"; import { twMerge } from "tailwind-merge"; -import { - fixPotentialBrokenUrl, - publicBuilderClient, -} from "@/hooks/use-client.jsx"; +import { publicBuilderClient } from "@/hooks/use-client.jsx"; export function cn(...inputs) { return twMerge(clsx(inputs)); @@ -271,7 +268,7 @@ export async function findQuestionnaireWithClient(client, ref) { .then((result) => [publicBuilderClient, unbundle(result)]), client.request(query).then((result) => [client, unbundle(result)]), publicBuilderClient - .request(fixPotentialBrokenUrl(ref)) + .request(ref) .then((result) => [publicBuilderClient, unbundle(result)]), ]); }