Exemplo n.º 1
0
        public virtual void TestParseCdWithAllMetadata()
        {
            XmlNode node = CreateNode("<something code=\"BARNEY\" codeSystem=\"1.2.3.4.5\" displayName=\"a display name\" specializationType=\"CD.LAB\">"
                                      + "<originalText>some original text</originalText>" + "<translation code=\"FRED\" codeSystem=\"1.2.3.4.5\" />" + "<translation code=\"WILMA\" codeSystem=\"1.2.3.4.5\" />"
                                      + "<translation code=\"BETTY\" codeSystem=\"1.2.3.4.5\" />" + "<translation code=\"BAM_BAM\" codeSystem=\"1.2.3.4.5\" /></something>"
                                      );
            BareANY cdAny = new AnyElementParser().Parse(ParseContextImpl.Create("ANY", typeof(object), SpecificationVersion.V02R02,
                                                                                 null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.MANDATORY, null, null, false), node, this.xmlResult);

            Assert.IsTrue(this.xmlResult.IsValid());
            Assert.IsNotNull(cdAny.BareValue);
            Assert.IsTrue(cdAny.BareValue is Code);
            Code value = (Code)cdAny.BareValue;

            Assert.IsNotNull(value, "main enum found");
            Assert.AreEqual("BARNEY", value.CodeValue, "main code");
            ANYMetaData cd = (ANYMetaData)cdAny;

            Assert.IsFalse(cd.Translations.IsEmpty(), "translation enums found");
            Assert.IsTrue(cd.Translations.Count == 4, "translation enums found");
            Assert.AreEqual(0, this.xmlResult.GetHl7Errors().Count, "error message count");
            Assert.AreEqual("FRED", cd.Translations[0].Value.CodeValue, "translation");
            Assert.AreEqual("WILMA", cd.Translations[1].Value.CodeValue, "translation");
            Assert.AreEqual("BETTY", cd.Translations[2].Value.CodeValue, "translation");
            Assert.AreEqual("BAM_BAM", cd.Translations[3].Value.CodeValue, "translation");
        }
Exemplo n.º 2
0
        public virtual void TestParsePqLabWithNullFlavorAndMetaData()
        {
            XmlNode node = CreateNode("<something nullFlavor=\"ASKU\" specializationType=\"PQ.LAB\">" + "<originalText>some more original text</originalText>"
                                      + "</something>");
            BareANY pqAny = new AnyElementParser().Parse(ParseContextImpl.Create("ANY", typeof(object), SpecificationVersion.R02_04_03
                                                                                 , null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.POPULATED, null, null, false), node, this.xmlResult);

            Assert.IsTrue(this.xmlResult.IsValid());
            Assert.IsNull(pqAny.BareValue);
            Assert.AreEqual(Ca.Infoway.Messagebuilder.Domainvalue.Nullflavor.NullFlavor.ASKED_BUT_UNKNOWN, pqAny.NullFlavor);
            ANYMetaData pq = (ANYMetaData)pqAny;

            Assert.AreEqual("some more original text", pq.OriginalText);
        }
Exemplo n.º 3
0
        private object DelegateToConcreteParser(ParseContext context, XmlNode node, BareANY hl7Result, XmlToModelResult xmlToModelResult
                                                )
        {
            object result             = null;
            string parentType         = context == null ? null : context.Type;
            string specializationType = ObtainSpecializationType(parentType, node, xmlToModelResult);

            if (StringUtils.IsNotBlank(specializationType))
            {
                string mappedSpecializationType = this.polymorphismHandler.MapCdaR1Type(StandardDataType.GetByTypeName(specializationType
                                                                                                                       ), context.IsCda());
                ElementParser elementParser = ParserRegistry.GetInstance().Get(mappedSpecializationType);
                if (elementParser == null || !IsValidTypeForAny(parentType, specializationType))
                {
                    xmlToModelResult.AddHl7Error(Hl7Error.CreateInvalidTypeError(specializationType, parentType, (XmlElement)node));
                }
                else
                {
                    BareANY parsedValue = elementParser.Parse(ParseContextImpl.CreateWithConstraints(mappedSpecializationType, DetermineReturnType
                                                                                                         (specializationType, GetReturnType(context)), context), Arrays.AsList(node), xmlToModelResult);
                    result = parsedValue.BareValue;
                    // Yes, this is a side effect of calling this method. If we don't do this then the actual type of the ANY.LAB (i.e. PQ.LAB) is lost.
                    hl7Result.DataType   = parsedValue.DataType;
                    hl7Result.NullFlavor = parsedValue.NullFlavor;
                    // preserve all metadata (yes, also not a great side effect); this will have to be adjusted whenever new metadata is added to a data type (extremely infrequently)
                    if (hl7Result is ANYMetaData && parsedValue is ANYMetaData)
                    {
                        ANYMetaData anyMetaDataResult = (ANYMetaData)hl7Result;
                        ANYMetaData anyMetaDataParsed = (ANYMetaData)parsedValue;
                        anyMetaDataResult.Language     = anyMetaDataParsed.Language;
                        anyMetaDataResult.DisplayName  = anyMetaDataParsed.DisplayName;
                        anyMetaDataResult.OriginalText = anyMetaDataParsed.OriginalText;
                        anyMetaDataResult.Translations.AddAll(anyMetaDataParsed.Translations);
                        anyMetaDataResult.IsCdata  = anyMetaDataParsed.IsCdata;
                        anyMetaDataResult.Operator = anyMetaDataParsed.Operator;
                        anyMetaDataResult.Unsorted = anyMetaDataParsed.Unsorted;
                    }
                }
            }
            else
            {
                xmlToModelResult.AddHl7Error(Hl7Error.CreateMissingMandatoryAttributeError(AbstractElementParser.SPECIALIZATION_TYPE, (XmlElement
                                                                                                                                       )node));
            }
            return(result);
        }
Exemplo n.º 4
0
        protected override IDictionary <string, string> GetAttributeNameValuePairs(FormatContext context, Code code, BareANY bareAny
                                                                                   )
        {
            IDictionary <string, string> result = base.GetAttributeNameValuePairs(context, code, bareAny);

            if (code != null)
            {
                if (StringUtils.IsNotBlank(code.CodeSystem))
                {
                    result["codeSystem"] = code.CodeSystem;
                }
            }
            // TM - RM18203 - displayName allowed in CV for older CeRx releases (see validations)
            ANYMetaData anyCv = (ANYMetaData)bareAny;

            if (anyCv != null && StringUtils.IsNotBlank(anyCv.DisplayName))
            {
                result["displayName"] = anyCv.DisplayName;
            }
            return(result);
        }
Exemplo n.º 5
0
        private CD ConvertAnyToCd(BareANY hl7Value)
        {
            ANYMetaData anyCd = (ANYMetaData)hl7Value;
            CD          cd    = new CDImpl();

            if (anyCd != null)
            {
                if (GenericClassUtil.IsInstanceOfANY(hl7Value))
                {
                    object value = GenericClassUtil.GetValueFromANY(hl7Value);
                    if (value is Code)
                    {
                        cd.Value = (Code)value;
                    }
                }
                cd.DataType     = hl7Value.DataType;
                cd.NullFlavor   = hl7Value.NullFlavor;
                cd.DisplayName  = anyCd.DisplayName;
                cd.OriginalText = anyCd.OriginalText;
                cd.Translations.AddAll(anyCd.Translations);
            }
            return(cd);
        }
Exemplo n.º 6
0
        public virtual SetOperator HandleOperator(XmlElement element, ParseContext context, Hl7Errors errors, ANYMetaData wrapper
                                                  )
        {
            string      type        = context == null ? null : context.Type;
            bool        isSxcm      = (type != null && type.StartsWith("SXCM<"));
            bool        hasOperator = (element != null && element.HasAttribute("operator"));
            SetOperator result      = null;

            if (isSxcm)
            {
                result = SetOperator.INCLUDE;
                // default
                if (hasOperator)
                {
                    string operatorString = element.GetAttribute("operator");
                    result = SetOperator.FindMatchingOperator(operatorString);
                    if (result == null)
                    {
                        errors.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Operator could not be determined from attribute value: '"
                                                        + operatorString + "'", element));
                    }
                }
                wrapper.Operator = result;
            }
            else
            {
                if (hasOperator)
                {
                    errors.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Operator property not applicable for type: " + type, element
                                                    ));
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public virtual void HandleOperator(IDictionary <string, string> attributes, FormatContext context, ANYMetaData wrapper)
        {
            string type        = context == null ? null : context.Type;
            bool   isSxcm      = (type != null && type.StartsWith("SXCM<"));
            bool   hasOperator = wrapper != null && wrapper.Operator != null;

            if (hasOperator)
            {
                if (isSxcm)
                {
                    attributes["operator"] = wrapper.Operator.CodeValue;
                }
                else
                {
                    context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Operator property not applicable for type: "
                                                                           + type, context.GetPropertyPath()));
                }
            }
        }