Workaround for commas in Lauris values.
- VERBESSERT: Kein Crash mehr, falls sich ein Komma in den Lauris-Block einschleicht.
This commit is contained in:
parent
8a1e236bd8
commit
66ad3886da
@ -30,6 +30,7 @@ namespace Tests.Importer.ZaaImporter
|
||||
{
|
||||
[Test]
|
||||
[TestCase("BE: 5.2 [-2 - 2] mmol/l", "BE", 5.2, "mmol/l", -2, 2, false)]
|
||||
[TestCase("Comma: 5,2 [-2,1 - 2,3] mmol/l", "Comma", 5.2, "mmol/l", -2.1, 2.3, false)]
|
||||
[TestCase("Natrium: 139 [135 - 145] mmol/l", "Natrium", 139, "mmol/l", 135, 145, true)]
|
||||
[TestCase("Kalium: 5.2 [3.5 - 5] mmol/l", "Kalium", 5.2, "mmol/l", 3.5, 5, false)]
|
||||
public void ParseLaurisWithBothLimits(
|
||||
|
@ -104,24 +104,25 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
// "Erythrozyten (U): + [negativ]"
|
||||
Match match;
|
||||
Regex numericalRegex = new Regex(
|
||||
@"(?<name>[^:]+):\s*(?<value>[\d.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
|
||||
@"(?<name>[^:]+):\s*(?<value>[\d,.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
|
||||
Regex categoricalRegex = new Regex(
|
||||
@"(?<name>[^:]+):\s*(?<value>[^[;]+)\s*(\[(?<normal>[^\]]+)])?");
|
||||
if (numericalRegex.IsMatch(LaurisText))
|
||||
{
|
||||
match = numericalRegex.Match(LaurisText);
|
||||
ParseLimits(match);
|
||||
Value = match.Groups["value"].Value.Trim().Replace(',', '.');
|
||||
}
|
||||
else
|
||||
{
|
||||
match = categoricalRegex.Match(LaurisText);
|
||||
Normal = match.Groups["normal"].Value.Trim();
|
||||
Value = match.Groups["value"].Value.Trim();
|
||||
}
|
||||
if (match != null)
|
||||
{
|
||||
OriginalName = match.Groups["name"].Value.Trim();
|
||||
Name = OriginalName;
|
||||
Value = match.Groups["value"].Value.Trim();
|
||||
Unit = match.Groups["unit"].Value.Trim();
|
||||
}
|
||||
}
|
||||
@ -135,14 +136,15 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
{
|
||||
if (match.Groups["limits"].Success)
|
||||
{
|
||||
Regex limitRegex = new Regex(@"\[(?<limit1>[-\d.]+)?\s*(?<operator>\S+)\s*(?<limit2>[-\d.]+)?]");
|
||||
Regex limitRegex = new Regex(@"\[(?<limit1>[-\d,.]+)?\s*(?<operator>\S+)\s*(?<limit2>[-\d,.]+)?]");
|
||||
Match limitMatch = limitRegex.Match(match.Groups["limits"].Value);
|
||||
if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success)
|
||||
{
|
||||
// Use InvariantCulture because Lauris always outputs dots as decimal separator
|
||||
LowerLimit = Double.Parse(limitMatch.Groups["limit1"].Value,
|
||||
// Only in rare cases, a comma sneaks in...
|
||||
LowerLimit = Double.Parse(limitMatch.Groups["limit1"].Value.Replace(',', '.'),
|
||||
CultureInfo.InvariantCulture);
|
||||
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value,
|
||||
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value.Replace(',', '.'),
|
||||
CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
@ -150,11 +152,11 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
||||
switch (limitMatch.Groups["operator"].Value.Trim())
|
||||
{
|
||||
case "<=":
|
||||
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value,
|
||||
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value.Replace(',', '.'),
|
||||
CultureInfo.InvariantCulture);
|
||||
break;
|
||||
case ">=":
|
||||
LowerLimit = Double.Parse(limitMatch.Groups["limit2"].Value,
|
||||
LowerLimit = Double.Parse(limitMatch.Groups["limit2"].Value.Replace(',', '.'),
|
||||
CultureInfo.InvariantCulture);
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user