From e30d583947053c04c99cbcc54594244b3bfe907b Mon Sep 17 00:00:00 2001 From: weeihan Date: Fri, 17 Jul 2026 19:08:27 +0800 Subject: [PATCH] feat: split alcohol and urine test into separate fields Co-Authored-By: Claude Sonnet 4.6 --- app/(protected)/hse/incidents/[id]/page.tsx | 2 +- app/api/incidents/[id]/investigation/route.ts | 2 + components/incidents/investigation-form.tsx | 44 +++++++++++++------ components/incidents/investigation-panel.tsx | 28 +++++++++--- ...20260717000001_split_drug_test_results.sql | 3 ++ 5 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 supabase/migrations/20260717000001_split_drug_test_results.sql diff --git a/app/(protected)/hse/incidents/[id]/page.tsx b/app/(protected)/hse/incidents/[id]/page.tsx index 98a3940..b69001b 100644 --- a/app/(protected)/hse/incidents/[id]/page.tsx +++ b/app/(protected)/hse/incidents/[id]/page.tsx @@ -41,7 +41,7 @@ export default async function HseIncidentDetailPage({ params }: Props) { .from('investigations') .select(` id, method, five_why_steps, fishbone_categories, - findings_text, root_cause_summary, alcohol_test_result, + findings_text, root_cause_summary, alcohol_test_result, urine_test_result, witness_statement_refs, completed_at, investigator:users!investigator_id (name, email) `) diff --git a/app/api/incidents/[id]/investigation/route.ts b/app/api/incidents/[id]/investigation/route.ts index bfb9d3d..44186b8 100644 --- a/app/api/incidents/[id]/investigation/route.ts +++ b/app/api/incidents/[id]/investigation/route.ts @@ -45,6 +45,7 @@ export async function POST( five_why_steps: method === 'five_why' ? (body.five_why_steps ?? []) : null, fishbone_categories: method === 'fishbone' ? (body.fishbone_categories ?? []) : null, alcohol_test_result: body.alcohol_test_result ?? null, + urine_test_result: body.urine_test_result ?? null, witness_statement_refs: Array.isArray(body.witness_statement_refs) ? body.witness_statement_refs : [], }) .select('id') @@ -93,6 +94,7 @@ export async function PATCH( five_why_steps: fields.five_why_steps ?? null, fishbone_categories: fields.fishbone_categories ?? null, alcohol_test_result: fields.alcohol_test_result ?? null, + urine_test_result: fields.urine_test_result ?? null, witness_statement_refs: Array.isArray(fields.witness_statement_refs) ? fields.witness_statement_refs : [], } if (complete) updateData.completed_at = new Date().toISOString() diff --git a/components/incidents/investigation-form.tsx b/components/incidents/investigation-form.tsx index d8ef541..571a6b7 100644 --- a/components/incidents/investigation-form.tsx +++ b/components/incidents/investigation-form.tsx @@ -38,6 +38,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props const [findingsText, setFindingsText] = useState('') const [rootCause, setRootCause] = useState('') const [alcoholTest, setAlcoholTest] = useState('') + const [urineTest, setUrineTest] = useState('') const [witnessRefs, setWitnessRefs] = useState(['']) const [complete, setComplete] = useState(false) const [saving, setSaving] = useState(false) @@ -95,6 +96,7 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props findings_text: findingsText || null, root_cause_summary: rootCause || null, alcohol_test_result: alcoholTest || null, + urine_test_result: urineTest || null, witness_statement_refs: witnessRefs.map(w => w.trim()).filter(Boolean), five_why_steps: method === 'five_why' ? fiveWhy.filter(s => s.answer) : null, fishbone_categories: method === 'fishbone' @@ -211,19 +213,35 @@ export function InvestigationForm({ incidentId, existingInvestigationId }: Props )} -
- - +
+
+ + +
+
+ + +
diff --git a/components/incidents/investigation-panel.tsx b/components/incidents/investigation-panel.tsx index de0ee58..2da2acd 100644 --- a/components/incidents/investigation-panel.tsx +++ b/components/incidents/investigation-panel.tsx @@ -8,6 +8,7 @@ interface Investigation { findings_text: string | null root_cause_summary: string | null alcohol_test_result: string | null + urine_test_result: string | null witness_statement_refs: string[] completed_at: string | null investigator: { name: string | null; email: string } | null @@ -23,6 +24,13 @@ const METHOD_LABELS = { other: 'Other Method', } +const TEST_RESULT_LABELS: Record = { + negative: 'Negative', + positive: 'Positive', + refused: 'Refused', + pending: 'Result pending', +} + export function InvestigationPanel({ investigation: inv }: Props) { const investigatorName = inv.investigator?.name ?? inv.investigator?.email ?? 'Unknown' @@ -105,11 +113,21 @@ export function InvestigationPanel({ investigation: inv }: Props) {
)} - {/* Alcohol test */} - {inv.alcohol_test_result && ( -
-

Alcohol Test Result

-

{inv.alcohol_test_result}

+ {/* Drug tests */} + {(inv.alcohol_test_result || inv.urine_test_result) && ( +
+ {inv.alcohol_test_result && ( +
+

Alcohol Test

+

{TEST_RESULT_LABELS[inv.alcohol_test_result] ?? inv.alcohol_test_result}

+
+ )} + {inv.urine_test_result && ( +
+

Urine Test

+

{TEST_RESULT_LABELS[inv.urine_test_result] ?? inv.urine_test_result}

+
+ )}
)} diff --git a/supabase/migrations/20260717000001_split_drug_test_results.sql b/supabase/migrations/20260717000001_split_drug_test_results.sql new file mode 100644 index 0000000..fad43bf --- /dev/null +++ b/supabase/migrations/20260717000001_split_drug_test_results.sql @@ -0,0 +1,3 @@ +ALTER TABLE investigations + ADD COLUMN IF NOT EXISTS urine_test_result text + CHECK (urine_test_result IN ('negative','positive','refused','pending'));