Add prescriptions importer.
This commit is contained in:
parent
c35c73f56a
commit
bcbed5bca3
44
zaaReloaded2/Helpers.cs
Executable file
44
zaaReloaded2/Helpers.cs
Executable file
@ -0,0 +1,44 @@
|
|||||||
|
/* Helpers.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;
|
||||||
|
|
||||||
|
namespace zaaReloaded2
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Common helper methods.
|
||||||
|
/// </summary>
|
||||||
|
public static class Helpers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Splits a text into paragraphs.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paragraph">Text to split.</param>
|
||||||
|
/// <returns>Array of paragraphs in the text.</returns>
|
||||||
|
/// <remarks>
|
||||||
|
/// This implementation relies on the fact that the order of
|
||||||
|
/// splitting strings in C#'s String.Split() method is
|
||||||
|
/// important; see http://stackoverflow.com/a/8664639/270712
|
||||||
|
/// </remarks>
|
||||||
|
public static string[] SplitParagraphs(string text)
|
||||||
|
{
|
||||||
|
return text.Split(
|
||||||
|
new string[] { "\r\n", "\n\r", "\r", "\n" },
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -67,12 +67,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
|
|||||||
/// <param name="text">ZAA-formatted Lauris output to import.</param>
|
/// <param name="text">ZAA-formatted Lauris output to import.</param>
|
||||||
public void Import(string text)
|
public void Import(string text)
|
||||||
{
|
{
|
||||||
// Split the text into parargraphs. This implementation relies on the fact
|
string[] paragraphs = Helpers.SplitParagraphs(text);
|
||||||
// that the order or splitting strings in C#'s String.Split() method is
|
|
||||||
// important; see http://stackoverflow.com/a/8664639/270712
|
|
||||||
string[] paragraphs = text.Split(
|
|
||||||
new string[] { "\r\n", "\n\r", "\r", "\n" },
|
|
||||||
StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
LaurisTimePoint timePoint = null;
|
LaurisTimePoint timePoint = null;
|
||||||
|
|
||||||
foreach (string paragraph in paragraphs)
|
foreach (string paragraph in paragraphs)
|
||||||
|
112
zaaReloaded2/Medication/Importer.cs
Executable file
112
zaaReloaded2/Medication/Importer.cs
Executable file
@ -0,0 +1,112 @@
|
|||||||
|
using Microsoft.Office.Interop.Word;
|
||||||
|
/* Importer.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.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace zaaReloaded2.Medication
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Imports prescriptions from a physician's letter.
|
||||||
|
/// </summary>
|
||||||
|
public class Importer
|
||||||
|
{
|
||||||
|
#region Static methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to automatically detect a block of prescriptions
|
||||||
|
/// in a document. The document is screened from end to start.
|
||||||
|
/// The detected block is selected.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if a block was detected, false if not.</returns>
|
||||||
|
public bool AutoDetect(Document document)
|
||||||
|
{
|
||||||
|
Paragraph start = null;
|
||||||
|
Paragraph end = null;
|
||||||
|
int i = document.Paragraphs.Count;
|
||||||
|
|
||||||
|
while (i > 1)
|
||||||
|
{
|
||||||
|
string line = document.Paragraphs[i].Range.Text;
|
||||||
|
if (Prescription.IsPrescriptionLine(line))
|
||||||
|
{
|
||||||
|
start = document.Paragraphs[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start != null)
|
||||||
|
{
|
||||||
|
end = start;
|
||||||
|
while (i > 1)
|
||||||
|
{
|
||||||
|
if (!Prescription.IsPrescriptionLine(document.Paragraphs[i - 1].Range.Text))
|
||||||
|
{
|
||||||
|
end = document.Paragraphs[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.Range(start.Range.Start, end.Range.End).Select();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public List<Prescription> Prescriptions { get; protected set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructor
|
||||||
|
|
||||||
|
public Importer() { }
|
||||||
|
|
||||||
|
public Importer(string text)
|
||||||
|
: this()
|
||||||
|
{
|
||||||
|
Import(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Private methods
|
||||||
|
|
||||||
|
protected virtual void Import(string text)
|
||||||
|
{
|
||||||
|
Prescriptions = new List<Prescription>();
|
||||||
|
string[] lines = Helpers.SplitParagraphs(text);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
if (Prescription.IsPrescriptionLine(line))
|
||||||
|
{
|
||||||
|
Prescriptions.Add(Prescription.FromLine(line));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,19 @@ namespace zaaReloaded2.Medication
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Prescription
|
public class Prescription
|
||||||
{
|
{
|
||||||
|
#region Static methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether a line contains prescriptions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="line">Line to inspect.</param>
|
||||||
|
/// <returns>True if the line contains prescriptions.</returns>
|
||||||
|
public static bool IsPrescriptionLine(string line)
|
||||||
|
{
|
||||||
|
return lineRegex.IsMatch(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
#region Factory
|
#region Factory
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -194,6 +194,7 @@
|
|||||||
-->
|
-->
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Commands.cs" />
|
<Compile Include="Commands.cs" />
|
||||||
|
<Compile Include="Helpers.cs" />
|
||||||
<Compile Include="Importer\ZaaImporter\AutoDetect.cs" />
|
<Compile Include="Importer\ZaaImporter\AutoDetect.cs" />
|
||||||
<Compile Include="Controller\Comments\CommentPool.cs" />
|
<Compile Include="Controller\Comments\CommentPool.cs" />
|
||||||
<Compile Include="Controller\Elements\ControlElementBase.cs" />
|
<Compile Include="Controller\Elements\ControlElementBase.cs" />
|
||||||
@ -221,6 +222,7 @@
|
|||||||
<Compile Include="Formatter\DanielsStyle.cs" />
|
<Compile Include="Formatter\DanielsStyle.cs" />
|
||||||
<Compile Include="Formatter\DocumentWriter.cs" />
|
<Compile Include="Formatter\DocumentWriter.cs" />
|
||||||
<Compile Include="Formatter\NoLaboratoryDataException.cs" />
|
<Compile Include="Formatter\NoLaboratoryDataException.cs" />
|
||||||
|
<Compile Include="Medication\Importer.cs" />
|
||||||
<Compile Include="Medication\Prescription.cs" />
|
<Compile Include="Medication\Prescription.cs" />
|
||||||
<Compile Include="Preferences.cs" />
|
<Compile Include="Preferences.cs" />
|
||||||
<Compile Include="Ribbon.cs" />
|
<Compile Include="Ribbon.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user