コード例 #1
0
        // Check the validity of a single field of a schema based on the supplied context.  The value of this key should be in the context as well
        // as any other properties needed to evaluation validity.  If the schema or field do no exist, false will be returned.
        // @param schemaId schema identifier
        // @param key input key
        // @param context Map of keys/values to validate against
        // @return a boolean indicating whether the code exists for the the passed schema field
        public bool isContextValid(String schemaId, String key, Dictionary <String, String> context)
        {
            // first get the algorithm
            StagingSchema schema = getSchema(schemaId);

            if (schema == null)
            {
                return(false);
            }

            // get the table id from the schema
            IInput input = null;

            if (!schema.getInputMap().TryGetValue(key, out input))
            {
                input = null;
            }

            if (input == null)
            {
                return(false);
            }

            // missing context will always return false
            if (context == null || context.Count == 0)
            {
                return(false);
            }

            // all context input needs to be trimmed
            Dictionary <String, String> testContext = new Dictionary <String, String>(20, StringComparer.Ordinal);

            foreach (KeyValuePair <String, String> entry in context)
            {
                testContext[entry.Key] = (entry.Value != null ? entry.Value.Trim() : "");
            }

            // if the input specifies a table for validation, test against it
            if (input.getTable() != null)
            {
                ITable table = getTable(input.getTable());

                return(table != null && (DecisionEngineFuncs.matchTable(table, testContext) != null));
            }

            return(true);
        }
コード例 #2
0
        // Look up a schema based on site, histology and an optional discriminator.
        // @param lookup schema lookup input
        // @return a list of StagingSchemaInfo objects
        private List <StagingSchema> getSchemas(SchemaLookup lookup)
        {
            List <StagingSchema> matchedSchemas = new List <StagingSchema>(5);

            String site             = lookup.getInput(StagingData.PRIMARY_SITE_KEY);
            String histology        = lookup.getInput(StagingData.HISTOLOGY_KEY);
            bool   hasDiscriminator = lookup.hasDiscriminator();

            // site or histology must be supplied and they must be valid; I am assuming that all algorithms must have tables that validate
            // both site and histology
            if ((site != null && !isValidSite(site)) || (histology != null && !isValidHistology(histology)))
            {
                return(matchedSchemas);
            }

            // searching on a discriminator is only supported if also searching on site and histology; if ssf25 supplied without either
            // of those fields, return no results
            if (hasDiscriminator && (site == null || (site.Length == 0) || histology == null || (histology.Length == 0)))
            {
                return(matchedSchemas);
            }

            // site or histology must be supplied
            if (site != null || histology != null)
            {
                HashSet <String> lstSchemaIds = getSchemaIds();

                // loop over selection table and match using only the supplied keys
                foreach (String schemaId in lstSchemaIds)
                {
                    StagingSchema schema = (StagingSchema)(getDefinition(schemaId));

                    if (schema.getSchemaSelectionTable() != null)
                    {
                        StagingTable table = (StagingTable)(getTable(schema.getSchemaSelectionTable()));
                        if (table != null && DecisionEngineFuncs.matchTable(table, lookup.getInputs(), lookup.getKeys()) != null)
                        {
                            matchedSchemas.Add(schema);
                        }
                    }
                }
            }

            return(matchedSchemas);
        }