diff --git a/zaaReloaded2/Helpers.cs b/zaaReloaded2/Helpers.cs
new file mode 100755
index 0000000..265bd15
--- /dev/null
+++ b/zaaReloaded2/Helpers.cs
@@ -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
+{
+ ///
+ /// Common helper methods.
+ ///
+ public static class Helpers
+ {
+ ///
+ /// Splits a text into paragraphs.
+ ///
+ /// Text to split.
+ /// Array of paragraphs in the text.
+ ///
+ /// 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
+ ///
+ public static string[] SplitParagraphs(string text)
+ {
+ return text.Split(
+ new string[] { "\r\n", "\n\r", "\r", "\n" },
+ StringSplitOptions.RemoveEmptyEntries);
+ }
+ }
+}
diff --git a/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs b/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs
index aea8b8a..3377e3d 100755
--- a/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs
+++ b/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs
@@ -67,12 +67,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
/// ZAA-formatted Lauris output to import.
public void Import(string text)
{
- // Split the text into parargraphs. This implementation relies on the fact
- // 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);
+ string[] paragraphs = Helpers.SplitParagraphs(text);
LaurisTimePoint timePoint = null;
foreach (string paragraph in paragraphs)
diff --git a/zaaReloaded2/Medication/Importer.cs b/zaaReloaded2/Medication/Importer.cs
new file mode 100755
index 0000000..2da3f3d
--- /dev/null
+++ b/zaaReloaded2/Medication/Importer.cs
@@ -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
+{
+ ///
+ /// Imports prescriptions from a physician's letter.
+ ///
+ public class Importer
+ {
+ #region Static methods
+
+ ///
+ /// Attempts to automatically detect a block of prescriptions
+ /// in a document. The document is screened from end to start.
+ /// The detected block is selected.
+ ///
+ /// True if a block was detected, false if not.
+ 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 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();
+ string[] lines = Helpers.SplitParagraphs(text);
+ foreach (string line in lines)
+ {
+ if (Prescription.IsPrescriptionLine(line))
+ {
+ Prescriptions.Add(Prescription.FromLine(line));
+ }
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/zaaReloaded2/Medication/Prescription.cs b/zaaReloaded2/Medication/Prescription.cs
index 7220230..482782b 100755
--- a/zaaReloaded2/Medication/Prescription.cs
+++ b/zaaReloaded2/Medication/Prescription.cs
@@ -28,6 +28,19 @@ namespace zaaReloaded2.Medication
///
public class Prescription
{
+ #region Static methods
+
+ ///
+ /// Determines whether a line contains prescriptions.
+ ///
+ /// Line to inspect.
+ /// True if the line contains prescriptions.
+ public static bool IsPrescriptionLine(string line)
+ {
+ return lineRegex.IsMatch(line);
+ }
+
+ #endregion
#region Factory
///
diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj
index 2e1f7cc..71af781 100755
--- a/zaaReloaded2/zaaReloaded2.csproj
+++ b/zaaReloaded2/zaaReloaded2.csproj
@@ -194,6 +194,7 @@
-->
+
@@ -221,6 +222,7 @@
+