Skip to content

Commit 6a5439a

Browse files
authored
Merge pull request #113 from imsweb/numeric-contains
Tweaks to table row matching with numerics
2 parents 4287f4c + 87c3bf7 commit 6a5439a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

algorithm-eod/src/test/java/com/imsweb/staging/eod/EodStagingTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ void testFindTableRow() {
214214
assertThat(_STAGING.findMatchingTableRow("tumor_size_clinical_60979", "size_clin", "999")).isEqualTo(Integer.valueOf(5));
215215
}
216216

217+
@Test
218+
void testFindTableRowDecimal() {
219+
// only do float comparison of ranges if the low or high vaslues have a decimal
220+
assertThat(_STAGING.findMatchingTableRow("age_at_diagnosis_validation_65093", "age_dx", "10.5")).isNull();
221+
222+
assertThat(_STAGING.findMatchingTableRow("age_at_diagnosis_validation_65093", "age_dx", "10")).isNotNull();
223+
}
224+
217225
@Test
218226
void testStagePancreas() {
219227
EodStagingData data = new EodStagingInputBuilder()

lib/src/main/java/com/imsweb/staging/entities/impl/StagingRange.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ public boolean contains(String value, Map<String, String> context) {
8181
String low = DecisionEngine.translateValue(_low, context);
8282
String high = DecisionEngine.translateValue(_high, context);
8383

84-
// if input, low and high values represent decimal numbers then do a float comparison
84+
// if input, low and high values represent numbers then do a float comparison
8585
if (!low.equals(high) && NumberUtils.isParsable(low) && NumberUtils.isParsable(high)) {
8686
if (!NumberUtils.isParsable(value))
8787
return false;
8888

89+
// if the numeric range is not using decimals then don't allow the value to match with a decimal
90+
if (!(low.contains(".") || high.contains(".")) && value.contains("."))
91+
return false;
92+
8993
Float converted = NumberUtils.createFloat(value);
9094

9195
return converted >= NumberUtils.createFloat(low) && converted <= NumberUtils.createFloat(high);

lib/src/test/java/com/imsweb/staging/entities/StagingRangeTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ void testNumericRanges() {
9696
// nothing checks that a decimal is there. Non-decimal value will still be considered in the range.
9797
assertTrue(new StagingRange("0.1", "99999.9").contains("1000", new HashMap<>()));
9898

99+
// however if the range do not contain decimals, then do not allow a mtch on decimals
100+
assertFalse(new StagingRange("001", "999").contains("10.5", new HashMap<>()));
101+
assertTrue(new StagingRange("001.1", "999").contains("10.5", new HashMap<>()));
102+
assertTrue(new StagingRange("001", "999.99").contains("10.5", new HashMap<>()));
103+
assertTrue(new StagingRange("001", "999").contains("10", new HashMap<>()));
104+
99105
assertFalse(new StagingRange("1.0", "999.999").contains("0.1", new HashMap<>()));
100106
assertTrue(new StagingRange("1.0", "999.999").contains("1.000001", new HashMap<>()));
101107
assertTrue(new StagingRange("1.0", "999.999").contains("1.9", new HashMap<>()));

0 commit comments

Comments
 (0)