Import prescriptions by columns.

This commit is contained in:
Daniel Kraus 2015-12-01 21:10:42 +01:00
parent def5fce235
commit 92153f6d6c
1 changed files with 20 additions and 2 deletions

View File

@ -96,15 +96,33 @@ namespace zaaReloaded2.Medication
protected virtual void Import(string text)
{
Prescriptions = new List<Prescription>();
List<Prescription> list = new List<Prescription>();
IList<Prescription> addition;
int columns = 1;
string[] lines = Helpers.SplitParagraphs(text);
foreach (string line in lines)
{
if (Prescription.IsPrescriptionLine(line))
{
Prescriptions.AddRange(Prescription.ManyFromLine(line));
addition = Prescription.ManyFromLine(line);
columns = System.Math.Max(columns, addition.Count);
list.AddRange(addition);
}
}
// If the input had several columns, sort the prescriptions by
// column.
// TODO: Make this more generic so it works with 3 or 4 columns as well.
if (columns == 2)
{
var firstCol = list.Where((item, index) => index % 2 == 0);
var secondCol = list.Where((item, index) => index % 2 != 0);
Prescriptions = firstCol.Concat(secondCol).ToList();
}
else
{
Prescriptions = list;
}
}
#endregion