Created
January 14, 2020 20:49
-
-
Save ctmay4/806cf6a32d68de0dcbb297de5a8ee40a to your computer and use it in GitHub Desktop.
Generic field description lookup for staging-client-java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the description of a staging field value. This will work for any field with a lookup and will return the first | |
* description field from the matching row. It will return null if there is not a match on schema, field, or table row. | |
*/ | |
public static String getFieldValueDescription(StagingSchema schema, String field, String value) { | |
if (schema == null) | |
return null; | |
// get the correct staging module | |
Staging staging; | |
switch (schema.getAlgorithm()) { | |
case "eod": | |
staging = _EOD_STAGING; | |
break; | |
case "tnm": | |
staging = _TNM_STAGING; | |
break; | |
case "cs": | |
staging = _CS_STAGING; | |
break; | |
default: | |
throw new IllegalStateException("Unknown staging algorithm: " + schema.getAlgorithm()); | |
} | |
StagingSchemaInput input = schema.getInputMap().get(field); | |
// make sure field is found and there is a table | |
if (input == null || input.getTable() == null) | |
return null; | |
// get the StagingTable | |
StagingTable table = staging.getTable(input.getTable()); | |
if (table == null) | |
return null; | |
Integer rowNum = staging.findMatchingTableRow(table.getId(), field, value); | |
if (rowNum == null) | |
return null; | |
String description = null; | |
for (int i = 0; i < table.getColumnDefinitions().size(); i++) | |
if (table.getColumnDefinitions().get(i).getType().equals(DESCRIPTION)) { | |
description = table.getRawRows().get(rowNum).get(i); | |
break; | |
} | |
return description; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testGetFieldValueDescription() { | |
Staging stage = StagingUtils.getEodStagingInstance(); | |
// first test EOD | |
// test single value match | |
Assert.assertEquals("Well differentiated", StagingUtils.getFieldValueDescription(stage.getSchema("breast"), "grade_post_therapy", "A")); | |
// test range match | |
Assert.assertEquals("Reported HER2 copy number of 0.0-99.9", StagingUtils.getFieldValueDescription(stage.getSchema("breast"), "her2_ish_sp_copy_no", "90.0")); | |
// test bad values | |
Assert.assertNull(StagingUtils.getFieldValueDescription(stage.getSchema("bad_schema"), "test", "test")); | |
Assert.assertNull(StagingUtils.getFieldValueDescription(stage.getSchema("lung"), "bad_field", "test")); | |
Assert.assertNull(StagingUtils.getFieldValueDescription(stage.getSchema("lung"), "grade_clin", "bad_value")); | |
// try with CS | |
stage = StagingUtils.getCsStagingInstance(); | |
Assert.assertEquals("TD identified, number unknown", StagingUtils.getFieldValueDescription(stage.getSchema("colon"), "ssf4", "990")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment