40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
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),
|
||
["SYSTOLIC_BP"] = (40, 300),
|
||
["DIASTOLIC_BP"] = (20, 200),
|
||
["LACTATE_MMOL_L"] = (0.1m, 30),
|
||
["AVPU"] = (0, 3),
|
||
["SUPPLEMENTAL_O2"] = (0, 1),
|
||
};
|
||
|
||
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;
|
||
}
|
||
} |