diff --git a/src/lib/components/order/ordertest/modal/search-param-modal.svelte b/src/lib/components/order/ordertest/modal/search-param-modal.svelte index 67858f0..13d955d 100644 --- a/src/lib/components/order/ordertest/modal/search-param-modal.svelte +++ b/src/lib/components/order/ordertest/modal/search-param-modal.svelte @@ -12,29 +12,62 @@ import ReusableEmpty from "$lib/components/reusable/reusable-empty.svelte"; import { Checkbox } from "$lib/components/ui/checkbox/index.js"; import * as Popover from "$lib/components/ui/popover/index.js"; + import { API } from "$lib/config/api"; + import { formatUTCDate } from "$lib/utils/formatUTCDate"; - // let { selectedPatient = $bindable(null), ...props } = $props(); let props = $props(); let tempSelectedPatient = $state(null); + let tempSelectedVisit = $state(null); + let visitData = $state(null); + let isLoadingVisit = $state(false); + let hasFetched = $state(false); let activeRowId = $state(null); let isPatientEmpty = $derived(!tempSelectedPatient); + let isVisitEmpty = $derived(!tempSelectedVisit); + + async function handleCheckboxChange(patient) { + if (tempSelectedPatient?.InternalPID === patient.InternalPID) { + tempSelectedPatient = null; + visitData = null; + hasFetched = false; + return; + } - function handleCheckboxChange(patient) { tempSelectedPatient = patient; + hasFetched = false; + isLoadingVisit = true; + + try { + const res = await fetch(`${API.BASE_URL}${API.VISITLIST}${patient.InternalPID}`); + visitData = await res.json(); + } finally { + isLoadingVisit = false; + hasFetched = true; + } + } + + function handleCheckboxVisit(visit) { + if (tempSelectedVisit?.PVID === visit.PVID) { + tempSelectedVisit = null; + return; + } + + tempSelectedVisit = visit; } function handleButtonClick() { - if (tempSelectedPatient) { + if (tempSelectedVisit) { props.onConfirm(tempSelectedPatient); - tempSelectedPatient = null; + tempSelectedVisit = null; } } + $inspect(tempSelectedVisit) -