qol ordertest page

-fix add selected button
-move var to parent master-page
-add spinner when data refresh
This commit is contained in:
faiztyanirh 2026-04-27 17:48:33 +07:00
parent cdb3fdc7dd
commit 24f1eaf985
6 changed files with 69 additions and 19 deletions

View File

@ -1,6 +1,7 @@
import PlusIcon from "@lucide/svelte/icons/plus"; import PlusIcon from "@lucide/svelte/icons/plus";
import Settings2Icon from "@lucide/svelte/icons/settings-2"; import Settings2Icon from "@lucide/svelte/icons/settings-2";
import PencilIcon from "@lucide/svelte/icons/pencil"; import PencilIcon from "@lucide/svelte/icons/pencil";
import RefreshIcon from "@lucide/svelte/icons/refresh-cw";
export const searchFields = [ export const searchFields = [
{ {
@ -53,8 +54,14 @@ export const detailSections = [
}, },
]; ];
export function orderTestActions(masterDetail, selectedPatient, selectedVisit) { export function orderTestActions(masterDetail, selectedPatient, selectedVisit, handlers) {
return [ return [
{
Icon: RefreshIcon,
label: 'Refresh Data',
onClick: handlers.refresh,
disabled: !selectedPatient,
},
{ {
Icon: PlusIcon, Icon: PlusIcon,
label: 'Add Order', label: 'Add Order',

View File

@ -15,13 +15,15 @@
import { API } from "$lib/config/api"; import { API } from "$lib/config/api";
import { formatUTCDate } from "$lib/utils/formatUTCDate"; import { formatUTCDate } from "$lib/utils/formatUTCDate";
let props = $props(); let {
let tempSelectedPatient = $state(null); tempSelectedPatient = $bindable(null),
let tempSelectedVisit = $state(null); tempSelectedVisit = $bindable(null),
let visitData = $state(null); visitData = $bindable(null),
let isLoadingVisit = $state(false); hasFetched = $bindable(false),
let hasFetched = $state(false); isLoadingVisit = $bindable(false),
...props
} = $props()
let activeRowId = $state(null); let activeRowId = $state(null);
let isPatientEmpty = $derived(!tempSelectedPatient); let isPatientEmpty = $derived(!tempSelectedPatient);
@ -61,7 +63,7 @@
if (tempSelectedVisit) { if (tempSelectedVisit) {
props.onConfirm(tempSelectedPatient, tempSelectedVisit); props.onConfirm(tempSelectedPatient, tempSelectedVisit);
tempSelectedVisit = null; // tempSelectedVisit = null;
} }
} }
</script> </script>

View File

@ -7,6 +7,7 @@
import { buildOrderTestPayload } from "$lib/components/order/ordertest/config/ordertest-form-config"; import { buildOrderTestPayload } from "$lib/components/order/ordertest/config/ordertest-form-config";
import { orderStore } from "$lib/components/order/ordertest/store/order-store.svelte"; import { orderStore } from "$lib/components/order/ordertest/store/order-store.svelte";
import { formatUTCDate } from "$lib/utils/formatUTCDate"; import { formatUTCDate } from "$lib/utils/formatUTCDate";
import { onMount } from "svelte";
let props = $props(); let props = $props();
@ -50,6 +51,12 @@
}); });
const secondaryActions = []; const secondaryActions = [];
onMount(() => {
if (!formState.form.TrnDate) {
formState.form.TrnDate = new Date().toISOString();
}
});
</script> </script>
<FormPageContainer title="Create Order for {formState.form?.PatientID} - {formState.form?.PatientName}" {primaryAction} {secondaryActions} {actions}> <FormPageContainer title="Create Order for {formState.form?.PatientID} - {formState.form?.PatientName}" {primaryAction} {secondaryActions} {actions}>

View File

@ -8,6 +8,7 @@
import { getChangedFields } from "$lib/utils/getChangedFields"; import { getChangedFields } from "$lib/utils/getChangedFields";
import { orderStore } from "$lib/components/order/ordertest/store/order-store.svelte"; import { orderStore } from "$lib/components/order/ordertest/store/order-store.svelte";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { untrack } from "svelte";
let props = $props(); let props = $props();
@ -100,10 +101,24 @@
// idCounter = maxId; // idCounter = maxId;
// } // }
// }); // });
$inspect(formState.form);
onMount(()=>{ onMount(()=>{
console.log('mount dr edit page'); console.log('mount dr edit page');
}) });
$effect(() => {
untrack(() => {
for (const group of formFields) {
for (const row of group.rows) {
for (const col of row.columns) {
if (col.type === 'select' && col.optionsEndpoint) {
formState.fetchOptions(col, formState.form);
}
}
}
}
});
});
</script> </script>
<FormPageContainer title="Edit Order for {orderStore.selectedPatient.PatientID} - {orderStore.selectedPatient.FullName}" {primaryAction} {secondaryActions}> <FormPageContainer title="Edit Order for {orderStore.selectedPatient.PatientID} - {orderStore.selectedPatient.FullName}" {primaryAction} {secondaryActions}>

View File

@ -16,18 +16,33 @@
import { patientStore } from "$lib/components/patient/list/store/patient-store.svelte"; import { patientStore } from "$lib/components/patient/list/store/patient-store.svelte";
import { formatUTCDate } from "$lib/utils/formatUTCDate"; import { formatUTCDate } from "$lib/utils/formatUTCDate";
import { orderStore } from "$lib/components/order/ordertest/store/order-store.svelte"; import { orderStore } from "$lib/components/order/ordertest/store/order-store.svelte";
import { Spinner } from "$lib/components/ui/spinner/index.js";
let props = $props(); let props = $props();
// let selectedPatient = $state(null);
// let selectedVisit = $state(null);
let isLoading = $state(false); let isLoading = $state(false);
let searchData = $state([]); let searchData = $state([]);
let tempSelectedPatient = $state(null);
let tempSelectedVisit = $state(null);
let visitData = $state(null);
let isLoadingVisit = $state(false);
let hasFetched = $state(false);
let isRefreshData = $state(false);
const search = useSearch(searchFields, searchParam); const search = useSearch(searchFields, searchParam);
const handlers = {
refresh: async () => {
isRefreshData = true;
try {
await handlePatientConfirm(tempSelectedPatient, tempSelectedVisit);
} finally {
isRefreshData = false;
}
}
};
let actions = $derived.by(() => { let actions = $derived.by(() => {
return orderTestActions(props.masterDetail, orderStore.selectedPatient, orderStore.selectedVisit).map(action => { return orderTestActions(props.masterDetail, orderStore.selectedPatient, orderStore.selectedVisit, handlers).map(action => {
if (action.label === 'Search Parameters') { if (action.label === 'Search Parameters') {
return { ...action, popoverContent: searchParamSnippet }; return { ...action, popoverContent: searchParamSnippet };
} }
@ -74,10 +89,11 @@
patientStore.pending = null; patientStore.pending = null;
} }
}) })
$inspect(tempSelectedVisit)
</script> </script>
{#snippet searchParamSnippet()} {#snippet searchParamSnippet()}
<SearchParamModal {search} {searchFields} onConfirm={handlePatientConfirm}/> <SearchParamModal {search} {searchFields} bind:tempSelectedPatient bind:tempSelectedVisit bind:visitData bind:hasFetched onConfirm={handlePatientConfirm}/>
{/snippet} {/snippet}
<div <div
@ -135,12 +151,16 @@
</div> </div>
</div> </div>
{/if} {/if}
<div class="flex-1 w-full h-full"> <div class="flex-1 w-full h-full relative overflow-hidden">
{#if isRefreshData}
<div class="absolute inset-0 flex items-center justify-center bg-background/50 z-10">
<Spinner class="size-6" />
</div>
{/if}
{#if searchData?.length > 0} {#if searchData?.length > 0}
<ReusableDataTable data={searchData} columns={orderTestColumns} handleRowClick={props.masterDetail.select} {activeRowId} rowIdKey="InternalOID" offset="8"/> <ReusableDataTable data={searchData} columns={orderTestColumns} handleRowClick={props.masterDetail.select} {activeRowId} rowIdKey="InternalOID" offset="8"/>
{:else} {:else}
<div class="flex h-full"> <div class="flex h-full">
<!-- <ReusableEmpty icon={ClipboardXIcon} desc="Try searching from search parameters"/> -->
<ReusableEmpty title="No Order" icon={ClipboardXIcon} desc={searchData ? "No order available" : "Try searching from search parameters"}/> <ReusableEmpty title="No Order" icon={ClipboardXIcon} desc={searchData ? "No order available" : "Try searching from search parameters"}/>
</div> </div>
{/if} {/if}

View File

@ -153,7 +153,6 @@
}); });
onMount(() => { onMount(() => {
console.log('mount dr render')
if (!formState.form.Tests?.length) return; if (!formState.form.Tests?.length) return;
pendingTests = formState.form.Tests.map(test => ({ pendingTests = formState.form.Tests.map(test => ({
@ -362,7 +361,7 @@
size="sm" size="sm"
class="px-4 py-2 rounded" class="px-4 py-2 rounded"
onclick={addSelected} onclick={addSelected}
disabled={selectedTests.length === 0} disabled={activeSelectedCount === 0}
> >
Add selected Add selected
</Button> </Button>