/* ClinicLine.cs
* part of zaaReloaded2
*
* Copyright 2017 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.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using zaaReloaded2.Thesaurus;
using zaaReloaded2.LabModel;
using zaaReloaded2.Importer.ZaaImporter;
using Bovender.Extensions;
namespace zaaReloaded2.Importer.ClinicImporter
{
///
/// Parses a line in a lab section produced by the outpatients clinic system,
/// and creates a list of s.
///
public class ClinicLine
{
#region Static methods
///
/// Investigates a paragraph and determines whether it looks
/// like a clinic laboratory items line.
///
public static bool ResemblesClinicLine(string line)
{
return _expectedFormat.IsMatch(line);
}
#endregion
#region Public properties
public LaurisItem Item { get; private set; }
///
/// Gets the original line that this object was constructed from.
///
public string OriginalLine{ get; private set; }
///
/// Is true if the matches the expected
/// format and contains s.
///
public bool IsClinicLine{ get; private set; }
#endregion
#region Constructor
public ClinicLine(string line)
{
OriginalLine = line;
Parse();
}
///
/// Constructs a object from a given line,
/// using a and a
/// to translate the individual
/// items' properties.
///
/// line to parse.
/// ParameterDictionary that contains
/// canonical names and material types.
/// Unit dictionary that contains canonical
/// unit names.
public ClinicLine(string line,
Thesaurus.Parameters parameterDictionary,
Thesaurus.Units unitDictionary)
{
OriginalLine = line;
_parameterDictionary = parameterDictionary;
_unitDictionary = unitDictionary;
Parse();
}
#endregion
#region Private methods
///
/// Attempts to parse a line.
///
void Parse()
{
Logger.Info("Parse: \"{0}\"", OriginalLine.TruncateWithEllipsis(40).Replace("\t", " "));
Match m = _expectedFormat.Match(OriginalLine);
if (m.Success)
{
Logger.Info("Parse: Matches clinic line format");
Item = new LaurisItem(m.Groups["item"].Value, _parameterDictionary, _unitDictionary);
IsClinicLine = true;
}
else
{
Logger.Info("Parse: Does not match clinic line format");
IsClinicLine = false;
}
}
#endregion
#region Fields
static readonly Regex _expectedFormat = new Regex(@"\t(?- [^:]+:(\t[^\t]+){3})");
Thesaurus.Parameters _parameterDictionary;
Thesaurus.Units _unitDictionary;
#endregion
#region Class logger
private static NLog.Logger Logger { get { return _logger.Value; } }
private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}