public void testBlankInputs() { InMemoryDataProvider provider = new InMemoryDataProvider("test", "1.0"); StagingTable table = new StagingTable(); table.setId("table_input1"); StagingColumnDefinition def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); StagingColumnDefinition def2 = new StagingColumnDefinition(); def2.setKey("result1"); def2.setName("Result1"); def2.setType(ColumnType.DESCRIPTION); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1", "ONE" }); table.getRawRows().Add(new List <String>() { "2", "TWO" }); provider.addTable(table); table = new StagingTable(); table.setId("table_input2"); def1 = new StagingColumnDefinition(); def1.setKey("input2"); def1.setName("Input 2"); def1.setType(ColumnType.INPUT); def2 = new StagingColumnDefinition(); def2.setKey("result2"); def2.setName("Result2"); def2.setType(ColumnType.DESCRIPTION); table.setColumnDefinitions(new List <IColumnDefinition>() { def1, def2 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "", "Blank" }); table.getRawRows().Add(new List <String>() { "A", "Letter A" }); table.getRawRows().Add(new List <String>() { "B", "Letter B" }); provider.addTable(table); table = new StagingTable(); table.setId("table_selection"); def1 = new StagingColumnDefinition(); def1.setKey("input1"); def1.setName("Input 1"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "*" }); provider.addTable(table); table = new StagingTable(); table.setId("primary_site"); def1 = new StagingColumnDefinition(); def1.setKey("site"); def1.setName("Site"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "C509" }); provider.addTable(table); table = new StagingTable(); table.setId("histology"); def1 = new StagingColumnDefinition(); def1.setKey("hist"); def1.setName("Histology"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "8000" }); provider.addTable(table); table = new StagingTable(); table.setId("table_year_dx"); def1 = new StagingColumnDefinition(); def1.setKey("year_dx"); def1.setName("Year DX"); def1.setType(ColumnType.INPUT); table.setColumnDefinitions(new List <IColumnDefinition>() { def1 }); table.setRawRows(new List <List <String> >()); table.getRawRows().Add(new List <String>() { "1900-2100" }); provider.addTable(table); StagingSchema schema = new StagingSchema(); schema.setId("schema_test"); schema.setSchemaSelectionTable("table_selection"); List <StagingSchemaInput> inputs = new List <StagingSchemaInput>(); inputs.Add(new StagingSchemaInput("site", "Primary Site", "primary_site")); inputs.Add(new StagingSchemaInput("hist", "Hist", "histology")); inputs.Add(new StagingSchemaInput("year_dx", "Year DX", "table_year_dx")); inputs.Add(new StagingSchemaInput("input1", "Input 1", "table_input1")); inputs.Add(new StagingSchemaInput("input2", "Input 2", "table_input2")); schema.setInputs(inputs); provider.addSchema(schema); TNMStagingCSharp.Src.Staging.Staging staging = TNMStagingCSharp.Src.Staging.Staging.getInstance(provider); Assert.AreEqual("schema_test", staging.getSchema("schema_test").getId()); // check case where required input field not supplied (i.e. no default); since there are is no workflow defined, this should // not cause an error StagingData data = new StagingData("C509", "8000"); data.setInput("year_dx", "2018"); data.setInput("input1", "1"); staging.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); // pass in blank for "input2" data = new StagingData("C509", "8000"); data.setInput("year_dx", "2018"); data.setInput("input1", "1"); data.setInput("input2", ""); staging.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); // pass in null for "input2" data = new StagingData("C509", "8000"); data.setInput("year_dx", "2018"); data.setInput("input1", "1"); data.setInput("input2", null); staging.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); }
public static void MultiTask_TaskCompute(int id, Object task_data) { MultiTask_DataObj thisDataObj = (MultiTask_DataObj)task_data; try { // load up inputs TnmStagingData data = new TnmStagingData(); foreach (KeyValuePair <TnmInput, String> kp in thisDataObj.mInputValues) { data.setInput(kp.Key, kp.Value); } // save the expected outputs Dictionary <String, String> output = new Dictionary <String, String>(100, StringComparer.Ordinal); String sKeyValue = ""; foreach (KeyValuePair <TnmOutput, String> entry in thisDataObj.mOutputValues) { sKeyValue = entry.Key.toString(); output[sKeyValue] = entry.Value; } // run collaborative stage; if no schema found, set the output to empty SchemaLookup lookup = new SchemaLookup(data.getInput(TnmInput.PRIMARY_SITE), data.getInput(TnmInput.HISTOLOGY)); lookup.setInput(TnmStagingData.SEX_KEY, data.getInput(TnmInput.SEX)); lookup.setInput(TnmStagingData.SSF25_KEY, data.getInput(TnmInput.SSF25)); List <StagingSchema> schemas = mMultiTask_Staging.lookupSchema(lookup); if (schemas.Count == 1) { mMultiTask_Staging.stage(data); } else { Dictionary <String, String> outResult = new Dictionary <String, String>(2, StringComparer.Ordinal); outResult["schema_id"] = "<invalid>"; data.setOutput(outResult); } List <String> mismatches = new List <String>(); // compare results if (!thisDataObj.mbJSONFormat) { String sNewResultStr = ""; String sOldResultStr = thisDataObj.msExpectedResult.Trim(); if (data.getResult() == StagingData.Result.STAGED) { sNewResultStr = "STAGED"; } else if (data.getResult() == StagingData.Result.FAILED_MISSING_SITE_OR_HISTOLOGY) { sNewResultStr = "FAILED_MISSING_SITE_OR_HISTOLOGY"; } else if (data.getResult() == StagingData.Result.FAILED_NO_MATCHING_SCHEMA) { sNewResultStr = "FAILED_NO_MATCHING_SCHEMA"; } else if (data.getResult() == StagingData.Result.FAILED_MULITPLE_MATCHING_SCHEMAS) { sNewResultStr = "FAILED_MULITPLE_MATCHING_SCHEMAS"; } else if (data.getResult() == StagingData.Result.FAILED_INVALID_YEAR_DX) { sNewResultStr = "FAILED_INVALID_YEAR_DX"; } else if (data.getResult() == StagingData.Result.FAILED_INVALID_INPUT) { sNewResultStr = "FAILED_INVALID_INPUT"; } if (sNewResultStr != sOldResultStr) { mismatches.Add(" " + thisDataObj.miLineNum + " --> Result: EXPECTED '" + sOldResultStr + "' ACTUAL: '" + sNewResultStr + "'"); } } // compare output foreach (KeyValuePair <String, String> entry in output) { String expected = ""; output.TryGetValue(entry.Key, out expected); if (expected == null) { expected = ""; } expected = expected.Trim(); String actual = ""; data.getOutput().TryGetValue(entry.Key, out actual); if (actual == null) { actual = ""; } actual = actual.Trim(); if (expected != actual) { mismatches.Add(" " + thisDataObj.miLineNum + " --> " + entry.Key + ": EXPECTED '" + expected + "' ACTUAL: '" + actual + "'"); } } if (mismatches.Count != 0) { String sSchemaIDValue = data.getSchemaId(); IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> [" + sSchemaIDValue + "] Mismatches in " + thisDataObj.msFileName); foreach (String mismatch in mismatches) { IntegrationUtils.WritelineToLog(mismatch); } IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " *** RESULT: " + data.getResult()); IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> Input: " + IntegrationUtils.convertInputMap(data.getInput())); IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> Output: " + IntegrationUtils.convertInputMap(data.getOutput())); if (data.getErrors().Count > 0) { IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> ERRORS: "); foreach (Error e in data.getErrors()) { IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> (" + e.getTable() + ": " + e.getMessage() + ") "); } } Interlocked.Increment(ref miMultiTask_FailedCases); } } catch (Exception e) { IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> Exception processing " + thisDataObj.msFileName + " : " + e.Message); Interlocked.Increment(ref miMultiTask_FailedCases); } Interlocked.Increment(ref miMultiTask_ThreadProcessedCases); }
public static void MultiTask_TaskCompute(int id, Object task_data) { MultiTask_DataObj thisDataObj = (MultiTask_DataObj)task_data; //IntegrationUtils.WritelineToLog("Task " + id + " - Executing Line " + thisDataObj.miLineNum + " - " + DateTime.Now.ToString("HH:mm:ss.ffff")); // load up inputs CsStagingData data = new CsStagingData(); data.setInput(CsInput.PRIMARY_SITE, thisDataObj.mValues[0]); data.setInput(CsInput.HISTOLOGY, thisDataObj.mValues[1]); data.setInput(CsInput.DX_YEAR, thisDataObj.mValues[2]); data.setInput(CsInput.CS_VERSION_ORIGINAL, thisDataObj.mValues[3]); data.setInput(CsInput.BEHAVIOR, thisDataObj.mValues[4]); data.setInput(CsInput.GRADE, thisDataObj.mValues[5]); data.setInput(CsInput.AGE_AT_DX, thisDataObj.mValues[6]); data.setInput(CsInput.LVI, thisDataObj.mValues[7]); data.setInput(CsInput.TUMOR_SIZE, thisDataObj.mValues[8]); data.setInput(CsInput.EXTENSION, thisDataObj.mValues[9]); data.setInput(CsInput.EXTENSION_EVAL, thisDataObj.mValues[10]); data.setInput(CsInput.LYMPH_NODES, thisDataObj.mValues[11]); data.setInput(CsInput.LYMPH_NODES_EVAL, thisDataObj.mValues[12]); data.setInput(CsInput.REGIONAL_NODES_POSITIVE, thisDataObj.mValues[13]); data.setInput(CsInput.REGIONAL_NODES_EXAMINED, thisDataObj.mValues[14]); data.setInput(CsInput.METS_AT_DX, thisDataObj.mValues[15]); data.setInput(CsInput.METS_EVAL, thisDataObj.mValues[16]); data.setInput(CsInput.SSF1, thisDataObj.mValues[17]); data.setInput(CsInput.SSF2, thisDataObj.mValues[18]); data.setInput(CsInput.SSF3, thisDataObj.mValues[19]); data.setInput(CsInput.SSF4, thisDataObj.mValues[20]); data.setInput(CsInput.SSF5, thisDataObj.mValues[21]); data.setInput(CsInput.SSF6, thisDataObj.mValues[22]); data.setInput(CsInput.SSF7, thisDataObj.mValues[23]); data.setInput(CsInput.SSF8, thisDataObj.mValues[24]); data.setInput(CsInput.SSF9, thisDataObj.mValues[25]); data.setInput(CsInput.SSF10, thisDataObj.mValues[26]); data.setInput(CsInput.SSF11, thisDataObj.mValues[27]); data.setInput(CsInput.SSF12, thisDataObj.mValues[28]); data.setInput(CsInput.SSF13, thisDataObj.mValues[29]); data.setInput(CsInput.SSF14, thisDataObj.mValues[30]); data.setInput(CsInput.SSF15, thisDataObj.mValues[31]); data.setInput(CsInput.SSF16, thisDataObj.mValues[32]); data.setInput(CsInput.SSF17, thisDataObj.mValues[33]); data.setInput(CsInput.SSF18, thisDataObj.mValues[34]); data.setInput(CsInput.SSF19, thisDataObj.mValues[35]); data.setInput(CsInput.SSF20, thisDataObj.mValues[36]); data.setInput(CsInput.SSF21, thisDataObj.mValues[37]); data.setInput(CsInput.SSF22, thisDataObj.mValues[38]); data.setInput(CsInput.SSF23, thisDataObj.mValues[39]); data.setInput(CsInput.SSF24, thisDataObj.mValues[40]); data.setInput(CsInput.SSF25, thisDataObj.mValues[41]); try { // save the expected outputs Dictionary <String, String> output = new Dictionary <String, String>(100, StringComparer.Ordinal); String sKeyValue = ""; foreach (KeyValuePair <CsOutput, int> entry in thisDataObj.mMappings) { sKeyValue = entry.Key.toString(); output[sKeyValue] = thisDataObj.mValues[entry.Value]; } // run collaborative stage; if no schema found, set the output to empty SchemaLookup lookup = new SchemaLookup(data.getInput(CsInput.PRIMARY_SITE), data.getInput(CsInput.HISTOLOGY)); lookup.setInput(CsStagingData.SSF25_KEY, data.getInput(CsInput.SSF25)); List <StagingSchema> schemas = mMultiTask_Staging.lookupSchema(lookup); if (schemas.Count == 1) { mMultiTask_Staging.stage(data); } else { Dictionary <String, String> outResult = new Dictionary <String, String>(2, StringComparer.Ordinal); outResult["schema_id"] = "<invalid>"; data.setOutput(outResult); } List <String> mismatches = new List <String>(); // compare results foreach (KeyValuePair <String, String> entry in output) { String expected = ""; output.TryGetValue(entry.Key, out expected); if (expected == null) { expected = ""; } expected = expected.Trim(); String actual = ""; data.getOutput().TryGetValue(entry.Key, out actual); if (actual == null) { actual = ""; } actual = actual.Trim(); if (expected != actual) { mismatches.Add(" " + thisDataObj.miLineNum + " --> " + entry.Key + ": EXPECTED '" + expected + "' ACTUAL: '" + actual + "'"); } } if (mismatches.Count != 0) { String sSchemaIDValue = data.getSchemaId(); IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> [" + sSchemaIDValue + "] Mismatches in " + thisDataObj.msFileName); foreach (String mismatch in mismatches) { IntegrationUtils.WritelineToLog(mismatch); } IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " *** RESULT: " + data.getResult()); IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> " + IntegrationUtils.convertInputMap(data.getInput())); if (data.getErrors().Count > 0) { IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> ERRORS: "); foreach (Error e in data.getErrors()) { IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> (" + e.getTable() + ": " + e.getMessage() + ") "); } } Interlocked.Increment(ref miMultiTask_FailedCases); } } catch (Exception e) { IntegrationUtils.WritelineToLog(" " + thisDataObj.miLineNum + " --> Exception processing " + thisDataObj.msFileName + " : " + e.Message); Interlocked.Increment(ref miMultiTask_FailedCases); } Interlocked.Increment(ref miMultiTask_ThreadProcessedCases); }
public void testExternalLoad() { Assert.AreEqual("testing", _STAGING.getAlgorithm()); Assert.AreEqual("99.99", _STAGING.getVersion()); Assert.AreEqual(1, _STAGING.getSchemaIds().Count); Assert.AreEqual(62, _STAGING.getTableIds().Count); StagingSchema schema = _STAGING.getSchema("urethra"); Assert.IsNotNull(schema); Assert.AreEqual("testing", schema.getAlgorithm()); Assert.AreEqual("99.99", schema.getVersion()); StagingTable table = _STAGING.getTable("ajcc_descriptor_codes"); Assert.IsNotNull(table); Assert.AreEqual("testing", table.getAlgorithm()); Assert.AreEqual("99.99", table.getVersion()); Assert.AreEqual(6, table.getTableRows().Count); HashSet <String> involved = _STAGING.getInvolvedTables("urethra"); Assert.AreEqual(62, involved.Count); Assert.IsTrue(involved.Contains("mets_eval_ipa")); StagingData data = new StagingData(); data.setInput("site", "C680"); data.setInput("hist", "8000"); data.setInput("behavior", "3"); data.setInput("grade", "9"); data.setInput("year_dx", "2013"); data.setInput("cs_input_version_original", "020550"); data.setInput("extension", "100"); data.setInput("extension_eval", "9"); data.setInput("nodes", "100"); data.setInput("nodes_eval", "9"); data.setInput("mets", "10"); data.setInput("mets_eval", "9"); // perform the staging _STAGING.stage(data); Assert.AreEqual(StagingData.Result.STAGED, data.getResult()); Assert.AreEqual("urethra", data.getSchemaId()); Assert.AreEqual(0, data.getErrors().Count); Assert.AreEqual(37, data.getPath().Count); // check output Assert.AreEqual("129", data.getOutput("schema_number")); Assert.AreEqual("020550", data.getOutput("csver_derived")); // AJCC 6 Assert.AreEqual("70", data.getOutput("stor_ajcc6_stage")); // AJCC 7 Assert.AreEqual("700", data.getOutput("stor_ajcc7_stage")); // Summary Stage Assert.AreEqual("7", data.getOutput("stor_ss77")); Assert.AreEqual("7", data.getOutput("stor_ss2000")); }