Files

6.0 KiB

Detailed implementation design

Object and interface boundaries

Type / group Role and state
Program Composition root, framework middleware and endpoints
Seven controllers HTTP/model/status translation; typed facade calls and explicit transaction completion
AccessPolicy Account-to-patient ownership or configured professional assignment lookup
AuthorizedPatientContext Read-only PatientId/CanWrite; internal constructor accessible to host; RequireWrite guard
RequestAdmission Singleton health and assessment semaphores
RequestBoundaryMiddleware Authorization before model validation; transaction, admission, cancellation and dependency failure boundary
ReleaseTransactionFilter Disposes unfinished transaction after action processing
RequestTransaction Scoped Npgsql connection/transaction; BeginAsync, EnlistAsync, FinishAsync, DisposeAsync
ProfileFacade / PatientDbContext / Patient Internal profile implementation and mutable persistence model
ObservationFacade / ObservationDbContext / BloodPressureObservation Internal measurement implementation and mutable persistence model
AnalyticsFacade Loads immutable selected observations once, closes snapshot, invokes policies
SummaryPolicy / TrendPolicy / ClinicalPolicy Stateless numerical and interpretation responsibilities
OverviewFacade Composes immutable response; no persistence
GuidanceQueries / ReviewedReferenceCatalog Bundled guidance and reference metadata; no patient state

The exported interfaces are ProfileQueries (ResolveAccountAsync/GetAsync), ProfileCommands (CreateAsync/UpdateAsync), ObservationQueries (ResolveOwnerAsync/GetAsync/LatestAsync/SelectedAsync), ObservationCommands (RecordAsync/PatchAsync/DeleteAsync), AnalyticsQueries (InsightAsync/TrendAsync), OverviewQueries (GetAsync) and ReferenceCatalog (Pulse/Pressure/Version). CancellationToken flows through I/O. DTO records carry values, not tracked EF entities. Observation requests retain presence flags where omitted and explicit null differ. The internal InsightCalculator is a test-compatible calculation entry, not another public component.

classDiagram
  ProfileFacade ..|> ProfileQueries
  ProfileFacade ..|> ProfileCommands
  ObservationFacade ..|> ObservationQueries
  ObservationFacade ..|> ObservationCommands
  AnalyticsFacade ..|> AnalyticsQueries
  OverviewFacade ..|> OverviewQueries
  ReviewedReferenceCatalog ..|> ReferenceCatalog
  ProfileFacade --> PatientDbContext
  PatientDbContext --> Patient
  ObservationFacade --> ObservationDbContext
  ObservationDbContext --> BloodPressureObservation
  ObservationFacade --> ProfileQueries
  AnalyticsFacade --> ObservationQueries
  AnalyticsFacade --> SummaryPolicy
  AnalyticsFacade --> TrendPolicy
  TrendPolicy --> ClinicalPolicy
  ClinicalPolicy --> ReferenceCatalog
  OverviewFacade --> ProfileQueries
  OverviewFacade --> ObservationQueries
  OverviewFacade --> AnalyticsQueries
  ProfileFacade --> RequestTransaction
  ObservationFacade --> RequestTransaction
  AnalyticsFacade --> RequestTransaction

This is a selected implementation class view; the source inventory provides complete source-file coverage, including request and response classes.

Transaction lifecycle and concurrency

Protected health requests enter the boundary after framework authentication/authorization. Admission is immediate rather than queued. The boundary opens a read RepeatableRead or write ReadCommitted transaction and resolves route ownership before MVC binding/validation. Controllers also obtain an authorized scope for the facade operation. Separate DbContexts enlist in the same connection and transaction; Infrastructure knows transaction mechanics only.

Successful simple reads/writes call FinishAsync, committing and returning the connection. Analytics captures selected data then calls FinishAsync before synchronous calculation. Overview reads profile and latest first, then Analytics reads the selected series and finishes that same snapshot. Early returns, validation errors and exceptions dispose uncommitted work; the filter and middleware provide cleanup. Row locks protect updates/deletes, and database uniqueness/FK/check constraints enforce integrity. There is no automatic ambiguous-write retry.

Cancellation combines client abort with a configurable deadline. I/O receives the token. Existing synchronous numerical policy code checks cancellation before and after calculation; it is not preempted within each arithmetic loop. A response already started is aborted if a failure cannot be represented safely.

Numerical and clinical policy

Summary arithmetic uses eligible observations, decimal means and final two-decimal rounding away from zero. Trends retain raw mean/min/max/range, group equal measurement instants by metric mean, and process ordered distinct instants with equal weight. Adjacent nonzero changes determine direction/reversals; total successive change sums absolute steps. Full-period OLS uses scaled time; slope/day is rounded to six decimals, while sign uses the unrounded slope. Fewer than two distinct instants produce unavailable temporal direction while retaining descriptive values.

TrendPolicy separates numerical description, recorded comparability and ClinicalPolicy. Home high-BP references are 135/85, clinic 140/90 (inclusive); resting pulse boundaries are below 50/above 100 (exclusive). Applicability depends on recorded context and preparation limitations. Preserved finite English/Danish phrase detection can withhold interpretation and is not general language understanding. There is no personalized target, diagnosis, significance test or combined good/bad score.

The method version is baseline-2026-10-05; guidance is baseline-2026-10-04. Exact algorithms, applicability, labels and caveats are documented in TRENDS and clinical provenance. Source review dates are inherited baseline metadata, not evidence of a new clinical review.