More work on Formatter; successful tests.
This commit is contained in:
@ -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
|
||||
ng/ml µg/l
|
||||
mmol/l mM
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user