Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/database/models/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ class PropertyValue(Base):
String,
nullable=True,
)
user_value: Mapped[str | None] = mapped_column(String, nullable=True)
user_value: Mapped[str | None] = mapped_column(String, nullable=True)
26 changes: 26 additions & 0 deletions web/components/FeedbackToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Chip } from '@helpwave/hightide'
import { useSystemSuggestionTasksOptional } from '@/context/SystemSuggestionTasksContext'

export function FeedbackToast() {
const ctx = useSystemSuggestionTasksOptional()
const toast = ctx?.toast ?? null

if (!toast) return null

return (
<div
className="fixed bottom-6 left-1/2 -translate-x-1/2 z-[100] pointer-events-none"
role="status"
aria-live="polite"
>
<Chip
color="neutral"
coloringStyle="solid"
size="md"
className="shadow-lg px-4 py-2"
>
{toast.message}
</Chip>
</div>
)
}
36 changes: 34 additions & 2 deletions web/components/patients/PatientDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import type { CreatePatientInput, PropertyValueInput } from '@/api/gql/generated'
import { usePatient } from '@/data'
import {
Button,
ProgressIndicator,
TabList,
TabPanel,
TabSwitcher,
Tooltip
Tooltip,

Check failure on line 11 in web/components/patients/PatientDetailView.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected trailing comma

Check failure on line 11 in web/components/patients/PatientDetailView.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected trailing comma
} from '@helpwave/hightide'
import { Sparkles } from 'lucide-react'
import { PatientStateChip } from '@/components/patients/PatientStateChip'
import { LocationChips } from '@/components/locations/LocationChips'
import { PatientTasksView } from './PatientTasksView'
import { PatientDataEditor } from './PatientDataEditor'
import { AuditLogTimeline } from '@/components/AuditLogTimeline'
import { PropertyList, type PropertyValue } from '../tables/PropertyList'
import { useUpdatePatient } from '@/data'
import { getAdherenceByPatientId, getSuggestionByPatientId } from '@/data/mockSystemSuggestions'
import type { SystemSuggestion } from '@/types/systemSuggestion'

export const toISODate = (d: Date | string | null | undefined): string | null => {
if (!d) return null
Expand Down Expand Up @@ -48,13 +52,15 @@
onClose: () => void,
onSuccess: () => void,
initialCreateData?: Partial<CreatePatientInput>,
onOpenSystemSuggestion?: (suggestion: SystemSuggestion, patientName: string) => void,
}

export const PatientDetailView = ({
patientId,
onClose,
onSuccess,
initialCreateData = {}
initialCreateData = {},
onOpenSystemSuggestion,
}: PatientDetailViewProps) => {
const translation = useTasksTranslation()

Expand Down Expand Up @@ -142,6 +148,11 @@
return []
}, [patientData?.position, patientData?.assignedLocations])

const adherence = patientId ? getAdherenceByPatientId(patientId) : 'unknown'
const systemSuggestion = patientId ? getSuggestionByPatientId(patientId) : null
const adherenceDotClass = adherence === 'adherent' ? 'bg-positive' : adherence === 'non_adherent' ? 'bg-negative' : 'bg-warning'
const adherenceLabel = adherence === 'adherent' ? 'Treatment standard adherent' : adherence === 'non_adherent' ? 'Treatment is not adherent with standards.' : 'In Progress'
const adherenceTooltip = adherenceLabel

return (
<div className="flex-col-0 overflow-hidden">
Expand Down Expand Up @@ -177,6 +188,27 @@
)}
</div>
)}
{isEditMode && patientId && (
<div className="flex items-center justify-between gap-3 mb-4 py-2 px-3 rounded-lg bg-surface-variant border border-border">
<div className="flex items-center gap-3 min-w-0">
<span className="font-bold pr-2">Analysis</span>
<span className="text-sm font-medium text-label">{adherenceLabel}</span>
<Tooltip tooltip={adherenceTooltip} alignment="top">
<span className={`w-3 h-3 rounded-full shrink-0 inline-block ${adherenceDotClass}`} aria-hidden />
</Tooltip>
</div>
<Button
size="sm"
color="primary"
onClick={() => systemSuggestion && onOpenSystemSuggestion?.(systemSuggestion, patientName)}
disabled={!systemSuggestion || !onOpenSystemSuggestion}
className="shrink-0 flex items-center gap-2"
>
<Sparkles className="size-4" />
Fix with AI
</Button>
</div>
)}
<TabSwitcher>
<TabList />
<TabPanel label={translation('tasks')} className="flex-col-0 flex-1overflow-hidden h-full" disabled={!(isEditMode && patientId)}>
Expand Down
55 changes: 44 additions & 11 deletions web/components/patients/PatientTasksView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useMemo, useEffect } from 'react'
import { useState, useMemo, useEffect, useCallback } from 'react'
import { Button, Drawer, ExpandableContent, ExpandableHeader, ExpandableRoot } from '@helpwave/hightide'
import { useTasksTranslation } from '@/i18n/useTasksTranslation'
import { CheckCircle2, ChevronDown, Circle, PlusIcon } from 'lucide-react'
Expand All @@ -7,19 +7,22 @@ import clsx from 'clsx'
import type { GetPatientQuery } from '@/api/gql/generated'
import { TaskDetailView } from '@/components/tasks/TaskDetailView'
import { useCompleteTask, useReopenTask } from '@/data'
import { useCreatedTasksForPatient, useSystemSuggestionTasksOptional } from '@/context/SystemSuggestionTasksContext'

interface PatientTasksViewProps {
patientId: string,
patientData: GetPatientQuery | undefined,
onSuccess?: () => void,
}

const sortByDueDate = <T extends { dueDate?: string | null }>(tasks: T[]): T[] => {
const sortByDueDate = <T extends { dueDate?: string | Date | null }>(tasks: T[]): T[] => {
return [...tasks].sort((a, b) => {
const aTime = a.dueDate ? new Date(a.dueDate).getTime() : 0
const bTime = b.dueDate ? new Date(b.dueDate).getTime() : 0
if (!a.dueDate && !b.dueDate) return 0
if (!a.dueDate) return 1
if (!b.dueDate) return -1
return new Date(a.dueDate).getTime() - new Date(b.dueDate).getTime()
return aTime - bTime
})
}

Expand All @@ -35,8 +38,10 @@ export const PatientTasksView = ({

const [completeTask] = useCompleteTask()
const [reopenTask] = useReopenTask()
const createdTasks = useCreatedTasksForPatient(patientId)
const suggestionTasksContext = useSystemSuggestionTasksOptional()

const tasks = useMemo(() => {
const apiTasksWithOptimistic = useMemo(() => {
const baseTasks = patientData?.patient?.tasks || []
return baseTasks.map(task => {
const optimisticDone = optimisticTaskUpdates.get(task.id)
Expand All @@ -47,14 +52,35 @@ export const PatientTasksView = ({
})
}, [patientData?.patient?.tasks, optimisticTaskUpdates])

const openTasks = useMemo(() => sortByDueDate(tasks.filter(t => !t.done)), [tasks])
const closedTasks = useMemo(() => sortByDueDate(tasks.filter(t => t.done)), [tasks])
const mergedCreatedTasks = useMemo(() => {
return createdTasks.map(t => ({
id: t.id,
title: t.title,
name: t.title,
description: t.description ?? undefined,
done: t.done,
dueDate: t.dueDate ?? undefined,
updateDate: t.updateDate,
priority: t.priority ?? undefined,
estimatedTime: t.estimatedTime ?? undefined,
assignee: t.assignedTo === 'me' ? { id: 'me', name: 'Me', avatarUrl: null, lastOnline: null, isOnline: false } : undefined,
assigneeTeam: undefined,
machineGenerated: true as const,
source: 'systemSuggestion' as const,
}))
}, [createdTasks])

useEffect(() => {
setOptimisticTaskUpdates(new Map())
}, [patientData?.patient?.tasks])
const tasks = useMemo(
() => [...apiTasksWithOptimistic, ...mergedCreatedTasks],
[apiTasksWithOptimistic, mergedCreatedTasks]
)

const handleToggleDone = (taskId: string, done: boolean) => {
const handleToggleDone = useCallback((taskId: string, done: boolean) => {
const isCreated = mergedCreatedTasks.some(t => t.id === taskId)
if (isCreated && suggestionTasksContext) {
suggestionTasksContext.setCreatedTaskDone(patientId, taskId, done)
return
}
setOptimisticTaskUpdates(prev => {
const next = new Map(prev)
next.set(taskId, done)
Expand Down Expand Up @@ -85,7 +111,14 @@ export const PatientTasksView = ({
},
})
}
}
}, [mergedCreatedTasks, suggestionTasksContext, patientId, completeTask, reopenTask, onSuccess])

const openTasks = useMemo(() => sortByDueDate(tasks.filter(t => !t.done)), [tasks])
const closedTasks = useMemo(() => sortByDueDate(tasks.filter(t => t.done)), [tasks])

useEffect(() => {
setOptimisticTaskUpdates(new Map())
}, [patientData?.patient?.tasks])

return (
<>
Expand Down
Loading
Loading