feature:
Full SOFA Score: Data Layer + Scoring Engine Glasgow Coma Scale: Data Layer + Scoring Engine
This commit is contained in:
@@ -10,19 +10,18 @@ public static class QsofaCalculator
|
||||
public static readonly IReadOnlySet<string> QsofaCodeSet =
|
||||
new HashSet<string>(QsofaCodes);
|
||||
|
||||
// qSOFA criteria (Sepsis-3 consensus):
|
||||
// - Respiratory rate ≥ 22 breaths/min
|
||||
// - Systolic blood pressure ≤ 100 mmHg
|
||||
// - Altered mentation: AVPU score ≥ 1 (any non-Alert state)
|
||||
public static bool MeetsCriterion(string observationCode, decimal value) =>
|
||||
observationCode switch
|
||||
{
|
||||
"RESP_RATE" => value >= 22m,
|
||||
"SYSTOLIC_BP" => value <= 100m,
|
||||
"AVPU" => value >= 1m,
|
||||
_ => false
|
||||
_ => false
|
||||
};
|
||||
|
||||
public static bool MeetsGcsAlteredMentation(int gcsTotal) =>
|
||||
GcsCalculator.MeetsQsofaAlteredMentation(gcsTotal);
|
||||
|
||||
public static string CriterionKey(Guid encounterId, string code) =>
|
||||
$"qsofa:{encounterId}:{code}";
|
||||
|
||||
|
||||
@@ -68,6 +68,44 @@ public class QsofaDetector
|
||||
return created ? QsofaResult.AlertCreated : QsofaResult.AlertAlreadyOpen;
|
||||
}
|
||||
|
||||
public async Task<QsofaResult> SyncAlteredMentationAsync(
|
||||
Guid encounterId,
|
||||
Guid patientId,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var cache = _redis.GetDatabase();
|
||||
var avpuKey = QsofaCalculator.CriterionKey(encounterId, "AVPU");
|
||||
var gcsValues = await cache.StringGetAsync(GcsCalculator.AllComponentKeys(encounterId));
|
||||
|
||||
if (gcsValues.All(v => v.HasValue))
|
||||
{
|
||||
var eye = decimal.Parse(gcsValues[0]!);
|
||||
var verbal = decimal.Parse(gcsValues[1]!);
|
||||
var motor = decimal.Parse(gcsValues[2]!);
|
||||
var total = GcsCalculator.ComputeTotal(eye, verbal, motor)!.Value;
|
||||
|
||||
if (QsofaCalculator.MeetsGcsAlteredMentation(total))
|
||||
{
|
||||
await cache.StringSetAsync(
|
||||
avpuKey, "1", TimeSpan.FromSeconds(QsofaTtlSeconds));
|
||||
}
|
||||
else
|
||||
{
|
||||
await cache.KeyDeleteAsync(avpuKey);
|
||||
}
|
||||
}
|
||||
|
||||
var allKeys = QsofaCalculator.AllCriterionKeys(encounterId);
|
||||
var values = await cache.StringGetAsync(allKeys);
|
||||
var activeCount = QsofaCalculator.CountActiveCriteria(values);
|
||||
|
||||
if (activeCount < 2)
|
||||
return QsofaResult.InsufficientCriteria(activeCount);
|
||||
|
||||
var created = await TryCreateAlertAsync(encounterId, patientId, activeCount, values, ct);
|
||||
return created ? QsofaResult.AlertCreated : QsofaResult.AlertAlreadyOpen;
|
||||
}
|
||||
|
||||
private async Task<bool> TryCreateAlertAsync(
|
||||
Guid encounterId,
|
||||
Guid patientId,
|
||||
|
||||
Reference in New Issue
Block a user