-
Notifications
You must be signed in to change notification settings - Fork 12
/
Result.cs
74 lines (69 loc) · 3.47 KB
/
Result.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
namespace UniversaLIS
{
public class Result
{
public Dictionary<string, string> Elements = new Dictionary<string, string>();
public string ResultMessage
{
get => GetResultString();
set => SetResultString(value);
}
private string GetResultString()
{
// Anything missing should be added as an empty string.
string[] elementArray = { "FrameNumber", "Sequence #", "Universal Test ID", "Data (result)", "Units", "Reference Ranges", "Result abnormal flags", "Nature of Abnormality Testing", "Result Status", "Date of change in instruments normal values or units", "Operator ID", "Date/Time Test Started", "Date/Time Test Completed", "Instrument ID" };
foreach (var item in elementArray)
{
if (!Elements.ContainsKey(item))
{
Elements.Add(item, "");
}
}
string output = Constants.STX + Elements["FrameNumber"].Trim('R') + "R|";
// Concatenate the Dictionary values and return the string.
output += Elements["Sequence #"] + "|";
output += Elements["Universal Test ID"] + "|";
output += Elements["Data (result)"] + "|";
output += Elements["Units"] + "|";
output += Elements["Reference Ranges"] + "|";
output += Elements["Result abnormal flags"] + "|";
output += Elements["Nature of Abnormality Testing"] + "|";
output += Elements["Result Status"] + "|";
output += Elements["Date of change in instruments normal values or units"] + "|";
output += Elements["Operator ID"] + "|";
output += Elements["Date/Time Test Started"] + "|";
output += Elements["Date/Time Test Completed"] + "|";
output += Elements["Instrument ID"] + Constants.CR + Constants.ETX;
return output;
}
private void SetResultString(string input)
{
string[] inArray = input.Split('|');
if (inArray.Length < 14)
{
// Invalid number of elements.
throw new Exception($"Invalid number of elements in result record string. Expected: 14 \tFound: {inArray.Length} \tString: \n{input}");
}
Elements["FrameNumber"] = inArray[0];
Elements["Sequence #"] = inArray[1];
Elements["Universal Test ID"] = inArray[2];
Elements["Data (result)"] = inArray[3];
Elements["Units"] = inArray[4];
Elements["Reference Ranges"] = inArray[5];
Elements["Result abnormal flags"] = inArray[6];
Elements["Nature of Abnormality Testing"] = inArray[7];
Elements["Result Status"] = inArray[8];
Elements["Date of change in instruments normal values or units"] = inArray[9];
Elements["Operator ID"] = inArray[10];
Elements["Date/Time Test Started"] = inArray[11];
Elements["Date/Time Test Completed"] = inArray[12];
Elements["Instrument ID"] = inArray[13].Substring(0, inArray[13].IndexOf(Constants.CR));
}
public Result(string resultMessage)
{
SetResultString(resultMessage);
}
}
}