- Consolidate fragmented test modal components into unified TestFormModal.svelte - Reorganize reference range components into organized tabs (RefNumTab, RefTxtTab) - Add new tab components: BasicInfoTab, TechDetailsTab, CalcDetailsTab, MappingsTab, GroupMembersTab - Move test-related type definitions to src/lib/types/test.types.ts for better type organization - Delete old component files: TestModal.svelte and 10+ sub-components - Add backup directory for old component preservation - Update AGENTS.md with coding guidelines and project conventions - Update tests.js API client with improved structure - Add documentation for frontend test management architecture
174 lines
6.5 KiB
Svelte
174 lines
6.5 KiB
Svelte
<script>
|
|
import { PlusCircle, FileText, X, ChevronDown, ChevronUp, Beaker, Filter } from 'lucide-svelte';
|
|
import { sexOptions, createTextRef } from '../referenceRange.js';
|
|
import { fetchValueSetByKey } from '$lib/api/valuesets.js';
|
|
import { onMount } from 'svelte';
|
|
|
|
/**
|
|
* @typedef {Object} Props
|
|
* @property {Array} reftxt - Text reference ranges array
|
|
* @property {(reftxt: Array) => void} onupdateReftxt - Update handler
|
|
*/
|
|
|
|
/** @type {Props} */
|
|
let {
|
|
reftxt = [],
|
|
onupdateReftxt = () => {}
|
|
} = $props();
|
|
|
|
let expandedRanges = $state({});
|
|
let specimenTypeOptions = $state([]);
|
|
|
|
onMount(async () => {
|
|
try {
|
|
const response = await fetchValueSetByKey('specimen_type');
|
|
specimenTypeOptions = response.data?.items?.map(item => ({
|
|
value: item.itemCode,
|
|
label: item.itemValue
|
|
})) || [];
|
|
} catch (err) {
|
|
console.error('Failed to load specimen types:', err);
|
|
}
|
|
});
|
|
|
|
function addRefRange() {
|
|
const newRef = createTextRef();
|
|
onupdateReftxt([...reftxt, newRef]);
|
|
expandedRanges[reftxt.length] = { specimen: false };
|
|
}
|
|
|
|
function removeRefRange(index) {
|
|
onupdateReftxt(reftxt.filter((_, i) => i !== index));
|
|
delete expandedRanges[index];
|
|
}
|
|
|
|
function toggleSpecimenExpand(index) {
|
|
expandedRanges[index] = { ...expandedRanges[index], specimen: !expandedRanges[index]?.specimen };
|
|
}
|
|
</script>
|
|
|
|
<div class="space-y-3">
|
|
<div class="flex justify-between items-center">
|
|
<div class="flex items-center gap-2">
|
|
<FileText class="w-5 h-5 text-primary" />
|
|
<h3 class="font-semibold">Text Reference Ranges</h3>
|
|
</div>
|
|
<button type="button" class="btn btn-sm btn-primary" onclick={addRefRange}>
|
|
<PlusCircle class="w-4 h-4 mr-1" />
|
|
Add Range
|
|
</button>
|
|
</div>
|
|
|
|
{#if reftxt?.length === 0}
|
|
<div class="text-center py-8 bg-base-200 rounded-lg border-2 border-dashed border-base-300">
|
|
<FileText class="w-12 h-12 mx-auto text-gray-400 mb-2" />
|
|
<p class="text-gray-500">No text ranges defined</p>
|
|
<button type="button" class="btn btn-sm btn-outline mt-2" onclick={addRefRange}>
|
|
<PlusCircle class="w-4 h-4 mr-1" />
|
|
Add First Range
|
|
</button>
|
|
</div>
|
|
{/if}
|
|
|
|
{#each reftxt || [] as ref, index (index)}
|
|
<div class="card bg-base-100 border-2 border-base-200 hover:border-primary/50 transition-colors">
|
|
<div class="card-body p-4">
|
|
<div class="flex justify-between items-center mb-4 pb-3 border-b border-base-200">
|
|
<span class="badge badge-primary badge-lg">Range {index + 1}</span>
|
|
<button type="button" class="btn btn-sm btn-ghost text-error" onclick={() => removeRefRange(index)}>
|
|
<X class="w-4 h-4" />
|
|
Remove
|
|
</button>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3">
|
|
<div class="form-control">
|
|
<span class="label-text text-xs mb-1">Sex</span>
|
|
<select class="select select-sm select-bordered w-full" bind:value={ref.Sex}>
|
|
{#each sexOptions as option (option.value)}
|
|
<option value={option.value}>{option.label}</option>
|
|
{/each}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-control">
|
|
<span class="label-text text-xs mb-1">Age From</span>
|
|
<input type="number" min="0" max="120" class="input input-sm input-bordered w-full" bind:value={ref.AgeStart} placeholder="0" />
|
|
</div>
|
|
|
|
<div class="form-control">
|
|
<span class="label-text text-xs mb-1">Age To</span>
|
|
<input type="number" min="0" max="120" class="input input-sm input-bordered w-full" bind:value={ref.AgeEnd} placeholder="120" />
|
|
</div>
|
|
|
|
<div class="form-control">
|
|
<span class="label-text text-xs mb-1">Flag</span>
|
|
<select class="select select-sm select-bordered w-full" bind:value={ref.Flag}>
|
|
<option value="N">N - Normal</option>
|
|
<option value="A">A - Abnormal</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-control mt-3">
|
|
<span class="label-text text-xs mb-1">Reference Text</span>
|
|
<textarea class="textarea textarea-bordered w-full" rows="2" bind:value={ref.RefTxt} placeholder="e.g., Negative for glucose"></textarea>
|
|
</div>
|
|
|
|
<!-- Expandable: Specimen and Criteria -->
|
|
<div class="border border-base-200 rounded-lg overflow-hidden mt-3">
|
|
<button
|
|
type="button"
|
|
class="w-full px-3 py-2 bg-base-200 hover:bg-base-300 flex items-center justify-between text-sm transition-colors"
|
|
onclick={() => toggleSpecimenExpand(index)}
|
|
>
|
|
<span class="flex items-center gap-2">
|
|
<Beaker class="w-3 h-3" />
|
|
<span class="text-xs">Specimen & Criteria</span>
|
|
{#if ref.SpcType || ref.Criteria}
|
|
<span class="text-xs text-primary">(Custom)</span>
|
|
{:else}
|
|
<span class="text-xs text-gray-500">(Optional)</span>
|
|
{/if}
|
|
</span>
|
|
{#if expandedRanges[index]?.specimen}
|
|
<ChevronUp class="w-4 h-4" />
|
|
{:else}
|
|
<ChevronDown class="w-4 h-4" />
|
|
{/if}
|
|
</button>
|
|
|
|
{#if expandedRanges[index]?.specimen}
|
|
<div class="p-3 bg-base-100 space-y-3">
|
|
<div class="form-control">
|
|
<span class="label-text text-xs mb-1 flex items-center gap-1">
|
|
<Beaker class="w-3 h-3" />
|
|
Specimen Type
|
|
</span>
|
|
<select class="select select-sm select-bordered w-full" bind:value={ref.SpcType}>
|
|
<option value="">Any specimen</option>
|
|
{#each specimenTypeOptions as option}
|
|
<option value={option.value}>{option.label}</option>
|
|
{/each}
|
|
</select>
|
|
</div>
|
|
<div class="form-control">
|
|
<span class="label-text text-xs mb-1 flex items-center gap-1">
|
|
<Filter class="w-3 h-3" />
|
|
Criteria
|
|
</span>
|
|
<input
|
|
type="text"
|
|
class="input input-sm input-bordered w-full"
|
|
bind:value={ref.Criteria}
|
|
placeholder="e.g., Fasting, Morning sample"
|
|
/>
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{/each}
|
|
</div>
|