feature: Observation Ingest, Synchronous Alert Detection, and Alert Lifecycle
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
public static class PlausibilityValidator
|
||||
{
|
||||
// Plausible ranges define the outer boundary of physically possible values.
|
||||
// These are NOT clinical thresholds — they catch device malfunctions and typos.
|
||||
// A heart rate of 300 is clinically impossible; 150 is critical but possible.
|
||||
private static readonly Dictionary<string, (decimal Min, decimal Max)> _ranges = new()
|
||||
{
|
||||
["HEART_RATE"] = (1, 300),
|
||||
["TEMP_C"] = (20, 50),
|
||||
["POTASSIUM_MEQ_L"] = (0.1m, 15),
|
||||
["SPO2"] = (50, 100),
|
||||
["RESP_RATE"] = (1, 80),
|
||||
["WBC_K_UL"] = (0.1m, 500),
|
||||
["GLUCOSE_MG_DL"] = (10, 1500),
|
||||
};
|
||||
|
||||
public static bool IsPlausible(string observationCode, decimal value, out string? reason)
|
||||
{
|
||||
if (!_ranges.TryGetValue(observationCode, out var range))
|
||||
{
|
||||
// Unknown codes pass plausibility — threshold lookup will validate the code
|
||||
reason = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value < range.Min || value > range.Max)
|
||||
{
|
||||
reason = $"Value {value} is outside the plausible range [{range.Min}–{range.Max}] for {observationCode}.";
|
||||
return false;
|
||||
}
|
||||
|
||||
reason = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user