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}