improvement: v1 standalone treatment/case creation made possible.

This commit is contained in:
2026-08-19 15:05:58 +03:30
parent e5c39c6b7e
commit 8bfa8c88fe
39 changed files with 3296 additions and 387 deletions

View File

@@ -22,7 +22,7 @@ Thin route: `app/[locale]/(dashboard)/treatment/page.tsx` (supports `?appointmen
1. **Appointments strip**`AppointmentsStrip.tsx` + `ScheduleDayPicker.tsx` (Today checkbox) + `pickAutoAppointment()` in `components/shared/treatmentSelection.ts`
1. **Day strip**`AppointmentsStrip.tsx` renders `DayStripItem[]` (`appointment` | `unscheduled`) via `DayStripCard`. Timed appointments show the slot; standalone treatments show i18n “No appointment” and sort after timed cards. Empty unscheduled cards (`details.length === 0`) show a trash control (`DELETE /treatments/:id`). Workspace fetches `GET /appointments` **and** `GET /treatments/day`. Strip stays dumb (no draft API). New treatment / Walk-in use shared `Button`.
2. **Treatment preview**`TreatmentPreviewCard.tsx` (read-only summary; no load button for current draft)
@@ -180,27 +180,37 @@ Use shared `Checkbox` (not native `<input type="checkbox">`) to avoid focus-driv
|----------|---------|
| `GET /appointments?from&to` | Strip |
| `GET /appointments?from&to` | Timed strip cards |
| `GET /treatments/day?from&to` | Standalone (unscheduled) strip cards |
| `POST /treatments` | Create standalone `{ patientId?, walkIn?, treatmentAt }` |
| `DELETE /treatments/:id` | Empty standalone only (`appointmentId` null, no details) |
| `GET /treatments/patients/:patientId/history` | History (patient + org; filtered by provider) |
| `GET /treatments/appointments/:id/draft` | Load form on appointment select |
| `PUT .../draft`, `PUT .../lab-cases` | Autosave (600ms debounce) |
| `GET/PUT /treatments/:treatmentId/draft` | Load/save when there is no appointment |
| `PUT .../lab-cases` | Autosave (600ms debounce) — appointment or treatment id |
Draft writes require provider match (`ensureAppointmentProvider`) unless org owner.
Walk-in uses one sentinel `Patient` per clinic (`isWalkIn`, hidden from Patients/search/booking). Display via i18n, never the stored name. Patient search: same workspace patient → no-op; else load latest history into the editor; **no history → auto-create** standalone on the selected day.
Draft writes for appointments require provider match (`ensureAppointmentProvider`). Standalone requires `treatment.providerUserId === actor`.
## Edit gating
```typescript
canEditTreatmentForDay = canEdit && selectedAppointment && !isViewingPastDay && workspaceMode === 'live'
canEditTreatmentForDay = canEdit && hasLiveContext && !isViewingPastDay && workspaceMode === 'live'
```
Past day or `historical` workspace mode freezes the treatment form + most lab-dispatch fields.
`hasLiveContext` is a selected live appointment **or** standalone treatment. Past day or `historical` workspace mode freezes the treatment form + most lab-dispatch fields.
### Per-detail sent lock