Skip to content

Commit

Permalink
Tweaks to table row matching with numerics
Browse files Browse the repository at this point in the history
  • Loading branch information
ctmay4 committed Jan 21, 2025
1 parent 8e2d659 commit a0e8c9e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ void testFindTableRow() {
assertThat(_STAGING.findMatchingTableRow("tumor_size_clinical_60979", "size_clin", "999")).isEqualTo(Integer.valueOf(5));
}

@Test
void testFindTableRowDecimal() {
// only do float comparison of ranges if the low or high vaslues have a decimal
assertThat(_STAGING.findMatchingTableRow("age_at_diagnosis_validation_65093", "age_dx", "10.5")).isNull();

assertThat(_STAGING.findMatchingTableRow("age_at_diagnosis_validation_65093", "age_dx", "10")).isNotNull();
}

@Test
void testStagePancreas() {
EodStagingData data = new EodStagingInputBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ public boolean contains(String value, Map<String, String> context) {
String low = DecisionEngine.translateValue(_low, context);
String high = DecisionEngine.translateValue(_high, context);

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

// if the numeric range is not using decimals then don't allow the value to match with a decimal
if (!(low.contains(".") || high.contains(".")) && value.contains("."))
return false;

Float converted = NumberUtils.createFloat(value);

return converted >= NumberUtils.createFloat(low) && converted <= NumberUtils.createFloat(high);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void testNumericRanges() {
// nothing checks that a decimal is there. Non-decimal value will still be considered in the range.
assertTrue(new StagingRange("0.1", "99999.9").contains("1000", new HashMap<>()));

// however if the range do not contain decimals, then do not allow a mtch on decimals
assertFalse(new StagingRange("001", "999").contains("10.5", new HashMap<>()));
assertTrue(new StagingRange("001", "999").contains("10", new HashMap<>()));

assertFalse(new StagingRange("1.0", "999.999").contains("0.1", new HashMap<>()));
assertTrue(new StagingRange("1.0", "999.999").contains("1.000001", new HashMap<>()));
assertTrue(new StagingRange("1.0", "999.999").contains("1.9", new HashMap<>()));
Expand Down

0 comments on commit a0e8c9e

Please sign in to comment.