Compose coherent Overview snapshots and preserve access ordering
This commit is contained in:
1 parent
cab10c5306
commit
cc7f87105d
16 files changed
+38314
-5
No files matched your search
@@ -0,0 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup><TargetFramework>net10.0</TargetFramework><Nullable>enable</Nullable><ImplicitUsings>enable</ImplicitUsings></PropertyGroup>
|
||||
<ItemGroup><FrameworkReference Include="Microsoft.AspNetCore.App" /><ProjectReference Include="../../HealthApp.Contracts/HealthApp.Contracts.csproj" /></ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using HealthApp.Contracts;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace HealthApp.Overview;
|
||||
internal sealed class OverviewFacade(ProfileQueries patients,ObservationQueries observations,AnalyticsQueries analytics) : OverviewQueries
|
||||
{
|
||||
public async Task<HealthOverviewDto?> GetAsync(AuthorizedPatientContext scope,DateTime from,DateTime to,ContextSelection selection,CancellationToken ct)
|
||||
{
|
||||
from=MeasurementPeriod.Normalize(from);to=MeasurementPeriod.Normalize(to);MeasurementPeriod.Validate(from,to);Validator.ValidateObject(selection,new ValidationContext(selection),true);
|
||||
var patient=await patients.GetAsync(scope,ct);if(patient is null)return null;
|
||||
var latest=await observations.LatestAsync(scope,ct);
|
||||
// Analytics captures the selected series once and closes the shared snapshot before calculation.
|
||||
var insight=await analytics.InsightAsync(scope,from,to,selection,ct);
|
||||
return new(patient,latest,insight,from,to,selection,insight?.ContributingCount??0,
|
||||
"Latest overall observation for the patient, independent of the insight period and context selections. "+
|
||||
"Its recorded context applies only to that observation, not to the insight's contributing observations.",
|
||||
insight is null?"No calculated insight is available: no observations match the requested period and insight selection.":
|
||||
"The insight uses the requested period and context selection only. "+insight.ContextExplanation);
|
||||
}
|
||||
}
|
||||
public static class OverviewModule
|
||||
{
|
||||
public static IServiceCollection AddOverview(this IServiceCollection services)=>services.AddScoped<OverviewQueries,OverviewFacade>();
|
||||
}
|
||||
Reference in new issue
Block a user