feat(observation): ObservationEditor wires zones + pathologies + severity + comment
This commit is contained in:
1 parent
10fa676f1e
commit
3ef1c60682
1 file changed
+125
-2
@@ -1,3 +1,126 @@
|
||||
export default function ObservationEditor() {
|
||||
return <div>ObservationEditor placeholder</div>
|
||||
import { useMemo } from 'react'
|
||||
import type { Observation, ObservationZone, Vertebra } from '@/domain/schema/observation'
|
||||
import type { Pathology } from '@/domain/schema/pathology'
|
||||
import type { Bone } from '@/anatomy/types'
|
||||
import Label from '@/components/ui/Label'
|
||||
import Textarea from '@/components/ui/Textarea'
|
||||
import Badge from '@/components/ui/Badge'
|
||||
import PathologyPicker from './PathologyPicker'
|
||||
import FreeTextPathologyInput from './FreeTextPathologyInput'
|
||||
import SeveritySelector from './SeveritySelector'
|
||||
|
||||
export interface ObservationEditorProps {
|
||||
observation: Observation
|
||||
bones: Map<string, Bone>
|
||||
speciesId: string
|
||||
pathologyPool: Pathology[]
|
||||
onChange: (next: Observation) => void
|
||||
onOpenVertebraPicker: (zoneIndex: number) => void
|
||||
onRemoveZone: (zoneIndex: number) => void
|
||||
}
|
||||
|
||||
function describeZone(z: ObservationZone, bones: Map<string, Bone>): string {
|
||||
const b = bones.get(z.boneId)
|
||||
const label = b?.fr ?? z.boneId
|
||||
if (z.vertebrae?.length) {
|
||||
const vs = z.vertebrae.map((v: Vertebra) => `${v.region}${v.index}`).join(', ')
|
||||
return `${label} (${vs})`
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
export default function ObservationEditor({
|
||||
observation,
|
||||
bones,
|
||||
speciesId,
|
||||
pathologyPool,
|
||||
onChange,
|
||||
onOpenVertebraPicker,
|
||||
onRemoveZone,
|
||||
}: ObservationEditorProps) {
|
||||
const zoneBoneIds = useMemo(
|
||||
() => observation.zones.map((z) => z.boneId),
|
||||
[observation.zones],
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<section>
|
||||
<Label>Zones sélectionnées</Label>
|
||||
{observation.zones.length === 0 ? (
|
||||
<p className="text-sm text-[var(--color-ink-muted)]">
|
||||
Cliquez sur les zones du schéma pour les ajouter à cette observation.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="flex flex-wrap gap-2">
|
||||
{observation.zones.map((z, i) => {
|
||||
const b = bones.get(z.boneId)
|
||||
const isSpine = b?.category === 'spine-zone'
|
||||
return (
|
||||
<li key={`${z.boneId}-${i}`}>
|
||||
<Badge tone="accent" className="gap-2">
|
||||
{describeZone(z, bones)}
|
||||
{isSpine && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onOpenVertebraPicker(i)}
|
||||
className="underline text-xs text-[var(--color-accent-strong)]"
|
||||
>
|
||||
Préciser…
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Retirer ${b?.fr ?? z.boneId}`}
|
||||
onClick={() => onRemoveZone(i)}
|
||||
className="ml-1 text-[var(--color-accent-strong)]"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</Badge>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label>Pathologies (référence)</Label>
|
||||
<PathologyPicker
|
||||
pool={pathologyPool}
|
||||
speciesId={speciesId}
|
||||
boneIds={zoneBoneIds}
|
||||
selected={observation.pathologyIds}
|
||||
onChange={(ids) => onChange({ ...observation, pathologyIds: ids })}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label>Pathologies (texte libre)</Label>
|
||||
<FreeTextPathologyInput
|
||||
items={observation.freeTextPathologies}
|
||||
onChange={(items) => onChange({ ...observation, freeTextPathologies: items })}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label>Sévérité</Label>
|
||||
<SeveritySelector
|
||||
value={observation.severity}
|
||||
onChange={(s) => onChange({ ...observation, severity: s })}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Label htmlFor="obs-comment">Commentaire</Label>
|
||||
<Textarea
|
||||
id="obs-comment"
|
||||
value={observation.comment}
|
||||
onChange={(e) => onChange({ ...observation, comment: e.target.value })}
|
||||
placeholder="Notes cliniques détaillées…"
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user