Full SOFA Score: Data Layer + Scoring Engine

Glasgow Coma Scale: Data Layer + Scoring Engine
This commit is contained in:
voltsrage
2026-06-21 01:09:50 +08:00
parent 78c043e4d3
commit 93ea473d2b
62 changed files with 7133 additions and 72 deletions
+18 -23
View File
@@ -9,18 +9,15 @@ public static class News2Calculator
};
public static RedisKey[] AllParameterKeys(Guid encounterId) =>
ParameterCodes
.Select(code => (RedisKey)$"news2:{encounterId}:{code}")
.ToArray();
ParameterCodes
.Select(code => (RedisKey)$"news2:{encounterId}:{code}")
.ToArray();
public static string ParameterKey(Guid encounterId, string code) =>
$"news2:{encounterId}:{code}";
public static bool IsNews2Code(string observationCode) =>
ParameterCodes.Contains(observationCode);
// --- Individual parameter scoring ---
// Each method returns 0-3 per the official NEWS2 scoring table.
ParameterCodes.Contains(observationCode) || GcsCalculator.IsGcsCode(observationCode);
public static int ScoreRespRate(decimal value) => value switch
{
@@ -28,16 +25,15 @@ public static class News2Calculator
<= 11 => 1,
<= 20 => 0,
<= 24 => 2,
_ => 3 // >= 25
_ => 3
};
// Scale 1 (standard). Scale 2 (hypercapnic respiratory failure) is not implemented.
public static int ScoreSpo2(decimal value) => value switch
{
<= 91 => 3,
<= 93 => 2,
<= 95 => 1,
_ => 0 // >= 96
_ => 0
};
public static int ScoreSystolicBp(decimal value) => value switch
@@ -46,7 +42,7 @@ public static class News2Calculator
<= 100 => 2,
<= 110 => 1,
<= 219 => 0,
_ => 3 // >= 220
_ => 3
};
public static int ScoreHeartRate(decimal value) => value switch
@@ -56,30 +52,30 @@ public static class News2Calculator
<= 90 => 0,
<= 110 => 1,
<= 130 => 2,
_ => 3 // >= 131
_ => 3
};
// AVPU: Alert=0, Voice/Pain/Unresponsive=3 (any non-Alert scores 3)
public static int ScoreConsciousness(decimal value) => value switch
{
0 => 0, // Alert
_ => 3 // Voice (1), Pain (2), Unresponsive (3)
0 => 0,
_ => 3
};
public static int ScoreConsciousnessFromGcs(int gcsTotal) =>
GcsCalculator.ToNews2ConsciousnessScore(gcsTotal);
public static int ScoreTemperature(decimal value) => value switch
{
<= 35.0m => 3,
<= 36.0m => 1,
<= 38.0m => 0,
<= 39.0m => 1,
_ => 2 // >= 39.1
_ => 2
};
// 0 = room air, 1 = on supplemental oxygen
public static int ScoreSupplementalO2(decimal value) =>
value >= 1 ? 2 : 0;
// Dispatch to the correct scoring function by observation code.
public static int ScoreParameter(string observationCode, decimal value) =>
observationCode switch
{
@@ -93,13 +89,12 @@ public static class News2Calculator
_ => throw new ArgumentOutOfRangeException(nameof(observationCode))
};
// Determine risk level from total score and single-param-3 flag.
public static string DetermineRiskLevel(int totalScore, bool hasSingleParamThree) =>
totalScore switch
{
>= 7 => "HIGH",
>= 5 => "MEDIUM",
_ when hasSingleParamThree => "LOW_MEDIUM",
_ => "LOW"
>= 7 => "HIGH",
>= 5 => "MEDIUM",
_ when hasSingleParamThree => "LOW_MEDIUM",
_ => "LOW"
};
}