Implement US-10 on-demand health insights

This commit is contained in:
Steffen committed 2026-10-02 09:57:06 +02:00
1 parent 4cb6798ec9
commit a5b269cfc3
25 files changed
+482 -4

No files matched your search

@@ -0,0 +1,22 @@
using InsightsService.Clients;
using InsightsService.Domain;
namespace InsightsService.Application;
public sealed class InsightsApplicationService(ObservationServiceClient observations, InsightCalculator calculator)
{
public async Task<HealthInsight?> GetSummaryAsync(Guid patientId, DateTime from, DateTime to,
CancellationToken cancellationToken)
{
from = NormalizeTimestamp(from);
to = NormalizeTimestamp(to);
if (to < from)
throw new ArgumentException("The end time must not be earlier than the start time.", nameof(to));
var history = await observations.GetByPeriodAsync(patientId, from, to, cancellationToken);
return calculator.CalculateSummary(patientId, from, to, history);
}
private static DateTime NormalizeTimestamp(DateTime value) =>
DateTime.SpecifyKind(value.Kind == DateTimeKind.Unspecified ? value : value.ToUniversalTime(),
DateTimeKind.Unspecified);
}