167 lines
5.6 KiB
C#
Executable File
167 lines
5.6 KiB
C#
Executable File
/* ParameterDictionary.cs
|
|
* part of zaaReloaded2
|
|
*
|
|
* Copyright 2015-2018 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.Reflection;
|
|
using System.Text;
|
|
using System.IO;
|
|
using zaaReloaded2.LabModel;
|
|
|
|
namespace zaaReloaded2.Thesaurus
|
|
{
|
|
/// <summary>
|
|
/// Thesaurus that is used to convert Lauris parameter names to
|
|
/// canonical parameter names, and to assign categories and determine
|
|
/// which parameters always require the output of reference intervals.
|
|
/// </summary>
|
|
public class Parameters : ThesaurusBase
|
|
{
|
|
#region Singleton
|
|
|
|
private static readonly Parameters _default = new Parameters();
|
|
|
|
/// <summary>
|
|
/// Gets the default singleton instance of the Parameters
|
|
/// thesaurus.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// http://csharpindepth.com/Articles/General/Singleton.aspx#cctor
|
|
/// </remarks>
|
|
public static Parameters Default { get { return _default; } }
|
|
|
|
static Parameters() { }
|
|
private Parameters() { }
|
|
|
|
#endregion
|
|
|
|
#region Public methods
|
|
|
|
/// <summary>
|
|
/// Looks up the canonical name for a given <paramref name="laurisName"/>.
|
|
/// </summary>
|
|
/// <param name="laurisName">Lauris item name to look up.</param>
|
|
/// <returns>Canonical name, or original Lauris name if no canonical name
|
|
/// is defined for this item.</returns>
|
|
public string GetCanonicalName(string laurisName)
|
|
{
|
|
return LookUpValue(laurisName, 1, laurisName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Looks up the material for a given <paramref name="laurisName"/>.
|
|
/// </summary>
|
|
/// <param name="laurisName">Lauris item name to look up.</param>
|
|
/// <returns><see cref="zaaReloaded2.LabModel.Material"/> enum; if no material is
|
|
/// found in the dictionary, the default material "S" (serum) is returned.</returns>
|
|
public Material GetMaterial(string laurisName, Material def)
|
|
{
|
|
string textValue = LookUpValue(laurisName, 2);
|
|
if (String.IsNullOrEmpty(textValue))
|
|
{
|
|
return def;
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
return MaterialFactory.FromAbbreviation(textValue);
|
|
}
|
|
catch
|
|
{
|
|
return Material.B;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the desired number of decimals for a given parameter.
|
|
/// </summary>
|
|
/// <param name="laurisName">Laboratory item to look up;
|
|
/// this must be an original Lauris string.</param>
|
|
/// <returns>Number of decimals for the parameter, or -1 if
|
|
/// undefined.</returns>
|
|
public int GetPrecision(string laurisName)
|
|
{
|
|
return LookUpValue(laurisName, 3, -1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns whether or not reference limits shall always
|
|
/// be displayed for a given item, regardless whether it
|
|
/// is normal or not.
|
|
/// </summary>
|
|
/// <param name="key">Laboratory item to look up; this must
|
|
/// be an original Lauris string.</param>
|
|
/// <returns></returns>
|
|
public bool GetForceReferenceDisplay(string laurisName)
|
|
{
|
|
return LookUpValue(laurisName, 4, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether an item is marked as blacklisted in the
|
|
/// thesaurus.
|
|
/// </summary>
|
|
/// <param name="laurisName">Laboratory item to lok up;
|
|
/// this must be an original Lauris string.</param>
|
|
/// <returns>True if the item is marked as blacklisted,
|
|
/// false if not. Default is false.</returns>
|
|
public bool GetIsBlacklisted(string laurisName)
|
|
{
|
|
return LookUpValue(laurisName, 5, false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks whether an item's label should be suppressed or not.
|
|
/// </summary>
|
|
/// <param name="laurisName">Laboratory item to lok up;
|
|
/// this must be an original Lauris string.</param>
|
|
/// <returns>True if the item should *not* be labelled,
|
|
/// false if not. Default is false (i.e., labels are .</returns>
|
|
public bool GetSuppressLabel(string laurisName)
|
|
{
|
|
return LookUpValue(laurisName, 6, false);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Overrides
|
|
|
|
/// <summary>
|
|
/// Returns the resource stream for Defaults\parameters.txt.
|
|
/// </summary>
|
|
protected override System.IO.Stream GetDefaultStream()
|
|
{
|
|
return Assembly.GetExecutingAssembly().GetManifestResourceStream(
|
|
"zaaReloaded2.Defaults.parameters.txt");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a path to a file parameters.txt in the addin directory
|
|
/// as provided by <see cref="ThisAddin.Subdir"/>.
|
|
/// </summary>
|
|
protected override string GetUserFileName()
|
|
{
|
|
return Path.Combine(ThisAddIn.Subdir, "parameters.txt");
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|