From 9cada5fbd4f77da4a1ff26c1a26bd18b32167455 Mon Sep 17 00:00:00 2001 From: faiztyanirh Date: Sat, 14 Feb 2026 14:26:01 +0700 Subject: [PATCH] continue location dict --- .../composable/use-dictionary-form.svelte.js | 12 +++ .../location/config/location-config.js | 39 ++++++++ .../location/config/location-form-config.js | 62 ++++++++----- .../location/page/create-page.svelte | 64 +++++++++++++ .../location/page/master-page.svelte | 2 +- .../dictionary/location/page/view-page.svelte | 92 ++++++++++++++++++- .../patient/admission/page/create-page.svelte | 18 ++-- .../reusable/reusable-search-param.svelte | 60 ------------ 8 files changed, 256 insertions(+), 93 deletions(-) create mode 100644 src/lib/components/composable/use-dictionary-form.svelte.js diff --git a/src/lib/components/composable/use-dictionary-form.svelte.js b/src/lib/components/composable/use-dictionary-form.svelte.js new file mode 100644 index 0000000..e5b8f7e --- /dev/null +++ b/src/lib/components/composable/use-dictionary-form.svelte.js @@ -0,0 +1,12 @@ +export function useDictionaryForm(formState) { + let uploadErrors = $state({}); + let isChecking = $state({}); + + let hasErrors = $derived( + Object.values(formState.errors).some(value => value !== null) + ); + + return { + get hasErrors() { return hasErrors }, + } +} \ No newline at end of file diff --git a/src/lib/components/dictionary/location/config/location-config.js b/src/lib/components/dictionary/location/config/location-config.js index 20d0a4f..9891e94 100644 --- a/src/lib/components/dictionary/location/config/location-config.js +++ b/src/lib/components/dictionary/location/config/location-config.js @@ -22,6 +22,45 @@ export const searchFields = [ ]; export const detailSections = [ + { + class: "grid grid-cols-2 gap-4 items-center", + fields: [ + { key: "SiteID", label: "Site" }, + { key: "Parent", label: "Parent" }, + { key: "LocCode", label: "Location Code" }, + { key: "LocFull", label: "Location Name" }, + { key: "LocType", label: "Location Type" }, + { key: "Description", label: "Description" }, + ] + }, + { + title: "", + class: "grid grid-cols-1 md:grid-cols-2 gap-4", + groups: [ + { + class: "space-y-3", + fields: [ + { key: "Province", label: "Province" }, + { key: "City", label: "City" }, + { key: "PostCode", label: "ZIP" }, + ] + }, + { + class: "space-y-3", + fields: [ + { key: "Street1", label: "Street 1" }, + { key: "Street2", label: "Street 2" }, + ] + } + ] + }, + { + class: "grid grid-cols-2 gap-4 items-center", + fields: [ + { key: "GeoLocationSystem", label: "Geo Location System" }, + { key: "GeoLocationData", label: "Geo Location Data" }, + ] + }, ]; export function locationActions(masterDetail) { diff --git a/src/lib/components/dictionary/location/config/location-form-config.js b/src/lib/components/dictionary/location/config/location-form-config.js index 098afca..dd7c624 100644 --- a/src/lib/components/dictionary/location/config/location-form-config.js +++ b/src/lib/components/dictionary/location/config/location-form-config.js @@ -2,7 +2,10 @@ import { API } from "$lib/config/api"; import EraserIcon from "@lucide/svelte/icons/eraser"; import { z } from "zod"; -export const locationSchema = z.object({}); +export const locationSchema = z.object({ + LocCode: z.string().min(1, "Required"), + LocFull: z.string().min(1, "Required"), +}); export const locationInitialForm = { LocationID: '', @@ -23,8 +26,7 @@ export const locationInitialForm = { export const locationDefaultErrors = { LocCode: "Required", - LocName: "Required", - LocType: "Required", + LocFull: "Required", }; export const locationFormFields = [ @@ -37,7 +39,7 @@ export const locationFormFields = [ { key: "SiteID", label: "Site ID", - required: true, + required: false, type: "select", optionsEndpoint: `${API.BASE_URL}${API.SITE}`, }, @@ -48,21 +50,26 @@ export const locationFormFields = [ type: "text", validateOn: ["input"] }, + ] + }, + { + type: "row", + columns: [ { key: "LocType", label: "Location Type", - required: true, + required: false, type: "text", - validateOn: ["input"] }, { key: "LocFull", label: "Location Name", - required: false, + required: true, type: "text", + validateOn: ["input"] } ] - } + }, ] }, { @@ -78,25 +85,26 @@ export const locationFormFields = [ type: "select", optionsEndpoint: `${API.BASE_URL}${API.PROVINCE}`, }, - { - key: "City", - label: "City", - required: false, - type: "select", - optionsEndpoint: `${API.BASE_URL}${API.CITY}`, - }, - { - key: "ZIP", - label: "ZIP", - required: false, - type: "text", - }, { key: "Street1", label: "Street 1", required: false, type: "text", }, + ] + }, + { + type: "row", + columns: [ + { + key: "City", + label: "City", + required: false, + type: "select", + optionsEndpoint: `${API.BASE_URL}${API.CITY}`, + dependsOn: "Province", + endpointParamKey: "Parent" + }, { key: "Street2", label: "Street 2", @@ -105,7 +113,17 @@ export const locationFormFields = [ } ] }, - + { + type: "row", + columns: [ + { + key: "ZIP", + label: "ZIP", + required: false, + type: "text", + }, + ] + }, ] }, { diff --git a/src/lib/components/dictionary/location/page/create-page.svelte b/src/lib/components/dictionary/location/page/create-page.svelte index e69de29..c7c5dc8 100644 --- a/src/lib/components/dictionary/location/page/create-page.svelte +++ b/src/lib/components/dictionary/location/page/create-page.svelte @@ -0,0 +1,64 @@ + + + + + + + \ No newline at end of file diff --git a/src/lib/components/dictionary/location/page/master-page.svelte b/src/lib/components/dictionary/location/page/master-page.svelte index 16622d9..d9213b9 100644 --- a/src/lib/components/dictionary/location/page/master-page.svelte +++ b/src/lib/components/dictionary/location/page/master-page.svelte @@ -55,7 +55,7 @@
{#if search.searchData.length > 0} - + {:else}
diff --git a/src/lib/components/dictionary/location/page/view-page.svelte b/src/lib/components/dictionary/location/page/view-page.svelte index 3e0b9eb..e556fd1 100644 --- a/src/lib/components/dictionary/location/page/view-page.svelte +++ b/src/lib/components/dictionary/location/page/view-page.svelte @@ -1 +1,91 @@ -vw \ No newline at end of file + + +{#snippet Fieldset({ value, label, isUTCDate = false })} +
+
+ {label} +
+
+ {#if isUTCDate} + {formatUTCDate(value)} + {:else} + {value ?? "-"} + {/if} +
+
+{/snippet} + +{#if masterDetail.selectedItem} +
+ +
+ {#each detailSections as section} +
+ {#if section.groups} +
+ {#each section.groups as group} +
+
+ {#each group.fields as field} + {@render Fieldset({ + label: field.label, + value: getFieldValue(field), + isUTCDate: field.isUTCDate + })} + {/each} +
+
+ {/each} +
+ {:else} +
+ {#each section.fields as field} + {@render Fieldset({ + label: field.label, + value: getFieldValue(field), + isUTCDate: field.isUTCDate + })} + {/each} +
+ {/if} +
+ {/each} +
+
+{:else} + +{/if} \ No newline at end of file diff --git a/src/lib/components/patient/admission/page/create-page.svelte b/src/lib/components/patient/admission/page/create-page.svelte index 7e4983f..0ac022c 100644 --- a/src/lib/components/patient/admission/page/create-page.svelte +++ b/src/lib/components/patient/admission/page/create-page.svelte @@ -24,16 +24,16 @@ let showConfirm = $state(false); - function handleExit() { - const ok = masterDetail.exitForm(); - if (!ok) { - showConfirm = true; - } - } + // function handleExit() { + // const ok = masterDetail.exitForm(); + // if (!ok) { + // showConfirm = true; + // } + // } - function confirmDiscard() { - masterDetail.exitForm(true); - } + // function confirmDiscard() { + // masterDetail.exitForm(true); + // } async function handleSave() { const payload = buildPayload(formState.form); diff --git a/src/lib/components/reusable/reusable-search-param.svelte b/src/lib/components/reusable/reusable-search-param.svelte index 4c72f54..e3e4aa0 100644 --- a/src/lib/components/reusable/reusable-search-param.svelte +++ b/src/lib/components/reusable/reusable-search-param.svelte @@ -9,14 +9,6 @@ let props = $props(); let loadedFields = $state(new Set()); - - function handleOpenSelect(field) { - if (loadedFields.has(field.key)) return; - - loadedFields.add(field.key); - props.fetchOptions(field); - } - $inspect(props.searchQuery)
@@ -55,58 +47,6 @@ {/each} - - - -
{/if} {/each}