From cde32f0a7e1b77a86458dab4e432d4d5c849893f Mon Sep 17 00:00:00 2001 From: Daniel Kraus Date: Mon, 24 Aug 2015 23:17:49 +0200 Subject: [PATCH 1/4] Implement styling of abnormal values. - NEU: Auszeichnung pathologischer Werte kann eingestellt werden. --- zaaReloaded2/Controller/Settings.cs | 12 ++++ zaaReloaded2/Formatter/AbnormalStyle.cs | 62 +++++++++++++++++++ zaaReloaded2/Formatter/DocumentWriter.cs | 6 ++ zaaReloaded2/Formatter/Formatter.cs | 2 +- zaaReloaded2/Formatter/ItemFormatter.cs | 14 +++-- zaaReloaded2/Formatter/TimePointFormatter.cs | 7 ++- zaaReloaded2/Properties/Settings.Designer.cs | 11 +++- zaaReloaded2/Properties/Settings.settings | 5 +- zaaReloaded2/ViewModels/SettingsViewModel.cs | 46 ++++++++++++++ .../Views/SettingsRepositoryView.xaml | 2 +- zaaReloaded2/Views/SettingsView.xaml | 8 +++ zaaReloaded2/app.config | 5 +- zaaReloaded2/zaaReloaded2.csproj | 1 + 13 files changed, 170 insertions(+), 11 deletions(-) create mode 100755 zaaReloaded2/Formatter/AbnormalStyle.cs diff --git a/zaaReloaded2/Controller/Settings.cs b/zaaReloaded2/Controller/Settings.cs index 561e561..acecf11 100755 --- a/zaaReloaded2/Controller/Settings.cs +++ b/zaaReloaded2/Controller/Settings.cs @@ -81,6 +81,12 @@ namespace zaaReloaded2.Controller /// public ReferenceStyle ReferenceStyle { get; set; } + /// + /// Gets or sets the style in which abnormal values + /// are formatted. + /// + public AbnormalStyle AbnormalStyle { get; set; } + /// /// Gets the list of controlling elements. /// @@ -156,6 +162,10 @@ namespace zaaReloaded2.Controller Uid = (Guid)info.GetValue("Uid", typeof(Guid)); Name = info.GetString("Name"); ReferenceStyle = (ReferenceStyle)info.GetValue("ReferenceStyle", typeof(ReferenceStyle)); + if (version >= 2) + { + AbnormalStyle = (AbnormalStyle)info.GetValue("AbnormalStyle", typeof(AbnormalStyle)); + } int elementsCount = info.GetInt32("ElementsCount"); Elements = new List(); for (int i = 0; i < elementsCount; i++) @@ -190,6 +200,7 @@ namespace zaaReloaded2.Controller Elements.Select(e => e.Clone() as ElementBase).ToList() ); clone.ReferenceStyle = ReferenceStyle; + clone.AbnormalStyle = AbnormalStyle; return clone; } @@ -203,6 +214,7 @@ namespace zaaReloaded2.Controller info.AddValue("Uid", Uid); info.AddValue("Name", Name); info.AddValue("ReferenceStyle", ReferenceStyle); + info.AddValue("AbnormalStyle", AbnormalStyle); info.AddValue("ElementsCount", Elements.Count); int i = 0; foreach (ElementBase e in Elements) diff --git a/zaaReloaded2/Formatter/AbnormalStyle.cs b/zaaReloaded2/Formatter/AbnormalStyle.cs new file mode 100755 index 0000000..cfac503 --- /dev/null +++ b/zaaReloaded2/Formatter/AbnormalStyle.cs @@ -0,0 +1,62 @@ +/* AbnormalStyle.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 +{ + /// + /// Defines styling for abnormal laboratory values + /// + [Flags] + public enum AbnormalStyle + { + [Description("Keine Auszeichnung")] + None = 0x00, + + [Description("Fett")] + Bold = 0x01, + + [Description("Kursiv")] + Italics = 0x02 + } + + public static class AbnormalStyleExtensions + { + /// + /// Converts an AbnormalStyle value to textual markup. + /// + /// AbnormalStyle value. + /// Indicates whether to return an opening or a closing + /// tag. + /// Markup that is understood by a DocumentWriter. + public static string ToMarkup(this AbnormalStyle style, bool close) + { + string markup = String.Empty; + string dash = close ? "/" : String.Empty; + if (style.HasFlag(AbnormalStyle.Bold)) + markup += String.Format("<{0}b>", dash); + if (style.HasFlag(AbnormalStyle.Italics)) + markup += String.Format("<{0}i>", dash); + return markup; + } + } +} diff --git a/zaaReloaded2/Formatter/DocumentWriter.cs b/zaaReloaded2/Formatter/DocumentWriter.cs index ad1acfd..dea1bb8 100755 --- a/zaaReloaded2/Formatter/DocumentWriter.cs +++ b/zaaReloaded2/Formatter/DocumentWriter.cs @@ -202,6 +202,12 @@ namespace zaaReloaded2.Formatter case "": sel.Font.Bold = 0; break; + case "": + sel.Font.Italic = 1; + break; + case "": + sel.Font.Italic = 0; + break; case "": sel.ClearCharacterStyle(); break; diff --git a/zaaReloaded2/Formatter/Formatter.cs b/zaaReloaded2/Formatter/Formatter.cs index 2d3e55d..6639198 100755 --- a/zaaReloaded2/Formatter/Formatter.cs +++ b/zaaReloaded2/Formatter/Formatter.cs @@ -54,7 +54,7 @@ namespace zaaReloaded2.Formatter foreach (TimePoint tp in _laboratory.TimePoints.Values) { _timePointFormatters[tp.TimeStamp] = - new TimePointFormatter(tp, Settings.ReferenceStyle); + new TimePointFormatter(tp, Settings.ReferenceStyle, Settings.AbnormalStyle); } } } diff --git a/zaaReloaded2/Formatter/ItemFormatter.cs b/zaaReloaded2/Formatter/ItemFormatter.cs index 4f6f1d7..7170964 100755 --- a/zaaReloaded2/Formatter/ItemFormatter.cs +++ b/zaaReloaded2/Formatter/ItemFormatter.cs @@ -41,6 +41,11 @@ namespace zaaReloaded2.Formatter /// public ReferenceStyle ReferenceStyle { get; set; } + /// + /// Gets or sets the style to use for abnormal values. + /// + public AbnormalStyle AbnormalStyle { get; set; } + /// /// Gets or sets a flag that indicates whether this ItemFormatter /// has been used, i.e. whether the LabItem was written to a @@ -73,11 +78,14 @@ namespace zaaReloaded2.Formatter /// Creates a new ItemFormatter that wraps a . /// /// LabItem to wrap in this ItemFormatter. - public ItemFormatter(LabItem labItem, ReferenceStyle referenceStyle) + public ItemFormatter(LabItem labItem, + ReferenceStyle referenceStyle, + AbnormalStyle abnormalStyle) { IncludeMaterial = true; LabItem = labItem; ReferenceStyle = referenceStyle; + AbnormalStyle = abnormalStyle; } #endregion @@ -164,9 +172,7 @@ namespace zaaReloaded2.Formatter ); if (!LabItem.IsNormal) { - output = String.Format( - "{0}", - output); + output = AbnormalStyle.ToMarkup(false) + output + AbnormalStyle.ToMarkup(true); } formatter.Write(output); diff --git a/zaaReloaded2/Formatter/TimePointFormatter.cs b/zaaReloaded2/Formatter/TimePointFormatter.cs index 0dccbaf..5a9704a 100755 --- a/zaaReloaded2/Formatter/TimePointFormatter.cs +++ b/zaaReloaded2/Formatter/TimePointFormatter.cs @@ -103,13 +103,16 @@ namespace zaaReloaded2.Formatter /// /// TimePoint whose LabItems will be /// used to create ItemFormatter objects. - public TimePointFormatter(TimePoint timePoint, ReferenceStyle referenceStyle) + public TimePointFormatter(TimePoint timePoint, + ReferenceStyle referenceStyle, + AbnormalStyle abnormalStyle) { TimeStamp = timePoint.TimeStamp; ItemFormatters = new ItemFormatterDictionary(); foreach (LabItem item in timePoint.Items.Values) { - ItemFormatters[item.QualifiedName] = new ItemFormatter(item, referenceStyle); + ItemFormatters[item.QualifiedName] = new ItemFormatter( + item, referenceStyle, abnormalStyle); } } diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index d2e1e93..735da12 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -177,7 +177,7 @@ namespace zaaReloaded2.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("1")] + [global::System.Configuration.DefaultSettingValueAttribute("2")] public int SerializationVersion { get { return ((int)(this["SerializationVersion"])); @@ -213,5 +213,14 @@ namespace zaaReloaded2.Properties { return ((string)(this["StyleAbnormal"])); } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("None")] + public global::zaaReloaded2.Formatter.AbnormalStyle AbnormalStyle { + get { + return ((global::zaaReloaded2.Formatter.AbnormalStyle)(this["AbnormalStyle"])); + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index 2ca76ce..ebde00b 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -51,7 +51,7 @@ Steuerungs-Elemente - 1 + 2 @@ -62,5 +62,8 @@ zaaReloaded2-Pathologisch + + None + \ No newline at end of file diff --git a/zaaReloaded2/ViewModels/SettingsViewModel.cs b/zaaReloaded2/ViewModels/SettingsViewModel.cs index 05af8a2..54c9e60 100755 --- a/zaaReloaded2/ViewModels/SettingsViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs @@ -116,6 +116,52 @@ namespace zaaReloaded2.ViewModels } } + /// + /// Gets or sets whether abnormal values shall be formatted in bold. + /// + public bool AbnormalBold + { + get + { + return _settings.AbnormalStyle.HasFlag(AbnormalStyle.Bold); + } + set + { + if (value) + { + _settings.AbnormalStyle |= AbnormalStyle.Bold; + } + else + { + _settings.AbnormalStyle &= ~AbnormalStyle.Bold; + } + OnPropertyChanged("AbnormalBold"); + } + } + + /// + /// Gets or sets whether abnormal values shall be formatted in italics. + /// + public bool AbnormalItalics + { + get + { + return _settings.AbnormalStyle.HasFlag(AbnormalStyle.Italics); + } + set + { + if (value) + { + _settings.AbnormalStyle |= AbnormalStyle.Italics; + } + else + { + _settings.AbnormalStyle &= ~AbnormalStyle.Italics; + } + OnPropertyChanged("AbnormalItalics"); + } + } + #endregion #region Constructors diff --git a/zaaReloaded2/Views/SettingsRepositoryView.xaml b/zaaReloaded2/Views/SettingsRepositoryView.xaml index 47fdc0a..71a6b1f 100755 --- a/zaaReloaded2/Views/SettingsRepositoryView.xaml +++ b/zaaReloaded2/Views/SettingsRepositoryView.xaml @@ -91,7 +91,7 @@ Margin="0 5 5 5"> - diff --git a/zaaReloaded2/Views/SettingsView.xaml b/zaaReloaded2/Views/SettingsView.xaml index fb64868..a678936 100755 --- a/zaaReloaded2/Views/SettingsView.xaml +++ b/zaaReloaded2/Views/SettingsView.xaml @@ -60,6 +60,14 @@ SelectedItem="{Binding ReferenceStyle.SelectedItem}" x:Name="ReferenceStyleChooser" HorizontalAlignment="Stretch" /> + +