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]
|
[Test]
|
||||||
[TestCase("BE: 5.2 [-2 - 2] mmol/l", "BE", 5.2, "mmol/l", -2, 2, false)]
|
[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("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)]
|
[TestCase("Kalium: 5.2 [3.5 - 5] mmol/l", "Kalium", 5.2, "mmol/l", 3.5, 5, false)]
|
||||||
public void ParseLaurisWithBothLimits(
|
public void ParseLaurisWithBothLimits(
|
||||||
|
@ -104,24 +104,25 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
|||||||
// "Erythrozyten (U): + [negativ]"
|
// "Erythrozyten (U): + [negativ]"
|
||||||
Match match;
|
Match match;
|
||||||
Regex numericalRegex = new Regex(
|
Regex numericalRegex = new Regex(
|
||||||
@"(?<name>[^:]+):\s*(?<value>[\d.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
|
@"(?<name>[^:]+):\s*(?<value>[\d,.]+)\s*(?<limits>\[[^\]]+])?\s*(?<unit>[^;]+)?");
|
||||||
Regex categoricalRegex = new Regex(
|
Regex categoricalRegex = new Regex(
|
||||||
@"(?<name>[^:]+):\s*(?<value>[^[;]+)\s*(\[(?<normal>[^\]]+)])?");
|
@"(?<name>[^:]+):\s*(?<value>[^[;]+)\s*(\[(?<normal>[^\]]+)])?");
|
||||||
if (numericalRegex.IsMatch(LaurisText))
|
if (numericalRegex.IsMatch(LaurisText))
|
||||||
{
|
{
|
||||||
match = numericalRegex.Match(LaurisText);
|
match = numericalRegex.Match(LaurisText);
|
||||||
ParseLimits(match);
|
ParseLimits(match);
|
||||||
|
Value = match.Groups["value"].Value.Trim().Replace(',', '.');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
match = categoricalRegex.Match(LaurisText);
|
match = categoricalRegex.Match(LaurisText);
|
||||||
Normal = match.Groups["normal"].Value.Trim();
|
Normal = match.Groups["normal"].Value.Trim();
|
||||||
|
Value = match.Groups["value"].Value.Trim();
|
||||||
}
|
}
|
||||||
if (match != null)
|
if (match != null)
|
||||||
{
|
{
|
||||||
OriginalName = match.Groups["name"].Value.Trim();
|
OriginalName = match.Groups["name"].Value.Trim();
|
||||||
Name = OriginalName;
|
Name = OriginalName;
|
||||||
Value = match.Groups["value"].Value.Trim();
|
|
||||||
Unit = match.Groups["unit"].Value.Trim();
|
Unit = match.Groups["unit"].Value.Trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,14 +136,15 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
|||||||
{
|
{
|
||||||
if (match.Groups["limits"].Success)
|
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);
|
Match limitMatch = limitRegex.Match(match.Groups["limits"].Value);
|
||||||
if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success)
|
if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success)
|
||||||
{
|
{
|
||||||
// Use InvariantCulture because Lauris always outputs dots as decimal separator
|
// 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);
|
CultureInfo.InvariantCulture);
|
||||||
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value,
|
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value.Replace(',', '.'),
|
||||||
CultureInfo.InvariantCulture);
|
CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -150,11 +152,11 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
|||||||
switch (limitMatch.Groups["operator"].Value.Trim())
|
switch (limitMatch.Groups["operator"].Value.Trim())
|
||||||
{
|
{
|
||||||
case "<=":
|
case "<=":
|
||||||
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value,
|
UpperLimit = Double.Parse(limitMatch.Groups["limit2"].Value.Replace(',', '.'),
|
||||||
CultureInfo.InvariantCulture);
|
CultureInfo.InvariantCulture);
|
||||||
break;
|
break;
|
||||||
case ">=":
|
case ">=":
|
||||||
LowerLimit = Double.Parse(limitMatch.Groups["limit2"].Value,
|
LowerLimit = Double.Parse(limitMatch.Groups["limit2"].Value.Replace(',', '.'),
|
||||||
CultureInfo.InvariantCulture);
|
CultureInfo.InvariantCulture);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user