Skip to content

Commit db4f600

Browse files
committed
Numeric range bugfix.
1 parent a605be0 commit db4f600

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ Versions supported:
3535

3636
## Download
3737

38-
To download [the beta version of staging library - TNMStagingCSharp_v14.zip](https://github.com/imsweb/staging-client-csharp/releases/download/v1.4-beta/TNMStagingCSharp_v14.zip).
38+
To download [the beta version of staging library - TNMStagingCSharp_v15.zip](https://github.com/imsweb/staging-client-csharp/releases/download/v1.5-beta/TNMStagingCSharp_v15.zip).
3939

4040
The download zip file contains the TNM Staging DLL and associated files. For more information, please reference the accompanying readme.txt file. Detailed documentation on how to use the DLL can be found in the [Wiki](https://github.com/imsweb/staging-client-csharp/wiki/).
4141

4242
## Requirements
4343

4444
Functional Requirements: You will need the .NET Framework 4.5.2 or higher installed to use this library.
4545

46-
Data Requirements: You will need the algorithm data files for the TNM Staging Library to work properly. At present there are CS 02.05.50 and TNM 1.5 algorithms. You can find a copy of these data files within the TNM Staging source code in the Resources\Algorithms directory. The algorithm data files can be either in separate JSON files, or can be collected together in a compressed file such as .ZIP or .GZ. You can download the zip versions of [CS 02.05.50](https://github.com/imsweb/staging-client-csharp/releases/download/v1.0-beta/CS_02_05_50.zip) and [TNM 1.6](https://github.com/imsweb/staging-client-csharp/releases/download/v1.3-beta/TNM_16.zip) here.
46+
Data Requirements: You will need the algorithm data files for the TNM Staging Library to work properly. At present there are CS 02.05.50 and TNM 1.5 algorithms. You can find a copy of these data files within the TNM Staging source code in the Resources\Algorithms directory. The algorithm data files can be either in separate JSON files, or can be collected together in a compressed file such as .ZIP or .GZ. You can download the zip versions of [CS 02.05.50](https://github.com/imsweb/staging-client-csharp/releases/download/v1.5-beta/CS_02_05_50.zip) and [TNM 1.6](https://github.com/imsweb/staging-client-csharp/releases/download/v1.5-beta/TNM_16.zip) here.
4747

4848
## Usage
4949

TNMStagingCSharp/TNMStagingCSharp/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.4.0.0")]
36-
[assembly: AssemblyFileVersion("1.4.0.0")]
35+
[assembly: AssemblyVersion("1.5.0.0")]
36+
[assembly: AssemblyFileVersion("1.5.0.0")]

TNMStagingCSharp/TNMStagingCSharp/Src/Staging/StagingDataProvider.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public static List<Range> splitValues(String values)
281281
convertedRanges.Add(_MATCH_ALL_ENDPOINT);
282282
else
283283
{
284-
// split the string; the "-1" makes sure to not discard empty strings
284+
// split the string; the "9999" makes sure to not discard empty strings
285285
String[] ranges = values.Split(",".ToCharArray(), 9999);
286286

287287
foreach (String range in ranges)
@@ -294,11 +294,20 @@ public static List<Range> splitValues(String values)
294294
String[] parts = range.Split("-".ToCharArray());
295295
if (parts.Length == 2)
296296
{
297-
// don't worry about length differences if one of the parts is a context variable
298-
if (parts[0].Trim().Length != parts[1].Trim().Length && !DecisionEngineFuncs.isReferenceVariable(parts[0].Trim()) && !DecisionEngineFuncs.isReferenceVariable(parts[1].Trim()))
299-
convertedRanges.Add(new StagingRange(range.Trim(), range.Trim()));
297+
String low = parts[0].Trim();
298+
String high = parts[1].Trim();
299+
300+
// check if both sides of the range are numeric values; if so the length does not have to match
301+
bool isNumericRange = StagingRange.isNumeric(low) && StagingRange.isNumeric(high);
302+
303+
// if same length, a numeric range, or one of the parts is a context variable, use the low and high as range. Otherwise consier
304+
// a single value (i.e. low = high)
305+
if (low.Length == high.Length || isNumericRange || DecisionEngineFuncs.isReferenceVariable(low) || DecisionEngineFuncs.isReferenceVariable(high))
306+
convertedRanges.Add(new StagingRange(low, high));
300307
else
301-
convertedRanges.Add(new StagingRange(parts[0].Trim(), parts[1].Trim()));
308+
convertedRanges.Add(new StagingRange(range.Trim(), range.Trim()));
309+
310+
302311
}
303312
else
304313
convertedRanges.Add(new StagingRange(range.Trim(), range.Trim()));

TNMStagingCSharp/TNMStaging_UnitTestApp/Src/Staging/BasicStagingTest.cs

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ namespace TNMStaging_UnitTestApp.Src.Staging
1616
[TestClass]
1717
public class BasicStagingTest
1818
{
19-
protected static TNMStagingCSharp.Src.Staging.Staging _STAGING;
2019

21-
[ClassInitialize()]
22-
public static void ClassInit(TestContext context)
20+
[TestMethod]
21+
public void testBlankInputs()
2322
{
2423
InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0");
2524

@@ -113,14 +112,10 @@ public static void ClassInit(TestContext context)
113112

114113
provider.addSchema(schema);
115114

116-
_STAGING = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider);
117-
}
115+
TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider);
118116

119117

120-
[TestMethod]
121-
public void testBlankInputs()
122-
{
123-
Assert.AreEqual("schema_test", _STAGING.getSchema("schema_test").getId());
118+
Assert.AreEqual("schema_test", staging.getSchema("schema_test").getId());
124119

125120
// check case where required input field not supplied (i.e. no default); since there are is no workflow defined, this should
126121
// not cause an error
@@ -129,7 +124,7 @@ public void testBlankInputs()
129124
data.setInput("year_dx", "2018");
130125
data.setInput("input1", "1");
131126

132-
_STAGING.stage(data);
127+
staging.stage(data);
133128
Assert.AreEqual(StagingData.Result.STAGED, data.getResult());
134129

135130
// pass in blank for "input2"
@@ -138,7 +133,7 @@ public void testBlankInputs()
138133
data.setInput("input1", "1");
139134
data.setInput("input2", "");
140135

141-
_STAGING.stage(data);
136+
staging.stage(data);
142137
Assert.AreEqual(StagingData.Result.STAGED, data.getResult());
143138

144139
// pass in null for "input2"
@@ -148,10 +143,44 @@ public void testBlankInputs()
148143
data.setInput("input1", "1");
149144
data.setInput("input2", null);
150145

151-
_STAGING.stage(data);
146+
staging.stage(data);
152147
Assert.AreEqual(StagingData.Result.STAGED, data.getResult());
153148
}
154149

150+
[TestMethod]
151+
public void testNumericRangeTableMatch()
152+
{
153+
InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0");
154+
155+
StagingTable table = new StagingTable();
156+
table.setId("psa");
157+
StagingColumnDefinition def1 = new StagingColumnDefinition();
158+
def1.setKey("psa");
159+
def1.setName("PSA Value");
160+
def1.setType(ColumnType.INPUT);
161+
StagingColumnDefinition def2 = new StagingColumnDefinition();
162+
def2.setKey("description");
163+
def2.setName("PSA Description");
164+
def2.setType(ColumnType.DESCRIPTION);
165+
table.setColumnDefinitions(new List<IColumnDefinition>() { def1, def2 });
166+
table.setRawRows(new List<List<String>>());
167+
table.getRawRows().Add(new List<String>() { "0.1", "0.1 or less nanograms/milliliter (ng/ml)" });
168+
table.getRawRows().Add(new List<String>() { "0.2-999.9", "0.2 – 999.9 ng/ml" });
169+
provider.addTable(table);
170+
171+
TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider);
172+
173+
Assert.AreEqual(0, staging.findMatchingTableRow("psa", "psa", "0.1"));
174+
Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "0.2"));
175+
Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "500"));
176+
Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "500.99"));
177+
Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "500.0001"));
178+
Assert.AreEqual(1, staging.findMatchingTableRow("psa", "psa", "999.9"));
179+
Assert.AreEqual(-1, staging.findMatchingTableRow("psa", "psa", "1000"));
180+
Assert.AreEqual(-1, staging.findMatchingTableRow("psa", "psa", "-1"));
181+
Assert.AreEqual(-1, staging.findMatchingTableRow("psa", "psa", "0.01"));
182+
}
183+
155184
}
156185
}
157186

TNMStagingCSharp/TNMStaging_UnitTestApp/Src/Staging/StagingDataProviderTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,16 @@ public void testSplitValues()
121121
Assert.AreEqual("N0(mol-)", ranges[0].getLow());
122122
Assert.AreEqual("N0(mol-)", ranges[0].getHigh());
123123

124+
// test numeric ranges
124125
ranges = StagingDataProvider.splitValues("1-21");
125126
Assert.AreEqual(1, ranges.Count);
126-
Assert.AreEqual("1-21", ranges[0].getLow());
127-
Assert.AreEqual("1-21", ranges[0].getHigh());
127+
Assert.AreEqual("1", ranges[0].getLow());
128+
Assert.AreEqual("21", ranges[0].getHigh());
128129

129130
ranges = StagingDataProvider.splitValues("21-111");
130131
Assert.AreEqual(1, ranges.Count);
131-
Assert.AreEqual("21-111", ranges[0].getLow());
132-
Assert.AreEqual("21-111", ranges[0].getHigh());
132+
Assert.AreEqual("21", ranges[0].getLow());
133+
Assert.AreEqual("111", ranges[0].getHigh());
133134
}
134135

135136
[TestMethod]

0 commit comments

Comments
 (0)