namespace HealthApp.Contracts; public interface ObservationQueries { Task ResolveOwnerAsync(Guid observationId, CancellationToken ct); Task GetAsync(AuthorizedPatientContext scope, Guid id, CancellationToken ct); Task LatestAsync(AuthorizedPatientContext scope, CancellationToken ct); Task> SelectedAsync(AuthorizedPatientContext scope, DateTime from, DateTime to, ContextSelection selection, CancellationToken ct); } public interface ObservationCommands { Task RecordAsync(AuthorizedPatientContext scope, RecordObservationRequest request, CancellationToken ct); Task PatchAsync(AuthorizedPatientContext scope, Guid id, PatchObservationRequest request, CancellationToken ct); Task DeleteAsync(AuthorizedPatientContext scope, Guid id, CancellationToken ct); } public static class MeasurementPeriod { public static DateTime Normalize(DateTime t) => DateTime.SpecifyKind(t.Kind == DateTimeKind.Unspecified ? t : t.ToUniversalTime(), DateTimeKind.Unspecified); public static void Validate(DateTime from, DateTime to) { if (Normalize(to) < Normalize(from)) throw new ArgumentException("The end time must not be earlier than the start time."); } }