Fix handling extreme values.

- VERBESSERT: Extreme Werte (mit "<" oder ">") wurden nicht sehr schön formatiert.
This commit is contained in:
Daniel Kraus 2015-09-18 17:22:04 +02:00
parent 7a5041e04c
commit 7997e307fa
3 changed files with 36 additions and 1 deletions

View File

@ -40,6 +40,7 @@ namespace Tests.Importer.ZaaImporter
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(unit, i.Unit, "Unit");
Assert.IsFalse(i.IsExtreme, "IsExtreme");
Assert.IsTrue(i.IsNumerical, "IsNumerical");
Assert.AreEqual(value, i.NumericalValue, "NumericalValue");
Assert.AreEqual(lowerLimit, i.LowerLimit, "Lower limit");
@ -50,6 +51,25 @@ namespace Tests.Importer.ZaaImporter
Assert.IsTrue(i.HasUpperLimit, "HasUpperLimit");
}
[TestCase("Folsäure: > 20 [2.0 - 9.1] ng/ml; ", "Folsäure", "> 20", "ng/ml", 2, 9.1, false)]
public void ParseLaurisWithGreaterOrLowerValue(
string laurisString, string name, string value,
string unit, double lowerLimit, double upperLimit, bool isNormal)
{
LaurisItem i = new LaurisItem(laurisString);
Assert.AreEqual(name, i.Name, "Name");
Assert.AreEqual(unit, i.Unit, "Unit");
Assert.IsTrue(i.IsExtreme, "IsExtreme");
Assert.IsFalse(i.IsNumerical, "IsNumerical");
Assert.AreEqual(value, i.Value, "Value");
Assert.AreEqual(lowerLimit, i.LowerLimit, "Lower limit");
Assert.AreEqual(upperLimit, i.UpperLimit, "Upper limit");
Assert.AreEqual(isNormal, i.IsNormal, "IsNormal");
Assert.IsTrue(i.HasLimits, "HasLimits");
Assert.IsTrue(i.HasLowerLimit, "HasLowerLimit");
Assert.IsTrue(i.HasUpperLimit, "HasUpperLimit");
}
[TestCase("HDL - Cholesterin: 45 [>= 35] mg/dl", "HDL - Cholesterin", 45, "mg/dl", 35, true)]
public void ParseLaurisWithLowerLimit(
string laurisString, string name, double value,

View File

@ -203,7 +203,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
#region Fields
static readonly Regex _numericalRegex = new Regex(
@"(?<name>[^:]+):\s*(?<value>[\d,.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
@"(?<name>[^:]+):\s*(?<value>([\<\>]\s)?[\d,.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
static readonly Regex _categoricalRegex = new Regex(
@"(?<name>[^:]+):\s*(?<value>[^[;]+)\s*(\[(?<normal>[^\]]+)])?");
static readonly Regex _limitRegex = new Regex(@"\[(?<limit1>[-\d,.]+)?\s*(?<operator>\S+)\s*(?<limit2>[-\d,.]+)?]");

View File

@ -74,6 +74,19 @@ namespace zaaReloaded2.LabModel
}
}
/// <summary>
/// Returns whether or not the value is an 'extreme' value,
/// i.e. marked with "&gt;" or "&lt;". These values are not
/// strictly numeric, and IsNumerical returns false for them.
/// </summary>
public bool IsExtreme
{
get
{
return "<>".Contains(Value.Substring(0, 1));
}
}
/// <summary>
/// Gets the normal value of the item. Need not be set. This is
/// used for items with nominal values (as opposed to numbers).
@ -130,6 +143,8 @@ namespace zaaReloaded2.LabModel
{
get
{
if (IsExtreme) return false;
if (HasLimits)
{
if (HasLowerLimit && HasUpperLimit)