diff --git a/src/lib/components/composable/use-patient-form.svelte.js b/src/lib/components/composable/use-patient-form.svelte.js index 5c16b5a..a99391c 100644 --- a/src/lib/components/composable/use-patient-form.svelte.js +++ b/src/lib/components/composable/use-patient-form.svelte.js @@ -25,7 +25,25 @@ export function usePatientForm(formState, patientSchema) { return status === "success" && data === false ? false : true; }, { message: "Patient ID already used" } - ) + ), + EmailAddress1: patientSchema.shape.EmailAddress1.refine( + async (value) => { + if (!value) return false; + const res = await fetch(`${API.BASE_URL}${API.CHECK}?EmailAddress1=${value}`); + const { status, data } = await res.json(); + return status === "success" && data === false ? false : true; + }, + { message: "Email address already used" } + ), + EmailAddress2: patientSchema.shape.EmailAddress2.refine( + async (value) => { + if (!value) return false; + const res = await fetch(`${API.BASE_URL}${API.CHECK}?EmailAddress1=${value}`); + const { status, data } = await res.json(); + return status === "success" && data === false ? false : true; + }, + { message: "Email address already used" } + ), }); const partial = asyncSchema.pick({ [field]: true }); diff --git a/src/lib/components/dictionary/testmap/page/create-page.svelte b/src/lib/components/dictionary/testmap/page/create-page.svelte index 523ecfb..20c01f7 100644 --- a/src/lib/components/dictionary/testmap/page/create-page.svelte +++ b/src/lib/components/dictionary/testmap/page/create-page.svelte @@ -114,10 +114,10 @@ tempMap, }); console.log(payload) - // const result = await formState.save(masterDetail.mode, payload); + const result = await formState.save(masterDetail.mode, payload); - // toast('Test Map Created!'); - // masterDetail?.exitForm(true); + toast('Test Map Created!'); + masterDetail?.exitForm(true); } const primaryAction = $derived({ diff --git a/src/lib/components/patient/list/config/patient-form-config.js b/src/lib/components/patient/list/config/patient-form-config.js index 9a09fd6..59f9f51 100644 --- a/src/lib/components/patient/list/config/patient-form-config.js +++ b/src/lib/components/patient/list/config/patient-form-config.js @@ -14,7 +14,10 @@ export const patientSchema = z.object({ EmailAddress2: z.string().trim().optional().refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val),"Invalid email format"), Phone: z.string().max(14, "Max 14 chars").regex(/^$|^[0-9]+$/, "Can only contain numbers"), MobilePhone: z.string().max(14, "Max 14 chars").regex(/^$|^[0-9]+$/, "Can only contain numbers"), - TimeOfDeath: z.string().optional(), + TimeOfDeath: z.string().optional().refine( + (date) => new Date(date) <= new Date(), + "Cannot exceed today's date" + ), }); export const patientInitialForm = { @@ -69,6 +72,7 @@ export const patientDefaultErrors = { PatIdt_Identifier: null, Phone: null, MobilePhone: null, + TimeOfDeath: null, }; export const patientFormFields = [ @@ -259,7 +263,7 @@ export const patientFormFields = [ { type: "row", columns: [ - { key: "EmailAddress2", label: "Email Address 2", required: false, type: "email", validateOn: ["input"] }, + { key: "EmailAddress2", label: "Email Address 2", required: false, type: "email", validateOn: ["input", "blur"] }, { key: "MobilePhone", label: "Mobile Phone", required: false, type: "text", validateOn: ["input"] }, ] }, @@ -277,7 +281,7 @@ export const patientFormFields = [ optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/death_indicator`, defaultValue: 'N' }, - { key: "TimeOfDeath", label: "Time of Death", required: false, type: "datetime" } + { key: "TimeOfDeath", label: "Time of Death", required: false, type: "datetime", validateOn: ["input"] } ] }, { key: "LinkTo", label: "Link To", required: false, type: "linkto" } diff --git a/src/lib/components/patient/reusable/patient-form-renderer.svelte b/src/lib/components/patient/reusable/patient-form-renderer.svelte index 10b514e..46f90a8 100644 --- a/src/lib/components/patient/reusable/patient-form-renderer.svelte +++ b/src/lib/components/patient/reusable/patient-form-renderer.svelte @@ -114,7 +114,7 @@ }} onblur={() => { if (validateOn?.includes("blur")) { - formState.validateField(key, formState.form[key], false); + validateFieldAsync(key, mode, originalData?.[key]); } }} /> @@ -147,12 +147,13 @@ { + parentFunction={(val) => { formState.form[key] = val; if (validateOn?.includes("input")) { - formState.validateField(key, formState.form[key], false); + formState.validateField(key, val, false); } }} + /> {:else if type === "textarea"}