예제 #1
0
 public virtual IiCollectionConstraintHandler.ConstraintResult CheckConstraints(string type, ConstrainedDatatype constraints
                                                                                , ICollection <BareANY> collection)
 {
     // pull out root/extension fixed constraints
     // check for a match within collection
     // if no match, add to collection (last?)
     if (constraints != null && collection != null)
     {
         if ("II".Equals(type))
         {
             string       fixedRootValue   = null;
             Relationship rootRelationship = constraints.GetRelationship("root");
             if (rootRelationship != null)
             {
                 fixedRootValue = rootRelationship.FixedValue;
             }
             string       fixedExtensionValue   = null;
             Relationship extensionRelationship = constraints.GetRelationship("extension");
             if (extensionRelationship != null)
             {
                 fixedExtensionValue = extensionRelationship.FixedValue;
             }
             bool hasFixedConstraint = fixedRootValue != null || fixedExtensionValue != null;
             if (hasFixedConstraint)
             {
                 Identifier matchingIdentifier = null;
                 foreach (BareANY item in collection)
                 {
                     object value = item.BareValue;
                     if (value is Identifier)
                     {
                         Identifier id = (Identifier)value;
                         if (fixedRootValue == null || fixedRootValue.Equals(id.Root))
                         {
                             if (fixedExtensionValue == null || fixedExtensionValue.Equals(id.Extension))
                             {
                                 matchingIdentifier = id;
                                 break;
                             }
                         }
                     }
                 }
                 bool       foundMatch   = (matchingIdentifier != null);
                 bool       isTemplateId = (constraints.Name == null ? false : constraints.Name.EndsWith(".templateId"));
                 Identifier identifer    = (foundMatch ? matchingIdentifier : new Identifier(fixedRootValue, fixedExtensionValue));
                 return(new IiCollectionConstraintHandler.ConstraintResult(this, foundMatch, isTemplateId, identifer));
             }
         }
     }
     return(null);
 }
예제 #2
0
        private Relationship ObtainConstraint(string name, ConstrainedDatatype constraints)
        {
            Relationship result = null;

            if (constraints != null)
            {
                result = constraints.GetRelationship(name);
            }
            return(result);
        }
예제 #3
0
        // only the following constraints are being handled for now:
        //	qualifier (mandatory)
        //	qualifier.name (mandatory)
        //	qualifier.name.code (mandatory, fixed)
        //	qualifier.name.codeSystem (mandatory, fixed)
        //	qualifier.value (mandatory)
        //	codeSystem (mandatory, fixed)
        public virtual void HandleConstraints(ConstrainedDatatype constraints, CodedTypeR2 <Code> codedType, ErrorLogger logger)
        {
            if (codedType == null || constraints == null)
            {
                return;
            }
            IList <CodeRole> qualifiers = codedType.Qualifier;
            int numberOfQualifiers      = qualifiers.Count;

            // check if qualifier fits into constrained number of items (1, 0-1)
            this.constraintsHandler.ValidateConstraint("qualifier", qualifiers.IsEmpty() ? null : "qualifiers", constraints, logger);
            // just checks if any qualifiers provided
            if (numberOfQualifiers == 1)
            {
                // if only one qualifier present, check other qualifier constraints
                CodeRole           qualifier     = qualifiers[0];
                CodedTypeR2 <Code> qualifierName = qualifier.Name;
                this.constraintsHandler.ValidateConstraint("qualifier.name", qualifierName == null ? null : "qualifierName", constraints,
                                                           logger);
                // just checks if name provided
                if (qualifierName != null)
                {
                    string nameCode          = qualifierName.GetCodeValue();
                    string newNameCode       = this.constraintsHandler.ValidateConstraint("qualifier.name.code", nameCode, constraints, logger);
                    string nameCodeSystem    = qualifierName.GetCodeSystem();
                    string newNameCodeSystem = this.constraintsHandler.ValidateConstraint("qualifier.name.codeSystem", nameCodeSystem, constraints
                                                                                          , logger);
                    if (!StringUtils.Equals(nameCode, newNameCode) || !StringUtils.Equals(nameCodeSystem, newNameCodeSystem))
                    {
                        Type type = typeof(Code);
                        //For .NET translation
                        Code newName = this.trivialCodeResolver.Lookup <Code>(type, newNameCode, newNameCodeSystem);
                        qualifierName.Code = newName;
                    }
                }
                CodedTypeR2 <Code> qualifierValue = qualifier.Value;
                this.constraintsHandler.ValidateConstraint("qualifier.value", qualifierValue == null ? null : "qualifierValue", constraints
                                                           , logger);
            }
            else
            {
                // just checks if value provided
                if (numberOfQualifiers > 1)
                {
                    // (qualifier can be constrained to at most 1 and to exactly 1)
                    Relationship qualifierConstraint = constraints.GetRelationship("qualifier");
                    if (qualifierConstraint != null)
                    {
                        Cardinality qualifierConstraintCardinality = qualifierConstraint.Cardinality;
                        if (qualifierConstraintCardinality != null && !qualifierConstraintCardinality.Contains(numberOfQualifiers))
                        {
                            string message = System.String.Format("Property {0} of type {1} is constrained to a cardinality of {2} but contains {3} values"
                                                                  , "qualifier", constraints.BaseType, qualifierConstraintCardinality, numberOfQualifiers);
                            logger.LogError(Hl7ErrorCode.CDA_CARDINALITY_CONSTRAINT, ErrorLevel.ERROR, message);
                        }
                    }
                }
            }
            string codeSystem = codedType.GetCodeSystem();

            codeSystem = StringUtils.IsBlank(codeSystem) ? "not provided" : codeSystem;
            string newCodedSystem = this.constraintsHandler.ValidateConstraint("codeSystem", codeSystem, constraints, logger);

            if (!StringUtils.Equals(codeSystem, newCodedSystem))
            {
            }
        }