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]
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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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)

View File

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

View File

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

View File

@ -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<string> _items;

View File

@ -40,6 +40,11 @@ namespace zaaReloaded2.Formatter
/// </summary>
public ElementsList Elements { get; private set; }
/// <summary>
/// Gets the working Word document.
/// </summary>
public Document Document { get; private set; }
/// <summary>
/// Gets or sets the style of the normal range reference.
/// </summary>
@ -67,6 +72,11 @@ namespace zaaReloaded2.Formatter
}
}
/// <summary>
/// Gets the current working set of TimePointFormatters.
/// </summary>
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
/// </summary>
/// <param name="document">Word document to write to (at the
/// 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

View File

@ -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;

View File

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