diff --git a/Tests/Formatter/Elements/ItemsTest.cs b/Tests/Formatter/Elements/ItemsTest.cs
new file mode 100755
index 0000000..5010d73
--- /dev/null
+++ b/Tests/Formatter/Elements/ItemsTest.cs
@@ -0,0 +1,84 @@
+/* ItemsTest.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;
+using NUnit.Framework;
+using Microsoft.Office.Interop.Word;
+using zaaReloaded2.LabModel;
+using zaaReloaded2.Formatter;
+using zaa = zaaReloaded2.Formatter.Elements;
+
+namespace Tests.Formatter.Elements
+{
+ [TestFixture]
+ class ItemsTest
+ {
+ [Test]
+ public void ItemsTestWithoutCaption()
+ {
+ zaa.Items i = new zaa.Items("Na, K, Cl");
+ TimePoint tp = new TimePoint();
+ tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
+ tp.AddItem(new LabItem("Na", "133", "133"));
+ tp.AddItem(new LabItem("K", "6", "5"));
+ // We do not add a 'Cl' item, and it should not appear in output.
+ TimePointFormatter tpf = new TimePointFormatter(tp, ReferenceStyle.IfAbnormal);
+ TimePointFormatterDictionary tpfd = new TimePointFormatterDictionary();
+ tpfd.Add(tpf.TimeStamp, tpf);
+ Document document = new Document();
+ i.WriteToDocument(document, tpfd);
+ Assert.AreEqual("Na 133, K 6 (5)\r", document.Range().Text);
+ }
+
+ [Test]
+ public void ItemsTestWithCaption()
+ {
+ zaa.Items i = new zaa.Items("Klinische Chemie: Na, K, Cl");
+ TimePoint tp = new TimePoint();
+ tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
+ tp.AddItem(new LabItem("Na", "133", ""));
+ tp.AddItem(new LabItem("K", "6", "5"));
+ // We do not add a 'Cl' item, and it should not appear in output.
+ TimePointFormatter tpf = new TimePointFormatter(tp, ReferenceStyle.IfAbnormal);
+ TimePointFormatterDictionary tpfd = new TimePointFormatterDictionary();
+ tpfd.Add(tpf.TimeStamp, tpf);
+ Document document = new Document();
+ i.WriteToDocument(document, tpfd);
+ Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", document.Range().Text);
+ }
+
+ [Test]
+ public void ItemsTestWithCaptionButNoItems()
+ {
+ zaa.Items i = new zaa.Items("Klinische Chemie: this, does, not, exist");
+ TimePoint tp = new TimePoint();
+ tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
+ tp.AddItem(new LabItem("Na", "133", ""));
+ tp.AddItem(new LabItem("K", "6", "5"));
+ // We do not add a 'Cl' item, and it should not appear in output.
+ TimePointFormatter tpf = new TimePointFormatter(tp, ReferenceStyle.IfAbnormal);
+ TimePointFormatterDictionary tpfd = new TimePointFormatterDictionary();
+ tpfd.Add(tpf.TimeStamp, tpf);
+ Document document = new Document();
+ i.WriteToDocument(document, tpfd);
+ Assert.AreEqual("\r", document.Range().Text);
+ }
+ }
+}
diff --git a/Tests/Formatter/FormatterTest.cs b/Tests/Formatter/FormatterTest.cs
new file mode 100755
index 0000000..bf55678
--- /dev/null
+++ b/Tests/Formatter/FormatterTest.cs
@@ -0,0 +1,45 @@
+/* FormatterTest.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;
+using NUnit.Framework;
+using f = zaaReloaded2.Formatter;
+using zaaReloaded2.LabModel;
+using zaaReloaded2.Importer.ZaaImporter;
+using Microsoft.Office.Interop.Word;
+
+namespace Tests.Formatter
+{
+ [TestFixture]
+ class FormatterTest
+ {
+ [Test]
+ public void FormatLaboratory()
+ {
+ ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
+ f.Formatter formatter = new f.Formatter();
+ formatter.Laboratory = importer.Laboratory;
+ formatter.Elements.Add(new f.Elements.Items("Klinische Chemie: Na, K, Cl"));
+ Document document = new Document();
+ formatter.WriteToDocument(document);
+ Assert.AreEqual("Klinische Chemie: Na: 132 mmol/l", document.Range().Text);
+ }
+ }
+}
diff --git a/Tests/Importer/ZaaImporter/ZaaImporterTest.cs b/Tests/Importer/ZaaImporter/ZaaImporterTest.cs
index 4b93d28..44b8e23 100755
--- a/Tests/Importer/ZaaImporter/ZaaImporterTest.cs
+++ b/Tests/Importer/ZaaImporter/ZaaImporterTest.cs
@@ -37,11 +37,7 @@ namespace Tests.Importer.ZaaImporter
[Test]
public void ParseTimePoints()
{
- Stream s = this.GetType().Assembly.GetManifestResourceStream("Tests.demo-output.txt");
- StreamReader r = new StreamReader(s);
- zaa.ZaaImporter importer = new zaa.ZaaImporter();
- importer.Import(r.ReadToEnd());
-
+ zaa.ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
// Only 6 distinct time points (see method documentation above).
Assert.AreEqual(6, importer.Laboratory.TimePoints.Count);
}
diff --git a/Tests/TestHelpers.cs b/Tests/TestHelpers.cs
new file mode 100755
index 0000000..b8d1587
--- /dev/null
+++ b/Tests/TestHelpers.cs
@@ -0,0 +1,42 @@
+/* TestHelpers.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.IO;
+using System.Linq;
+using System.Text;
+using zaaReloaded2.Importer.ZaaImporter;
+
+namespace Tests
+{
+ class TestHelpers
+ {
+ ///
+ /// Creates a ZaaImporter object and imports demo-output.txt.
+ ///
+ ///
+ public static ZaaImporter ZaaImporterFromResource()
+ {
+ Stream s = typeof(TestHelpers).Assembly.GetManifestResourceStream("Tests.demo-output.txt");
+ StreamReader r = new StreamReader(s);
+ ZaaImporter importer = new ZaaImporter();
+ importer.Import(r.ReadToEnd());
+ return importer;
+ }
+ }
+}
diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj
index 1a7ff88..72792a8 100755
--- a/Tests/Tests.csproj
+++ b/Tests/Tests.csproj
@@ -41,6 +41,9 @@
zaaReloaded2.pfx
+
+ True
+
False
..\packages\NUnit.2.6.4\lib\nunit.framework.dll
@@ -64,6 +67,8 @@
+
+
@@ -71,6 +76,7 @@
+
@@ -89,6 +95,7 @@
+
diff --git a/zaaReloaded2/Formatter/Elements/ElementBase.cs b/zaaReloaded2/Formatter/Elements/ElementBase.cs
new file mode 100755
index 0000000..d6bb6bd
--- /dev/null
+++ b/zaaReloaded2/Formatter/Elements/ElementBase.cs
@@ -0,0 +1,47 @@
+/* ElementBase.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;
+using Microsoft.Office.Interop.Word;
+using zaaReloaded2.LabModel;
+
+namespace zaaReloaded2.Formatter.Elements
+{
+ ///
+ /// Base class for formatting elements.
+ ///
+ [Serializable]
+ abstract class ElementBase
+ {
+ ///
+ /// Returns the label for this formatting element.
+ ///
+ abstract public string Label { get; }
+
+ ///
+ /// Writes the formatting element to a Word document.
+ ///
+ /// Word document to write to.
+ /// Laboratory time points to work with.
+ abstract public void WriteToDocument(
+ Document document,
+ ITimePointFormatterDictionary workingTimePoints);
+ }
+}
diff --git a/zaaReloaded2/Formatter/Elements/ElementsList.cs b/zaaReloaded2/Formatter/Elements/ElementsList.cs
new file mode 100755
index 0000000..966122e
--- /dev/null
+++ b/zaaReloaded2/Formatter/Elements/ElementsList.cs
@@ -0,0 +1,29 @@
+/* ElementsList.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.Formatter.Elements
+{
+ [Serializable]
+ class ElementsList : List
+ {
+ }
+}
diff --git a/zaaReloaded2/Formatter/Elements/Items.cs b/zaaReloaded2/Formatter/Elements/Items.cs
new file mode 100755
index 0000000..7d36122
--- /dev/null
+++ b/zaaReloaded2/Formatter/Elements/Items.cs
@@ -0,0 +1,164 @@
+/* Items.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;
+using System.Text.RegularExpressions;
+using Microsoft.Office.Interop.Word;
+using zaaReloaded2.LabModel;
+using System.Diagnostics;
+
+namespace zaaReloaded2.Formatter.Elements
+{
+ ///
+ /// This formatting element is concerned with writing s
+ /// to a Word document.
+ ///
+ class Items : ElementBase
+ {
+ #region ElementBase implementation
+
+ public override string Label
+ {
+ get { return Line; }
+ }
+
+ public override void WriteToDocument(
+ Document document,
+ ITimePointFormatterDictionary workingTimePoints)
+ {
+ _document = document;
+ bool _needComma = false;
+
+ // Find out if we have any items that we can write
+ // to the document
+ List items = new List();
+ if (_items != null && _items.Count > 0)
+ {
+ foreach (string itemName in _items)
+ {
+ TimePointFormatter tpf = workingTimePoints
+ .FirstOrDefault(tp => tp.Value.ContainsItem(itemName))
+ .Value;
+ if (tpf != null)
+ {
+ // If tpf is not null, this means that it contains an
+ // item with itemName.
+ items.Add(tpf.ItemFormatters[itemName]);
+ }
+ }
+ }
+
+ // If there are items, write the caption (if any), then the items
+ if (items.Count > 0)
+ {
+ if (!String.IsNullOrEmpty(_caption))
+ {
+ document.Range().InsertAfter(
+ String.Format("{0}: ", _caption)
+ );
+ };
+ foreach (ItemFormatter i in items)
+ {
+ if (_needComma)
+ {
+ document.Range().InsertAfter(", ");
+ }
+ else
+ {
+ _needComma = true;
+ }
+ i.WriteToDocument(document);
+ }
+ }
+ }
+
+ #endregion
+
+ #region Properties
+
+ ///
+ /// Gets or sets a text line that contains a comma-separated list of
+ /// parsable laboratory item names. The list may optionally be preceded
+ /// with a caption followed by a colon.
+ ///
+ public string Line
+ {
+ [DebuggerStepThrough]
+ get
+ {
+ return _line;
+ }
+ set
+ {
+ _line = value;
+ ParseLine();
+ }
+ }
+
+ #endregion
+
+ #region Constructors
+
+ public Items() : base() { }
+
+ public Items(string line)
+ : this()
+ {
+ Line = line;
+ }
+
+ #endregion
+
+ #region Private methods
+
+ ///
+ /// Parses the Line and splits it into an optional caption and individual
+ /// items.
+ ///
+ void ParseLine()
+ {
+ _items = null;
+ _caption = null;
+ Regex r = new Regex(@"((?[^:]+):\s*)?((?[^,]+),\s*)+");
+ Match m = r.Match(Line);
+ if (m.Success)
+ {
+ if (m.Groups["caption"].Success)
+ {
+ _caption = m.Groups["caption"].Value;
+ }
+ _items = m.Groups["items"].Captures
+ .Cast()
+ .Select(c => c.Value).ToList();
+ }
+ }
+
+ #endregion
+
+ #region Fields
+
+ Document _document;
+ string _line;
+ string _caption;
+ List _items;
+
+ #endregion
+ }
+}
diff --git a/zaaReloaded2/Formatter/Formatter.cs b/zaaReloaded2/Formatter/Formatter.cs
new file mode 100755
index 0000000..959331e
--- /dev/null
+++ b/zaaReloaded2/Formatter/Formatter.cs
@@ -0,0 +1,101 @@
+/* Formatter.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;
+using Microsoft.Office.Interop.Word;
+using zaaReloaded2.Formatter.Elements;
+using zaaReloaded2.LabModel;
+using System.Diagnostics;
+
+namespace zaaReloaded2.Formatter
+{
+ ///
+ /// Formats and writes a to a Word document.
+ ///
+ [Serializable]
+ class Formatter
+ {
+ #region Properties
+
+ ///
+ /// Gets a list of formatting elements (derived from
+ /// ).
+ ///
+ public ElementsList Elements { get; private set; }
+
+ ///
+ /// Gets or sets the style of the normal range reference.
+ ///
+ public ReferenceStyle ReferenceStyle { get; set; }
+
+ ///
+ /// Gets or sets the that shall be
+ /// formatted.
+ ///
+ public Laboratory Laboratory
+ {
+ [DebuggerStepThrough]
+ get
+ {
+ return _laboratory;
+ }
+ set
+ {
+ _laboratory = value;
+ _timePointFormatters = new TimePointFormatterDictionary();
+ foreach (TimePoint tp in _laboratory.TimePoints.Values)
+ {
+ _timePointFormatters[tp.TimeStamp] = new TimePointFormatter(tp, ReferenceStyle);
+ }
+ }
+ }
+
+ #endregion
+
+ #region Constructor
+
+ public Formatter()
+ {
+ Elements = new ElementsList();
+ }
+
+ #endregion
+
+ #region Public methods
+
+ ///
+ /// Formats the laboratory and writes it to a Word document.
+ ///
+ /// Word document to write to (at the
+ /// current position of the cursor).
+ public void WriteToDocument(Document document)
+ {
+ }
+
+ #endregion
+
+ #region Fields
+
+ ITimePointFormatterDictionary _timePointFormatters;
+ Laboratory _laboratory;
+
+ #endregion
+ }
+}
diff --git a/zaaReloaded2/Formatter/IItemFormatterDictionary.cs b/zaaReloaded2/Formatter/IItemFormatterDictionary.cs
new file mode 100755
index 0000000..18b77c8
--- /dev/null
+++ b/zaaReloaded2/Formatter/IItemFormatterDictionary.cs
@@ -0,0 +1,28 @@
+/* IItemFormatterDictionary.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.Formatter
+{
+ public interface IItemFormatterDictionary : IDictionary
+ {
+ }
+}
diff --git a/zaaReloaded2/Formatter/ITimePointFormatterDictionary.cs b/zaaReloaded2/Formatter/ITimePointFormatterDictionary.cs
new file mode 100755
index 0000000..87c30d0
--- /dev/null
+++ b/zaaReloaded2/Formatter/ITimePointFormatterDictionary.cs
@@ -0,0 +1,28 @@
+/* ITimePointFormatterDictionary.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.Formatter
+{
+ public interface ITimePointFormatterDictionary : IDictionary
+ {
+ }
+}
diff --git a/zaaReloaded2/Formatter/ItemFormatter.cs b/zaaReloaded2/Formatter/ItemFormatter.cs
new file mode 100755
index 0000000..89b5ef9
--- /dev/null
+++ b/zaaReloaded2/Formatter/ItemFormatter.cs
@@ -0,0 +1,127 @@
+/* ItemFormatter.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;
+using Microsoft.Office.Interop.Word;
+using zaaReloaded2.LabModel;
+
+namespace zaaReloaded2.Formatter
+{
+ ///
+ /// Wraps a and provides methods to format it.
+ ///
+ public class ItemFormatter
+ {
+ #region Properties
+
+ ///
+ /// Gets or sets the LabItem wrapped by this ItemFormatter.
+ ///
+ public LabItem LabItem { get; set; }
+
+ ///
+ /// Gets or sets the ReferenceStyle to use in formatting.
+ ///
+ public ReferenceStyle ReferenceStyle { get; set; }
+
+ ///
+ /// Gets or sets a flag that indicates whether this ItemFormatter
+ /// has been used, i.e. whether the LabItem was written to a
+ /// document.
+ ///
+ public bool HasBeenUsed { get; set; }
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates a new ItemFormatter that wraps a .
+ ///
+ /// LabItem to wrap in this ItemFormatter.
+ public ItemFormatter(LabItem labItem, ReferenceStyle referenceStyle)
+ {
+ LabItem = labItem;
+ ReferenceStyle = referenceStyle;
+ }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// Formats and writes the LabItem details to a word .
+ ///
+ /// Word document to write to.
+ public void WriteToDocument(Document document)
+ {
+ string reference;
+ if (
+ LabItem.HasLimitsOrNormal &&
+ (
+ ReferenceStyle == ReferenceStyle.Always ||
+ (ReferenceStyle == ReferenceStyle.IfAbnormal && !LabItem.IsNormal) ||
+ (ReferenceStyle == ReferenceStyle.IfSpecialItem && LabItem.AlwaysPrintLimits) ||
+ (ReferenceStyle == ReferenceStyle.IfSpecialOrAbnormal &&
+ (!LabItem.IsNormal || LabItem.AlwaysPrintLimits))
+ )
+ )
+ {
+ string normal;
+ if (LabItem.HasLowerLimit && LabItem.HasUpperLimit)
+ {
+ normal = String.Format("{0}-{1}", LabItem.LowerLimit, LabItem.UpperLimit);
+ }
+ else
+ {
+ if (LabItem.HasLowerLimit)
+ {
+ normal = String.Format("> {0}", LabItem.LowerLimit);
+ }
+ else if (LabItem.HasUpperLimit)
+ {
+ normal = String.Format("< {0}", LabItem.UpperLimit);
+ }
+ else
+ {
+ normal = LabItem.Normal;
+ }
+ }
+ reference = String.Format(" ({0})", normal);
+ }
+ else
+ {
+ reference = String.Empty;
+ }
+
+ // Insert the formatted text into the document.
+ document.Range().InsertAfter(
+ String.Format(
+ "{0} {1}{2}",
+ LabItem.QualifiedName,
+ LabItem.Value,
+ reference
+ ));
+ HasBeenUsed = true;
+ }
+
+ #endregion
+ }
+}
diff --git a/zaaReloaded2/Formatter/ItemFormatterDictionary.cs b/zaaReloaded2/Formatter/ItemFormatterDictionary.cs
new file mode 100755
index 0000000..b419280
--- /dev/null
+++ b/zaaReloaded2/Formatter/ItemFormatterDictionary.cs
@@ -0,0 +1,30 @@
+/* ItemFormatterDictionary.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.Formatter
+{
+ class ItemFormatterDictionary
+ : Dictionary,
+ IItemFormatterDictionary
+ {
+ }
+}
diff --git a/zaaReloaded2/Formatter/ReferenceStyle.cs b/zaaReloaded2/Formatter/ReferenceStyle.cs
new file mode 100755
index 0000000..0e6c8f7
--- /dev/null
+++ b/zaaReloaded2/Formatter/ReferenceStyle.cs
@@ -0,0 +1,62 @@
+/* ReferenceStyle.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.ComponentModel;
+using System.Linq;
+using System.Text;
+
+namespace zaaReloaded2.Formatter
+{
+ ///
+ /// Describes the style of normal range references.
+ ///
+ [Serializable]
+ public enum ReferenceStyle
+ {
+ ///
+ /// Never write normal ranges
+ ///
+ [Description("Referenzbereich nie ausgeben")]
+ Never,
+
+ ///
+ /// Write normal range if item is marked in dictionary
+ ///
+ [Description("Referenzbereich ausgeben, falls Parameter so markiert ist")]
+ IfSpecialItem,
+
+ ///
+ /// Write normal range if value is abnormal
+ ///
+ [Description("Referenzbereich ausgeben, falls Wert nicht normal ist")]
+ IfAbnormal,
+
+ ///
+ /// Write normal range if item is marked in dictionary, or if value is abnormal
+ ///
+ [Description("Referenzbereich ausgeben, falls Parameter so markiert ist oder falls Wert nicht normal ist")]
+ IfSpecialOrAbnormal,
+
+ ///
+ /// Always write normal range reference
+ ///
+ [Description("Referenzbereich immer ausgeben")]
+ Always
+ }
+}
diff --git a/zaaReloaded2/Formatter/TimePointFormatter.cs b/zaaReloaded2/Formatter/TimePointFormatter.cs
new file mode 100755
index 0000000..56c6fa3
--- /dev/null
+++ b/zaaReloaded2/Formatter/TimePointFormatter.cs
@@ -0,0 +1,76 @@
+/* TimePointFormatter.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;
+using zaaReloaded2.LabModel;
+
+namespace zaaReloaded2.Formatter
+{
+ ///
+ /// Creates a list of ItemFormatter objects from a TimePoint.
+ ///
+ public class TimePointFormatter
+ {
+ #region Properties
+
+ ///
+ /// Gets the time stamp of the from which this
+ /// TimePointFormatter was built.
+ ///
+ public DateTime TimeStamp { get; private set; }
+
+ ///
+ /// Gets a dictionary of ItemFormatter objects that wrap LabItems.
+ /// The QualifiedName of each LabItem is used as key.
+ ///
+ public IItemFormatterDictionary ItemFormatters { get; private set; }
+
+ #endregion
+
+ #region Constructor
+
+ ///
+ /// Creates a new TimePointFormatter object using a given
+ /// .
+ ///
+ /// TimePoint whose LabItems will be
+ /// used to create ItemFormatter objects.
+ public TimePointFormatter(TimePoint timePoint, ReferenceStyle referenceStyle)
+ {
+ TimeStamp = timePoint.TimeStamp;
+ ItemFormatters = new ItemFormatterDictionary();
+ foreach (LabItem item in timePoint.Items.Values)
+ {
+ ItemFormatters[item.QualifiedName] = new ItemFormatter(item, referenceStyle);
+ }
+ }
+
+ #endregion
+
+ #region Methods
+
+ public bool ContainsItem(string itemName)
+ {
+ return ItemFormatters.ContainsKey(itemName);
+ }
+
+ #endregion
+ }
+}
diff --git a/zaaReloaded2/Formatter/TimePointFormatterDictionary.cs b/zaaReloaded2/Formatter/TimePointFormatterDictionary.cs
new file mode 100755
index 0000000..8916da1
--- /dev/null
+++ b/zaaReloaded2/Formatter/TimePointFormatterDictionary.cs
@@ -0,0 +1,30 @@
+/* TimePointFormatterDictionary.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.Formatter
+{
+ public class TimePointFormatterDictionary
+ : Dictionary,
+ ITimePointFormatterDictionary
+ {
+ }
+}
diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs
index e256983..c844f40 100755
--- a/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs
+++ b/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs
@@ -155,7 +155,6 @@ namespace zaaReloaded2.Importer.ZaaImporter
/// and contains s in the others.
bool ParseParagraphs()
{
- Items = new ItemDictionary();
if (Paragraphs.Length > 0)
{
if (!ParseTimeStamp()) return false;
diff --git a/zaaReloaded2/Dictionaries/IItemDictionary.cs b/zaaReloaded2/LabModel/IItemDictionary.cs
similarity index 96%
rename from zaaReloaded2/Dictionaries/IItemDictionary.cs
rename to zaaReloaded2/LabModel/IItemDictionary.cs
index 7d530be..7f408b8 100755
--- a/zaaReloaded2/Dictionaries/IItemDictionary.cs
+++ b/zaaReloaded2/LabModel/IItemDictionary.cs
@@ -20,7 +20,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
-namespace zaaReloaded2.Dictionaries
+namespace zaaReloaded2.LabModel
{
///
/// A dictionary of s.
diff --git a/zaaReloaded2/LabModel/ITimePointsDictionary.cs b/zaaReloaded2/LabModel/ITimePointsDictionary.cs
new file mode 100755
index 0000000..6a0df4d
--- /dev/null
+++ b/zaaReloaded2/LabModel/ITimePointsDictionary.cs
@@ -0,0 +1,28 @@
+/* ITimePointsDictionary.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.LabModel
+{
+ public interface ITimePointsDictionary : IDictionary
+ {
+ }
+}
diff --git a/zaaReloaded2/Dictionaries/ItemDictionary.cs b/zaaReloaded2/LabModel/ItemDictionary.cs
similarity index 97%
rename from zaaReloaded2/Dictionaries/ItemDictionary.cs
rename to zaaReloaded2/LabModel/ItemDictionary.cs
index 131f88d..1bab52a 100755
--- a/zaaReloaded2/Dictionaries/ItemDictionary.cs
+++ b/zaaReloaded2/LabModel/ItemDictionary.cs
@@ -21,7 +21,7 @@ using System.Linq;
using System.Text;
using zaaReloaded2.LabModel;
-namespace zaaReloaded2.Dictionaries
+namespace zaaReloaded2.LabModel
{
public class ItemDictionary : SortedDictionary, IItemDictionary
{
diff --git a/zaaReloaded2/LabModel/LabItem.cs b/zaaReloaded2/LabModel/LabItem.cs
index 4ec7aa8..b068088 100755
--- a/zaaReloaded2/LabModel/LabItem.cs
+++ b/zaaReloaded2/LabModel/LabItem.cs
@@ -161,6 +161,18 @@ namespace zaaReloaded2.LabModel
get { return (HasLowerLimit || HasUpperLimit); }
}
+ ///
+ /// Is true if the item has numerical limits or a categorical normal
+ /// value.
+ ///
+ public bool HasLimitsOrNormal
+ {
+ get
+ {
+ return HasLimits || !String.IsNullOrEmpty(Normal);
+ }
+ }
+
///
/// Returns the canonical name prefixed with the abbreviation
/// for the material, e.g. "U-Na" for sodium in the spot urine,
@@ -187,10 +199,23 @@ namespace zaaReloaded2.LabModel
#endregion
- #region Constructor
+ #region Constructors
public LabItem() { }
+ ///
+ /// Creates a new LabItem object that has a normal value, but
+ /// no upper or lower limits. This is constructor is used for
+ /// testing purposes.
+ ///
+ public LabItem(string name, string value, string normal)
+ : this()
+ {
+ Name = name;
+ Value = value;
+ Normal = normal;
+ }
+
#endregion
#region Fields
diff --git a/zaaReloaded2/LabModel/Laboratory.cs b/zaaReloaded2/LabModel/Laboratory.cs
index 95825f8..8964ae9 100755
--- a/zaaReloaded2/LabModel/Laboratory.cs
+++ b/zaaReloaded2/LabModel/Laboratory.cs
@@ -29,7 +29,7 @@ namespace zaaReloaded2.LabModel
{
#region Properties
- public SortedDictionary TimePoints { get; set; }
+ public ITimePointsDictionary TimePoints { get; private set; }
#endregion
@@ -37,7 +37,7 @@ namespace zaaReloaded2.LabModel
public Laboratory()
{
- TimePoints = new SortedDictionary();
+ TimePoints = new TimePointsDictionary();
}
#endregion
diff --git a/zaaReloaded2/LabModel/TimePoint.cs b/zaaReloaded2/LabModel/TimePoint.cs
index c4866ba..d4d8ac8 100755
--- a/zaaReloaded2/LabModel/TimePoint.cs
+++ b/zaaReloaded2/LabModel/TimePoint.cs
@@ -45,12 +45,34 @@ namespace zaaReloaded2.LabModel
/// the . If a laboratory parameter occurs more
/// than once, only the last occurrence is saved.
///
- public IItemDictionary Items { get; set; }
+ public IItemDictionary Items { get; private set; }
+
+ #endregion
+
+ #region Constructor
+
+ public TimePoint()
+ {
+ Items = new ItemDictionary();
+ }
#endregion
#region Methods
+ ///
+ /// Adds an item to the TimePoint.
+ ///
+ /// LabItem to add.
+ public void AddItem(LabItem item)
+ {
+ if (String.IsNullOrEmpty(item.QualifiedName))
+ {
+ throw new ArgumentException("Cannot add item that has no qualified name.");
+ }
+ Items.Add(item.QualifiedName, item);
+ }
+
///
/// Adds the items from another time point to this
/// time point. There is no check for plausibility,
@@ -67,6 +89,18 @@ namespace zaaReloaded2.LabModel
Items.Merge(otherTimePoint.Items);
}
+ ///
+ /// Returns true if contains a given
+ /// item.
+ ///
+ /// Item string to look for.
+ /// True if contains
+ ///
+ public bool ContainsItem(string item)
+ {
+ return Items.ContainsKey(item);
+ }
+
#endregion
}
}
diff --git a/zaaReloaded2/LabModel/TimePointsDictionary.cs b/zaaReloaded2/LabModel/TimePointsDictionary.cs
new file mode 100755
index 0000000..ee631ef
--- /dev/null
+++ b/zaaReloaded2/LabModel/TimePointsDictionary.cs
@@ -0,0 +1,28 @@
+/* TimePointsDictionary.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.LabModel
+{
+ class TimePointsDictionary : SortedDictionary, ITimePointsDictionary
+ {
+ }
+}
diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj
index 06ab5ed..a19d713 100755
--- a/zaaReloaded2/zaaReloaded2.csproj
+++ b/zaaReloaded2/zaaReloaded2.csproj
@@ -164,20 +164,33 @@
-->
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Code
@@ -216,9 +229,7 @@
-
-
-
+
10.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)