diff --git a/src/routes/(app)/master-data/tests/test-modal/tabs/RefNumTab.svelte b/src/routes/(app)/master-data/tests/test-modal/tabs/RefNumTab.svelte
index 109447e..3a91668 100644
--- a/src/routes/(app)/master-data/tests/test-modal/tabs/RefNumTab.svelte
+++ b/src/routes/(app)/master-data/tests/test-modal/tabs/RefNumTab.svelte
@@ -107,6 +107,47 @@
showAdvanced = false;
}
+ function sexOverlaps(sex1, sex2) {
+ if (sex1 === '0' || sex2 === '0') return true;
+ return sex1 === sex2;
+ }
+
+ function specimenOverlaps(spec1, spec2) {
+ if (!spec1 && !spec2) return true;
+ if ((!spec1 && spec2) || (spec1 && !spec2)) return false;
+ return spec1 === spec2;
+ }
+
+ function ageOverlaps(start1, end1, start2, end2) {
+ const s1 = start1 || 0;
+ const e1 = end1 || 54750;
+ const s2 = start2 || 0;
+ const e2 = end2 || 54750;
+ return s1 < e2 && e1 > s2;
+ }
+
+ function findOverlappingRange(newRef, excludeIndex = null) {
+ const ageStart = convertAgeToDays(simpleRefNum.AgeStart, simpleRefNum.AgeUnit) || 0;
+ const ageEnd = convertAgeToDays(simpleRefNum.AgeEnd, simpleRefNum.AgeUnit) || 54750;
+
+ for (let i = 0; i < (formData.refnum?.length || 0); i++) {
+ if (excludeIndex !== null && i === excludeIndex) continue;
+
+ const existing = formData.refnum[i];
+
+ if (existing.NumRefType !== newRef.NumRefType) continue;
+
+ if (!sexOverlaps(existing.Sex, newRef.Sex)) continue;
+
+ if (!specimenOverlaps(existing.SpcType, newRef.SpcType)) continue;
+
+ if (ageOverlaps(existing.AgeStart, existing.AgeEnd, ageStart, ageEnd)) {
+ return existing;
+ }
+ }
+ return null;
+ }
+
function validateSimpleRefNum() {
if (!simpleRefNum.Low && !simpleRefNum.High) {
return { valid: false, error: 'Please enter at least one value' };
@@ -128,6 +169,24 @@
}
}
+ const newRef = {
+ NumRefType: simpleRefNum.NumRefType,
+ Sex: simpleRefNum.Sex,
+ SpcType: simpleRefNum.SpcType || null,
+ AgeStart: convertAgeToDays(simpleRefNum.AgeStart, simpleRefNum.AgeUnit) || 0,
+ AgeEnd: convertAgeToDays(simpleRefNum.AgeEnd, simpleRefNum.AgeUnit) || 54750
+ };
+
+ const excludeIndex = isEditing ? editingIndex : null;
+ const overlap = findOverlappingRange(newRef, excludeIndex);
+
+ if (overlap) {
+ return {
+ valid: false,
+ error: `Overlaps with existing range: ${getNumRefTypeLabel(overlap.NumRefType)}, ${getSexLabel(overlap.Sex)}, ${getAgeDisplay(overlap.AgeStart)}-${getAgeDisplay(overlap.AgeEnd)}`
+ };
+ }
+
return { valid: true };
}
@@ -447,46 +506,47 @@
Type
- Range
Sex
Age
Specimen
Flag
Disp
- Actions
+ Range
+ Edit
+ Del