From a4c2e0ec5fd69c8a876f092e2fc2d12a675a59d4 Mon Sep 17 00:00:00 2001 From: faiztyanirh Date: Sat, 7 Feb 2026 13:44:32 +0700 Subject: [PATCH] continuing admission page --- src/lib/api/api-client.js | 26 +++++++++++++- .../admission/api/patient-admission-api.js | 7 ++-- .../admission/modal/search-param-modal.svelte | 36 +++++-------------- .../patient/admission/page/master-page.svelte | 31 +++++++++++----- .../patient/admission/table/visit-columns.js | 4 +++ src/routes/patient/admission/+page.svelte | 4 +-- 6 files changed, 67 insertions(+), 41 deletions(-) diff --git a/src/lib/api/api-client.js b/src/lib/api/api-client.js index d4eb0be..15d48e6 100644 --- a/src/lib/api/api-client.js +++ b/src/lib/api/api-client.js @@ -15,7 +15,26 @@ function cleanQuery(searchQuery) { return result; } -export async function getById(endpoint, id) { +// export async function getById(endpoint, id) { +// try { +// const res = await fetch(`${API.BASE_URL}${endpoint}/${id}`); + +// if (!res.ok) { +// const error = await res.json(); +// console.error('API Error:', error); +// return { data: null, error }; +// } + +// const response = await res.json(); +// console.log(response); +// return { data: response.data?.[0] || response.data, error: null }; +// } catch (err) { +// console.error('Network Error:', err); +// return { data: null, error: err }; +// } +// } + +export async function getById(endpoint, id, returnAll = false) { try { const res = await fetch(`${API.BASE_URL}${endpoint}/${id}`); @@ -26,6 +45,11 @@ export async function getById(endpoint, id) { } const response = await res.json(); + + if (returnAll) { + return { data: response.data, error: null }; + } + return { data: response.data?.[0] || response.data, error: null }; } catch (err) { console.error('Network Error:', err); diff --git a/src/lib/components/patient/admission/api/patient-admission-api.js b/src/lib/components/patient/admission/api/patient-admission-api.js index c1499d1..8d612bf 100644 --- a/src/lib/components/patient/admission/api/patient-admission-api.js +++ b/src/lib/components/patient/admission/api/patient-admission-api.js @@ -5,9 +5,12 @@ export async function searchParam(searchQuery) { return await searchWithParams(API.PATIENTS, searchQuery) } +export async function getVisitList(searchQuery) { + return await getById(API.VISITLIST, searchQuery, true) +} + export async function getVisit(searchQuery) { - const { data: visit, error } = await getById(API.VISITLIST, searchQuery) - return { visit }; + return await getById(API.PATVISIT, searchQuery) } export async function getPatient(searchQuery) { diff --git a/src/lib/components/patient/admission/modal/search-param-modal.svelte b/src/lib/components/patient/admission/modal/search-param-modal.svelte index e16830b..5b8cc97 100644 --- a/src/lib/components/patient/admission/modal/search-param-modal.svelte +++ b/src/lib/components/patient/admission/modal/search-param-modal.svelte @@ -14,34 +14,19 @@ import { Checkbox } from "$lib/components/ui/checkbox/index.js"; import * as Popover from "$lib/components/ui/popover/index.js"; - let props = $props(); + let { selectedPatient = $bindable(null), ...props } = $props(); let activeRowId = $state(null); - let selectedPatient = $state({ - InternalPID: null, - PatientID: null, - }); + let isPatientEmpty = $derived(!selectedPatient); - const isPatientEmpty = $derived(!selectedPatient.InternalPID || !selectedPatient.PatientID); - - function togglePatientSelection(patient) { - if (selectedPatient.InternalPID === patient.InternalPID) { - selectedPatient = { - InternalPID: null, - PatientID: null, - }; - } else { - selectedPatient = { - InternalPID: patient.InternalPID, - PatientID: patient.PatientID, - }; - } + function handleCheckboxChange(patient) { + selectedPatient = patient; } function handleButtonClick() { if (selectedPatient) { - props.onConfirm(selectedPatient.InternalPID); + props.onConfirm(selectedPatient); } } @@ -108,13 +93,13 @@ {#each props.search.searchData as patient, i} togglePatientSelection(patient)} + onclick={() => handleCheckboxChange(patient)} > e.stopPropagation()}> togglePatientSelection(patient)} + checked={selectedPatient?.InternalPID === patient.InternalPID} + onCheckedChange={() => handleCheckboxChange(patient)} /> {patient.PatientID} @@ -134,12 +119,9 @@ disabled={isPatientEmpty} onclick={handleButtonClick} > - Confirm + Select Patient - {:else} diff --git a/src/lib/components/patient/admission/page/master-page.svelte b/src/lib/components/patient/admission/page/master-page.svelte index 5c218bc..940bdd3 100644 --- a/src/lib/components/patient/admission/page/master-page.svelte +++ b/src/lib/components/patient/admission/page/master-page.svelte @@ -1,6 +1,6 @@ {#snippet searchParamSnippet()} - + {/snippet}
- + {#if searchData?.data?.length > 0} + + {:else}
- + {/if}
{/if} diff --git a/src/lib/components/patient/admission/table/visit-columns.js b/src/lib/components/patient/admission/table/visit-columns.js index d1f736a..84ae648 100644 --- a/src/lib/components/patient/admission/table/visit-columns.js +++ b/src/lib/components/patient/admission/table/visit-columns.js @@ -3,4 +3,8 @@ export const visitColumns = [ accessorKey: "PVID", header: "Visit ID", }, + { + accessorKey: "EpisodeID", + header: "Episode ID", + }, ]; \ No newline at end of file diff --git a/src/routes/patient/admission/+page.svelte b/src/routes/patient/admission/+page.svelte index 8b16bf5..13b3e99 100644 --- a/src/routes/patient/admission/+page.svelte +++ b/src/routes/patient/admission/+page.svelte @@ -9,10 +9,10 @@ const masterDetail = useMasterDetail({ onSelect: async (row) => { - return await getVisit(row.InternalPID); + return await getVisit(row.PVID); }, }); - + $inspect(masterDetail.selectedItem)