ADR-006: Mobile UI and state architecture for delegated healthcare access


Sep 28, 2026

ACCEPTED

Md Khaled Bin Joha

Status

Proposed

Date

2026-09-28

Context

Problem

ADR-005

lets an authenticated caregiver act on another person's healthcare data, with authorisation resolved by the server and the patient identified explicitly in each request.

The mobile application has no concept of acting for someone else. Every patient screen assumes the signed-in user is the patient, so the subject is never stated — it is inferred from whoever is logged in. Before a caregiver can manage a child's medications, the application needs a subject that is explicit, visible on screen, and cleaned up correctly when it changes.

The risk this introduces is new in kind: one device will display, and write to, several different people's health records. The most likely user-caused error is a caregiver believing they are acting on their own account while actually acting on a dependent's.

Existing architecture, in brief

  • Shape. A React Native application built with Expo, using file-based routing. Routes are grouped by role: authentication, patient, and doctor. A guard redirects a user who reaches the wrong group.
  • Identity. One authentication context holds exactly one signed-in user. The user's role decides which route group they land in.
  • State. No global store and no persisted cache. Each feature has its own hook holding its own data in component state, so health data exists only while its screen is mounted.
  • Networking. A single request function that every API module calls. It attaches the access token, optionally attaches the doctor session header, and transparently refreshes an expired token once before retrying.
  • Storage. Encrypted device keychain only, holding the two tokens and the doctor session. No health data is written to key-value storage.
  • Notifications. Two separate systems. Remote push is used only for clinic-queue events and carries identifiers rather than clinical content. Medication reminders are local device alarms scheduled by the operating system, with permission handling, restoration after reboot, and a self-repair check when the app comes to the foreground.
  • Session cleanup. Signing out clears tokens, unregisters the push token, and clears the doctor session. A separate mechanism watches for the signed-in user changing and then clears device-held state — cached document scans and scheduled alarms — which also covers the paths that never reach the sign-out routine.
  • A working precedent exists. The doctor's patient screen already does the right thing: it takes the patient identifier from the route, holds the doctor session separately, checks that the two agree, and blocks the screen if they do not. That is the pattern to copy.

Constraints

  1. The frontend is not a security boundary. Any permission the client knows about can only hide a button; the server decides.
  2. Device alarms have no notion of whose medication they are. They are keyed by medication alone, and the self-repair check reconciles the device's alarms against the signed-in user's own medication list. If a caregiver's screen reused the existing medication logic, the dependent's alarms and the caregiver's own would collide in one namespace, and the next repair pass would silently cancel or duplicate them. This is a patient-safety risk, not a privacy one.
  3. Record images are currently opened in the system browser. That moves health data outside the application sandbox into a browser with its own cache and history, where it can outlive the authorisation that produced it.
  4. There is no screenshot or app-switcher protection. Health screens appear in the operating system task-switcher preview and can be screenshotted.
  5. There is no central handling for losing access. An expired token is handled globally, but a caregiver whose access is revoked mid-session sees only a per-screen error while the application keeps the subject selected and its data on screen.
  6. Local-only alarms mean caregiver reminders must come from the server, so they will require connectivity.

Requirements

  1. The screen must always make it unmistakable whose healthcare account is being acted on.
  2. Switching subject must leave no trace of the previous subject in view or in device state.
  3. Losing access must be handled the same way everywhere, not screen by screen.
  4. The caregiver's own medication alarms must never be affected by viewing someone else's medications.
  5. Health data must not leave the application sandbox.
  6. All new text must ship in both English and Bengali.

Decision

Core decisions

  1. The subject is a route parameter, never an ambient value. A new subject-scoped route group carries the patient identifier in the path, mirroring the server's endpoints and following the existing doctor patient screen. The shared request function is not given an implicit subject: an invisible subject inside a shared client is how one person's data reaches another person's screen.

  2. Existing self screens are left alone. The subject-scoped group reuses them as components rather than adding a subject parameter to them. Managing one's own health data stays the default path and gains no new risk.

  3. A subject context carries identity for display; the server carries authority. It holds the subject's name, whether the account is managed, and the granted permissions. Permissions are used only to show or hide controls. Every delegated write is authorised server-side and covered by a server test that ignores the interface entirely. Permissions are never written to device storage, because unlike the short doctor session, a delegation is long-lived and must be re-checked against the server.

  4. A persistent, non-dismissible subject banner appears on every subject-scoped screen, reading "Signed in as … / Managing …", and the group carries a distinct visual treatment. Given the risk named in the context, this banner is the primary control against wrong-subject actions.

  5. Subject change reuses the existing session-change cleanup. That mechanism already watches for the signed-in user changing; it is extended to watch the user and subject as a pair. Screens are keyed on the subject so a switch remounts rather than reusing stale data. Because there is no global cache, nothing further needs invalidating. The existing rule that a cold start must not clear alarms is preserved.

  6. Caregiver reminders arrive only as server push; device alarms stay strictly self-only. The alarm namespace gains no subject dimension, the self-repair check keeps reconciling against the signed-in user's own medications, and the subject-scoped medication screen does not schedule any device alarm. This resolves constraint 2 and must ship in the same release as the first caregiver medication screen, not after it.

  7. Records render inside the application. The system browser is no longer handed health data. Paired with the server-side link capping in ADR-005, health data no longer outlives the authorisation that produced it.

  8. Screenshot and task-switcher protection is applied to health screens, including all subject-scoped screens. This matters more once one device shows several people's records.

  9. Losing access is handled centrally, in the same request layer that already handles an expired session. When the server refuses a subject, the application drops the subject, purges its state, returns to the signed-in user's own home, and shows one clear message.

  10. The subject-scoped group validates the subject on entry and on focus, so a stale link to a subject the user no longer has access to routes home rather than rendering a partly-populated screen.

  11. Naming stays unambiguous. "Grant" continues to mean the doctor session. The family mechanism is a delegation throughout, matching ADR-005.

System design

Route structure.

authentication group        unchanged
doctor group                unchanged  (contains the pattern being copied)
patient group
  own tabs and screens      unchanged — no subject parameter
  family/                                                    NEW
    families, members, relationships
    invite a member
    create a dependent
    who can see this person / revoke
  managing/<patientId>/                                       NEW
    layout: subject provider + banner + subject guard
    home, medications, records, appointments, share a PIN

Context composition.

authentication provider          the actor        (existing)
  preferences provider           theme, language  (existing)
    family provider              NEW — discovery and the switcher only;
    |                            never consulted to permit an action
    +-- self screens             subject implied = the actor
    |
    +-- subject provider         NEW — scoped to managing/<patientId>
          name, managed flag, permissions (display only), revoked flag

Family data and subject authorisation are kept in separate providers on purpose. It mirrors the server's separation and makes the "they are in my family, so show the button" mistake structurally harder to write.

Subject selection states.

        SELF  (default, no subject parameter)
          |  choose a subject
          v
      RESOLVING  ---- refused ----> back to SELF, with a message
          |
       allowed
          v
       MANAGING  (banner visible, distinct styling)
          |
          +-- choose another subject -> remount on the new subject
          +-- server refuses a request -> drop subject, purge, SELF, message

There is no partially-authorised state: either the subject resolves and the screen renders, or the application is on the user's own account.

Delegated action.

tap "Book for <child>"     (button shown only if the permission is present)
  -> request to the child's subject-scoped endpoint, with the caregiver's own token
  -> the server authorises; the banner still reads "Managing <child>"
  -> if the server refuses: central handling drops the subject and returns home

Notification routing.

clinic-queue push   (existing)  -> the actor's own appointment queue screen
medication push     (NEW)       -> carries the subject and occurrence identifier,
                                   never the drug name
                                -> deep link into the subject's medication screen
                                -> the subject guard re-checks access before render,
                                   so a revoked caregiver lands on their own home

Where each new concept lives.

current user          authentication context        exists
current family        family provider               new
active subject        route parameter + provider    exists only in the doctor screen
authorisation state   subject access lookup         exists only as the doctor session
subject cleanup       extended session-change hook  exists for user change
access-lost handling  extended request layer        exists for expired tokens

Alternatives

An ambient subject held in a global context or the request layer. The smallest change, since existing hooks would need no new arguments. Rejected: a new screen would silently inherit whichever subject was last selected, turning wrong-patient writes from implausible into likely, and logs would lose the subject.

Add a subject parameter to the existing patient screens instead of new routes. Avoids duplicate routes. Rejected: every self screen would inherit subject-handling risk, so a defect in subject resolution would break the signed-in user's own data access — which is the majority of usage.

Introduce a data-fetching cache or global store for subject-scoped data. Would bring request deduplication and background refresh. Rejected: it introduces exactly the stale-data-across-subject-switch problem the current architecture does not have, and a wrongly-keyed cache entry is a cross-patient data leak. The absence of a cache is an asset here.

Give device alarms a subject dimension instead of using server push. Caregiver reminders would then work offline like the patient's own. Rejected: the scheduler, the reboot restore path and the permission handling would all have to become subject-aware, while the server must provide multi-caregiver fan-out and escalation regardless — two delivery paths for one feature.

Enforce permissions on the client as the primary gate. Fewer round trips and a snappier interface. Rejected: the frontend is not a security boundary. Client permissions stay cosmetic.

Require re-authentication before entering a subject-scoped screen. Protects a shared family phone picked up by someone else. Deferred to product: it adds friction to the most common caregiver action.

Consequences

Positive

  • No global cache means subject switching needs only a remount, not a cache-invalidation layer.
  • A single request function means the subject-explicit contract is enforced in one place.
  • The existing doctor patient screen is a working template, so the delegated view is largely assembly rather than new design.
  • The existing session-change cleanup already handles the awkward cases and extends naturally to subject change.
  • Three standing privacy weaknesses — health data in the system browser, no screenshot protection, and no central handling for lost access — are closed as part of this work.

Negative

  • Duplicate route surface for medications, records and appointments, reduced but not eliminated by reusing the existing screens as components.
  • Caregiver reminders will not work offline, unlike the patient's own alarms. This is a direct consequence of decision 6 and should be confirmed with product.
  • Screenshot protection will prompt support questions from users who screenshot their own records.
  • An in-app record viewer is more work than handing a link to the browser, including zoom and document handling.
  • Alarm behaviour must be regression-tested on physical devices, because the automated suite cannot observe the operating system scheduler.

Operational

  • The in-app record viewer and screenshot protection are independent of this feature and can ship immediately.
  • Everything else is sequenced behind the server work: the subject-aware request layer and route group first (no visible change), then the banner, switcher, cleanup, guard and central access-lost handling, then delegation and family screens, then dependent creation, then caregiver reminder subscriptions together with decision 6.
  • Both languages ship with each screen rather than as a later pass.

Open with product

Switcher placement; whether the first delegated write in a session needs confirmation; whether a shared device should require re-authentication before a subject-scoped screen; the visual treatment for subject-scoped mode; whether screenshot protection covers all health screens or only subject-scoped ones; and whether offline caregiver reminders are required.

  • ADR-005 — the server model. Its subject-explicit endpoints are the contract boundary between the two records.