From 7997e307fa5db5ae6c883887b6e4ad32b623324e Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Fri, 18 Sep 2015 17:22:04 +0200 Subject: [PATCH] Fix handling extreme values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - VERBESSERT: Extreme Werte (mit "<" oder ">") wurden nicht sehr schön formatiert. --- Tests/Importer/ZaaImporter/LaurisItemTest.cs | 20 +++++++++++++++++++ .../Importer/ZaaImporter/LaurisItem.cs | 2 +- zaaReloaded2/LabModel/LabItem.cs | 15 ++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Tests/Importer/ZaaImporter/LaurisItemTest.cs b/Tests/Importer/ZaaImporter/LaurisItemTest.cs index 3f58977..47383c9 100755 --- a/Tests/Importer/ZaaImporter/LaurisItemTest.cs +++ b/Tests/Importer/ZaaImporter/LaurisItemTest.cs @@ -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, diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs index efda5b4..dec443e 100755 --- a/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs +++ b/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs @@ -203,7 +203,7 @@ namespace zaaReloaded2.Importer.ZaaImporter #region Fields static readonly Regex _numericalRegex = new Regex( - @"(?[^:]+):\s*(?[\d,.]+)\s*(?\[[^\]]+])?\s*(?[^;]+)?"); + @"(?[^:]+):\s*(?([\<\>]\s)?[\d,.]+)\s*(?\[[^\]]+])?\s*(?[^;]+)?"); static readonly Regex _categoricalRegex = new Regex( @"(?[^:]+):\s*(?[^[;]+)\s*(\[(?[^\]]+)])?"); static readonly Regex _limitRegex = new Regex(@"\[(?[-\d,.]+)?\s*(?\S+)\s*(?[-\d,.]+)?]"); diff --git a/zaaReloaded2/LabModel/LabItem.cs b/zaaReloaded2/LabModel/LabItem.cs index 9eb5410..a95de4b 100755 --- a/zaaReloaded2/LabModel/LabItem.cs +++ b/zaaReloaded2/LabModel/LabItem.cs @@ -74,6 +74,19 @@ namespace zaaReloaded2.LabModel } } + /// + /// Returns whether or not the value is an 'extreme' value, + /// i.e. marked with ">" or "<". These values are not + /// strictly numeric, and IsNumerical returns false for them. + /// + public bool IsExtreme + { + get + { + return "<>".Contains(Value.Substring(0, 1)); + } + } + /// /// 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)