Import prescriptions by columns.
This commit is contained in:
parent
def5fce235
commit
92153f6d6c
@ -96,15 +96,33 @@ namespace zaaReloaded2.Medication
|
|||||||
|
|
||||||
protected virtual void Import(string text)
|
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);
|
string[] lines = Helpers.SplitParagraphs(text);
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
if (Prescription.IsPrescriptionLine(line))
|
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
|
#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user