diff --git a/Tests/Formatter/Elements/ItemsTest.cs b/Tests/Formatter/Elements/ItemsTest.cs
index 5010d73..56f49fb 100755
--- a/Tests/Formatter/Elements/ItemsTest.cs
+++ b/Tests/Formatter/Elements/ItemsTest.cs
@@ -30,55 +30,72 @@ namespace Tests.Formatter.Elements
[TestFixture]
class ItemsTest
{
+ zaaReloaded2.Formatter.Formatter _formatter;
+
+ [SetUp]
+ public void SetUp()
+ {
+ _formatter = new zaaReloaded2.Formatter.Formatter(new Document());
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ ((_Document)_formatter.Document).Close(WdSaveOptions.wdDoNotSaveChanges);
+ }
+
[Test]
public void ItemsTestWithoutCaption()
{
- zaa.Items i = new zaa.Items("Na, K, Cl");
+ Laboratory lab = new Laboratory();
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);
+ lab.AddTimePoint(tp);
+
+ _formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
+ _formatter.Laboratory = lab;
+ _formatter.Elements.Add(new zaa.Items("Na, K, Cl"));
+ _formatter.Run();
+ Assert.AreEqual("Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
}
[Test]
public void ItemsTestWithCaption()
{
- zaa.Items i = new zaa.Items("Klinische Chemie: Na, K, Cl");
+ Laboratory lab = new Laboratory();
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);
+ lab.AddTimePoint(tp);
+
+ _formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
+ _formatter.Laboratory = lab;
+ _formatter.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
+ _formatter.Run();
+ Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
}
[Test]
public void ItemsTestWithCaptionButNoItems()
{
- zaa.Items i = new zaa.Items("Klinische Chemie: this, does, not, exist");
+ Laboratory lab = new Laboratory();
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);
+ lab.AddTimePoint(tp);
+
+ _formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
+ _formatter.Laboratory = lab;
+ _formatter.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
+ _formatter.Run();
+ Assert.AreEqual("\r", _formatter.Document.Range().Text);
}
}
}
diff --git a/Tests/Formatter/FormatterTest.cs b/Tests/Formatter/FormatterTest.cs
index bf55678..eb150c5 100755
--- a/Tests/Formatter/FormatterTest.cs
+++ b/Tests/Formatter/FormatterTest.cs
@@ -33,13 +33,14 @@ namespace Tests.Formatter
[Test]
public void FormatLaboratory()
{
+ Document document = new Document();
ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
- f.Formatter formatter = new f.Formatter();
+ f.Formatter formatter = new f.Formatter(document);
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);
+ formatter.Run();
+ Assert.AreEqual("Klinische Chemie: Na 144 mM, K 4,3 mM\r", document.Range().Text);
+ ((_Document)document).Close(WdSaveOptions.wdDoNotSaveChanges);
}
}
}
diff --git a/Tests/demo-output.txt b/Tests/demo-output.txt
index ddb3216..a1cd56f 100755
--- a/Tests/demo-output.txt
+++ b/Tests/demo-output.txt
@@ -1,18 +1,18 @@
# This file contains 7 time points.
# This leading text should be ignored.
# DO NOT CHANGE THE FOLLOWING TEXT, LEST THE TESTS WILL FAIL!
-(06.07.2015 15:16:00)
+(04.07.2015 15:16:00)
Urin - Klin. Chemie: Sammelzeit (U): 24 h; Sammelmenge (U): 1300 ml; Natrium (SU): 107.8 [54 - 150] mmol/l; Natrium (SU)/die: 140.1 [40 - 220] mmol/d;
-(06.07.2015 13:39:00)
+(04.07.2015 13:39:00)
Urin - Klin. Chemie: Creatinin (PU): 153.7 [40 - 278] mg/dl;
-(06.07.2015 12:31:00)
+(04.07.2015 12:31:00)
Klinische Chemie: Natrium: 144 [135 - 145] mmol/l; Kalium: 4.3 [3.5 - 5] mmol/l; Calcium: 2.3 [2.0 - 2.7] mmol/l; Korrigiertes Calcium: 2.3 [2.0 - 2.7] mmol/l; Magnesium: 0.87 [0.7 - 1.05] mmol/l; anorg. Phosphat: 0.98 [0.87 - 1.45] mmol/l; Calcium-Phosphat-Produkt: 2.25 [<= 4.4] mmol²/l²; Glucose: 93 [74 - 106] mg/dl; glomerul. Filtrationsr. CKD-EP: 56 ml/min /1,73qm; glomerul. Filtrationsr. (MDRD): 54 ml/min /1,73qm; Creatinin: 1.52 [0 - 1.17] mg/dl; Harnstoff: 41.1 [10 - 50] mg/dl; Harnsäure: 7.7 [3.4 - 7] mg/dl; Gesamt-Bilirubin: 0.2 [0.1 - 1.2] mg/dl; GOT (ASAT): 22.2 [<= 50] U/l; GPT (ALAT): 28.0 [<= 50] U/l; GGT: 49.0 [<= 60] U/l; Alk. Phosphatase: 70 [40 - 130] U/l; Lactat Dehydrogenase: 205 [<= 250] U/l; Cholesterin: 219 [130 - 220] mg/dl; Triglyceride: 195 [74 - 172] mg/dl; LDL - Cholesterin: 141 [0 - 150] mg/dl; HDL - Cholesterin: 39 [>= 35] mg/dl; Albumin: 4.1 [3.5 - 5.5] g/dl;
Hämatologie: Leukozyten: 7.2 [5 - 10] n*1000/µl; Erythrozyten: 4.79 [4 - 6] n*10E6/µl; Hämoglobin: 14.0 [14 - 18] g/dl; Hämatokrit: 41.0 [42 - 50] %; MCV: 85.6 [82 - 94] fl; MCH (HbE): 29.2 [27 - 33] pg; MCHC: 34.1 [32 - 36] g/dl; Thrombozyten: 269 [150 - 450] n*1000/µl; Mittleres Plättchenvolumen: 10.3 [9.7 - 11.9] fl;
Urin - Klin. Chemie: Sammelzeit (U): 24 h; Sammelmenge (U): 1300 ml; Creatinin-Clearance (SU)/min: 90 [98 - 156] ml/min; Harnstoff-Clearance (SU)/min: 40 [60 - 80] ml/min; glomeruläre Filtrationsrate: 65 ml/min; Calcium (SU): 0.64 mmol/l; Calcium (SU)/die: 0.83 [2.5 - 8] mmol/d; Creatinin (SU): 151.5 mg/dl; Harnstoff (SU): 1831 [900 - 3000] mg/dl; Harnstoff (SU)/die: 23.8 [<= 35] g/d; Kalium (SU): 39.2 [20 - 80] mmol/l; Kalium (SU)/die: 50.96 [25 - 125] mmol/d; Natrium (SU): 108.1 [54 - 150] mmol/l; Natrium (SU)/die: 140.5 [40 - 220] mmol/d;
Serumproteine und Tumormarker: C-reaktives Protein: 0.71 [0 - 0.5] mg/dl;
-(06.07.2015 13:29:00)
+(04.07.2015 13:29:00)
Hepatitis Serologie: HBs-Antikörper: neg. ;
-(06.07.2015 12:20:00)
+(04.07.2015 12:20:00)
Schilddrüse: TSH: 1.30 [0.3 - 4.0] mIU/l;
Ca-Phosphat-Stoffwechsel: PTH intakt: 56.1 [12 - 65] ng/l;
(06.07.2015 10:28:00)
diff --git a/zaaReloaded2/Defaults/units.txt b/zaaReloaded2/Defaults/units.txt
index 9c6f2d7..48a907b 100755
--- a/zaaReloaded2/Defaults/units.txt
+++ b/zaaReloaded2/Defaults/units.txt
@@ -3,4 +3,5 @@
# WICHTIG: Nur direkt austauschbare Einheiten verwenden,
# weil (bislang) keine Umrechnung der Werte vorgesehen ist!
"ml/min/ 1,73qm" "ml/min/1,73 m²"
-ng/ml µg/l
\ No newline at end of file
+ng/ml µg/l
+mmol/l mM
\ No newline at end of file
diff --git a/zaaReloaded2/Formatter/Elements/ElementBase.cs b/zaaReloaded2/Formatter/Elements/ElementBase.cs
index d6bb6bd..82d62c3 100755
--- a/zaaReloaded2/Formatter/Elements/ElementBase.cs
+++ b/zaaReloaded2/Formatter/Elements/ElementBase.cs
@@ -36,12 +36,13 @@ namespace zaaReloaded2.Formatter.Elements
abstract public string Label { get; }
///
- /// Writes the formatting element to a Word document.
+ /// Executes the action described by this formatting element.
+ /// For example, an Items element Writes the laboratory items
+ /// listed in its Line property to a Word document.
///
- /// Word document to write to.
- /// Laboratory time points to work with.
- abstract public void WriteToDocument(
- Document document,
- ITimePointFormatterDictionary workingTimePoints);
+ /// Formatter object that this
+ /// Element belongs to. The Formatter object provides access
+ /// to the current Word document etc.
+ abstract public void Run(Formatter formatter);
}
}
diff --git a/zaaReloaded2/Formatter/Elements/Items.cs b/zaaReloaded2/Formatter/Elements/Items.cs
index 7d36122..b4f2664 100755
--- a/zaaReloaded2/Formatter/Elements/Items.cs
+++ b/zaaReloaded2/Formatter/Elements/Items.cs
@@ -39,11 +39,8 @@ namespace zaaReloaded2.Formatter.Elements
get { return Line; }
}
- public override void WriteToDocument(
- Document document,
- ITimePointFormatterDictionary workingTimePoints)
+ public override void Run(Formatter formatter)
{
- _document = document;
bool _needComma = false;
// Find out if we have any items that we can write
@@ -53,7 +50,7 @@ namespace zaaReloaded2.Formatter.Elements
{
foreach (string itemName in _items)
{
- TimePointFormatter tpf = workingTimePoints
+ TimePointFormatter tpf = formatter.WorkingTimePoints
.FirstOrDefault(tp => tp.Value.ContainsItem(itemName))
.Value;
if (tpf != null)
@@ -70,7 +67,7 @@ namespace zaaReloaded2.Formatter.Elements
{
if (!String.IsNullOrEmpty(_caption))
{
- document.Range().InsertAfter(
+ formatter.Document.Range().InsertAfter(
String.Format("{0}: ", _caption)
);
};
@@ -78,13 +75,13 @@ namespace zaaReloaded2.Formatter.Elements
{
if (_needComma)
{
- document.Range().InsertAfter(", ");
+ formatter.Document.Range().InsertAfter(", ");
}
else
{
_needComma = true;
}
- i.WriteToDocument(document);
+ i.WriteToDocument(formatter.Document);
}
}
}
@@ -154,7 +151,6 @@ namespace zaaReloaded2.Formatter.Elements
#region Fields
- Document _document;
string _line;
string _caption;
List _items;
diff --git a/zaaReloaded2/Formatter/Formatter.cs b/zaaReloaded2/Formatter/Formatter.cs
index 959331e..f8f65c5 100755
--- a/zaaReloaded2/Formatter/Formatter.cs
+++ b/zaaReloaded2/Formatter/Formatter.cs
@@ -40,6 +40,11 @@ namespace zaaReloaded2.Formatter
///
public ElementsList Elements { get; private set; }
+ ///
+ /// Gets the working Word document.
+ ///
+ public Document Document { get; private set; }
+
///
/// Gets or sets the style of the normal range reference.
///
@@ -67,6 +72,11 @@ namespace zaaReloaded2.Formatter
}
}
+ ///
+ /// Gets the current working set of TimePointFormatters.
+ ///
+ public ITimePointFormatterDictionary WorkingTimePoints { get; private set; }
+
#endregion
#region Constructor
@@ -76,6 +86,12 @@ namespace zaaReloaded2.Formatter
Elements = new ElementsList();
}
+ public Formatter(Document document)
+ : this()
+ {
+ Document = document;
+ }
+
#endregion
#region Public methods
@@ -85,8 +101,13 @@ namespace zaaReloaded2.Formatter
///
/// Word document to write to (at the
/// current position of the cursor).
- public void WriteToDocument(Document document)
+ public void Run()
{
+ WorkingTimePoints = _timePointFormatters;
+ foreach (ElementBase element in Elements)
+ {
+ element.Run(this);
+ }
}
#endregion
diff --git a/zaaReloaded2/Formatter/ItemFormatter.cs b/zaaReloaded2/Formatter/ItemFormatter.cs
index 89b5ef9..1bf7e20 100755
--- a/zaaReloaded2/Formatter/ItemFormatter.cs
+++ b/zaaReloaded2/Formatter/ItemFormatter.cs
@@ -111,12 +111,35 @@ namespace zaaReloaded2.Formatter
reference = String.Empty;
}
+ string unit;
+ if (LabItem.HasUnit)
+ {
+ unit = String.Format(" {0}", LabItem.Unit);
+ }
+ else
+ {
+ unit = String.Empty;
+ }
+
+ string value;
+ if (LabItem.IsNumerical)
+ {
+ // Format the numerical value; this will convert
+ // decimal points to commas as needed.
+ value = String.Format("{0}", LabItem.NumericalValue);
+ }
+ else
+ {
+ value = LabItem.Value;
+ }
+
// Insert the formatted text into the document.
document.Range().InsertAfter(
String.Format(
- "{0} {1}{2}",
+ "{0} {1}{2}{3}",
LabItem.QualifiedName,
- LabItem.Value,
+ value,
+ unit,
reference
));
HasBeenUsed = true;
diff --git a/zaaReloaded2/LabModel/LabItem.cs b/zaaReloaded2/LabModel/LabItem.cs
index b068088..7600fa2 100755
--- a/zaaReloaded2/LabModel/LabItem.cs
+++ b/zaaReloaded2/LabModel/LabItem.cs
@@ -173,6 +173,14 @@ namespace zaaReloaded2.LabModel
}
}
+ public bool HasUnit
+ {
+ get
+ {
+ return !String.IsNullOrEmpty(Unit);
+ }
+ }
+
///
/// Returns the canonical name prefixed with the abbreviation
/// for the material, e.g. "U-Na" for sodium in the spot urine,