diff --git a/src/lib/components/dictionary/test/config/test-form-config.js b/src/lib/components/dictionary/test/config/test-form-config.js index 979f267..ed243c8 100644 --- a/src/lib/components/dictionary/test/config/test-form-config.js +++ b/src/lib/components/dictionary/test/config/test-form-config.js @@ -456,7 +456,7 @@ export const testFormFields = [ type: 'row', columns: [ { - key: 'VSet', + key: 'Vset', label: 'Value Set', required: false, type: 'select', @@ -1066,7 +1066,7 @@ export function buildTestPayload({ mainForm, activeFormStates, testType, refNumD })) } else if (key === 'refTxt' && refTxtData?.length > 0) { // payload[key] = refTxtData; - payload.refTxt = refTxtData.map(row => ({ + payload.reftxt = refTxtData.map(row => ({ ...row, AgeStart: toDays(row.AgeStart), AgeEnd: toDays(row.AgeEnd), @@ -1077,7 +1077,7 @@ export function buildTestPayload({ mainForm, activeFormStates, testType, refNumD Members: state.form?.Members?.map((m) => m.value).filter(Boolean) ?? [] }; } else if (key === 'map' && mapData?.length > 0) { - payload.testMap = mapData; + payload.testmap = mapData; } else if (key === 'cal') { payload[key] = { ...state.form diff --git a/src/lib/components/dictionary/test/page/create-page.svelte b/src/lib/components/dictionary/test/page/create-page.svelte index d3825cf..f04224a 100644 --- a/src/lib/components/dictionary/test/page/create-page.svelte +++ b/src/lib/components/dictionary/test/page/create-page.svelte @@ -220,7 +220,7 @@ let hiddenFields = $derived.by(() => { const resultType = formState?.form?.ResultType; - return resultType !== 'VSET' ? ['VSet'] : []; + return resultType !== 'VSET' ? ['Vset'] : []; }); let refComponent = $derived.by(() => { @@ -238,7 +238,7 @@ columns: row.columns.map((col) => { if (col.key !== 'RefTxt') return col; - if (formState.form.ResultType !== 'VSET' || !formState.form.VSet) { + if (formState.form.ResultType !== 'VSET' || !formState.form.Vset) { return { ...col, type: 'textarea', @@ -249,7 +249,7 @@ return { ...col, type: 'select', - optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.VSet}`, + optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.Vset}`, fullWidth: false }; }) diff --git a/src/lib/components/dictionary/test/page/edit-page.svelte b/src/lib/components/dictionary/test/page/edit-page.svelte index 330cb6a..ffbd140 100644 --- a/src/lib/components/dictionary/test/page/edit-page.svelte +++ b/src/lib/components/dictionary/test/page/edit-page.svelte @@ -52,8 +52,6 @@ const { formState } = masterDetail; - $inspect(formState.form) - const calFormState = useForm({ schema: testCalSchema, initialForm: testCalInitialForm, @@ -213,7 +211,7 @@ let hiddenFields = $derived.by(() => { const resultType = formState?.form?.ResultType; - return resultType !== 'VSET' ? ['VSet'] : []; + return resultType !== 'VSET' ? ['Vset'] : []; }); let refComponent = $derived.by(() => { @@ -231,7 +229,7 @@ columns: row.columns.map((col) => { if (col.key !== 'RefTxt') return col; - if (formState.form.ResultType !== 'VSET' || !formState.form.VSet) { + if (formState.form.ResultType !== 'VSET' || !formState.form.Vset) { return { ...col, type: 'textarea', @@ -242,7 +240,7 @@ return { ...col, type: 'select', - optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.VSet}`, + optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.Vset}`, fullWidth: false }; }) @@ -328,14 +326,28 @@ $effect(() => { const mainForm = formState.form; - if (mainForm.refnum && Array.isArray(mainForm.refnum)) { - refNumData = mainForm.refnum.map((row, index) => ({ + if (mainForm.refnum && Array.isArray(mainForm.refnum)) { + refNumData = mainForm.refnum.map((row, index) => ({ id: row.id ?? index + 1, ...row, AgeStart: typeof row.AgeStart === 'number' ? buildAgeText(daysToAge(row.AgeStart)) : row.AgeStart, AgeEnd: typeof row.AgeEnd === 'number' ? buildAgeText(daysToAge(row.AgeEnd)) : row.AgeEnd, })); } + if (mainForm.reftxt && Array.isArray(mainForm.reftxt)) { + refTxtData = mainForm.reftxt.map((row, index) => ({ + id: row.id ?? index + 1, + ...row, + AgeStart: typeof row.AgeStart === 'number' ? buildAgeText(daysToAge(row.AgeStart)) : row.AgeStart, + AgeEnd: typeof row.AgeEnd === 'number' ? buildAgeText(daysToAge(row.AgeEnd)) : row.AgeEnd, + })); + } + // if (mainForm.testmap && Array.isArray(mainForm.testmap)) { + // mapData = mainForm.testmap.map((row, index) => ({ + // id: row.id ?? index + 1, + // ...row, + // })); + // } }) $effect(() => { diff --git a/src/lib/components/dictionary/test/page/tabs/ref-num.svelte b/src/lib/components/dictionary/test/page/tabs/ref-num.svelte index 41951a1..18f45a1 100644 --- a/src/lib/components/dictionary/test/page/tabs/ref-num.svelte +++ b/src/lib/components/dictionary/test/page/tabs/ref-num.svelte @@ -434,14 +434,14 @@ - {/if} - +
{#if row.Low && row.High} - {row.LowSign} {row.Low} – {row.HighSign} {row.High} + [ {row.LowSign} {row.Low} ] – [ {row.HighSign} {row.High} ] {:else if row.Low} - {row.LowSign} {row.Low} + [ {row.LowSign} {row.Low} ] {:else if row.High} - {row.HighSign} {row.High} + [ {row.HighSign} {row.High} ] {:else} - {/if} diff --git a/src/lib/components/dictionary/test/page/tabs/ref-txt.svelte b/src/lib/components/dictionary/test/page/tabs/ref-txt.svelte index f4be67e..0b3a3bd 100644 --- a/src/lib/components/dictionary/test/page/tabs/ref-txt.svelte +++ b/src/lib/components/dictionary/test/page/tabs/ref-txt.svelte @@ -11,7 +11,7 @@ import { toDays } from "$lib/utils/ageUtils"; let { tempTxt = $bindable([]), resetRefTxt = $bindable(), ...props } = $props() - +$inspect(props.refTxtFormFields) let editingId = $state(null); let idCounter = $state(0); @@ -59,17 +59,22 @@ const newEnd = toDays(props.refTxtState.form.AgeEnd); const isOverlap = tempTxt.some(row => { + if ((row.SpcType ?? '') !== (props.refTxtState.form.SpcType ?? '')) return false; + if ((row.Sex ?? '') !== (props.refTxtState.form.Sex ?? '')) return false; + if ((row.TxtRefType ?? '') !== (props.refTxtState.form.TxtRefType ?? '')) return false; + + if (row.id === editingId) return false; + const existingStart = toDays(row.AgeStart); const existingEnd = toDays(row.AgeEnd); - if (existingStart == null || existingEnd == null) return false; + if (existingStart == null || existingEnd == null) return false; - return !(newEnd < existingStart || newStart > existingEnd); + return (newStart <= existingEnd && newEnd >= existingStart); }); if (isOverlap) { - props.refTxtState.errors.AgeEnd = - "Age range overlaps with existing data"; + props.refTxtState.errors.AgeEnd = "Age range overlaps with existing data"; return; } @@ -137,16 +142,31 @@ $effect(() => { for (const key of ["AgeStart", "AgeEnd"]) { - props.refTxtState.form[key] = - buildAgeText(joinFields[key]); + props.refTxtState.form[key] = buildAgeText(joinFields[key]); } + untrack(() => { + props.refTxtState.validateAll?.(); + }) }); $effect(() => { - const allColumns = props.refTxtFormFields.flatMap( - (section) => section.rows.flatMap( - (row) => row.columns ?? [] - ) + const currentEditingId = editingId; + if (currentEditingId === null) return; + + untrack(() => { + for (const key of ['AgeStart', 'AgeEnd']) { + const val = props.refTxtState.form[key] ?? ''; + const match = val.match(/(\d+)Y\s*(\d+)M\s*(\d+)D/); + if (match) { + joinFields[key] = { YY: match[1], MM: match[2], DD: match[3] }; + } + } + }); + }); + + $effect(() => { + const allColumns = props.refTxtFormFields.flatMap((section) => + section.rows.flatMap((row) => row.columns ?? []) ); untrack(() => { @@ -165,6 +185,17 @@ } }) }); + + $effect(() => { + const maxId = tempTxt.reduce((max, row) => { + const rowId = typeof row.id === 'number' ? row.id : 0; + return rowId > max ? rowId : max; + }, 0); + + if (maxId > idCounter) { + idCounter = maxId; + } + });