125 lines
3.5 KiB
C#
Executable File
125 lines
3.5 KiB
C#
Executable File
/* ZaaImporter.cs
|
|
* part of zaaReloaded2
|
|
*
|
|
* Copyright 2015 Daniel Kraus
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Bovender.Extensions;
|
|
using zaaReloaded2.LabModel;
|
|
using zaaReloaded2.Thesaurus;
|
|
|
|
namespace zaaReloaded2.Importer.ZaaImporter
|
|
{
|
|
/// <summary>
|
|
/// Imports laboratory items by parsing the Lauris data from a
|
|
/// physician's letter.
|
|
/// </summary>
|
|
public class ZaaImporter : IImporter
|
|
{
|
|
#region IImporter implementation
|
|
|
|
public Laboratory Laboratory
|
|
{
|
|
[DebuggerStepThrough]
|
|
get
|
|
{
|
|
if (_laboratory == null)
|
|
{
|
|
_laboratory = new Laboratory();
|
|
}
|
|
return _laboratory;
|
|
}
|
|
[DebuggerStepThrough]
|
|
set
|
|
{
|
|
_laboratory = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Splits the <paramref name="text"/> into individual time points
|
|
/// and creates <see cref="LaurisTimePoint"/> objects from them.
|
|
/// </summary>
|
|
/// <param name="text">ZAA-formatted Lauris output to import.</param>
|
|
public void Import(string text)
|
|
{
|
|
string[] paragraphs = text.Split(
|
|
new string[] { Environment.NewLine },
|
|
StringSplitOptions.RemoveEmptyEntries);
|
|
int i = 0;
|
|
int start = 0;
|
|
int numParagraphs = paragraphs.Length;
|
|
|
|
while (i < numParagraphs)
|
|
{
|
|
// Search for the next occurrence of a time stamp line
|
|
while (i < numParagraphs
|
|
&& !LaurisTimePoint.IsTimeStampLine(paragraphs[i]))
|
|
{
|
|
i++;
|
|
}
|
|
|
|
// TODO: Find an alternative to returning in the middle of the method.
|
|
if (i >= numParagraphs) return;
|
|
|
|
if (LaurisTimePoint.IsTimeStampLine(paragraphs[i]))
|
|
{
|
|
// Remember the time stamp line's index
|
|
start = i;
|
|
|
|
// Seek the next time stamp line
|
|
while (i + 1 < numParagraphs
|
|
&& !LaurisTimePoint.IsTimeStampLine(paragraphs[i + 1]))
|
|
{
|
|
i++;
|
|
}
|
|
}
|
|
|
|
Laboratory.AddTimePoint(
|
|
new LaurisTimePoint(
|
|
paragraphs.Slice(start, i - start + 1),
|
|
_parameters,
|
|
_units
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
public ZaaImporter()
|
|
{
|
|
_parameters = new Parameters();
|
|
_units = new Units();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Fields
|
|
|
|
Laboratory _laboratory;
|
|
Parameters _parameters;
|
|
Units _units;
|
|
|
|
#endregion
|
|
}
|
|
}
|