Ejemplo n.º 1
0
 private void HandleCodeValue(CodedTypeR2 <Code> codedType, IDictionary <string, string> result, FormatContext context)
 {
     if (HasCodeValue(codedType))
     {
         if (CodeValueAllowed())
         {
             result["code"] = codedType.GetCodeValue();
         }
         else
         {
             LogValueNotAllowed("code", context);
         }
     }
 }
Ejemplo n.º 2
0
        public virtual void TestIncorrectCodeSystem()
        {
            Code incorrectCode = this.trivialCodeResolver.Lookup <ActStatus>(TYPE, "badCode", "badCodeSystem");
            ConstrainedDatatype constraints = CreateConstraints(true);
            CodedTypeR2 <Code>  codedType   = CreateCodedType();

            codedType.Code = incorrectCode;
            this.constraintsHandler.HandleConstraints(constraints, codedType, this.errorLogger);
            Assert.IsFalse(this.errors.IsEmpty());
            Assert.AreEqual(1, this.errors.Count);
            Assert.AreEqual(Hl7ErrorCode.CDA_FIXED_CONSTRAINT_MISSING, this.errors[0].GetHl7ErrorCode());
            Assert.IsTrue(this.errors[0].GetMessage().Contains(" codeSystem "));
            Assert.AreEqual("badCode", codedType.GetCodeValue());
            Assert.AreEqual("badCodeSystem", codedType.GetCodeSystem());
        }
Ejemplo n.º 3
0
        public virtual void TestMissingCodeSystem()
        {
            Code codeMissingCodeSystem      = this.trivialCodeResolver.Lookup <ActStatus>(TYPE, "okCode", null);
            ConstrainedDatatype constraints = CreateConstraints(true);
            CodedTypeR2 <Code>  codedType   = CreateCodedType();

            codedType.Code = codeMissingCodeSystem;
            this.constraintsHandler.HandleConstraints(constraints, codedType, this.errorLogger);
            Assert.IsFalse(this.errors.IsEmpty());
            Assert.AreEqual(1, this.errors.Count);
            Assert.AreEqual(Hl7ErrorCode.CDA_FIXED_CONSTRAINT_MISSING, this.errors[0].GetHl7ErrorCode());
            Assert.IsTrue(this.errors[0].GetMessage().Contains(" codeSystem "));
            Assert.IsTrue(this.errors[0].GetMessage().Contains(" not provided"));
            // these checks may eventually change
            Assert.AreEqual("okCode", codedType.GetCodeValue());
            Assert.IsNull(codedType.GetCodeSystem());
        }
Ejemplo n.º 4
0
        public virtual void TestParse()
        {
            XmlNode node = CreateNode("<top>" + "<targetSiteCode code=\"416949008\" codeSystem=\"2.16.840.1.113883.6.96\" codeSystemName=\"SNOMED CT\" displayName=\"Abdomen and pelvis\"/>"
                                      + "</top>");
            Type         expectedReturnType = typeof(ObservationValue);
            ParseContext parseContext       = ParseContextImpl.Create("LIST<CD>", expectedReturnType, SpecificationVersion.CCDA_R1_1, null,
                                                                      null, null, Cardinality.Create("0-4"), null, true);
            BareANY result = new ListR2ElementParser(this.parserR2Registry).Parse(parseContext, AsList(node.ChildNodes), this.xmlResult
                                                                                  );

            Assert.IsTrue(this.xmlResult.IsValid());
            IList <CodedTypeR2 <ObservationValue> > list = ((LIST <CD_R2 <ObservationValue>, CodedTypeR2 <ObservationValue> >)result).RawList
                                                               ();

            Assert.IsNotNull(list, "null");
            Assert.AreEqual(1, list.Count, "size");
            CodedTypeR2 <ObservationValue> firstValue = list[0];

            Assert.AreEqual("416949008", firstValue.GetCodeValue());
            Assert.AreEqual("2.16.840.1.113883.6.96", firstValue.GetCodeSystem());
            Assert.AreEqual("SNOMED CT", firstValue.CodeSystemName);
            Assert.AreEqual("Abdomen and pelvis", firstValue.DisplayName);
        }
Ejemplo n.º 5
0
 private bool HasCodeValue(CodedTypeR2 <Code> codedType)
 {
     return(codedType != null && StringUtils.IsNotBlank(codedType.GetCodeValue()));
 }
Ejemplo n.º 6
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))
            {
            }
        }