Add formatter and initial tests.

This commit is contained in:
Daniel Kraus 2015-07-13 23:57:35 +02:00
parent a847c1f8ba
commit e36fee52ad
25 changed files with 1038 additions and 17 deletions

View File

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

View File

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

View File

@ -37,11 +37,7 @@ namespace Tests.Importer.ZaaImporter
[Test] [Test]
public void ParseTimePoints() public void ParseTimePoints()
{ {
Stream s = this.GetType().Assembly.GetManifestResourceStream("Tests.demo-output.txt"); zaa.ZaaImporter importer = TestHelpers.ZaaImporterFromResource();
StreamReader r = new StreamReader(s);
zaa.ZaaImporter importer = new zaa.ZaaImporter();
importer.Import(r.ReadToEnd());
// Only 6 distinct time points (see method documentation above). // Only 6 distinct time points (see method documentation above).
Assert.AreEqual(6, importer.Laboratory.TimePoints.Count); Assert.AreEqual(6, importer.Laboratory.TimePoints.Count);
} }

42
Tests/TestHelpers.cs Executable file
View File

@ -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
{
/// <summary>
/// Creates a ZaaImporter object and imports demo-output.txt.
/// </summary>
/// <returns></returns>
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;
}
}
}

View File

@ -41,6 +41,9 @@
<AssemblyOriginatorKeyFile>zaaReloaded2.pfx</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>zaaReloaded2.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.Office.Interop.Word, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> <Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
@ -64,6 +67,8 @@
</Choose> </Choose>
<ItemGroup> <ItemGroup>
<Compile Include="Dictionaries\DictionaryTest.cs" /> <Compile Include="Dictionaries\DictionaryTest.cs" />
<Compile Include="Formatter\Elements\ItemsTest.cs" />
<Compile Include="Formatter\FormatterTest.cs" />
<Compile Include="Importer\ZaaImporter\LaurisItemTest.cs" /> <Compile Include="Importer\ZaaImporter\LaurisItemTest.cs" />
<Compile Include="Importer\ZaaImporter\LaurisParagraphTest.cs" /> <Compile Include="Importer\ZaaImporter\LaurisParagraphTest.cs" />
<Compile Include="Importer\ZaaImporter\ZaaImporterTest.cs" /> <Compile Include="Importer\ZaaImporter\ZaaImporterTest.cs" />
@ -71,6 +76,7 @@
<Compile Include="LineParserTest.cs" /> <Compile Include="LineParserTest.cs" />
<Compile Include="Dictionaries\TestDictionary.cs" /> <Compile Include="Dictionaries\TestDictionary.cs" />
<Compile Include="Importer\ZaaImporter\TimePointTest.cs" /> <Compile Include="Importer\ZaaImporter\TimePointTest.cs" />
<Compile Include="TestHelpers.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
@ -89,6 +95,7 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="demo-output.txt" /> <EmbeddedResource Include="demo-output.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Choose> <Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup> <ItemGroup>

View File

@ -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
{
/// <summary>
/// Base class for formatting elements.
/// </summary>
[Serializable]
abstract class ElementBase
{
/// <summary>
/// Returns the label for this formatting element.
/// </summary>
abstract public string Label { get; }
/// <summary>
/// Writes the formatting element 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);
}
}

View File

@ -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<ElementBase>
{
}
}

View File

@ -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
{
/// <summary>
/// This formatting element is concerned with writing <see cref="LabItem"/>s
/// to a Word document.
/// </summary>
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<ItemFormatter> items = new List<ItemFormatter>();
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
/// <summary>
/// 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.
/// </summary>
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
/// <summary>
/// Parses the Line and splits it into an optional caption and individual
/// items.
/// </summary>
void ParseLine()
{
_items = null;
_caption = null;
Regex r = new Regex(@"((?<caption>[^:]+):\s*)?((?<items>[^,]+),\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<Capture>()
.Select<Capture, string>(c => c.Value).ToList<string>();
}
}
#endregion
#region Fields
Document _document;
string _line;
string _caption;
List<string> _items;
#endregion
}
}

View File

@ -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
{
/// <summary>
/// Formats and writes a <see cref="Laboratory"/> to a Word document.
/// </summary>
[Serializable]
class Formatter
{
#region Properties
/// <summary>
/// Gets a list of formatting elements (derived from
/// <see cref="ElementBase"/>).
/// </summary>
public ElementsList Elements { get; private set; }
/// <summary>
/// Gets or sets the style of the normal range reference.
/// </summary>
public ReferenceStyle ReferenceStyle { get; set; }
/// <summary>
/// Gets or sets the <see cref="Laboratory"/> that shall be
/// formatted.
/// </summary>
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
/// <summary>
/// Formats the laboratory and writes it to a Word document.
/// </summary>
/// <param name="document">Word document to write to (at the
/// current position of the cursor).</param>
public void WriteToDocument(Document document)
{
}
#endregion
#region Fields
ITimePointFormatterDictionary _timePointFormatters;
Laboratory _laboratory;
#endregion
}
}

View File

@ -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<string, ItemFormatter>
{
}
}

View File

@ -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<DateTime, TimePointFormatter>
{
}
}

View File

@ -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
{
/// <summary>
/// Wraps a <see cref="LabItem"/> and provides methods to format it.
/// </summary>
public class ItemFormatter
{
#region Properties
/// <summary>
/// Gets or sets the LabItem wrapped by this ItemFormatter.
/// </summary>
public LabItem LabItem { get; set; }
/// <summary>
/// Gets or sets the ReferenceStyle to use in formatting.
/// </summary>
public ReferenceStyle ReferenceStyle { get; set; }
/// <summary>
/// Gets or sets a flag that indicates whether this ItemFormatter
/// has been used, i.e. whether the LabItem was written to a
/// document.
/// </summary>
public bool HasBeenUsed { get; set; }
#endregion
#region Constructor
/// <summary>
/// Creates a new ItemFormatter that wraps a <paramref name="labItem"/>.
/// </summary>
/// <param name="labItem">LabItem to wrap in this ItemFormatter.</param>
public ItemFormatter(LabItem labItem, ReferenceStyle referenceStyle)
{
LabItem = labItem;
ReferenceStyle = referenceStyle;
}
#endregion
#region Methods
/// <summary>
/// Formats and writes the LabItem details to a word <paramref name="document"/>.
/// </summary>
/// <param name="document">Word document to write to.</param>
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
}
}

View File

@ -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<string, ItemFormatter>,
IItemFormatterDictionary
{
}
}

View File

@ -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
{
/// <summary>
/// Describes the style of normal range references.
/// </summary>
[Serializable]
public enum ReferenceStyle
{
/// <summary>
/// Never write normal ranges
/// </summary>
[Description("Referenzbereich nie ausgeben")]
Never,
/// <summary>
/// Write normal range if item is marked in dictionary
/// </summary>
[Description("Referenzbereich ausgeben, falls Parameter so markiert ist")]
IfSpecialItem,
/// <summary>
/// Write normal range if value is abnormal
/// </summary>
[Description("Referenzbereich ausgeben, falls Wert nicht normal ist")]
IfAbnormal,
/// <summary>
/// Write normal range if item is marked in dictionary, or if value is abnormal
/// </summary>
[Description("Referenzbereich ausgeben, falls Parameter so markiert ist oder falls Wert nicht normal ist")]
IfSpecialOrAbnormal,
/// <summary>
/// Always write normal range reference
/// </summary>
[Description("Referenzbereich immer ausgeben")]
Always
}
}

View File

@ -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
{
/// <summary>
/// Creates a list of ItemFormatter objects from a TimePoint.
/// </summary>
public class TimePointFormatter
{
#region Properties
/// <summary>
/// Gets the time stamp of the <see cref="TimePoint"/> from which this
/// TimePointFormatter was built.
/// </summary>
public DateTime TimeStamp { get; private set; }
/// <summary>
/// Gets a dictionary of ItemFormatter objects that wrap LabItems.
/// The QualifiedName of each LabItem is used as key.
/// </summary>
public IItemFormatterDictionary ItemFormatters { get; private set; }
#endregion
#region Constructor
/// <summary>
/// Creates a new TimePointFormatter object using a given
/// <paramref name="timePoint"/>.
/// </summary>
/// <param name="timePoint">TimePoint whose LabItems will be
/// used to create ItemFormatter objects.</param>
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
}
}

View File

@ -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<DateTime, TimePointFormatter>,
ITimePointFormatterDictionary
{
}
}

View File

@ -155,7 +155,6 @@ namespace zaaReloaded2.Importer.ZaaImporter
/// and contains <see cref="LabItem"/>s in the others.</returns> /// and contains <see cref="LabItem"/>s in the others.</returns>
bool ParseParagraphs() bool ParseParagraphs()
{ {
Items = new ItemDictionary();
if (Paragraphs.Length > 0) if (Paragraphs.Length > 0)
{ {
if (!ParseTimeStamp()) return false; if (!ParseTimeStamp()) return false;

View File

@ -20,7 +20,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace zaaReloaded2.Dictionaries namespace zaaReloaded2.LabModel
{ {
/// <summary> /// <summary>
/// A dictionary of <see cref="LabItem"/>s. /// A dictionary of <see cref="LabItem"/>s.

View File

@ -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<DateTime, TimePoint>
{
}
}

View File

@ -21,7 +21,7 @@ using System.Linq;
using System.Text; using System.Text;
using zaaReloaded2.LabModel; using zaaReloaded2.LabModel;
namespace zaaReloaded2.Dictionaries namespace zaaReloaded2.LabModel
{ {
public class ItemDictionary : SortedDictionary<string, LabItem>, IItemDictionary public class ItemDictionary : SortedDictionary<string, LabItem>, IItemDictionary
{ {

View File

@ -161,6 +161,18 @@ namespace zaaReloaded2.LabModel
get { return (HasLowerLimit || HasUpperLimit); } get { return (HasLowerLimit || HasUpperLimit); }
} }
/// <summary>
/// Is true if the item has numerical limits or a categorical normal
/// value.
/// </summary>
public bool HasLimitsOrNormal
{
get
{
return HasLimits || !String.IsNullOrEmpty(Normal);
}
}
/// <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,
@ -187,10 +199,23 @@ namespace zaaReloaded2.LabModel
#endregion #endregion
#region Constructor #region Constructors
public LabItem() { } public LabItem() { }
/// <summary>
/// Creates a new LabItem object that has a normal value, but
/// no upper or lower limits. This is constructor is used for
/// testing purposes.
/// </summary>
public LabItem(string name, string value, string normal)
: this()
{
Name = name;
Value = value;
Normal = normal;
}
#endregion #endregion
#region Fields #region Fields

View File

@ -29,7 +29,7 @@ namespace zaaReloaded2.LabModel
{ {
#region Properties #region Properties
public SortedDictionary<DateTime, TimePoint> TimePoints { get; set; } public ITimePointsDictionary TimePoints { get; private set; }
#endregion #endregion
@ -37,7 +37,7 @@ namespace zaaReloaded2.LabModel
public Laboratory() public Laboratory()
{ {
TimePoints = new SortedDictionary<DateTime, TimePoint>(); TimePoints = new TimePointsDictionary();
} }
#endregion #endregion

View File

@ -45,12 +45,34 @@ namespace zaaReloaded2.LabModel
/// the <see cref="LaurisText"/>. If a laboratory parameter occurs more /// the <see cref="LaurisText"/>. If a laboratory parameter occurs more
/// than once, only the last occurrence is saved. /// than once, only the last occurrence is saved.
/// </summary> /// </summary>
public IItemDictionary Items { get; set; } public IItemDictionary Items { get; private set; }
#endregion
#region Constructor
public TimePoint()
{
Items = new ItemDictionary();
}
#endregion #endregion
#region Methods #region Methods
/// <summary>
/// Adds an item to the TimePoint.
/// </summary>
/// <param name="item">LabItem to add.</param>
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);
}
/// <summary> /// <summary>
/// Adds the items from another time point to this /// Adds the items from another time point to this
/// time point. There is no check for plausibility, /// time point. There is no check for plausibility,
@ -67,6 +89,18 @@ namespace zaaReloaded2.LabModel
Items.Merge(otherTimePoint.Items); Items.Merge(otherTimePoint.Items);
} }
/// <summary>
/// Returns true if <see cref="Items"/> contains a given
/// item.
/// </summary>
/// <param name="item">Item string to look for.</param>
/// <returns>True if <see cref="Items"/> contains <paramref name="item."/>
/// </returns>
public bool ContainsItem(string item)
{
return Items.ContainsKey(item);
}
#endregion #endregion
} }
} }

View File

@ -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<DateTime, TimePoint>, ITimePointsDictionary
{
}
}

View File

@ -164,20 +164,33 @@
--> -->
<ItemGroup> <ItemGroup>
<Compile Include="Dictionaries\DictionaryBase.cs" /> <Compile Include="Dictionaries\DictionaryBase.cs" />
<Compile Include="Dictionaries\IItemDictionary.cs" /> <Compile Include="Formatter\Elements\ElementsList.cs" />
<Compile Include="Dictionaries\ItemDictionary.cs" /> <Compile Include="Formatter\IItemFormatterDictionary.cs" />
<Compile Include="Formatter\ItemFormatter.cs" />
<Compile Include="Formatter\ItemFormatterDictionary.cs" />
<Compile Include="Formatter\ITimePointFormatterDictionary.cs" />
<Compile Include="Formatter\TimePointFormatter.cs" />
<Compile Include="Formatter\TimePointFormatterDictionary.cs" />
<Compile Include="LabModel\IItemDictionary.cs" />
<Compile Include="LabModel\ItemDictionary.cs" />
<Compile Include="Dictionaries\LineParser.cs" /> <Compile Include="Dictionaries\LineParser.cs" />
<Compile Include="Dictionaries\ParameterDictionary.cs" /> <Compile Include="Dictionaries\ParameterDictionary.cs" />
<Compile Include="Dictionaries\UnitDictionary.cs" /> <Compile Include="Dictionaries\UnitDictionary.cs" />
<Compile Include="Formatter\Elements\ElementBase.cs" />
<Compile Include="Formatter\Elements\Items.cs" />
<Compile Include="Formatter\Formatter.cs" />
<Compile Include="Formatter\ReferenceStyle.cs" />
<Compile Include="Importer\IImporter.cs" /> <Compile Include="Importer\IImporter.cs" />
<Compile Include="Importer\ZaaImporter\LaurisItem.cs" /> <Compile Include="Importer\ZaaImporter\LaurisItem.cs" />
<Compile Include="Importer\ZaaImporter\LaurisTimePoint.cs" /> <Compile Include="Importer\ZaaImporter\LaurisTimePoint.cs" />
<Compile Include="Importer\ZaaImporter\ZaaImporter.cs" /> <Compile Include="Importer\ZaaImporter\ZaaImporter.cs" />
<Compile Include="LabModel\ITimePointsDictionary.cs" />
<Compile Include="LabModel\LabItem.cs" /> <Compile Include="LabModel\LabItem.cs" />
<Compile Include="LabModel\Laboratory.cs" /> <Compile Include="LabModel\Laboratory.cs" />
<Compile Include="Importer\ZaaImporter\LaurisParagraph.cs" /> <Compile Include="Importer\ZaaImporter\LaurisParagraph.cs" />
<Compile Include="LabModel\Material.cs" /> <Compile Include="LabModel\Material.cs" />
<Compile Include="LabModel\TimePoint.cs" /> <Compile Include="LabModel\TimePoint.cs" />
<Compile Include="LabModel\TimePointsDictionary.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@ -216,9 +229,7 @@
<EmbeddedResource Include="Defaults\parameters.txt" /> <EmbeddedResource Include="Defaults\parameters.txt" />
<EmbeddedResource Include="Defaults\units.txt" /> <EmbeddedResource Include="Defaults\units.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="Formatter\" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>