I am using C# in a .NET 6.0 web application and I want to calculate a score based on medical formula with 15 variables. Is there a more structured way in order to avoid multiple and enfolded switch & if then statements? I tried using Microsoft's Rules Engine but the output of each rule is constant while in my scenario the output should be related on the variable input. For example the output of the rule if Ejection Fraction is between 20-24 should be +6
Should I use the rule design pattern or is it overkill for my scenario? I want to achieve something like the following example.
Avoiding code like that:
switch (patientDataJson.EjectionFraction)
{
case int n when (n < 20):
score += 7;
break;
case int n when (n >= 20 && n <= 24):
score += 6;
break;
case int n when (n >= 25 && n <= 29):
score += 5;
break;
case int n when (n >= 30 && n <= 34):
score += 3;
break;
case int n when (n >= 35 && n <= 39):
score += 2;
break;
case int n when (n >= 40):
score += 0;
break;
default:
score += 0;
break;
}
Any help will be highly appreciated ! Thank you !