diff --git a/Tests/LabItemTest.cs b/Tests/LabItemTest.cs index a270dd6..3226d50 100755 --- a/Tests/LabItemTest.cs +++ b/Tests/LabItemTest.cs @@ -126,5 +126,14 @@ namespace Tests Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit"); // TODO: Define the behavior of LabItem.IsNormal if no normal value known } + + [TestCase("Albumin (SU)/die: 149.9 [<= 30] mg/d; ", Material.SU)] + [TestCase("Gesamt-Eiweiss/Creatinin (PU): 281 [<= 70] mg/g Crea;", Material.U)] + [TestCase("Cystatin C (N Latex): 2.37 [0.57 - 0.96] mg/l; ", Material.B)] + public void ParseLaurisMaterial(string laurisString, Material expectedMaterial) + { + LabItem i = new LabItem(laurisString); + Assert.AreEqual(expectedMaterial, i.Material); + } } } diff --git a/Tests/LaurisParagraphTest.cs b/Tests/LaurisParagraphTest.cs new file mode 100755 index 0000000..13985e4 --- /dev/null +++ b/Tests/LaurisParagraphTest.cs @@ -0,0 +1,36 @@ +/* LaurisParagraphTest.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 NUnit.Framework; +using zaaReloaded2.Models; + +namespace Tests +{ + [TestFixture] + class LaurisParagraphTest + { + [Test] + public void ParseParagraph() + { + string demo = "Klinische Chemie: Natrium: 139 [135 - 145] mmol/l;  " + + "Kalium: 5.2 [3.5 - 5] mmol/l;  Calcium: 2.4 [2.0 - 2.7] mmol/l;"; + LaurisParagraph lp = new LaurisParagraph(demo); + Assert.AreEqual(139, lp.Items["Natrium"].NumericalValue); + Assert.AreEqual(2.4, lp.Items["Calcium"].NumericalValue); + } + } +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 4f90ff6..60ff0c4 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -59,6 +59,7 @@ + @@ -76,6 +77,9 @@ + + + diff --git a/Tests/demo-output.txt b/Tests/demo-output.txt new file mode 100755 index 0000000..61287bb --- /dev/null +++ b/Tests/demo-output.txt @@ -0,0 +1,17 @@ +[22.10.2013 12:30:00] +Aerobe Kultur: Enterokokken ;  Wachstum: 10 ; +Auftragskommentare: Untersuchungsmaterial:: Mittelstrahlurin (nativ) ;  Befundstatus Auftrag: Endbefund ; +Urinproteine quantitativ: Gesamt-Eiweiss (PU): 135 [<= 120] mg/l;  Gesamt-Eiweiss/Creatinin (PU): 281 [<= 70] mg/g Crea;  Albumin (PU): 57 [<= 30] mg/l;  Albumin/Creatinin (PU): 118.8 [<= 30] mg/g Crea; +Urin - Klin. Chemie: Creatinin (PU): 48.0 [40 - 278] mg/dl; +Urinproteine quantitativ: Gesamt-Eiweiss (SU): 184 [<= 120] mg/l;  Gesamt-Eiweiss (SU)/die: 340 [<= 150] mg/d;  Albumin (SU): 81 mg/l;  Albumin (SU)/die: 149.9 [<= 30] mg/d;  a1-Microglobulin (SU): 35.3 mg/l;  a1-Microglobulin (SU)/die: 65.3 [<= 20] mg/d;  Immunglobulin G (SU): 8 mg/l;  Immunglobulin G (SU)/die: 14.8 [<= 15] mg/d; +Urin - Klin. Chemie: Sammelzeit (U): 24 h;  Sammelmenge (U): 1850 ml; +Klinische Chemie: Natrium: 139 [135 - 145] mmol/l;  Kalium: 5.2 [3.5 - 5] mmol/l;  Calcium: 2.4 [2.0 - 2.7] mmol/l;  anorg. Phosphat: 0.58 [0.87 - 1.45] mmol/l;  Calcium-Phosphat-Produkt: 1.39 [<= 4.4] mmol²/l²;  Glucose: 112 [74 - 106] mg/dl;  glomerul. Filtrationsr. CKD-EP: 42 ml/min /1,73qm;  glomerul. Filtrationsr. (MDRD): 42 ml/min /1,73qm;  Creatinin: 1.84 [0 - 1.17] mg/dl;  Harnstoff: 54.3 [10 - 50] mg/dl;  Harnsäure: 4.6 [3.4 - 7] mg/dl;  Gesamt-Bilirubin: 0.7 [0.1 - 1.2] mg/dl;  GOT (ASAT): 303.0 [<= 50] U/l;  GPT (ALAT): 508.0 [<= 50] U/l;  GGT: 489.0 [<= 60] U/l;  Alk. Phosphatase: 56 [40 - 130] U/l;  Lactat Dehydrogenase: 320 [<= 250] U/l;  CK gesamt: 52 [<= 190] U/l;  Amylase: 62 [<= 110] U/l;  Cholesterin: 120 [130 - 220] mg/dl;  Triglyceride: 94 [74 - 172] mg/dl;  LDL - Cholesterin: 56 [0 - 150] mg/dl;  HDL - Cholesterin: 45 [>= 35] mg/dl;  Eisen: 215 [59 - 158] µg/dl;  Gesamt-Eiweiss: 5.7 [6.6 - 8.7] g/dl;  Albumin: 4.0 [3.5 - 5.5] g/dl; +Gerinnung: Niedermol. Heparin (Anti-Xa): 0.99 U/ml; +Hämatologie: Leukozyten: 2.9 [5 - 10] n*1000/µl;  Erythrozyten: 3.23 [4 - 6] n*10E6/µl;  Hämoglobin: 10.1 [14 - 18] g/dl;  Hämatokrit: 30.8 [42 - 50] %;  MCV: 95.4 [82 - 94] fl;  MCH (HbE): 31.3 [27 - 33] pg;  MCHC: 32.8 [32 - 36] g/dl;  Thrombozyten: 112 [150 - 450] n*1000/µl;  Mittleres Plättchenvolumen: 11.1 [9.7 - 11.9] fl;  Neutrophile: 74.4 [41 - 70] %;  Lymphozyten: 13.0 [25 - 40] %;  Monozyten: 11.3 [2 - 8] %;  Eosinophile: 1.0 [0.8 - 6.2] %;  Basophile: 0.3 [0 - 1] %;  Neutrophile: 2.18 [1.8 - 7.2] n*1000/µl;  Lymphozyten: 0.38 [1 - 4.05] n*1000/µl;  Monozyten: 0.33 [0.08 - 0.8] n*1000/µl;  Eosinophile: 0.0 [0.04 - 0.36] n*1000/µl;  Basophile: 0.0 [0 - 0.08] n*1000/µl;  Unreife Granulozyten: 0.3 %; +Urinproteine quantitativ: Gesamt-Eiweiss (SU): 186 [<= 120] mg/l;  Gesamt-Eiweiss (SU)/die: 344 [<= 150] mg/d;  Albumin (SU): 79 mg/l;  Albumin (SU)/die: 146.2 [<= 30] mg/d; +Urin - Klin. Chemie: Sammelzeit (U): 24 h;  Sammelmenge (U): 1850 ml;  Creatinin-Clearance (SU)/min: 46 [98 - 156] ml/min;  Harnstoff-Clearance (SU)/min: 21 [60 - 80] ml/min;  glomeruläre Filtrationsrate: 34 ml/min;  Calcium (SU): 0.79 mmol/l;  Calcium (SU)/die: 1.46 [2.5 - 8] mmol/d;  Creatinin (SU): 65.5 mg/dl;  Harnstoff (SU): 904 [900 - 3000] mg/dl;  Harnstoff (SU)/die: 16.7 [<= 35] g/d;  Kalium (SU): 24.4 [20 - 80] mmol/l;  Kalium (SU)/die: 45.14 [25 - 125] mmol/d;  Natrium (SU): 133.2 [54 - 150] mmol/l;  Natrium (SU)/die: 246.4 [40 - 220] mmol/d; +Serumproteine und Tumormarker: Ferritin: 3754 [30 - 400] µg/l;  Transferrin: 217 [200 - 380] mg/dl;  Transferrinsättigung: 70.2 [16 - 45] %;  Haptoglobin: < 10 [34 - 200] mg/dl;  C-reaktives Protein: < 0.01 [0 - 0.5] mg/dl;  Cystatin C (N Latex): 2.37 [0.57 - 0.96] mg/l; +Akutbestimmungen / TDM / Drogen: Tacrolimus (FK506): 10.7 µg/l; +Klinische Chemie: Natrium: 140 [135 - 145] mmol/l;  Kalium: 5.2 [3.5 - 5] mmol/l;  Calcium: 2.3 [2.0 - 2.7] mmol/l;  anorg. Phosphat: 0.59 [0.87 - 1.45] mmol/l;  Chlorid: 109 [94 - 110] mmol/l;  Glucose: 114 [74 - 106] mg/dl;  glomerul. Filtrationsr. CKD-EP: 42 ml/min /1,73qm;  glomerul. Filtrationsr. (MDRD): 42 ml/min /1,73qm;  Creatinin: 1.85 [0 - 1.17] mg/dl;  Harnstoff: 56.1 [10 - 50] mg/dl;  Cholinesterase: 3387 [5320 - 12920] U/l;  Lactat Dehydrogenase: 318 [<= 250] U/l;  Gesamt-Eiweiss: 5.7 [6.6 - 8.7] g/dl;  Albumin: 3.9 [3.5 - 5.5] g/dl; +Serumproteine und Tumormarker: C-reaktives Protein: < 0.01 [0 - 0.5] mg/dl; +Akutbestimmungen / TDM / Drogen: PO2 (art.): 64.0 [70 - 100] mmHg;  PCO2 (art.): 36.3 [36 - 44] mmHg;  pH: 7.393 [7.36 - 7.44] ;  Basenabweichung: -2.4 [-2 - 2] mmol/l;  aktuelles Bicarbonat: 21.6 [22 - 26] mmol/l;  Standard Bicarbonat: 22.4 [22 - 26] mmol/l;  Sauerstoffsättigung (art.): 95.8 [95 - 99] %; diff --git a/zaaReloaded2/Defaults/parameters.txt b/zaaReloaded2/Defaults/parameters.txt index ce876eb..20cf176 100755 --- a/zaaReloaded2/Defaults/parameters.txt +++ b/zaaReloaded2/Defaults/parameters.txt @@ -1,117 +1,114 @@ # LAURIS-NAME "KANONISCHER NAME" MATERIAL "IMMER REFERENZBEREICH" # =========== ================== ======== ======================= -"Lactat Dehydrogenase" LDH S -"Cystatin C" --- S X -"glomerul. Filtrationsr. CKD-EP" "eGFR (CKD-EPI)" S -Übergangsepithelien (U) --- U -a1-Microglobulin (SU) --- SU -a1-Microglobulin (SU)/die --- SU -aktuelles Bicarbonat --- BGA -Albumin (PU) --- U -Albumin (SU) --- SU -Albumin (SU)/die --- SU -Albumin --- S -Albumin/Creatinin (PU) --- U -Alk. Phosphatase --- S -Amylase --- S -anorg. Phosphat --- S -Bakterien (U) --- U -Basenabweichung --- BGA -Basophile --- E -Bilirubin (U) --- U -C-reaktives Protein --- S -Calcium (SU) --- SU -Calcium (SU)/die --- SU -Calcium --- S -Calcium-Phosphat-Produkt --- S -Cholesterin --- S -CK gesamt --- S -CK MB --- S -Creatinin (PU) --- U -Creatinin (SU) --- SU -Creatinin --- S -Creatinin-Clearance (SU)/min --- SU -Cyclosporin-A vor Gabe --- S -Cystatin C (N Latex) --- S -Eisen --- S -Eosinophile --- E -Erythrozyten (U) --- U -Erythrozyten --- E -Ferritin --- S -Gesamt-Bilirubin --- S -Gesamt-Eiweiss (PU) --- U -Gesamt-Eiweiss (SU) --- SU -Gesamt-Eiweiss (SU)/die --- SU -Gesamt-Eiweiss --- S -Gesamt-Eiweiss/Creatinin (PU) --- U -GGT --- S -glomeruläre Filtrationsrate --- SU -glomerul. Filtrationsr. (MDRD) --- S -glomerul. Filtrationsr. CKD-EP --- S -Glucose (U) --- U -Glucose --- S -GOT (ASAT) --- S -GPT (ALAT) --- S -Hämatokrit --- E -Hämoglobin --- E -Haptoglobin --- S -Harnsäure --- S -Harnstoff (SU) --- SU -Harnstoff (SU)/die --- SU -Harnstoff --- S -Harnstoff-Clearance (SU)/min --- SU -HbA1c (NGSP) --- E -HDL - Cholesterin --- S -hyaline Zylinder (U) --- U -Kalium (SU) --- U -Kalium (SU)/die --- SU -Kalium --- S -Ketonkörper (U) --- U -Lactat Dehydrogenase --- S -LDL - Cholesterin --- S -Leukozyten (U) --- U -Leukozyten --- E -Lymphozyten --- E -MCH (HbE) --- E -MCHC --- E -MCV --- E -Mittleres Plättchenvolumen --- E -Monozyten --- E -Natrium (SU) --- SU -Natrium (SU)/die --- SU -Natrium --- S -Neutrophile --- E -Nitrit (U) --- U -NT-proBNP --- S -PCO2 (art.) --- BGA -pH (U) --- U -pH --- BGA -Plattenepithelien (U) --- U -PO2 (art.) --- BGA -Protein (U) --- U -Sammelmenge (U) --- SU -Sammelzeit (U) --- SU -Sauerstoffsättigung (art.) --- BGA -Sirolimus --- S -spezifisches Gewicht (U) --- U -Standard Bicarbonat --- BGA -Tacrolimus (FK506) --- S -Thrombozyten --- E -Transferrin --- S -Transferrinsättigung --- S -Triglyceride --- S -Troponin T (high sensitive) --- S -Unreife Granulozyten --- E -Urobilinogen (U) --- U -Niedermol. Heparin (Anti-Xa) --- Z -Thromboplastinzeit n. Quick --- Z -PTT --- Z -Ratio int. norm. --- Z -Komplementfaktor C3c --- S -Komplementfaktor C4 --- S -Anti-DNAse B --- S -Anti-Streptolysin --- S -PTH intakt --- S -TSH --- S -HAPTOGLOBIN --- S -FRAGMENTOZYTEN --- E +"Übergangsepithelien (U)" Übergangsep. U +"a1-Microglobulin (SU)" a1-Microglobulin SU +"a1-Microglobulin (SU)/die" a1-Microglobulin SU +"aktuelles Bicarbonat" Bic BGA +"Albumin (PU)" Alb U +"Albumin (SU)" Alb SU +"Albumin (SU)/die" Alb SU +Albumin Alb S +Albumin/Creatinin (PU)" ACR U +"Alk. Phosphatase" AP S +Amylase Amylase S +anorg. Phosphat" Phosphat S +Bakterien (U)" Bakt U +Basenabweichung BE BGA +Basophile Baso E +Bilirubin (U)" Bilirubin U +C-reaktives Protein" CRP S +Calcium (SU)" Ca SU +Calcium (SU)/die" Ca SU +Calcium Ca S +Calcium-Phosphat-Produkt CaxP S +Cholesterin Chol S +CK gesamt" CK S +CK MB" CK-MB S +Creatinin (PU)" Krea U +Creatinin (SU)" Krea SU +Creatinin Krea S +Creatinin-Clearance (SU)/min" CrCl SU +Cyclosporin-A vor Gabe" "CsA (C0)" S X +Cystatin C (N Latex)" "Cystatin C" S X +Eisen Fe S +Eosinophile Eos E +Erythrozyten (U)" Ery U +Erythrozyten Ery E +Ferritin Ferr S +Gesamt-Bilirubin Bilirubin S +Gesamt-Eiweiss (PU)" Protein U +Gesamt-Eiweiss (SU)" Protein SU +Gesamt-Eiweiss (SU)/die" Proteinurie SU +Gesamt-Eiweiss Protein S +Gesamt-Eiweiss/Creatinin (PU)" TPCR U +GGT GGT S +glomeruläre Filtrationsrate" GFR SU +glomerul. Filtrationsr. (MDRD)" "eGFR (MDRD)" S +glomerul. Filtrationsr. CKD-EP" "eGFR (CKD-EPI)" S +Glucose (U)" Glukose U +Glucose Glukose S +GOT (ASAT)" GOT S +GPT (ALAT)" GPT S +Hämatokrit Hkt E +Hämoglobin Hb E +Haptoglobin Haptoglobin S X +Harnsäure Harnsäure S +Harnstoff (SU)" Hst SU +Harnstoff (SU)/die" Hst/Tag SU +Harnstoff" Hst S +Harnstoff-Clearance (SU)/min" HstCl SU +HbA1c (NGSP)" HbA1c E +HDL - Cholesterin" HDL S +hyaline Zylinder (U)" "hyal. Zyl." U +Kalium (SU)" K U +Kalium (SU)/die" K SU +Kalium K S +Ketonkörper (U)" KK U +Lactat Dehydrogenase" LDH S +LDL - Cholesterin" LDL S +Leukozyten (U)" Leu U +Leukozyten Leu E +Lymphozyten Lym E +MCH (HbE) MCH E +MCHC MCHC E +MCV MCV E +Mittleres Plättchenvolumen MPV E +Monozyten Mon E +Natrium (SU)" Na SU +Natrium (SU)/die" Na SU +Natrium Na S +Neutrophile Neu E +Nitrit (U)" Nitrit U +NT-proBNP NT-proBNP S +PCO2 (art.)" pCO2 BGA +pH (U)" pH U +pH" pH BGA +Plattenepithelien (U)" Plattenep U +PO2 (art.)" pO2 BGA +Protein (U)" Protein U +Sammelmenge (U)" Volumen SU +Sammelzeit (U)" Zeit SU +Sauerstoffsättigung (art.)" SO2 BGA +Sirolimus SIR S +spezifisches Gewicht (U)" "spez. Gew." U +Standard Bicarbonat" "Std.-Bic." BGA +Tacrolimus (FK506)" TAC S +Thrombozyten Thr E +Transferrin Transferrin S +Transferrinsättigung" Tf.-Sätt. S +Triglyceride" TG S +Troponin T (high sensitive)" hsTnT S +Unreife Granulozyten" Gran E +Urobilinogen (U)" Urobilinogen U +Niedermol. Heparin (Anti-Xa)" Anti-Xa Z +Thromboplastinzeit n. Quick" Quick Z +PTT aPTT Z +Ratio int. norm." INR Z +Komplementfaktor C3c C3c S X +Komplementfaktor C4 C4 S X +Anti-DNAse B "Anti-DNAse B" S +Anti-Streptolysin ASL S +PTH intakt" iPTH S +TSH TSH S +HAPTOGLOBIN Haptoglobin S +FRAGMENTOZYTEN Fragmentozyten E diff --git a/zaaReloaded2/Dictionaries/ParameterDictionary.cs b/zaaReloaded2/Dictionaries/ParameterDictionary.cs index 0a8c4c1..bf5a7b1 100755 --- a/zaaReloaded2/Dictionaries/ParameterDictionary.cs +++ b/zaaReloaded2/Dictionaries/ParameterDictionary.cs @@ -30,7 +30,7 @@ namespace zaaReloaded2.Dictionaries /// canonical parameter names, and to assign categories and determine /// which parameters always require the output of reference intervals. /// - class ParameterDictionary : DictionaryBase + public class ParameterDictionary : DictionaryBase { #region Public methods @@ -49,19 +49,18 @@ namespace zaaReloaded2.Dictionaries /// Looks up the material for a given . /// /// Lauris item name to look up. - /// enum; if no material is + /// enum; if no material is /// found in the dictionary, the default material "S" (serum) is returned. - public Materials GetMaterial(string laurisName) + public Material GetMaterial(string laurisName) { string textValue = LookUpValue(laurisName, 2); try { - Materials m = (Materials)Enum.Parse(typeof(Materials), textValue, true); - return m; + return MaterialFactory.FromAbbreviation(textValue); } catch { - return Materials.S; + return Material.B; } } diff --git a/zaaReloaded2/Dictionaries/UnitDictionary.cs b/zaaReloaded2/Dictionaries/UnitDictionary.cs index 534caa4..0b4e4a1 100755 --- a/zaaReloaded2/Dictionaries/UnitDictionary.cs +++ b/zaaReloaded2/Dictionaries/UnitDictionary.cs @@ -28,7 +28,7 @@ namespace zaaReloaded2.Dictionaries /// Dictionary that is used to convert Lauris units to canonical /// zaaReloaded2 units. /// - class UnitDictionary : DictionaryBase + public class UnitDictionary : DictionaryBase { #region Public methods diff --git a/zaaReloaded2/Models/LabItem.cs b/zaaReloaded2/Models/LabItem.cs index 0ec8b12..d321ab5 100755 --- a/zaaReloaded2/Models/LabItem.cs +++ b/zaaReloaded2/Models/LabItem.cs @@ -172,9 +172,29 @@ namespace zaaReloaded2.Models /// public string CanonicalName { get; private set; } + /// + /// Returns the canonical name prefixed with the abbreviation + /// for the material, e.g. "U-Na" for sodium in the spot urine, + /// but only if the material is not blood. + /// + public string QualifiedCanonicalName + { + get + { + if (Material == Models.Material.B) + { + return CanonicalName; + } + else + { + return String.Format("{0}-{1}", Material.ToString(), CanonicalName); + } + } + } + public bool AlwaysPrintLimits { get; private set; } - public Materials Material { get; private set; } + public Material Material { get; private set; } #endregion @@ -185,15 +205,11 @@ namespace zaaReloaded2.Models /// public LabItem() { } - /// - /// Creates a LabItem object from a given Lauris output. - /// - /// Lauris output to parse. public LabItem(string laurisString) - :this() { Lauris = laurisString; ParseLauris(); + DetectMaterial(); } /// @@ -203,15 +219,27 @@ namespace zaaReloaded2.Models /// to always print the reference interval). /// /// Lauris output to parse. - /// ParameterDictionary that is used + /// ParameterDictionary that is used /// to look up the canonical name, material type, and whether or /// not to always print the reference interval - public LabItem(string laurisString, Dictionaries.ParameterDictionary dictionary) + public LabItem(string laurisString, + Dictionaries.ParameterDictionary parameterDictionary, + Dictionaries.UnitDictionary unitDictionary) : this(laurisString) { - CanonicalName = dictionary.GetCanonicalName(Name); - AlwaysPrintLimits = dictionary.GetForceReferenceDisplay(Name); - Material = dictionary.GetMaterial(Name); + if (parameterDictionary != null) + { + CanonicalName = parameterDictionary.GetCanonicalName(Name); + AlwaysPrintLimits = parameterDictionary.GetForceReferenceDisplay(Name); + } + else + { + CanonicalName = Name; + } + if (unitDictionary != null) + { + Unit = unitDictionary.TranslateLaurisUnit(Unit); + } } #endregion @@ -222,7 +250,7 @@ namespace zaaReloaded2.Models /// Parses the original Lauris string contained in /// . /// - private void ParseLauris() + void ParseLauris() { // Examples of Lauris output strings: // "Natrium: 139 [135 - 145] mmol/l" @@ -294,6 +322,32 @@ namespace zaaReloaded2.Models } } + /// + /// Analyses the Lauris name for a material abbreviation. + /// If the parameter does not refer to blood (serum, whole + /// blood, etc.), Lauris appends an abbreviation in parentheses + /// to the parameter name. + /// + /// + /// Gesamt-Eiweiss (SU), Albumin (SU)/die, Gesamt-Eiweiss (PU) + /// + void DetectMaterial() + { + Match m = _materialRegex.Match(Name); + if (m.Success) + { + switch (m.Groups["material"].Value.ToUpper()) + { + case "SU": + Material = Models.Material.SU; + break; + case "PU": + Material = Models.Material.U; + break; + } + } + } + #endregion #region Fields @@ -301,6 +355,7 @@ namespace zaaReloaded2.Models double _numericalValue; double _lowerLimit; double _upperLimit; + static readonly Regex _materialRegex = new Regex(@"\((?(SU|PU))\)"); #endregion } diff --git a/zaaReloaded2/Models/LaurisParagraph.cs b/zaaReloaded2/Models/LaurisParagraph.cs new file mode 100755 index 0000000..3983c0e --- /dev/null +++ b/zaaReloaded2/Models/LaurisParagraph.cs @@ -0,0 +1,129 @@ +/* LaurisParagraph.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.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace zaaReloaded2.Models +{ + /// + /// Parses an entire Lauris paragraph (such as "Klinische Chemie: ...") + /// and creates a list of s. + /// + public class LaurisParagraph + { + #region Public properties + + /// + /// Gets a collection of s found in this paragraph. + /// + public IDictionary Items { get; private set; } + + /// + /// Gets the caption that was extracted from the , + /// e.g. "Klin. Chemie" in "Klin. Chemie: Natrium ...". + /// + public string Caption { get; private set; } + + /// + /// Gets the original paragraph that this object was constructed from. + /// + public string OriginalParagraph { get; private set; } + + /// + /// Is true if the matches the expected + /// format and contains s. + /// + public bool IsLaurisParagraph { get; private set; } + + #endregion + + #region Constructor + + public LaurisParagraph(string paragraph) + { + OriginalParagraph = paragraph; + Parse(); + } + + /// + /// Constructs a object from a given + /// Lauris paragraph, using a + /// and a to translate the individual + /// items' properties. + /// + /// lauris paragraph to parse. + /// ParameterDictionary that contains + /// canonical names and material types. + /// Unit dictionary that contains canonical + /// unit names. + public LaurisParagraph(string paragraph, + Dictionaries.ParameterDictionary parameterDictionary, + Dictionaries.UnitDictionary unitDictionary) + { + OriginalParagraph = paragraph; + _parameterDictionary = parameterDictionary; + _unitDictionary = unitDictionary; + Parse(); + } + + #endregion + + #region Private methods + + /// + /// Attempts to parse a Lauris paragraph. + /// + void Parse() + { + Match m = _expectedFormat.Match(OriginalParagraph); + if (m.Success) + { + Items = new Dictionary(); + if (m.Groups["caption"].Success) + { + Caption = m.Groups["caption"].Value.Trim(new char[] {' ', ':'}); + } + + foreach (Capture itemCapture in m.Groups["items"].Captures) + { + LabItem i = new LabItem(itemCapture.Value, _parameterDictionary, _unitDictionary); + Items.Add(i.QualifiedCanonicalName, i); + } + IsLaurisParagraph = Items.Count > 0; + } + else + { + IsLaurisParagraph = false; + } + } + + #endregion + + #region Fields + + static readonly Regex _expectedFormat = new Regex(@"(?[^:]+:\s*)?(?[^:]+:\s*[^;]+;)*"); + Dictionaries.ParameterDictionary _parameterDictionary; + Dictionaries.UnitDictionary _unitDictionary; + + #endregion + } +} diff --git a/zaaReloaded2/Models/Materials.cs b/zaaReloaded2/Models/Material.cs similarity index 57% rename from zaaReloaded2/Models/Materials.cs rename to zaaReloaded2/Models/Material.cs index 318c23b..e634519 100755 --- a/zaaReloaded2/Models/Materials.cs +++ b/zaaReloaded2/Models/Material.cs @@ -26,34 +26,32 @@ namespace zaaReloaded2.Models /// /// Enumerates the known materials. /// - enum Materials + public enum Material { - [Description("Serum")] - /// Serum - S, - [Description("Plasma")] - /// Plasma - P, - [Description("EDTA-Blut")] - /// EDTA-Blut - E, - [Description("BGA")] - /// BGA - BGA, - [Description("Zitrat")] - /// Zitrat-Blut - Z, - [Description("Laktat")] - /// Laktat-Blut - L, + [Description("Blut")] + /// Blood + B, [Description("Urin")] - /// Urin (Spoturin) + /// Urine (spot) U, [Description("Sammelurin")] - /// Sammelurin + /// Collected urine SU, - [Description("Sondermaterial")] - /// Sondermaterial - X + } + + /// + /// Contains factory methods to create Material values. + /// + public static class MaterialFactory + { + /// + /// Creates a value from an abbreviation of a material. + /// + /// Abbreviation of a material. + /// Materials value. + public static Material FromAbbreviation(string abbreviation) + { + return (Material)Enum.Parse(typeof(Material), abbreviation, true); + } } } diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 0e8df32..0ec9ef0 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -165,7 +165,8 @@ - + + Code