From de7321dbaae8cd326b3bfdcdd2114b3e8b1474e2 Mon Sep 17 00:00:00 2001 From: faiztyanirh Date: Mon, 20 Apr 2026 16:09:40 +0700 Subject: [PATCH] continue testorder modal --- .../ordertest/modal/search-param-modal.svelte | 109 +++++++++++++++--- 1 file changed, 92 insertions(+), 17 deletions(-) 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) -
+
@@ -115,23 +148,65 @@
-
- - - -
{:else}
{/if}
+
+ {#if isLoadingVisit} + + {:else if visitData && visitData.data?.length > 0} +
+
+ Active Visit + + + + + Visit # + Visit Date + + + + {#each visitData.data as visit, i} + handleCheckboxVisit(visit)} + > + e.stopPropagation()}> + handleCheckboxVisit(visit)} + /> + + {visit.PVID} + {formatUTCDate(visit.PVCreateDate)} + + {/each} + + +
+
+
+ + + +
+ {:else if hasFetched} +
+ +
+ {/if} +
\ No newline at end of file