Fix parsing of prescriptions without regular dosing.

This commit is contained in:
Daniel Kraus 2015-12-02 12:25:30 +01:00
parent 92153f6d6c
commit 2296fcfe41
2 changed files with 18 additions and 5 deletions

View File

@ -102,5 +102,14 @@ namespace Tests.Medication
Assert.AreEqual("0", list[1].Night);
Assert.AreEqual("neu", list[1].Comment);
}
[Test]
public void PrescriptionWithoutTypicalDosing()
{
Prescription p = Prescription.FromLine("Eusaprim forte\t alle zwei Tage");
Assert.AreEqual("Eusaprim forte", p.Drug);
Assert.AreEqual("alle zwei Tage", p.Comment);
Assert.AreEqual("Eusaprim forte\talle zwei Tage", p.ToString(), "ToString");
}
}
}

View File

@ -157,14 +157,18 @@ namespace zaaReloaded2.Medication
}
if (!String.IsNullOrEmpty(Comment))
{
s += " " + Comment.Trim();
if (!s.EndsWith("\t"))
{
s += " ";
}
s += Comment;
}
return s;
}
#endregion
#region Constructor
#region Constructors
public Prescription() { }
@ -190,18 +194,18 @@ namespace zaaReloaded2.Medication
#region Fields
private const string DOSE_GROUP = "dose";
private const string DOSE = @"(\d\s+1/[234]|[\u00bd\u2153\u00bc]|\d+)";
private const string DOSE = @"(\d\s+1/[234]|(\d\s?)?[\u00bd\u2153\u00bc]|\d+)";
private const string SPACER = @"(\s*[-\u2012\u2013\u2014]+\s*)";
// Enclose entire regular expression in parentheses so we can use it
// to split a line and capture the delimiter.
private static readonly Regex lineRegex = new Regex(
@"((?<drug>[^\t]+)\s+" +
@"(((?<drug>[^\t]+)\s+" +
@"(?<dose>" + DOSE + @")" + SPACER +
@"(?<dose>" + DOSE + @")" + SPACER +
@"(?<dose>" + DOSE + @")" +
@"(" + SPACER + @"(?<dose>" + DOSE + @"))?" +
@"( +(?<comment>[^\t]+))?\s*)");
@"( +(?<comment>[^\t]+))?)|((?<drug>[^\t]+)( +|\t+)(?<comment>[^\t]+)))");
private static readonly Regex spaceRegex = new Regex(@"\s+");