Adds 4 new intents for intake workflow: - intake_status: shows completion percentage and section checklist - intake_navigeer: navigation to specific intake tabs - risico_query: displays risk assessments with severity indicators - diagnose_query: shows primary/secondary diagnoses New components: - IntakeStatusBlock, RisicoBlock, DiagnoseBlock - Shared block components (BlockLoading, BlockError, BlockEmpty, BlockSection, BlockItem, BlockFooter) - useBlockData and useIntakeContext hooks New API routes: - GET /api/cortex/intake/status - GET /api/cortex/intake/risico - GET /api/cortex/intake/diagnose Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
'use client';
|
|
|
|
/**
|
|
* useIntakeContext Hook
|
|
*
|
|
* Provides patient and intake context for Cortex blocks.
|
|
* Falls back to activePatient from store when prefill is not provided.
|
|
*
|
|
* Epic: E2.S2 - Custom Hooks
|
|
*/
|
|
|
|
import { useMemo } from 'react';
|
|
import { useCortexStore } from '@/stores/cortex-store';
|
|
import type { BlockPrefillData } from '@/stores/cortex-store';
|
|
import { formatPatientName } from '@/lib/fhir/patient-mapper';
|
|
|
|
// ============================================================================
|
|
// Types
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Extended prefill data with intake-specific fields.
|
|
* Blocks can pass this to get intake context.
|
|
*/
|
|
export interface IntakePrefillData extends BlockPrefillData {
|
|
/** Intake ID for intake-specific operations */
|
|
intakeId?: string;
|
|
}
|
|
|
|
interface UseIntakeContextResult {
|
|
/** Patient ID (van prefill of activePatient) */
|
|
patientId: string | null;
|
|
/** Intake ID (van prefill) */
|
|
intakeId: string | null;
|
|
/** Patient naam (voor display) */
|
|
patientName: string | null;
|
|
/** Of er patient context is */
|
|
hasPatientContext: boolean;
|
|
/** Of er intake context is */
|
|
hasIntakeContext: boolean;
|
|
}
|
|
|
|
// ============================================================================
|
|
// Hook
|
|
// ============================================================================
|
|
|
|
/**
|
|
* Hook for getting patient and intake context in Cortex blocks.
|
|
*
|
|
* Priority:
|
|
* 1. Explicit prefill data (from intent classification)
|
|
* 2. activePatient from store (fallback)
|
|
*
|
|
* @example
|
|
* const { patientId, intakeId, hasPatientContext } = useIntakeContext(prefill);
|
|
*
|
|
* if (!hasPatientContext) {
|
|
* return <BlockEmpty icon={User} message="Selecteer eerst een patiënt" />;
|
|
* }
|
|
*/
|
|
export function useIntakeContext(
|
|
prefill?: IntakePrefillData
|
|
): UseIntakeContextResult {
|
|
const { activePatient } = useCortexStore();
|
|
|
|
return useMemo(() => {
|
|
// Patient context: prefill takes priority, then activePatient
|
|
const patientId = prefill?.patientId || activePatient?.id || null;
|
|
const patientName =
|
|
prefill?.patientName ||
|
|
(activePatient ? formatPatientName(activePatient) : null);
|
|
|
|
// Intake context: only from prefill for now
|
|
// TODO: Add activeIntake to cortex-store for persistent intake context
|
|
const intakeId = prefill?.intakeId || null;
|
|
|
|
return {
|
|
patientId,
|
|
intakeId,
|
|
patientName,
|
|
hasPatientContext: Boolean(patientId),
|
|
hasIntakeContext: Boolean(intakeId),
|
|
};
|
|
}, [prefill, activePatient]);
|
|
}
|