Make AutoDetector aware of clinic mode.
This commit is contained in:
parent
ba485ac560
commit
08bd137e94
@ -203,6 +203,7 @@ namespace zaaReloaded2
|
||||
Word.Window activeWindow = word.ActiveWindow;
|
||||
Word.Selection selection = activeWindow.Selection;
|
||||
Word.Paragraphs paragraphs = selection.Paragraphs;
|
||||
Importer.IImporter importer = null;
|
||||
if (!(paragraphs.Count > 1
|
||||
|| (selection.Text.Length > 1 && selection.Text.EndsWith("\r"))))
|
||||
{
|
||||
@ -221,10 +222,10 @@ namespace zaaReloaded2
|
||||
}
|
||||
// Don't release the COM object here
|
||||
// Bovender.ComHelpers.ReleaseComObject(doc);
|
||||
importer = autoDetector.CreateImporter();
|
||||
}
|
||||
|
||||
Logger.Info("DoFormat: Importing");
|
||||
ZaaImporter importer = new ZaaImporter();
|
||||
importer.Import(selection.Text);
|
||||
Formatter.Formatter formatter = new Formatter.Formatter(activeDocument);
|
||||
|
||||
|
Binary file not shown.
@ -27,6 +27,12 @@ namespace zaaReloaded2.Importer
|
||||
{
|
||||
class AutoDetector
|
||||
{
|
||||
#region Properties
|
||||
|
||||
public ImportMode ImportMode { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public methods
|
||||
|
||||
/// <summary>
|
||||
@ -53,6 +59,7 @@ namespace zaaReloaded2.Importer
|
||||
|
||||
if (document.Bookmarks.Exists("Labor"))
|
||||
{
|
||||
Logger.Info("Detect: Found lab bookmark");
|
||||
i = GetParagraphIndex(
|
||||
document,
|
||||
document.Bookmarks["Labor"].Range.Paragraphs[1]);
|
||||
@ -65,10 +72,10 @@ namespace zaaReloaded2.Importer
|
||||
// lines such as "Tel. (09 31) 201-39432; -39126", which
|
||||
// happen to structurally resemble a paragraph with
|
||||
// laboratory items.
|
||||
if (LaurisTimePoint.IsTimeStampLine(
|
||||
document.Paragraphs[i].Range.Text))
|
||||
if (IsTimeStampParagraph(document.Paragraphs[i]))
|
||||
{
|
||||
start = document.Paragraphs[i];
|
||||
Logger.Info("Detect: Found time stamp line in paragraph #{0}", i);
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
@ -76,11 +83,14 @@ namespace zaaReloaded2.Importer
|
||||
|
||||
if (start != null)
|
||||
{
|
||||
Logger.Info("Detect: Determining lab block");
|
||||
end = start;
|
||||
while (i <= document.Paragraphs.Count - 1)
|
||||
{
|
||||
if (!IsLabParagraph(document.Paragraphs[i+1]))
|
||||
Paragraph p = document.Paragraphs[i+1];
|
||||
if (!IsLabParagraph(p) && !IsEmptyParagraph(p))
|
||||
{
|
||||
Logger.Info("Detect: Last lab paragraph is #{0}", i);
|
||||
end = document.Paragraphs[i];
|
||||
break;
|
||||
}
|
||||
@ -90,9 +100,23 @@ namespace zaaReloaded2.Importer
|
||||
document.Range(start.Range.Start, end.Range.End).Select();
|
||||
return true;
|
||||
}
|
||||
Logger.Warn("Detect: Did not find lab block!");
|
||||
return false;
|
||||
}
|
||||
|
||||
public IImporter CreateImporter()
|
||||
{
|
||||
switch (ImportMode)
|
||||
{
|
||||
case ImportMode.Zaa:
|
||||
return new ZaaImporter.ZaaImporter();
|
||||
case ImportMode.Clinic:
|
||||
return new ClinicImporter.ClinicImporter();
|
||||
default:
|
||||
throw new InvalidOperationException("Cannot create Importer for undefined import mode!");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
@ -109,9 +133,10 @@ namespace zaaReloaded2.Importer
|
||||
// the lab mode *must* be ZAA, because it will be a line in the form
|
||||
// "(17.09.2015-201710:44:00) Cyclosporin-A vor Gabe: 130 µg/l;" which does not
|
||||
// occur in the clinic format.
|
||||
if ((_mode == Mode.Undefined) && isZaaTimePoint && !isCinicTimePoint)
|
||||
if ((ImportMode == ImportMode.Undefined) && isZaaTimePoint && !isCinicTimePoint)
|
||||
{
|
||||
_mode = Mode.Zaa;
|
||||
Logger.Info("IsTimeStampParagraph: Found ZAA time stamp, setting mode to ZAA");
|
||||
ImportMode = ImportMode.Zaa;
|
||||
}
|
||||
return isCinicTimePoint || isZaaTimePoint;
|
||||
}
|
||||
@ -131,24 +156,26 @@ namespace zaaReloaded2.Importer
|
||||
{
|
||||
string text = paragraph.Range.Text;
|
||||
bool isLabParagraph = false;
|
||||
switch (_mode)
|
||||
switch (ImportMode)
|
||||
{
|
||||
case Mode.Undefined:
|
||||
case ImportMode.Undefined:
|
||||
if (LaurisParagraph.ResemblesLaurisParagraph(text) || LaurisTimePoint.IsTimeStampLine(text))
|
||||
{
|
||||
_mode = Mode.Zaa;
|
||||
ImportMode = ImportMode.Zaa;
|
||||
Logger.Info("IsLabParagraph: Setting mode to ZAA");
|
||||
isLabParagraph = true;
|
||||
}
|
||||
else if (ClinicLine.ResemblesClinicLine(text) || ClinicTimePoint.IsTimeStampLine(text))
|
||||
{
|
||||
_mode = Mode.Clinic;
|
||||
ImportMode = ImportMode.Clinic;
|
||||
Logger.Info("IsLabParagraph: Setting mode to Clinic");
|
||||
isLabParagraph = true;
|
||||
}
|
||||
break;
|
||||
case Mode.Zaa:
|
||||
case ImportMode.Zaa:
|
||||
isLabParagraph = LaurisParagraph.ResemblesLaurisParagraph(text) || LaurisTimePoint.IsTimeStampLine(text);
|
||||
break;
|
||||
case Mode.Clinic:
|
||||
case ImportMode.Clinic:
|
||||
isLabParagraph = ClinicLine.ResemblesClinicLine(text) || ClinicTimePoint.IsTimeStampLine(text);
|
||||
break;
|
||||
default:
|
||||
@ -170,18 +197,19 @@ namespace zaaReloaded2.Importer
|
||||
return document.Range(0, paragraph.Range.Start).Paragraphs.Count;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private enum Mode
|
||||
private bool IsEmptyParagraph(Paragraph paragraph)
|
||||
{
|
||||
Undefined,
|
||||
Zaa,
|
||||
Clinic
|
||||
string text = paragraph.Range.Text;
|
||||
return String.IsNullOrWhiteSpace(text);
|
||||
}
|
||||
|
||||
private Mode _mode;
|
||||
#endregion
|
||||
|
||||
#region Class logger
|
||||
|
||||
private static NLog.Logger Logger { get { return _logger.Value; } }
|
||||
|
||||
private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ namespace zaaReloaded2.Importer.ClinicImporter
|
||||
|
||||
#region Fields
|
||||
|
||||
static readonly Regex _expectedFormat = new Regex(@"\t(?<item>[^:]+:(\t[^\t]+){3})");
|
||||
static readonly Regex _expectedFormat = new Regex(@"\t(?<item>[^:]+:(\t([^\t]+)?){3})");
|
||||
Thesaurus.Parameters _parameterDictionary;
|
||||
Thesaurus.Units _unitDictionary;
|
||||
|
||||
|
31
zaaReloaded2/Importer/ImportMode.cs
Executable file
31
zaaReloaded2/Importer/ImportMode.cs
Executable file
@ -0,0 +1,31 @@
|
||||
/* ImportMode.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.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace zaaReloaded2.Importer
|
||||
{
|
||||
public enum ImportMode
|
||||
{
|
||||
Undefined,
|
||||
Zaa,
|
||||
Clinic
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user