feat(cortex): implement activePatient fallback in various components
- Updated DagnotatieBlock to use activePatient for prefill if no patientId is provided. - Enhanced PatientDashboardBlock to fallback to activePatient for patientId and name. - Adjusted usePatientSelection to handle pending actions and re-route after patient selection. - Refined chat components to manage nudge messages and integrate them into the chat flow. - Improved UI elements for better patient selection experience. This update enhances user experience by ensuring that the active patient context is utilized across multiple components, streamlining workflows and reducing manual input.
This commit is contained in:
@@ -23,9 +23,11 @@ import { safeFetch, getErrorInfo } from '@/lib/cortex/error-handler';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { BLOCK_CONFIGS } from '@/lib/cortex/types';
|
||||
import type { BlockPrefillData } from '@/stores/cortex-store';
|
||||
import { useCortexStore } from '@/stores/cortex-store';
|
||||
import type { FHIRPatient } from '@/lib/fhir';
|
||||
import type { Intake } from '@/lib/types/intake';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { formatPatientName } from '@/lib/fhir/patient-mapper';
|
||||
|
||||
interface PatientDashboardBlockProps {
|
||||
prefill?: BlockPrefillData;
|
||||
@@ -103,9 +105,13 @@ function getPatientBsn(patient?: FHIRPatient): string | null {
|
||||
|
||||
export function PatientDashboardBlock({ prefill }: PatientDashboardBlockProps) {
|
||||
const config = BLOCK_CONFIGS['patient-dashboard'];
|
||||
const patientId = prefill?.patientId;
|
||||
const { activePatient } = useCortexStore();
|
||||
const { toast } = useToast();
|
||||
|
||||
// E3.S2: Use activePatient as fallback for patientId
|
||||
const patientId = prefill?.patientId || activePatient?.id;
|
||||
const patientNameFromPrefill = prefill?.patientName || (activePatient ? formatPatientName(activePatient) : undefined);
|
||||
|
||||
const [data, setData] = useState<PatientDashboardResponse | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(Boolean(patientId));
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -178,8 +184,9 @@ export function PatientDashboardBlock({ prefill }: PatientDashboardBlockProps) {
|
||||
? data?.carePlan?.activities.length
|
||||
: 0;
|
||||
|
||||
const title = prefill?.patientName
|
||||
? `${config.title} - ${prefill.patientName}`
|
||||
// E3.S2: Use patientNameFromPrefill for title
|
||||
const title = patientNameFromPrefill
|
||||
? `${config.title} - ${patientNameFromPrefill}`
|
||||
: config.title;
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user