diff --git a/src/lib/components/composable/use-search.svelte.js b/src/lib/components/composable/use-search.svelte.js index f733c69..20666fc 100644 --- a/src/lib/components/composable/use-search.svelte.js +++ b/src/lib/components/composable/use-search.svelte.js @@ -4,6 +4,7 @@ export function useSearch(searchFields, searchApiFunction) { let searchData = $state([]); let selectOptions = $state({}); let loadingOptions = $state({}); + let isRefreshData = $state(false); function initializeSearchQuery(fields) { const query = {}; @@ -63,6 +64,8 @@ export function useSearch(searchFields, searchApiFunction) { get isLoading() { return isLoading; }, get loadingOptions() { return loadingOptions; }, get selectOptions() { return selectOptions; }, + get isRefreshData() { return isRefreshData; }, + set isRefreshData(val) { isRefreshData = val; }, handleSearch, handleReset, fetchOptions, diff --git a/src/lib/components/order/ordertest/config/ordertest-form-config.js b/src/lib/components/order/ordertest/config/ordertest-form-config.js index e5a1639..20df693 100644 --- a/src/lib/components/order/ordertest/config/ordertest-form-config.js +++ b/src/lib/components/order/ordertest/config/ordertest-form-config.js @@ -10,7 +10,21 @@ export const orderTestSchema = z.object({ }) ) .min(1, " "), + TrnDate: z.string(), + EffDate: z.string(), }) +.superRefine((data, ctx) => { + const trn = new Date(data.TrnDate); + const eff = new Date(data.EffDate); + if (trn > eff) { + console.log('ff') + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: 'Cant set before Trn Date', + path: ['EffDate'] + }); + } + }); export const orderTestInitialForm = { InternalOID: '', @@ -19,7 +33,6 @@ export const orderTestInitialForm = { InternalPID: '', SiteID: '', PVADTID: '', - ReqApp: '', Priority: '', TrnDate: '', EffDate: '', @@ -30,6 +43,7 @@ export const orderTestInitialForm = { export const orderTestDefaultErrors = { Tests: '', + EffDate: '', }; export const orderTestFormFields = [ @@ -66,12 +80,6 @@ export const orderTestFormFields = [ required: false, type: "text", }, - { - key: "ReqApp", - label: "Requested Application", - required: false, - type: "text", - }, ] }, { @@ -89,7 +97,8 @@ export const orderTestFormFields = [ label: "Effective Date", required: false, type: "datetime", - allowFuture: true + allowFuture: true, + validateOn: ['input'] }, ] }, diff --git a/src/lib/components/order/ordertest/page/master-page.svelte b/src/lib/components/order/ordertest/page/master-page.svelte index ac593dc..8fba4a0 100644 --- a/src/lib/components/order/ordertest/page/master-page.svelte +++ b/src/lib/components/order/ordertest/page/master-page.svelte @@ -27,16 +27,15 @@ let visitData = $state(null); let isLoadingVisit = $state(false); let hasFetched = $state(false); - let isRefreshData = $state(false); const search = useSearch(searchFields, searchParam); const handlers = { refresh: async () => { - isRefreshData = true; + search.isRefreshData = true; try { await handlePatientConfirm(tempSelectedPatient, tempSelectedVisit); } finally { - isRefreshData = false; + search.isRefreshData = false; } } }; @@ -152,7 +151,7 @@ {/if}
- {#if isRefreshData} + {#if search.isRefreshData}
diff --git a/src/lib/components/reusable/form/order-form-renderer.svelte b/src/lib/components/reusable/form/order-form-renderer.svelte index 65310dd..4151b2f 100644 --- a/src/lib/components/reusable/form/order-form-renderer.svelte +++ b/src/lib/components/reusable/form/order-form-renderer.svelte @@ -163,6 +163,7 @@ selectedTests = [...pendingTests]; }); + $inspect(formState.errors) {#snippet Fieldset({ @@ -179,7 +180,8 @@ labelKey, withLabel = true, })} -
+ +
{#if withLabel}
@@ -190,7 +192,8 @@ {/if}
{/if} -
+ +
{#if type === 'text'} {:else if type === "tests"}
-
+

Test list

@@ -367,7 +370,7 @@
-
+

Test ordered

{pendingTests.length} test(s) @@ -416,19 +419,22 @@ placeholder="Custom field type: {type}" /> {/if} -
- {#if formState.errors[key]} - - {formState.errors[key]} - - {/if} -
+ + {#if type !== 'tests'} +
+ {#if formState.errors[key]} + + {formState.errors[key]} + + {/if} +
+ {/if}
{/snippet} {#snippet GroupBlock(groups)} -
+
{#each groups as group}
{#if group.title} @@ -439,7 +445,7 @@ {#each group.rows as row}
col.key === "Tests")} class:md:grid-cols-1={row.columns.length === 1} class:md:grid-cols-2={row.columns.length === 2}