mirror of
https://github.com/faiztyanirh/clqms-shadcn-v1.git
synced 2026-04-28 11:35:55 +07:00
initial reftxt edit
This commit is contained in:
parent
b546db4a01
commit
9d4f295522
@ -456,7 +456,7 @@ export const testFormFields = [
|
|||||||
type: 'row',
|
type: 'row',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
key: 'VSet',
|
key: 'Vset',
|
||||||
label: 'Value Set',
|
label: 'Value Set',
|
||||||
required: false,
|
required: false,
|
||||||
type: 'select',
|
type: 'select',
|
||||||
@ -1066,7 +1066,7 @@ export function buildTestPayload({ mainForm, activeFormStates, testType, refNumD
|
|||||||
}))
|
}))
|
||||||
} else if (key === 'refTxt' && refTxtData?.length > 0) {
|
} else if (key === 'refTxt' && refTxtData?.length > 0) {
|
||||||
// payload[key] = refTxtData;
|
// payload[key] = refTxtData;
|
||||||
payload.refTxt = refTxtData.map(row => ({
|
payload.reftxt = refTxtData.map(row => ({
|
||||||
...row,
|
...row,
|
||||||
AgeStart: toDays(row.AgeStart),
|
AgeStart: toDays(row.AgeStart),
|
||||||
AgeEnd: toDays(row.AgeEnd),
|
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) ?? []
|
Members: state.form?.Members?.map((m) => m.value).filter(Boolean) ?? []
|
||||||
};
|
};
|
||||||
} else if (key === 'map' && mapData?.length > 0) {
|
} else if (key === 'map' && mapData?.length > 0) {
|
||||||
payload.testMap = mapData;
|
payload.testmap = mapData;
|
||||||
} else if (key === 'cal') {
|
} else if (key === 'cal') {
|
||||||
payload[key] = {
|
payload[key] = {
|
||||||
...state.form
|
...state.form
|
||||||
|
|||||||
@ -220,7 +220,7 @@
|
|||||||
|
|
||||||
let hiddenFields = $derived.by(() => {
|
let hiddenFields = $derived.by(() => {
|
||||||
const resultType = formState?.form?.ResultType;
|
const resultType = formState?.form?.ResultType;
|
||||||
return resultType !== 'VSET' ? ['VSet'] : [];
|
return resultType !== 'VSET' ? ['Vset'] : [];
|
||||||
});
|
});
|
||||||
|
|
||||||
let refComponent = $derived.by(() => {
|
let refComponent = $derived.by(() => {
|
||||||
@ -238,7 +238,7 @@
|
|||||||
columns: row.columns.map((col) => {
|
columns: row.columns.map((col) => {
|
||||||
if (col.key !== 'RefTxt') return col;
|
if (col.key !== 'RefTxt') return col;
|
||||||
|
|
||||||
if (formState.form.ResultType !== 'VSET' || !formState.form.VSet) {
|
if (formState.form.ResultType !== 'VSET' || !formState.form.Vset) {
|
||||||
return {
|
return {
|
||||||
...col,
|
...col,
|
||||||
type: 'textarea',
|
type: 'textarea',
|
||||||
@ -249,7 +249,7 @@
|
|||||||
return {
|
return {
|
||||||
...col,
|
...col,
|
||||||
type: 'select',
|
type: 'select',
|
||||||
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.VSet}`,
|
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.Vset}`,
|
||||||
fullWidth: false
|
fullWidth: false
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|||||||
@ -52,8 +52,6 @@
|
|||||||
|
|
||||||
const { formState } = masterDetail;
|
const { formState } = masterDetail;
|
||||||
|
|
||||||
$inspect(formState.form)
|
|
||||||
|
|
||||||
const calFormState = useForm({
|
const calFormState = useForm({
|
||||||
schema: testCalSchema,
|
schema: testCalSchema,
|
||||||
initialForm: testCalInitialForm,
|
initialForm: testCalInitialForm,
|
||||||
@ -213,7 +211,7 @@
|
|||||||
|
|
||||||
let hiddenFields = $derived.by(() => {
|
let hiddenFields = $derived.by(() => {
|
||||||
const resultType = formState?.form?.ResultType;
|
const resultType = formState?.form?.ResultType;
|
||||||
return resultType !== 'VSET' ? ['VSet'] : [];
|
return resultType !== 'VSET' ? ['Vset'] : [];
|
||||||
});
|
});
|
||||||
|
|
||||||
let refComponent = $derived.by(() => {
|
let refComponent = $derived.by(() => {
|
||||||
@ -231,7 +229,7 @@
|
|||||||
columns: row.columns.map((col) => {
|
columns: row.columns.map((col) => {
|
||||||
if (col.key !== 'RefTxt') return col;
|
if (col.key !== 'RefTxt') return col;
|
||||||
|
|
||||||
if (formState.form.ResultType !== 'VSET' || !formState.form.VSet) {
|
if (formState.form.ResultType !== 'VSET' || !formState.form.Vset) {
|
||||||
return {
|
return {
|
||||||
...col,
|
...col,
|
||||||
type: 'textarea',
|
type: 'textarea',
|
||||||
@ -242,7 +240,7 @@
|
|||||||
return {
|
return {
|
||||||
...col,
|
...col,
|
||||||
type: 'select',
|
type: 'select',
|
||||||
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.VSet}`,
|
optionsEndpoint: `${API.BASE_URL}${API.VALUESET}/${formState.form.Vset}`,
|
||||||
fullWidth: false
|
fullWidth: false
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
@ -328,14 +326,28 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const mainForm = formState.form;
|
const mainForm = formState.form;
|
||||||
if (mainForm.refnum && Array.isArray(mainForm.refnum)) {
|
if (mainForm.refnum && Array.isArray(mainForm.refnum)) {
|
||||||
refNumData = mainForm.refnum.map((row, index) => ({
|
refNumData = mainForm.refnum.map((row, index) => ({
|
||||||
id: row.id ?? index + 1,
|
id: row.id ?? index + 1,
|
||||||
...row,
|
...row,
|
||||||
AgeStart: typeof row.AgeStart === 'number' ? buildAgeText(daysToAge(row.AgeStart)) : row.AgeStart,
|
AgeStart: typeof row.AgeStart === 'number' ? buildAgeText(daysToAge(row.AgeStart)) : row.AgeStart,
|
||||||
AgeEnd: typeof row.AgeEnd === 'number' ? buildAgeText(daysToAge(row.AgeEnd)) : row.AgeEnd,
|
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(() => {
|
$effect(() => {
|
||||||
|
|||||||
@ -434,14 +434,14 @@
|
|||||||
-
|
-
|
||||||
{/if}
|
{/if}
|
||||||
</Table.Cell>
|
</Table.Cell>
|
||||||
<Table.Cell class="font-medium flex justify-between">
|
<Table.Cell class="font-medium font-mono flex justify-between ">
|
||||||
<div>
|
<div>
|
||||||
{#if row.Low && row.High}
|
{#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}
|
{:else if row.Low}
|
||||||
{row.LowSign} {row.Low}
|
[ {row.LowSign} {row.Low} ]
|
||||||
{:else if row.High}
|
{:else if row.High}
|
||||||
{row.HighSign} {row.High}
|
[ {row.HighSign} {row.High} ]
|
||||||
{:else}
|
{:else}
|
||||||
-
|
-
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
import { toDays } from "$lib/utils/ageUtils";
|
import { toDays } from "$lib/utils/ageUtils";
|
||||||
|
|
||||||
let { tempTxt = $bindable([]), resetRefTxt = $bindable(), ...props } = $props()
|
let { tempTxt = $bindable([]), resetRefTxt = $bindable(), ...props } = $props()
|
||||||
|
$inspect(props.refTxtFormFields)
|
||||||
let editingId = $state(null);
|
let editingId = $state(null);
|
||||||
let idCounter = $state(0);
|
let idCounter = $state(0);
|
||||||
|
|
||||||
@ -59,17 +59,22 @@
|
|||||||
const newEnd = toDays(props.refTxtState.form.AgeEnd);
|
const newEnd = toDays(props.refTxtState.form.AgeEnd);
|
||||||
|
|
||||||
const isOverlap = tempTxt.some(row => {
|
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 existingStart = toDays(row.AgeStart);
|
||||||
const existingEnd = toDays(row.AgeEnd);
|
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) {
|
if (isOverlap) {
|
||||||
props.refTxtState.errors.AgeEnd =
|
props.refTxtState.errors.AgeEnd = "Age range overlaps with existing data";
|
||||||
"Age range overlaps with existing data";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,16 +142,31 @@
|
|||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
for (const key of ["AgeStart", "AgeEnd"]) {
|
for (const key of ["AgeStart", "AgeEnd"]) {
|
||||||
props.refTxtState.form[key] =
|
props.refTxtState.form[key] = buildAgeText(joinFields[key]);
|
||||||
buildAgeText(joinFields[key]);
|
|
||||||
}
|
}
|
||||||
|
untrack(() => {
|
||||||
|
props.refTxtState.validateAll?.();
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const allColumns = props.refTxtFormFields.flatMap(
|
const currentEditingId = editingId;
|
||||||
(section) => section.rows.flatMap(
|
if (currentEditingId === null) return;
|
||||||
(row) => row.columns ?? []
|
|
||||||
)
|
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(() => {
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col gap-4 w-full">
|
<div class="flex flex-col gap-4 w-full">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user