More work on Formatter; successful tests.

This commit is contained in:
Daniel Kraus 2015-07-14 23:19:41 +02:00
parent c43b0af1e3
commit b810cc8a74
9 changed files with 117 additions and 49 deletions

View File

@ -30,55 +30,72 @@ namespace Tests.Formatter.Elements
[TestFixture] [TestFixture]
class ItemsTest 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] [Test]
public void ItemsTestWithoutCaption() public void ItemsTestWithoutCaption()
{ {
zaa.Items i = new zaa.Items("Na, K, Cl"); Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint(); TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00); tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", "133")); tp.AddItem(new LabItem("Na", "133", "133"));
tp.AddItem(new LabItem("K", "6", "5")); tp.AddItem(new LabItem("K", "6", "5"));
// We do not add a 'Cl' item, and it should not appear in output. // We do not add a 'Cl' item, and it should not appear in output.
TimePointFormatter tpf = new TimePointFormatter(tp, ReferenceStyle.IfAbnormal); lab.AddTimePoint(tp);
TimePointFormatterDictionary tpfd = new TimePointFormatterDictionary();
tpfd.Add(tpf.TimeStamp, tpf); _formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
Document document = new Document(); _formatter.Laboratory = lab;
i.WriteToDocument(document, tpfd); _formatter.Elements.Add(new zaa.Items("Na, K, Cl"));
Assert.AreEqual("Na 133, K 6 (5)\r", document.Range().Text); _formatter.Run();
Assert.AreEqual("Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
} }
[Test] [Test]
public void ItemsTestWithCaption() public void ItemsTestWithCaption()
{ {
zaa.Items i = new zaa.Items("Klinische Chemie: Na, K, Cl"); Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint(); TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00); tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", "")); tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("K", "6", "5")); tp.AddItem(new LabItem("K", "6", "5"));
// We do not add a 'Cl' item, and it should not appear in output. // We do not add a 'Cl' item, and it should not appear in output.
TimePointFormatter tpf = new TimePointFormatter(tp, ReferenceStyle.IfAbnormal); lab.AddTimePoint(tp);
TimePointFormatterDictionary tpfd = new TimePointFormatterDictionary();
tpfd.Add(tpf.TimeStamp, tpf); _formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
Document document = new Document(); _formatter.Laboratory = lab;
i.WriteToDocument(document, tpfd); _formatter.Elements.Add(new zaa.Items("Klinische Chemie: Na, K, Cl"));
Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", document.Range().Text); _formatter.Run();
Assert.AreEqual("Klinische Chemie: Na 133, K 6 (5)\r", _formatter.Document.Range().Text);
} }
[Test] [Test]
public void ItemsTestWithCaptionButNoItems() public void ItemsTestWithCaptionButNoItems()
{ {
zaa.Items i = new zaa.Items("Klinische Chemie: this, does, not, exist"); Laboratory lab = new Laboratory();
TimePoint tp = new TimePoint(); TimePoint tp = new TimePoint();
tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00); tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00);
tp.AddItem(new LabItem("Na", "133", "")); tp.AddItem(new LabItem("Na", "133", ""));
tp.AddItem(new LabItem("K", "6", "5")); tp.AddItem(new LabItem("K", "6", "5"));
// We do not add a 'Cl' item, and it should not appear in output. // We do not add a 'Cl' item, and it should not appear in output.
TimePointFormatter tpf = new TimePointFormatter(tp, ReferenceStyle.IfAbnormal); lab.AddTimePoint(tp);
TimePointFormatterDictionary tpfd = new TimePointFormatterDictionary();
tpfd.Add(tpf.TimeStamp, tpf); _formatter.ReferenceStyle = ReferenceStyle.IfAbnormal;
Document document = new Document(); _formatter.Laboratory = lab;
i.WriteToDocument(document, tpfd); _formatter.Elements.Add(new zaa.Items("Klinische Chemie: this, does, not, exist"));
Assert.AreEqual("\r", document.Range().Text); _formatter.Run();
Assert.AreEqual("\r", _formatter.Document.Range().Text);
} }
} }
} }

View File

@ -33,13 +33,14 @@ namespace Tests.Formatter
[Test] [Test]
public void FormatLaboratory() public void FormatLaboratory()
{ {
Document document = new Document();
ZaaImporter importer = TestHelpers.ZaaImporterFromResource(); ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
f.Formatter formatter = new f.Formatter(); f.Formatter formatter = new f.Formatter(document);
formatter.Laboratory = importer.Laboratory; formatter.Laboratory = importer.Laboratory;
formatter.Elements.Add(new f.Elements.Items("Klinische Chemie: Na, K, Cl")); formatter.Elements.Add(new f.Elements.Items("Klinische Chemie: Na, K, Cl"));
Document document = new Document(); formatter.Run();
formatter.WriteToDocument(document); Assert.AreEqual("Klinische Chemie: Na 144 mM, K 4,3 mM\r", document.Range().Text);
Assert.AreEqual("Klinische Chemie: Na: 132 mmol/l", document.Range().Text); ((_Document)document).Close(WdSaveOptions.wdDoNotSaveChanges);
} }
} }
} }

View File

@ -1,18 +1,18 @@
# This file contains 7 time points. # This file contains 7 time points.
# This leading text should be ignored. # This leading text should be ignored.
# DO NOT CHANGE THE FOLLOWING TEXT, LEST THE TESTS WILL FAIL! # 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; 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; 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; 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; 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; 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; 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. ; 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; Schilddrüse: TSH: 1.30 [0.3 - 4.0] mIU/l;
Ca-Phosphat-Stoffwechsel: PTH intakt: 56.1 [12 - 65] ng/l; Ca-Phosphat-Stoffwechsel: PTH intakt: 56.1 [12 - 65] ng/l;
(06.07.2015 10:28:00) (06.07.2015 10:28:00)

View File

@ -4,3 +4,4 @@
# weil (bislang) keine Umrechnung der Werte vorgesehen ist! # weil (bislang) keine Umrechnung der Werte vorgesehen ist!
"ml/min/ 1,73qm" "ml/min/1,73 m²" "ml/min/ 1,73qm" "ml/min/1,73 m²"
ng/ml µg/l ng/ml µg/l
mmol/l mM

View File

@ -36,12 +36,13 @@ namespace zaaReloaded2.Formatter.Elements
abstract public string Label { get; } abstract public string Label { get; }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
/// <param name="document">Word document to write to.</param> /// <param name="formatter">Formatter object that this
/// <param name="timePoints">Laboratory time points to work with.</param> /// Element belongs to. The Formatter object provides access
abstract public void WriteToDocument( /// to the current Word document etc.</param>
Document document, abstract public void Run(Formatter formatter);
ITimePointFormatterDictionary workingTimePoints);
} }
} }

View File

@ -39,11 +39,8 @@ namespace zaaReloaded2.Formatter.Elements
get { return Line; } get { return Line; }
} }
public override void WriteToDocument( public override void Run(Formatter formatter)
Document document,
ITimePointFormatterDictionary workingTimePoints)
{ {
_document = document;
bool _needComma = false; bool _needComma = false;
// Find out if we have any items that we can write // Find out if we have any items that we can write
@ -53,7 +50,7 @@ namespace zaaReloaded2.Formatter.Elements
{ {
foreach (string itemName in _items) foreach (string itemName in _items)
{ {
TimePointFormatter tpf = workingTimePoints TimePointFormatter tpf = formatter.WorkingTimePoints
.FirstOrDefault(tp => tp.Value.ContainsItem(itemName)) .FirstOrDefault(tp => tp.Value.ContainsItem(itemName))
.Value; .Value;
if (tpf != null) if (tpf != null)
@ -70,7 +67,7 @@ namespace zaaReloaded2.Formatter.Elements
{ {
if (!String.IsNullOrEmpty(_caption)) if (!String.IsNullOrEmpty(_caption))
{ {
document.Range().InsertAfter( formatter.Document.Range().InsertAfter(
String.Format("{0}: ", _caption) String.Format("{0}: ", _caption)
); );
}; };
@ -78,13 +75,13 @@ namespace zaaReloaded2.Formatter.Elements
{ {
if (_needComma) if (_needComma)
{ {
document.Range().InsertAfter(", "); formatter.Document.Range().InsertAfter(", ");
} }
else else
{ {
_needComma = true; _needComma = true;
} }
i.WriteToDocument(document); i.WriteToDocument(formatter.Document);
} }
} }
} }
@ -154,7 +151,6 @@ namespace zaaReloaded2.Formatter.Elements
#region Fields #region Fields
Document _document;
string _line; string _line;
string _caption; string _caption;
List<string> _items; List<string> _items;

View File

@ -40,6 +40,11 @@ namespace zaaReloaded2.Formatter
/// </summary> /// </summary>
public ElementsList Elements { get; private set; } public ElementsList Elements { get; private set; }
/// <summary>
/// Gets the working Word document.
/// </summary>
public Document Document { get; private set; }
/// <summary> /// <summary>
/// Gets or sets the style of the normal range reference. /// Gets or sets the style of the normal range reference.
/// </summary> /// </summary>
@ -67,6 +72,11 @@ namespace zaaReloaded2.Formatter
} }
} }
/// <summary>
/// Gets the current working set of TimePointFormatters.
/// </summary>
public ITimePointFormatterDictionary WorkingTimePoints { get; private set; }
#endregion #endregion
#region Constructor #region Constructor
@ -76,6 +86,12 @@ namespace zaaReloaded2.Formatter
Elements = new ElementsList(); Elements = new ElementsList();
} }
public Formatter(Document document)
: this()
{
Document = document;
}
#endregion #endregion
#region Public methods #region Public methods
@ -85,8 +101,13 @@ namespace zaaReloaded2.Formatter
/// </summary> /// </summary>
/// <param name="document">Word document to write to (at the /// <param name="document">Word document to write to (at the
/// current position of the cursor).</param> /// current position of the cursor).</param>
public void WriteToDocument(Document document) public void Run()
{ {
WorkingTimePoints = _timePointFormatters;
foreach (ElementBase element in Elements)
{
element.Run(this);
}
} }
#endregion #endregion

View File

@ -111,12 +111,35 @@ namespace zaaReloaded2.Formatter
reference = String.Empty; 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. // Insert the formatted text into the document.
document.Range().InsertAfter( document.Range().InsertAfter(
String.Format( String.Format(
"{0} {1}{2}", "{0} {1}{2}{3}",
LabItem.QualifiedName, LabItem.QualifiedName,
LabItem.Value, value,
unit,
reference reference
)); ));
HasBeenUsed = true; HasBeenUsed = true;

View File

@ -173,6 +173,14 @@ namespace zaaReloaded2.LabModel
} }
} }
public bool HasUnit
{
get
{
return !String.IsNullOrEmpty(Unit);
}
}
/// <summary> /// <summary>
/// Returns the canonical name prefixed with the abbreviation /// Returns the canonical name prefixed with the abbreviation
/// for the material, e.g. "U-Na" for sodium in the spot urine, /// for the material, e.g. "U-Na" for sodium in the spot urine,