diff --git a/Tests/LineParserTest.cs b/Tests/LineParserTest.cs new file mode 100755 index 0000000..07e5d03 --- /dev/null +++ b/Tests/LineParserTest.cs @@ -0,0 +1,65 @@ +/* UnitTest1.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 NUnit.Framework; +using zaaReloaded2.Dictionaries; + +namespace Tests +{ + [TestFixture] + class LineParserTest + { + [Test] + public void ParseSimpleLine() + { + LineParser lp = new LineParser(); + lp.Line = "this is a simple line"; + Assert.AreEqual("this", lp.Fields[0]); + Assert.AreEqual("simple", lp.Fields[3]); + } + + [Test] + public void ParseSimpleLineWithComment() + { + LineParser lp = new LineParser(); + lp.Line = "this is a simple line # with a comment"; + Assert.AreEqual("this", lp.Fields[0]); + Assert.AreEqual("simple", lp.Fields[3]); + Assert.AreEqual(5, lp.Fields.Length); + } + + [Test] + public void ParseLineWithQuotes() + { + LineParser lp = new LineParser(); + lp.Line = "this \"is a\" simple line"; + Assert.AreEqual("simple", lp.Fields[2]); + Assert.AreEqual("line", lp.Fields[3]); + } + + [Test] + public void ParseLineWithQuotesAndPunctuation() + { + LineParser lp = new LineParser(); + lp.Line = "this-is \"a , simple ;\" line"; + Assert.AreEqual("this-is", lp.Fields[0]); + Assert.AreEqual("a , simple ;", lp.Fields[1]); + Assert.AreEqual("line", lp.Fields[2]); + } + } +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 83fb960..497a060 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -59,6 +59,7 @@ + diff --git a/zaaReloaded2/Defaults/parameters.txt b/zaaReloaded2/Defaults/parameters.txt new file mode 100755 index 0000000..724f045 --- /dev/null +++ b/zaaReloaded2/Defaults/parameters.txt @@ -0,0 +1,5 @@ +# LAURIS-NAME "KANONISCHER NAME" KATEGORIE "IMMER REFERENZBEREICH" +# =========== ================== ========= ======================= +"Lactat Dehydrogenase" LDH Klinische Chemie +"Cystatin C" --- Nierenfunktion X +"glomerul. Filtrationsr. CKD-EP" "eGFR (CKD-EPI)" Nierenfunktion \ No newline at end of file diff --git a/zaaReloaded2/Defaults/units.txt b/zaaReloaded2/Defaults/units.txt new file mode 100755 index 0000000..1c42357 --- /dev/null +++ b/zaaReloaded2/Defaults/units.txt @@ -0,0 +1,3 @@ +# LAURIS-EINHEIT "KANONISCHE EINHEIT" +# ============== ==================== +"ml/min/ 1,73qm" "ml/min/1,73 m²" \ No newline at end of file diff --git a/zaaReloaded2/Dictionaries/DictionaryBase.cs b/zaaReloaded2/Dictionaries/DictionaryBase.cs new file mode 100755 index 0000000..88aeabd --- /dev/null +++ b/zaaReloaded2/Dictionaries/DictionaryBase.cs @@ -0,0 +1,33 @@ +/* DictionaryBase.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.Linq; +using System.Text; + +namespace zaaReloaded2.Dictionaries +{ + /// + /// Base class for the + /// and the ; implements methods + /// to read configuration files. + /// + abstract class DictionaryBase + { + } +} diff --git a/zaaReloaded2/Dictionaries/LineParser.cs b/zaaReloaded2/Dictionaries/LineParser.cs new file mode 100755 index 0000000..11b420c --- /dev/null +++ b/zaaReloaded2/Dictionaries/LineParser.cs @@ -0,0 +1,81 @@ +/* LineParser.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.Linq; +using System.Text.RegularExpressions; + +namespace zaaReloaded2.Dictionaries +{ + /// + /// Simple parser that separates a line from a text file into + /// space-separated fields; field values that contain spaces must + /// be enclosed by double quotation marks. + /// + /// + /// Everything after a hash (#) will be ignored. + /// + public class LineParser + { + #region Public properties + + /// + /// Gets or sets the line being parsed. + /// + public string Line + { + get + { + return _line; + } + set + { + _line = value; + ParseLine(); + } + } + + /// + /// Gets an array of fields in the line. + /// + public string[] Fields { get; private set; } + + #endregion + + #region Private methods + + void ParseLine() + { + string s = Line.Split('#')[0]; + Fields = _parser + .Matches(s) + .Cast() + .Select(m => m.Groups["match"].Value) + .ToArray(); + } + + #endregion + + #region Fields + + // Regex modified after http://stackoverflow.com/a/554068/270712 + static readonly Regex _parser = new Regex(@"(?[^\s""]+)|\""(?[^""]*)"""); + string _line; + + #endregion + } +} diff --git a/zaaReloaded2/Dictionaries/ParameterDictionary.cs b/zaaReloaded2/Dictionaries/ParameterDictionary.cs new file mode 100755 index 0000000..4a13252 --- /dev/null +++ b/zaaReloaded2/Dictionaries/ParameterDictionary.cs @@ -0,0 +1,33 @@ +/* ParameterDictionary.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.Linq; +using System.Text; + +namespace zaaReloaded2.Dictionaries +{ + /// + /// Dictionary 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. + /// + class ParameterDictionary : DictionaryBase + { + } +} diff --git a/zaaReloaded2/Dictionaries/UnitDictionary.cs b/zaaReloaded2/Dictionaries/UnitDictionary.cs new file mode 100755 index 0000000..2257eee --- /dev/null +++ b/zaaReloaded2/Dictionaries/UnitDictionary.cs @@ -0,0 +1,32 @@ +/* UnitDictionary.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.Linq; +using System.Text; + +namespace zaaReloaded2.Dictionaries +{ + /// + /// Dictionary that is used to convert Lauris units to canonical + /// zaaReloaded2 units. + /// + class UnitDictionary : DictionaryBase + { + } +} diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 43f5e5a..039ab10 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -160,6 +160,10 @@ can be found. --> + + + + Code @@ -193,9 +197,10 @@ - - - + + + + 10.0