Skip to content

Care calendar focus date + care-module tasks — design

Version: 1.1 Last Updated: 2026-07-31 15:27:24 Status: Built — focus date, calendar_actions manifest contract, dated care tasks, and the focus-day panel are implemented. As-built file map and interaction rules are canonical in 15-CARE-CALENDAR-COMPOSITION.md; read that first. Outstanding: removal of the cancer board’s derived day type, and marking applied-action dates on the month grid. Related: 29-CARE-MODULE-UI-ARCHITECTURE.md · 30-CARE-MODULE-PLUGIN-ARCHITECTURE.md · 11-DATABASE-SAFETY-AND-MIGRATIONS.md


The care calendar and the care board both answer “what is happening on this day”, in different vocabularies, against different storage, with no shared record. A carer who opens the calendar cannot see the work the board is asking for, and a carer who opens the board cannot see the roster.

Three concrete symptoms in the current code:

Dated facts are stored as undated settings. The cancer board writes the day type to settings.today_day_types — one global bag with no date. It cannot be set ahead, cannot be looked back on, must be re-set every morning, and is invisible to every other carer.

Care plan steps are synthesised, never persisted. buildTodayPlan() in frontend/src/care-modules/cancer/cancerBoardV2Model.ts derives steps such as “Infusion visit packing” and “Tablet day safety” at render time. Two carers looking at the same day can see different work, and nothing appears on the calendar.

The board has grown its own calendar. CancerComfortDateStrip carries independent monthDate state, month navigation, and a 90-day “days with data” set from comfortCheckinDates(patientId, slug, 90). Counting the month grid, WeekAtAGlance on Home, and the shared DayDateStrip, the app now has four date surfaces.

A fourth symptom is structural rather than user-visible: the cancer module has already leaked into shared calendar code. frontend/src/components/calendar/AddShiftFormView.tsx hardcodes ONCOLOGY_APPT_TYPES, duplicating a list the backend already serves as catalog.oncology_appointment_types. With ten more care profiles specified, that pattern does not scale.


  • One home for scheduled events. Dated care work lives on the calendar; the board reads it.
  • Reaching the scheduler must not cost more interactions than it does today.
  • Care modules contribute to the calendar through a declared contract, not through calendar code that names them.
  • Day type becomes dated, shared, historical data.
  • Changing the calendar’s identity. It remains a rostering and upcoming-events service.
  • Moving treatment modes off the board. They are regimen-level, not per-day.
  • Retiring CancerComfortDateStrip. It is a capture history for the radar, not a schedule. Revisit after this lands.
  • Putting medication doses on the calendar. /medication-schedule stays a separate time axis.

GestureResult
Quick tap on a daySets the focus date. Nothing else changes on screen.
Long-press on a dayOpens the existing scheduling sheet, unchanged.
Drag across daysRange selection, then the scheduling sheet, unchanged.
Keyboard / pointerFocus date via Enter/Space; scheduling via a control in the focus-day panel.

The focus date defaults to today on load, so the panel is populated before the user touches anything and the tap-to-change relationship teaches itself without instructional copy. The existing hint line under the grid — “Tap a date to add a shift or appointment · Drag across dates to add shifts for a range” — is reworded rather than supplemented with a coach mark.

CalendarView.tsx already juggles pending taps, range drags, month swipes, and synthetic-click suppression. Long-press is a fourth participant and must arbitrate explicitly.

Vertical beyond scroll threshold

Horizontal into another cell

No movement, timer fires

No movement, touchend first

touchstart on day cell

Arm long-press timer

Record pending tap

Movement before timer fires?

Cancel timer and pending tap

Page scrolls

Cancel timer

Begin range drag

Disarm drag

Haptic + open scheduling sheet

Set focus date

Once the timer fires, drag is disarmed for the remainder of that touch. Once drag begins, the timer is cancelled and cannot fire.

A hold reads as the app being slow unless it is acknowledged while it is happening. The cell shows a progressing ring or scale during the hold, and navigator.vibrate(10) fires at the moment the timer completes — matching the haptic convention already described in doc 29 §8.


care_tasks (live schema, backend/schema/lyncareos_v1_baseline.sql) is a child of care_shifts:

ColumnNote
shift_idNOT NULL, REFERENCES care_shifts (id) ON DELETE CASCADE
title, sort_order, completed, completed_at, completed_by
arranged_by_user_id, assigned_to_user_id, deleted_at, created_at

There is no patient_id and no tenant_id. Tenancy is inherited entirely through the join to care_shifts.patient_id, and RLS covers care_shifts but not care_tasks (see backend/migrations/archive/pre-v1/V034__row_level_security.sql).

A task therefore cannot exist without a rostered shift, which blocks the whole feature: tapping a pill on an unrostered future date has nowhere to write.

Care tasks become date-scoped. shift_id becomes optional attribution of who is doing it rather than a structural requirement.

Security-critical: making shift_id nullable severs the only tenancy path this table has. Adding patient_id and an RLS policy is mandatory in the same migration, not a follow-up.

backend/migrations/V026__care_tasks_date_scoped.sql:

ALTER TABLE care_tasks ADD COLUMN IF NOT EXISTS patient_id INTEGER REFERENCES patients (id) ON DELETE CASCADE;
ALTER TABLE care_tasks ADD COLUMN IF NOT EXISTS date TEXT;
ALTER TABLE care_tasks ADD COLUMN IF NOT EXISTS source_care_profile_slug TEXT;
ALTER TABLE care_tasks ADD COLUMN IF NOT EXISTS source_action_id TEXT;
-- Legacy rows inherit patient and date from their parent shift. No guessed defaults.
UPDATE care_tasks ct
SET patient_id = cs.patient_id,
date = cs.date
FROM care_shifts cs
WHERE cs.id = ct.shift_id
AND (ct.patient_id IS NULL OR ct.date IS NULL);
ALTER TABLE care_tasks ALTER COLUMN patient_id SET NOT NULL;
ALTER TABLE care_tasks ALTER COLUMN date SET NOT NULL;
ALTER TABLE care_tasks ALTER COLUMN shift_id DROP NOT NULL;
-- Deleting a shift must not destroy dated care work that outlives the roster entry.
ALTER TABLE care_tasks DROP CONSTRAINT care_tasks_shift_id_fkey;
ALTER TABLE care_tasks ADD CONSTRAINT care_tasks_shift_id_fkey
FOREIGN KEY (shift_id) REFERENCES care_shifts (id) ON DELETE SET NULL;
CREATE INDEX IF NOT EXISTS idx_care_tasks_patient_date ON care_tasks (patient_id, date);
-- Re-tapping a pill is idempotent rather than duplicating its task set.
CREATE UNIQUE INDEX IF NOT EXISTS uq_care_tasks_module_action
ON care_tasks (patient_id, date, source_care_profile_slug, source_action_id, title)
WHERE source_action_id IS NOT NULL AND deleted_at IS NULL;

RLS must mirror the function-based policy already used for care_shifts, keyed on patient_id through patients.tenant_id and the transaction-local app.current_tenant_id setting.

The date column name matches care_shifts.date and patient_appointments.date, both TEXT holding ISO dates.

With tasks dated and carrying source_action_id, “Thursday is an infusion day” is answerable from the tasks on Thursday. No day-type table is added and settings.today_day_types is deleted rather than replaced.

This removes the suggest-then-apply mechanism entirely: suggested_day_type_from_calendar() and today_oncology_appointments() in backend/care_modules/services/cancer_hub_service.py, plus the amber calendar_day alert reading “tap Actions for today to confirm”.

The appointment-type mapping survives in better form. If the focus date carries an iv_infusion appointment, the Infusion pill renders as suggested; tapping it applies. This now works on any date rather than only today.

Consequence worth stating plainly: if a carer deletes every task a pill created, that day is no longer that day type. This is intended — the day type is an honest reflection of the work recorded against the date.


A care module declares its dated actions. The calendar renders them generically and never learns anything profile-specific.

{
"slug": "cancer_at_home",
"calendar_actions": [
{
"id": "infusion",
"label": "Infusion day",
"icon": "Syringe",
"suggested_by_appointment_types": ["iv_infusion"],
"tasks": [
{ "title": "Confirm transport to clinic" },
{ "title": "Pack port card, labs, snacks" },
{ "title": "Check how they feel before leaving" }
]
}
]
}

Because a patient has one care_profile_slug, only one module’s pills are ever on screen. Visual clutter is bounded by construction; the thing being prevented is twelve modules hardcoded into two already-oversized files.

This contract is also the vehicle for removing ONCOLOGY_APPT_TYPES from AddShiftFormView.tsx. Appointment types become part of the module declaration, served from the API that already exposes catalog.oncology_appointment_types.

MethodPathPurpose
GET/api/patients/{id}/care-tasks?year=&month=Month task rows, no shift required
POST/api/patients/{id}/care-tasksCreate a dated task
DELETE/api/patients/{id}/care-tasks/{taskId}Soft-delete; replaces the shift-scoped route
GET/api/patients/{id}/care-modules/calendar-actions?slug=&date=Pills plus applied and suggested state for a date
POST/api/patients/{id}/care-modules/calendar-actions/apply?slug=Apply an action to a date, creating its tasks

api.tasks.remove(patientId, shiftId, taskId) in frontend/src/lib/api.ts migrates to the task-id route. Per the OpenAPI contract rule, python backend/scripts/export_openapi.py then npm run generate:types must run, committing openapi/openapi.json and frontend/src/lib/api.types.ts together.


CareActionsForTodayBlock is deleted and its slot — between the month grid and the appointments section — is taken by a focus-day panel containing:

  1. The focus date heading.
  2. Care action pills with applied and suggested state.
  3. Tasks already on that date.
  4. A scheduling control (the pointer and keyboard route to the sheet).

Month lists below stay month-scoped. Month-at-a-glance is their reason to exist; the panel is additive above them.

No new day-cell icon is needed. Cells already render a ClipboardList marker when care tasks exist, via dayActivityIndicators(), so module-created tasks light it up for free.

Superseded (2026-07-31): Module pill tasks are date-scoped (shift_id null), so shift-only dayActivityIndicators() never showed them. Shipped behaviour: GET …/calendar-actions/range + per-action icons in CalendarDayCell — see 15-CARE-CALENDAR-COMPOSITION.md §8 (was open follow-up, now done).

Selecting a day auto-scrolls the panel under the grid so both stay visible. This interacts with the sticky filter dock’s existing scroll machinery — computeRegionScrollTop() and the trailing scrollSpacerPx both assume the current section stack and need revisiting.


ComponentChange
CancerTodayPlanReads today’s calendar tasks instead of synthesising them
buildTodayPlan()Becomes the task template applied by a pill, not a render-time synthesiser
CancerTodayContextPanelDay-type chips removed; treatment modes stay
cancer_hub_service.pyDay-type suggestion and apply flow deleted
CancerComfortDateStripUnchanged this round

  • Every new query includes tenant_id in its WHERE clause via patients; RLS is the backstop, not the mechanism.
  • New endpoints use require_tenant_member, and patient-scoped reads validate patient_access for non-admin roles.
  • Care tasks are patient-linked clinical records, so create, apply, and delete each write an audit entry in the same transaction with before and after snapshots, per ADR 0001. Routers build the AuditContext; services never receive a FastAPI Request.
  • Deletion stays soft (deleted_at), consistent with the existing column.
  • Task titles come from module declarations, not free text from the patient record, so no PHI enters log output.

Day cells are currently plain <div>s with onClick and no role or tabIndex, so the calendar is not keyboard-reachable today. This is pre-existing, and long-press would make it load-bearing.

Cells become buttons. Enter and Space set the focus date, matching tap. The focus-day panel’s scheduling control is the keyboard and pointer route to the sheet — touch users never encounter it as an extra step. Touch targets stay at or above 44px, and the hold indicator must respect prefers-reduced-motion.


Both files in the blast radius already breach the 300-line component limit in .cursor/rules/rules.mdc.

FileLinesRequired work
frontend/src/components/calendar/AddShiftFormView.tsx1,226Split before care-module content is added
frontend/src/pages/calendar/CalendarView.tsx1,167Extract the gesture layer into a useCalendarDayGestures hook; extract the focus-day panel

Adding a long-press timer to CalendarView in its current shape, alongside pending-tap tracking, range drag, month swipe, and synthetic-click suppression, would be unsafe. These extractions are prerequisites, not follow-up cleanup.


This design is too large for one implementation plan. It decomposes into three stages, each independently shippable and each leaving the app in a working state.

StageContentsWhy this boundary
1 — FoundationsV026 migration, RLS policy, dated care-task API, OpenAPI regeneration, the two file splitsNo user-visible change. Everything after depends on tasks being dated and safely scoped.
2 — Calendar interactionFocus date, long-press arbitration, focus-day panel, keyboard access, CareActionsForTodayBlock removalShips the interaction model with existing task data, before any module contributes
3 — Module contractcalendar_actions declaration, pills with applied and suggested state, ONCOLOGY_APPT_TYPES extraction, board reads calendar, day-type settings deletedThe only stage that touches the cancer board

Stage 3 is the one with a preview gate implication: cancer board changes stay behind CARE_MODULE_PREVIEW_USER_IDS per doc 30, and deploy.ps1 runs verify-care-module-preview-gate.ps1 against it.


  • Migration: legacy tasks inherit the correct patient and date; deleting a shift leaves its tasks intact with shift_id null.
  • Tenancy: a task with shift_id IS NULL is not readable from another tenant, with RLS both enabled and bypassed, since RLS is a backstop and not the mechanism.
  • Idempotency: applying the same pill to the same date twice produces one task set.
  • Gestures: unit tests over the arbitration logic in the extracted hook — tap, hold, hold-then-move, move-then-hold, vertical scroll cancellation.
  • Keyboard: focus date and scheduler both reachable without a pointer.
  • Regression: existing shift, appointment, task, and handover flows unchanged, including range drag.

#QuestionCurrent position
1Long-press duration500ms, tunable after device testing
2Do tasks auto-attach when a shift is later created on their date?No. Attribution is a deliberate act.
3Does the focus date persist across month navigation?Yes, until another day is tapped
4Does the focus date survive a page reload?No. Defaults to today.

VersionDateChange
1.02026-07-31Initial design — focus date interaction, date-scoped care tasks, care-module calendar contract