private void ValidateAssociationCardinality(Hl7Source source, IList <XmlNode> nodes, string traversalName, Relationship relationship ) { Cardinality cardinality = relationship.Cardinality; int numberOfAssociations = nodes.Count; if (cardinality != null && !cardinality.Contains(numberOfAssociations)) { Hl7Error error = Hl7Error.CreateWrongNumberOfAssociationsError(traversalName, source.GetCurrentElement(), numberOfAssociations , cardinality); source.GetResult().AddHl7Error(error); } }
// 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)) { } }