public void testTableRowParsing()
        {
            StagingTable table = new StagingTable();

            table.setId("test_table");
            table.setColumnDefinitions(new List <IColumnDefinition>()
            {
                new StagingColumnDefinition("key1", "Input 1", ColumnType.INPUT)
            });
            table.setRawRows(new List <List <String> >());
            table.getRawRows().Add(new List <String>()
            {
                ",1,2,3"
            });
            table.getRawRows().Add(new List <String>()
            {
                "1,2,3,"
            });

            StagingDataProvider.initTable(table);

            Assert.AreEqual(2, table.getTableRows().Count);


            //StagingTableRow
            List <ITableRow> tablerows = table.getTableRows();

            StagingTableRow row = (tablerows[0] as StagingTableRow);

            Assert.AreEqual(4, row.getInputs()["key1"].Count);

            row = (tablerows[1] as StagingTableRow);
            Assert.AreEqual(4, row.getInputs()["key1"].Count);
        }
        public void testRangeParsing()
        {
            StagingTable table = _STAGING.getTable("path_n_daj");

            Assert.IsNotNull(table);
            Assert.AreEqual("p0I-", table.getRawRows()[2][0]);

            StagingTableRow tablerow = (table.getTableRows()[2] as StagingTableRow);

            Assert.AreEqual("p0I-", tablerow.getInputs()["path_n"][0].getLow());

            tablerow = (table.getTableRows()[2] as StagingTableRow);
            Assert.AreEqual("p0I-", tablerow.getInputs()["path_n"][0].getHigh());
        }
        // Given a table, return a Set of all the distinct input values.  This is for tables that have a single INPUT column.
        // @param tableId table identifier
        // @return A set of unique inputs
        private HashSet <String> getAllInputValues(String tableId)
        {
            HashSet <String> values = new HashSet <String>();

            // if the table is not found, return right away with an empty list
            //StagingTable table = (getTable(tableId) as StagingTable);
            StagingTable table = (StagingTable)(getTable(tableId));

            if (table == null)
            {
                return(values);
            }

            // find the input key
            HashSet <String> inputKeys = new HashSet <String>();

            foreach (StagingColumnDefinition col in table.getColumnDefinitions())
            {
                if (col.getType() == ColumnType.INPUT)
                {
                    inputKeys.Add(col.getKey());
                }
            }

            if (inputKeys.Count != 1)
            {
                throw new System.InvalidOperationException("Table '" + table.getId() + "' must have one and only one INPUT column.");
            }

            HashSet <String> .Enumerator enumInput = inputKeys.GetEnumerator();
            enumInput.MoveNext();
            String inputKey = enumInput.Current;

            foreach (StagingTableRow row in table.getTableRows())
            {
                foreach (StagingRange range in row.getColumnInput(inputKey))
                {
                    if (range.getLow() != null)
                    {
                        if (range.getLow() == range.getHigh())
                        {
                            values.Add(range.getLow());
                        }
                        else
                        {
                            int low  = Convert.ToInt32(range.getLow());
                            int high = Convert.ToInt32(range.getHigh());

                            // add all values in range
                            for (int i = low; i <= high; i++)
                            {
                                values.Add(padStart(i.ToString(), range.getLow().Length, '0'));
                            }
                        }
                    }
                }
            }

            return(values);
        }
Esempio n. 4
0
        // * Return the input length from a specified table
        // * @param tableId table indentifier
        // * @param key input key
        // * @return null if no length couild be determined, or the length
        protected int getInputLength(String tableId, String key)
        {
            StagingTable table  = _STAGING.getTable(tableId);
            int          length = -1;

            // loop over each row
            foreach (StagingTableRow row in table.getTableRows())
            {
                List <Range> ranges = row.getInputs()[key];

                foreach (StagingRange range in ranges)
                {
                    String low  = range.getLow();
                    String high = range.getHigh();

                    if (range.matchesAll() || low.Length == 0)
                    {
                        continue;
                    }

                    if (low.StartsWith("{{") && low.Contains(TNMStagingCSharp.Src.Staging.Staging.CTX_YEAR_CURRENT))
                    {
                        low = DateTime.Now.Year.ToString();
                    }
                    if (high.StartsWith("{{") && high.Contains(TNMStagingCSharp.Src.Staging.Staging.CTX_YEAR_CURRENT))
                    {
                        high = DateTime.Now.Year.ToString();
                    }

                    if (length >= 0 && (low.Length != length || high.Length != length))
                    {
                        throw new System.InvalidOperationException("Inconsistent lengths in table " + tableId + " for key " + key);
                    }

                    length = low.Length;
                }
            }

            return(length);
        }
        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"));
        }