feature: Medication Tracking & Vital Sign Correlation

This commit is contained in:
voltsrage
2026-06-19 10:47:55 +08:00
parent e2d40331b7
commit 5c7e37471b
29 changed files with 2512 additions and 4 deletions
@@ -0,0 +1,39 @@
using Microsoft.Extensions.Options;
public class MedicationCorrelationHelper
{
private readonly IMedicationService _medicationService;
private readonly MedicationCorrelationOptions _options;
public MedicationCorrelationHelper(
IMedicationService medicationService,
IOptions<MedicationCorrelationOptions> options)
{
_medicationService = medicationService;
_options = options.Value;
}
/// <summary>
/// Appends medication context to alert details if a correlated administration
/// exists within the lookback window. Returns the original details if none found.
/// </summary>
public async Task<string> TryAnnotateDetailsAsync(
Guid encounterId,
string observationCode,
string details,
CancellationToken ct = default)
{
var recent = await _medicationService.GetRecentForEncounterAsync(
encounterId, observationCode, _options.CorrelationWindowMinutes);
if (recent.Count == 0)
return details;
// Use the most recent correlated administration
var med = recent[0];
var minutesAgo = (int)(DateTimeOffset.UtcNow - med.AdministeredAt).TotalMinutes;
return $"{details} — note: {med.DrugName} {med.Dose}{med.DoseUnit} " +
$"({med.Route}) administered {minutesAgo} min ago";
}
}