From 06a74992ef054bdd6cc3b7250da2c083f001dd6f Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Wed, 5 Aug 2015 06:15:07 +0200 Subject: [PATCH] Make tests pass with refactored ZaaImporter. --- Tests/Formatter/FormatterTest.cs | 1 + .../Importer/ZaaImporter/LaurisTimePoint.cs | 13 +++++++--- .../Importer/ZaaImporter/ZaaImporter.cs | 16 ++++++++++--- zaaReloaded2/LabModel/Laboratory.cs | 24 +++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Tests/Formatter/FormatterTest.cs b/Tests/Formatter/FormatterTest.cs index 7437d6b..10b05b0 100755 --- a/Tests/Formatter/FormatterTest.cs +++ b/Tests/Formatter/FormatterTest.cs @@ -55,6 +55,7 @@ namespace Tests.Formatter { _formatter.Settings.Elements.Add(new Items("Klinische Chemie: Na, K, Cl")); _formatter.Run(); + Console.WriteLine(_document.Range().Text); Assert.AreEqual( GetResourceText("Tests.Formatter.FormatterTest-all.txt"), _document.Range().Text); diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs index 080527c..c293938 100755 --- a/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs +++ b/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs @@ -135,10 +135,8 @@ namespace zaaReloaded2.Importer.ZaaImporter IList paragraphs, Parameters parameterDictionary, Units unitDictionary) - : this() + : this(parameterDictionary, unitDictionary) { - _parameterDictionary = parameterDictionary; - _unitDictionary = unitDictionary; Paragraphs = paragraphs; } @@ -147,6 +145,15 @@ namespace zaaReloaded2.Importer.ZaaImporter { } + public LaurisTimePoint( + Parameters parameterDictionary, + Units unitDictionary) + : this() + { + _parameterDictionary = parameterDictionary; + _unitDictionary = unitDictionary; + } + #endregion #region Public methods diff --git a/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs b/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs index 9583d7b..223aadf 100755 --- a/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs +++ b/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs @@ -78,8 +78,18 @@ namespace zaaReloaded2.Importer.ZaaImporter // create a new time point. if (LaurisTimePoint.IsTimeStampLine(paragraph)) { - timePoint = new LaurisTimePoint(paragraph); - Laboratory.AddTimePoint(timePoint); + timePoint = new LaurisTimePoint(paragraph, _parameters, _units); + // Add the time point to the laboratory only if none + // with the same time stamp exists yet. + TimePoint existing = null; + if (Laboratory.TryGetTimePoint(timePoint.TimeStamp, ref existing)) + { + timePoint = existing as LaurisTimePoint; + } + else + { + Laboratory.AddTimePoint(timePoint); + } } // If the current paragraph looks like a paragraph with // laboratory items, add it to the current time point; @@ -88,7 +98,7 @@ namespace zaaReloaded2.Importer.ZaaImporter { if (timePoint == null) { - timePoint = new LaurisTimePoint(); + timePoint = new LaurisTimePoint(_parameters, _units); Laboratory.AddTimePoint(timePoint); } timePoint.AddParagraph(paragraph); diff --git a/zaaReloaded2/LabModel/Laboratory.cs b/zaaReloaded2/LabModel/Laboratory.cs index 8964ae9..99dae9a 100755 --- a/zaaReloaded2/LabModel/Laboratory.cs +++ b/zaaReloaded2/LabModel/Laboratory.cs @@ -66,6 +66,30 @@ namespace zaaReloaded2.LabModel } } + /// + /// Checks if the Laboratory contains a TimePoint with an identical + /// time stamp to the one being queried. + /// + /// TimePoint whose time stamp to look for. + /// True if a TimePoint with identical time stamp exists. + public bool HasTimePoint(TimePoint timePoint) + { + return TimePoints.ContainsKey(timePoint.TimeStamp); + } + + /// + /// Looks for a TimePoint with a given timeStamp and returns + /// it as a reference parameter. + /// + /// Time stamp to look for. + /// Resulting TimePoint (if any). + /// True if TimePoints contains a TimePoint with + /// the requested timeStamp. + public bool TryGetTimePoint(DateTime timeStamp, ref TimePoint timePoint) + { + return TimePoints.TryGetValue(timeStamp, out timePoint); + } + #endregion } }