Exemple #1
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override Boolean?ParseNonNullNode(ParseContext context, XmlNode node, BareANY result, Type expectedReturnType,
                                                    XmlToModelResult xmlToModelResult)
        {
            XmlElement element = (XmlElement)node;

            return(ParseBooleanValue(xmlToModelResult, GetAttributeValue(element, "value"), element, null));
        }
Exemple #2
0
 private void HandleCompression(EncapsulatedData ed, XmlElement element, XmlToModelResult xmlToModelResult)
 {
     if (element.HasAttribute("compression"))
     {
         ed.Compression = Compression.Get(element.GetAttribute("compression"));
     }
 }
Exemple #3
0
        protected override EncapsulatedData ParseNonNullNode(ParseContext context, XmlNode node, BareANY bareAny, Type expectedReturnType
                                                             , XmlToModelResult result)
        {
            XmlElement       element = (XmlElement)node;
            EncapsulatedData ed      = new EncapsulatedData();

            if (!this.isR2 && element.HasAttribute("compression"))
            {
                ed = new CompressedData();
            }
            HandleRepresentation(ed, element, context, result);
            HandleMediaType(ed, element, result);
            HandleLanguage(ed, element, result);
            HandleCompression(ed, element, result);
            HandleIntegrityCheck(ed, element, context, result);
            HandleIntegrityCheckAlgorithm(ed, element, context, result);
            ValidateInnerNodes(element, result);
            HandleContent(ed, element, result, context);
            HandleReference(ed, element, result, context);
            HandleThumbnail(ed, element, result, context);
            HandleConstraints(ed, context.GetConstraints(), element, result);
            if (!this.isR2)
            {
                Validate(ed, element, context, result);
            }
            if (ed.IsEmpty())
            {
                ed = null;
            }
            return(ed);
        }
Exemple #4
0
 private void ValidateDecimal(string value, string type, XmlToModelResult result, XmlElement element)
 {
     if (NumberUtil.IsNumber(value))
     {
         if (!StandardDataType.REAL.Type.Equals(type))
         {
             string     integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
             string     decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
             RealFormat format      = GetFormat(type);
             if (StandardDataType.REAL_CONF.Type.Equals(type) && !ValueIsBetweenZeroAndOneInclusive(integerPart, decimalPart))
             {
                 RecordValueMustBeBetweenZeroAndOneError(value, type, result, element);
             }
             // TM - decided to remove check on overall length; we check before and after decimal lengths, which should be sufficient
             if (StringUtils.Length(integerPart) > format.GetMaxIntegerPartLength())
             {
                 RecordTooManyCharactersBeforeDecimalError(value, type, result, element, format);
             }
             if (StringUtils.Length(decimalPart) > format.GetMaxDecimalPartLength())
             {
                 RecordTooManyDigitsAfterDecimalError(value, type, result, element, format);
             }
         }
     }
     else
     {
         if (StringUtils.IsBlank(value))
         {
             RecordValueMustBeSpecifiedError(result, element);
         }
     }
 }
Exemple #5
0
        public virtual void TestPivlPhasePeriod()
        {
            XmlToModelResult result = new XmlToModelResult();
            XmlNode          node   = CreateNode("<pivl><period unit=\"d\" value=\"1\"/><phase><low value=\"20120503\"/><high value=\"20120708\"/></phase></pivl>"
                                                 );
            ParseContext context = ParseContextImpl.Create("PIVLTSCDAR1", null, SpecificationVersion.R02_04_03, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                           .MANDATORY, Cardinality.Create("1"), null, true);
            BareANY          parseResult    = this.parser.Parse(context, Arrays.AsList(node), result);
            PhysicalQuantity expectedPeriod = new PhysicalQuantity(BigDecimal.ONE, Ca.Infoway.Messagebuilder.Domainvalue.Basic.UnitsOfMeasureCaseSensitive
                                                                   .DAY);
            PlatformDate            dateLow             = DateUtil.GetDate(2012, 4, 3);
            DateWithPattern         dateWithPatternLow  = new DateWithPattern(dateLow, "yyyyMMdd");
            PlatformDate            dateHigh            = DateUtil.GetDate(2012, 6, 8);
            DateWithPattern         dateWithPatternHigh = new DateWithPattern(dateHigh, "yyyyMMdd");
            Interval <PlatformDate> expectedPhase       = IntervalFactory.CreateLowHigh((PlatformDate)dateWithPatternLow, (PlatformDate)dateWithPatternHigh
                                                                                        );

            Assert.IsTrue(result.IsValid());
            Assert.IsTrue(parseResult is PIVLTSCDAR1);
            PeriodicIntervalTimeR2 pivl = (PeriodicIntervalTimeR2)parseResult.BareValue;

            Assert.AreEqual(expectedPeriod.Quantity, pivl.Period.Quantity);
            Assert.AreEqual(expectedPeriod.Unit.CodeValue, pivl.Period.Unit.CodeValue);
            Assert.AreEqual(expectedPhase, pivl.Phase);
            Assert.IsNull(pivl.FrequencyRepetitions);
            Assert.IsNull(pivl.FrequencyQuantity);
        }
Exemple #6
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override EntityName ParseNode(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            PersonName result = new PersonName();

            HandlePersonName(xmlToModelResult, result, node.ChildNodes);
            return(result);
        }
Exemple #7
0
        /// <summary>The xsi:type attribute is used to check against valid ANY types.</summary>
        /// <remarks>
        /// The xsi:type attribute is used to check against valid ANY types. This has a bit of "magic"
        /// involved, as the CHI specializationType notation (eg. URG_PQ) just happens to match up to our
        /// StandardDataType enum names.
        /// </remarks>
        /// <param name="parentType"></param>
        /// <param name="node"></param>
        /// <param name="xmlToModelResult"></param>
        /// <returns>the actual type</returns>
        private string ObtainActualType(string parentType, XmlNode node, XmlToModelResult xmlToModelResult)
        {
            string actualType = null;
            string xsiType    = GetXsiType(node);

            if (xsiType != null)
            {
                string      innerType  = null;
                XmlNodeList childNodes = node.ChildNodes;
                foreach (XmlNode child in new XmlNodeListIterable(childNodes))
                {
                    innerType = GetXsiType(child);
                    if (StringUtils.IsNotBlank(innerType))
                    {
                        break;
                    }
                }
                if (StringUtils.IsNotBlank(innerType))
                {
                    // the "true" type, in this case, is found by combining the outer xsi:type with the inner xsi:type
                    int xsiTypeIndex = xsiType.IndexOf("_");
                    xsiType    = (xsiTypeIndex >= 0 ? Ca.Infoway.Messagebuilder.StringUtils.Substring(xsiType, 0, xsiTypeIndex) : xsiType);
                    actualType = xsiType + "_" + innerType;
                }
                else
                {
                    actualType = xsiType;
                }
                if (StringUtils.IsNotBlank(actualType))
                {
                    actualType = ConvertSpecializationType(actualType);
                }
            }
            return(actualType);
        }
Exemple #8
0
        private IList <XmlElement> FindComponents(XmlElement element, XmlToModelResult xmlToModelResult)
        {
            IList <XmlElement> result = new List <XmlElement>();
            XmlNodeList        list   = element.ChildNodes;

            if (list != null)
            {
                foreach (XmlNode node in new XmlNodeListIterable(list))
                {
                    if (node.NodeType != System.Xml.XmlNodeType.Element)
                    {
                    }
                    else
                    {
                        // skip it
                        if (StringUtils.Equals("comp", NodeUtil.GetLocalOrTagName((XmlElement)node)))
                        {
                            result.Add((XmlElement)node);
                        }
                        else
                        {
                            xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Unexpected tag {0} in GTS.BOUNDEDPIVL"
                                                                                                                         , XmlDescriber.DescribeSingleElement((XmlElement)node)), (XmlElement)node));
                        }
                    }
                }
            }
            return(result);
        }
Exemple #9
0
        protected virtual GeneralTimingSpecification ParseNonNullNode(ParseContext context, XmlElement element, Type expectedReturnType
                                                                      , XmlToModelResult xmlResult)
        {
            GeneralTimingSpecification result     = null;
            IList <XmlElement>         components = FindComponents(element, xmlResult);

            if (components.Count == 2)
            {
                Interval <PlatformDate> duration  = ParseDuration(context, xmlResult, components[0]);
                PeriodicIntervalTime    frequency = ParseFrequency(context, xmlResult, components[1]);
                if (duration != null && frequency != null)
                {
                    result = new GeneralTimingSpecification(duration, frequency);
                }
                else
                {
                    if (duration == null)
                    {
                        xmlResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Could not parse the duration portion of the GTS.BOUNDEDPIVL"
                                                           , components[0]));
                    }
                    if (frequency == null)
                    {
                        xmlResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Could not parse the frequency portion of the GTS.BOUNDEDPIVL"
                                                           , components[1]));
                    }
                }
            }
            else
            {
                xmlResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Expected to find 2 <comp> sub-elements, but found {0}"
                                                                                                      , components.Count), element));
            }
            return(result);
        }
Exemple #10
0
 private void ValidateII_BUS(XmlToModelResult xmlToModelResult, XmlElement element, string root, string extension, StandardDataType
                             type, VersionNumber version, bool isCda)
 {
     ValidateRootAndExtensionAsOidOrUuid(xmlToModelResult, element, root, extension, version, type, isCda);
     ValidateUnallowedAttributes(type, element, xmlToModelResult, "displayable");
     ValidateAttributeEquals(type, element, xmlToModelResult, "use", "BUS");
 }
Exemple #11
0
 private void ValidateExtensionLength(XmlElement element, string extension, XmlToModelResult xmlToModelResult)
 {
     if (iiValidationUtils.IsExtensionLengthInvalid(extension))
     {
         RecordError(iiValidationUtils.GetInvalidExtensionLengthErrorMessage(extension), element, xmlToModelResult);
     }
 }
Exemple #12
0
        private void ParseUseablePeriods(XmlNode node, XmlToModelResult xmlToModelResult, TelecommunicationAddress result, ParseContext
                                         context)
        {
            XmlNodeList childNodes = node.ChildNodes;

            foreach (XmlNode childNode in new XmlNodeListIterable(childNodes))
            {
                if (childNode is XmlElement)
                {
                    XmlElement useablePeriodElement = (XmlElement)childNode;
                    string     name = NodeUtil.GetLocalOrTagName(useablePeriodElement);
                    if ("useablePeriod".Equals(name))
                    {
                        BareANY tsAny  = tsR2ElementParser.Parse(TsContext(context), useablePeriodElement, xmlToModelResult);
                        MbDate  mbDate = (MbDate)tsAny.BareValue;
                        result.AddUseablePeriod(mbDate == null ? null : mbDate.Value, ((ANYMetaData)tsAny).Operator);
                    }
                    else
                    {
                        xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Unexpected TEL child element: \"" + useablePeriodElement
                                                                  .Name + "\"", useablePeriodElement));
                    }
                }
            }
        }
Exemple #13
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override EntityName ParseNode(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            string name           = null;
            int    childNodeCount = node.ChildNodes.Count;

            if (childNodeCount == 0)
            {
            }
            else
            {
                // name portion is null
                if (childNodeCount == 1)
                {
                    XmlNode childNode = node.FirstChild;
                    if (childNode.NodeType != System.Xml.XmlNodeType.Text)
                    {
                        throw new XmlToModelTransformationException("Expected TN node to have a text node");
                    }
                    name = childNode.Value;
                }
                else
                {
                    throw new XmlToModelTransformationException("Expected TN node to have at most one child");
                }
            }
            return(new TrivialName(name));
        }
Exemple #14
0
        public virtual void TestIvlTsConstraintsInvalid()
        {
            XmlToModelResult    result      = new XmlToModelResult();
            XmlNode             node        = CreateNode("<ivl><low value=\"20120503\"/><high value=\"20120708\"/></ivl>");
            ConstrainedDatatype constraints = new ConstrainedDatatype("ivl", "IVL<TS>");

            constraints.Relationships.Add(new Relationship("low", "TS", Cardinality.Create("0")));
            constraints.Relationships.Add(new Relationship("high", "TS", Cardinality.Create("0")));
            ParseContext context = ParseContextImpl.Create("IVLTSCDAR1", null, SpecificationVersion.R02_04_03, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                           .MANDATORY, Cardinality.Create("1"), constraints, true);
            BareANY                 parseResult         = this.parser.Parse(context, Arrays.AsList(node), result);
            PlatformDate            dateLow             = DateUtil.GetDate(2012, 4, 3);
            DateWithPattern         dateWithPatternLow  = new DateWithPattern(dateLow, "yyyyMMdd");
            PlatformDate            dateHigh            = DateUtil.GetDate(2012, 6, 8);
            DateWithPattern         dateWithPatternHigh = new DateWithPattern(dateHigh, "yyyyMMdd");
            Interval <PlatformDate> expectedIvl         = IntervalFactory.CreateLowHigh((PlatformDate)dateWithPatternLow, (PlatformDate)dateWithPatternHigh
                                                                                        );

            Assert.IsFalse(result.IsValid());
            Assert.AreEqual(2, result.GetHl7Errors().Count);
            Assert.IsTrue(parseResult is IVLTSCDAR1);
            DateInterval ivl = (DateInterval)parseResult.BareValue;

            Assert.AreEqual(expectedIvl, ivl.Interval);
        }
Exemple #15
0
        private BigDecimal ValidateValue(string value, string type, XmlToModelResult xmlToModelResult, XmlElement element)
        {
            if (StringUtils.IsBlank(value))
            {
                return(null);
            }
            if (NumberUtil.IsNumber(value))
            {
                string integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
                string decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
                if (StringUtils.Length(integerPart) > MAX_DIGITS_BEFORE_DECIMAL)
                {
                    RecordTooManyDigitsBeforeDecimalError(value, type, xmlToModelResult, element);
                }
                if (StringUtils.Length(decimalPart) > MAX_DIGITS_AFTER_DECIMAL)
                {
                    RecordTooManyDigitsAfterDecimalError(value, type, xmlToModelResult, element);
                }
                if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                {
                    RecordMustContainDigitsOnlyError(value, xmlToModelResult, element);
                }
            }
            BigDecimal result = null;

            try
            {
                result = new BigDecimal(value);
            }
            catch (FormatException)
            {
                RecordInvalidNumberError(value, type, element, xmlToModelResult);
            }
            return(result);
        }
Exemple #16
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override EntityName ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                       , XmlToModelResult xmlToModelResult)
        {
            EntityName result = null;
            // The incoming xml should specify a specializationType or xsi:type in order to determine how to process the field. (CDA/R1 does allow for EN)
            // However, it should be possible to determine which concrete type to use by applying all known name parsers.
            string specializationType = GetSpecializationType(node);

            if (StringUtils.IsBlank(specializationType))
            {
                specializationType = GetXsiType(node);
            }
            string     upperCaseST = StringUtils.IsBlank(specializationType) ? string.Empty : specializationType.ToUpper();
            NameParser nameParser  = nameParsers.SafeGet(upperCaseST);

            if (nameParser == null && StringUtils.IsNotBlank(specializationType))
            {
                // log error based on bad ST/XT
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Could not determine appropriate parser to use for EN specializationType/xsi:type of: "
                                                          + specializationType, (XmlElement)node));
            }
            if (nameParser != null && nameParser.IsParseable(node, context))
            {
                result = (EntityName)nameParser.Parse(context, node, xmlToModelResult).BareValue;
            }
            else
            {
                string actualParserUsed = null;
                // try all known name parsers
                if (tnElementParser.IsParseable(node, context))
                {
                    actualParserUsed = "TN";
                    result           = (EntityName)tnElementParser.Parse(context, node, xmlToModelResult).BareValue;
                }
                else
                {
                    if (pnElementParser.IsParseable(node, context))
                    {
                        actualParserUsed = "PN";
                        result           = (EntityName)pnElementParser.Parse(context, node, xmlToModelResult).BareValue;
                    }
                    else
                    {
                        if (onElementParser.IsParseable(node, context))
                        {
                            actualParserUsed = "ON";
                            result           = (EntityName)onElementParser.Parse(context, node, xmlToModelResult).BareValue;
                        }
                        else
                        {
                            throw new XmlToModelTransformationException("Cannot figure out how to parse EN node " + node.ToString());
                        }
                    }
                }
                // need to log warning - not able to parse name as expected
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, ErrorLevel.WARNING, "EN field has been handled as type "
                                                          + actualParserUsed, (XmlElement)node));
            }
            return(result);
        }
Exemple #17
0
        protected virtual PeriodicIntervalTime ParseFrequency(ParseContext context, XmlElement element, Type expectedReturnType,
                                                              XmlToModelResult xmlToModelResult)
        {
            XmlElement numerator   = (XmlElement)GetNamedChildNode(element, "numerator");
            XmlElement denominator = (XmlElement)GetNamedChildNode(element, "denominator");

            if (numerator != null && denominator != null)
            {
                Int32?repetitions = ParseNumerator(context, numerator, xmlToModelResult);
                if (SpecificationVersion.IsExactVersion(SpecificationVersion.V01R04_2_SK, context.GetVersion()))
                {
                    Interval <PhysicalQuantity> quantityInterval = ParseDenominatorSk(context, denominator, xmlToModelResult);
                    return(PeriodicIntervalTimeSk.CreateFrequencySk(repetitions, quantityInterval == null ? null : quantityInterval.Low, quantityInterval
                                                                    == null ? null : quantityInterval.High));
                }
                else
                {
                    PhysicalQuantity quantity = ParseDenominator(context, denominator, xmlToModelResult);
                    return(PeriodicIntervalTime.CreateFrequency(repetitions, quantity));
                }
            }
            else
            {
                if (numerator == null)
                {
                    CreateMandatoryChildElementHl7Error(element, "numerator", xmlToModelResult);
                }
                if (denominator == null)
                {
                    CreateMandatoryChildElementHl7Error(element, "denominator", xmlToModelResult);
                }
                return(null);
            }
        }
Exemple #18
0
        private PostalAddress ParseAddressPartTypes(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            PostalAddress result     = new PostalAddress();
            XmlNodeList   childNodes = node.ChildNodes;

            foreach (XmlNode childNode in new XmlNodeListIterable(childNodes))
            {
                if (IsNonBlankTextNode(childNode))
                {
                    string value = childNode.Value;
                    result.AddPostalAddressPart(new PostalAddressPart(value));
                }
                else
                {
                    if (childNode is XmlElement)
                    {
                        XmlElement element = (XmlElement)childNode;
                        string     name    = NodeUtil.GetLocalOrTagName(element);
                        if (!"useablePeriod".Equals(name))
                        {
                            PostalAddressPartType postalAddressPartType = GetPostalAddressPartType(name, element, xmlToModelResult);
                            string value = GetTextValue(name, element, xmlToModelResult);
                            if (postalAddressPartType != null)
                            {
                                result.AddPostalAddressPart(new PostalAddressPart(postalAddressPartType, value));
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemple #19
0
 /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
 private void HandlePersonName(XmlToModelResult xmlToModelResult, PersonName result, XmlNodeList childNodes)
 {
     foreach (XmlNode childNode in new XmlNodeListIterable(childNodes))
     {
         if (childNode is XmlElement)
         {
             XmlElement element                = (XmlElement)childNode;
             string     name                   = NodeUtil.GetLocalOrTagName(element);
             string     value                  = GetTextValue(element, xmlToModelResult);
             string     qualifierString        = GetAttributeValue(element, NAME_PART_TYPE_QUALIFIER);
             EntityNamePartQualifier qualifier = CodeResolverRegistry.Lookup <EntityNamePartQualifier>(qualifierString);
             if (StringUtils.IsNotBlank(value))
             {
                 result.AddNamePart(new EntityNamePart(value, GetPersonalNamePartType(name), qualifier));
             }
         }
         else
         {
             //GN: Added in fix similar to what was done for AD.BASIC.  Issue with XML containing mixture of elements and untyped text nodes.
             if (IsNonBlankTextNode(childNode))
             {
                 // validation will catch if this type does not allow for a free-form name
                 result.AddNamePart(new EntityNamePart(childNode.Value.Trim(), null));
             }
         }
     }
 }
Exemple #20
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override PhysicalQuantity ParseNonNullNode(ParseContext context, XmlNode node, BareANY bareAny, Type expectedReturnType
                                                             , XmlToModelResult xmlToModelResult)
        {
            XmlElement element = (XmlElement)node;
            BigDecimal value   = this.pqValidationUtils.ValidateValueR2(element.GetAttribute("value"), context.GetVersion(), context.Type
                                                                        , false, element, null, xmlToModelResult);
            string unitAsString = element.GetAttribute("unit");

            Ca.Infoway.Messagebuilder.Domainvalue.UnitsOfMeasureCaseSensitive unit = null;
            if (StringUtils.IsNotBlank(unitAsString))
            {
                unit = this.pqValidationUtils.ValidateUnits(context.Type, unitAsString, element, null, xmlToModelResult, true);
            }
            // TM - MBR-285: units default to "1" if not specified; however, this part of the schemas will be ignored
            PhysicalQuantity physicalQuantity = (value != null || unit != null) ? new PhysicalQuantity(value, unit) : null;

            if (physicalQuantity != null)
            {
                HandleTranslations(element, physicalQuantity, context, xmlToModelResult);
            }
            this.sxcmHelper.HandleOperator((XmlElement)node, context, xmlToModelResult, (ANYMetaData)bareAny);
            // this is not the usual way of doing things; this is to make validation easier
            ((BareANYImpl)bareAny).BareValue = physicalQuantity;
            return(physicalQuantity);
        }
Exemple #21
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        public override BareANY Parse(ParseContext context, XmlNode node, XmlToModelResult xmlToModelResult)
        {
            BareANY result = CreateDataTypeInstance(context != null ? GetType(context) : null);

            // RM20416 - some PQ specifications allow for NF to coexist with other properties
            if (HasValidNullFlavorAttribute(context, node, xmlToModelResult))
            {
                NullFlavor nullFlavor = ParseNullNode(context, node, xmlToModelResult);
                result.NullFlavor = nullFlavor;
            }
            PhysicalQuantity value = ParseNonNullNode(context, node, result, GetReturnType(context), xmlToModelResult);

            if (value != null && (value.Quantity != null || value.Unit != null))
            {
                ((BareANYImpl)result).BareValue = value;
            }
            XmlElement element = (XmlElement)node;
            // validation of OT done a bit later below
            string originalText = GetOriginalText(element);

            if (HasOriginalText(element))
            {
                ((PQ)result).OriginalText = originalText;
            }
            bool hasValues     = HasAnyValues(element);
            bool hasNullFlavor = HasValidNullFlavorAttribute(context, node, xmlToModelResult);

            this.pqValidationUtils.ValidateOriginalText(context.Type, originalText, hasValues, hasNullFlavor, context.GetVersion(), element
                                                        , null, xmlToModelResult);
            return(result);
        }
Exemple #22
0
 private void RecordAnyErrors(IList <string> errors, XmlElement element, XmlToModelResult xmlToModelResult)
 {
     foreach (string error in errors)
     {
         RecordError(error, element, xmlToModelResult);
     }
 }
Exemple #23
0
        // Note that the behaviour for this datatype has not been fully defined by CHI. It is likely that the code below will need to be adjusted at some point.
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override string ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                   , XmlToModelResult xmlToModelResult)
        {
            StandardDataType type = StandardDataType.GetByTypeName(context);

            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "compression");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "language");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "reference");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "integrityCheck");
            ValidateUnallowedAttributes(type, (XmlElement)node, xmlToModelResult, "thumbnail");
            ValidateMaxChildCount(context, node, 1);
            if (!Ca.Infoway.Messagebuilder.Domainvalue.Basic.MediaType.XML_TEXT.CodeValue.Equals(GetAttributeValue(node, "mediaType")
                                                                                                 ))
            {
                xmlToModelResult.AddHl7Error(CreateHl7Error("Attribute mediaType must be included with a value of \"text/xml\" for ED.SIGNATURE"
                                                            , (XmlElement)node));
            }
            string  result        = null;
            XmlNode signatureNode = GetNamedChildNode(node, "signature");

            if (signatureNode == null || signatureNode.NodeType != System.Xml.XmlNodeType.Element)
            {
                xmlToModelResult.AddHl7Error(CreateHl7Error("Expected ED.SIGNATURE node to have a child element named signature", (XmlElement
                                                                                                                                   )node));
            }
            else
            {
                result = (string)this.stElementParser.Parse(context, signatureNode, xmlToModelResult).BareValue;
            }
            return(result);
        }
Exemple #24
0
		// public as a result of needing to call this method from ValidatingVistor
		public virtual Boolean? ParseBooleanValue(XmlToModelResult result, string unparsedBoolean, XmlElement element, XmlAttribute
			 attr)
		{
			Boolean? booleanResult = null;
			if (StringUtils.IsBlank(unparsedBoolean))
			{
				result.AddHl7Error(Hl7Error.CreateMandatoryBooleanValueError(element, attr));
			}
			else
			{
				if (VALID_BOOLEAN_STRINGS.Contains(unparsedBoolean))
				{
					booleanResult = Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(unparsedBoolean);
				}
				else
				{
					if (VALID_BOOLEAN_STRINGS.Contains(unparsedBoolean.ToLower()))
					{
						result.AddHl7Error(Hl7Error.CreateIncorrectCapitalizationBooleanValueError(unparsedBoolean, element, attr));
						booleanResult = Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(unparsedBoolean);
					}
					else
					{
						result.AddHl7Error(Hl7Error.CreateInvalidBooleanValueError(element, attr));
					}
				}
			}
			return booleanResult;
		}
Exemple #25
0
 private void HandleLanguage(EncapsulatedData ed, XmlElement element, XmlToModelResult xmlToModelResult)
 {
     if (element.HasAttribute("language"))
     {
         ed.Language = element.GetAttribute("language");
     }
 }
Exemple #26
0
        public override BareANY Parse(ParseContext context, XmlNode node, XmlToModelResult result)
        {
            BareANY            codedTypeAny = DoCreateR2DataTypeInstance(context);
            XmlElement         element      = (XmlElement)node;
            CodedTypeR2 <Code> codedType    = new CodedTypeR2 <Code>();

            // attributes
            HandleNullFlavor(element, codedTypeAny, context, result);
            HandleCodeAndCodeSystem(element, codedType, context, result);
            HandleCodeSystemName(element, codedType, context, result);
            HandleCodeSystemVersion(element, codedType, context, result);
            HandleDisplayName(element, codedType, context, result);
            HandleValue(element, codedType, context, result);
            HandleQty(element, codedType, context, result);
            HandleOperator(element, codedTypeAny, codedType, context, result);
            // elements
            HandleSimpleValue(element, codedType, context, result);
            HandleOriginalText(element, codedType, context, result);
            HandleQualifier(element, codedType, context, result);
            HandleTranslation(element, codedType, context, result);
            HandleValidTime(element, codedType, context, result);
            HandleConstraints(codedType, context.GetConstraints(), element, result);
            // want to return null if no attributes or elements are present
            if (codedType.IsEmpty())
            {
                codedType = null;
            }
            ((BareANYImpl)codedTypeAny).BareValue = CodedTypeR2Helper.ConvertCodedTypeR2(codedType, context.GetExpectedReturnType());
            return(codedTypeAny);
        }
Exemple #27
0
 private void HandleMediaType(EncapsulatedData ed, XmlElement element, XmlToModelResult xmlToModelResult)
 {
     if (element.HasAttribute("mediaType"))
     {
         ed.MediaType = Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_DocumentMediaType.Get(element.GetAttribute("mediaType"));
     }
 }
Exemple #28
0
        private BigDecimal ValidateValue(string value, string type, XmlToModelResult xmlToModelResult, XmlElement element)
        {
            if (StringUtils.IsBlank(value))
            {
                if (element.HasAttribute("value"))
                {
                    RecordInvalidNumberError(value, type, element, xmlToModelResult);
                }
                return(null);
            }
            if (NumberUtil.IsNumber(value))
            {
                string integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
                string decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
                if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                {
                    RecordMustContainDigitsOnlyError(value, xmlToModelResult, element);
                }
            }
            BigDecimal result = null;

            try
            {
                result = new BigDecimal(value);
            }
            catch (FormatException)
            {
                RecordInvalidNumberError(value, type, element, xmlToModelResult);
            }
            return(result);
        }
Exemple #29
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override MbDate ParseNonNullNode(ParseContext context, XmlNode node, BareANY bareAny, Type expectedReturnType,
                                                   XmlToModelResult xmlToModelResult)
        {
            XmlElement element      = (XmlElement)node;
            MbDate     result       = null;
            string     unparsedDate = GetAttributeValue(node, "value");

            if (StringUtils.IsBlank(unparsedDate))
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Timestamp value must be non-blank.", element));
            }
            else
            {
                try
                {
                    PlatformDate parsedDate = ParseDate(unparsedDate, GetAllDateFormats(context), context);
                    result = (parsedDate == null ? null : new MbDate(parsedDate));
                }
                catch (ArgumentException)
                {
                    string message = "The timestamp " + unparsedDate + " in element " + XmlDescriber.DescribeSingleElement(element) + " cannot be parsed.";
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, message, element));
                }
                this.sxcmHelper.HandleOperator(element, context, xmlToModelResult, (ANYMetaData)bareAny);
            }
            return(result);
        }
Exemple #30
0
        protected override EntityName ParseNode(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            OrganizationName result     = new OrganizationName();
            XmlNodeList      childNodes = node.ChildNodes;

            foreach (XmlNode childNode in new XmlNodeListIterable(childNodes))
            {
                if (childNode.NodeType == System.Xml.XmlNodeType.Text)
                {
                    string value = childNode.Value;
                    result.AddNamePart(new EntityNamePart(value));
                }
                else
                {
                    if (childNode is XmlElement)
                    {
                        XmlElement element = (XmlElement)childNode;
                        string     name    = NodeUtil.GetLocalOrTagName(element);
                        string     value   = GetTextValue(element, xmlToModelResult);
                        result.AddNamePart(new EntityNamePart(value, GetOrganizationNamePartType(name)));
                    }
                }
            }
            return(result);
        }