Esempio n. 1
0
        public virtual void TestParse()
        {
            XmlNode node = CreateNode("<top>" + "<something>" + "<numerator unit=\"mg\" value=\"1000\" />" + "<denominator unit=\"d\" value=\"1\" />"
                                      + "</something>" + "<something>" + "<numerator unit=\"mg\" value=\"1001\"	/>" + "<denominator unit=\"d\" value=\"2\" />"
                                      + "</something>" + "</top>");
            BareANY result = new SetElementParser(ParserRegistry.GetInstance()).Parse(ParseContextImpl.Create("SET<RTO<PQ.DRUG,PQ.TIME>>"
                                                                                                              , null, SpecificationVersion.V01R04_2_SK, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.MANDATORY, Cardinality
                                                                                                              .Create("1-5"), null, false), AsList(node.ChildNodes), null);
            ICollection <Ratio <PhysicalQuantity, PhysicalQuantity> > set = ((SET <RTO <PhysicalQuantity, PhysicalQuantity>, Ratio <PhysicalQuantity
                                                                                                                                    , PhysicalQuantity> >)result).RawSet();

            Assert.IsNotNull(set, "null");
            Assert.AreEqual(2, set.Count, "size");
            bool foundFirst  = false;
            bool foundSecond = false;

            foreach (Ratio <PhysicalQuantity, PhysicalQuantity> ratio in set)
            {
                if (ratio.Numerator.Quantity.Value == 1000 && ratio.Denominator.Quantity.Value == 1)
                {
                    foundFirst = true;
                }
                else
                {
                    if (ratio.Numerator.Quantity.Value == 1001 && ratio.Denominator.Quantity.Value == 2)
                    {
                        foundSecond = true;
                    }
                }
            }
            Assert.IsTrue(foundFirst);
            Assert.IsTrue(foundSecond);
        }
Esempio n. 2
0
        private PhysicalQuantity ParseDenominator(ParseContext context, XmlElement numerator, XmlToModelResult xmlToModelResult)
        {
            ElementParser parser     = ParserRegistry.GetInstance().Get("PQ.TIME");
            ParseContext  subContext = ParseContextImpl.Create("PQ.TIME", typeof(PhysicalQuantity), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                               .MANDATORY, Cardinality.Create("1"), context);

            return((PhysicalQuantity)parser.Parse(subContext, Arrays.AsList((XmlNode)numerator), xmlToModelResult).BareValue);
        }
Esempio n. 3
0
        private Int32?ParseNumerator(ParseContext context, XmlElement numerator, XmlToModelResult xmlToModelResult)
        {
            ElementParser parser     = ParserRegistry.GetInstance().Get("INT.NONNEG");
            ParseContext  subContext = ParseContextImpl.Create("INT.NONNEG", typeof(Int32?), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                               .MANDATORY, Cardinality.Create("1"), context);

            return((Int32?)parser.Parse(subContext, Arrays.AsList((XmlNode)numerator), xmlToModelResult).BareValue);
        }
Esempio n. 4
0
        private PeriodicIntervalTime ParseFrequency(ParseContext context, XmlToModelResult xmlToModelResult, XmlElement durationElement
                                                    )
        {
            ParseContext subContext = ParseContextImpl.Create("PIVL<TS.DATETIME>", typeof(PeriodicIntervalTime), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                              .MANDATORY, Cardinality.Create("1"), context);

            return((PeriodicIntervalTime)ParserRegistry.GetInstance().Get("PIVL<TS.DATETIME>").Parse(subContext, Arrays.AsList((XmlNode
                                                                                                                                )durationElement), xmlToModelResult).BareValue);
        }
Esempio n. 5
0
        private Interval <PlatformDate> ParseDuration(ParseContext context, XmlToModelResult xmlResult, XmlElement durationElement
                                                      )
        {
            ParseContext subContext = ParseContextImpl.Create("IVL<TS.FULLDATE>", typeof(Interval <object>), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                              .MANDATORY, Cardinality.Create("1"), context);

            return((Interval <PlatformDate>)ParserRegistry.GetInstance().Get("IVL<TS.FULLDATE>").Parse(subContext, Arrays.AsList((XmlNode
                                                                                                                                  )durationElement), xmlResult).BareValue);
        }
Esempio n. 6
0
        // this case shouldn't happen, but is useful when the code is
        // translated
        /// <exception cref="System.Exception"></exception>
        private void AssertParserIsRegistered(Type classObj)
        {
            IList <string> keys = ParserRegistry.GetInstance().GetRegistrationKey(classObj);

            foreach (string @string in keys)
            {
                Assert.IsNotNull(ParserRegistry.GetInstance().Get(@string), "register " + classObj.FullName + " (" + @string + ")");
            }
        }
Esempio n. 7
0
        private Interval <PhysicalQuantity> ParseDenominatorSk(ParseContext context, XmlElement numerator, XmlToModelResult xmlToModelResult
                                                               )
        {
            // TM - Unsure if SK is allowed to send in any kind of PQ, or only specific ones. Picked PQ.BASIC to cover most scenarios.
            ElementParser parser     = ParserRegistry.GetInstance().Get("IVL<PQ.BASIC>");
            ParseContext  subContext = ParseContextImpl.Create("IVL<PQ.BASIC>", typeof(PhysicalQuantity), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                               .MANDATORY, Cardinality.Create("1"), context);

            return((Interval <PhysicalQuantity>)parser.Parse(subContext, Arrays.AsList((XmlNode)numerator), xmlToModelResult).BareValue);
        }
Esempio n. 8
0
        public virtual void TestShouldFindRtoParsers()
        {
            ElementParser elementParser = ParserRegistry.GetInstance().Get("RTO<PQ.DRUG,PQ.TIME>");

            Assert.IsNotNull(elementParser);
            Assert.IsTrue(elementParser is RtoPqPqElementParser, "RTO<PQ,PQ>");
            elementParser = ParserRegistry.GetInstance().Get("RTO<PQ.DRUG,PQ.DRUG>");
            Assert.IsNotNull(elementParser);
            Assert.IsTrue(elementParser is RtoPqPqElementParser, "RTO<PQ,PQ>");
            elementParser = ParserRegistry.GetInstance().Get("RTO<MO.CAD,PQ.BASIC>");
            Assert.IsNotNull(elementParser);
            Assert.IsTrue(elementParser is RtoMoPqElementParser, "RTO<MO,PQ>");
        }
Esempio n. 9
0
        public virtual void TestParse()
        {
            XmlToModelResult result = new XmlToModelResult();
            XmlNode          node   = CreateNode("<top><name>Fred</name>" + "<name>Flinstone</name></top>");

            new ListElementParser(ParserRegistry.GetInstance()).Parse(ParseContextImpl.Create("LIST<ABCDEFGHIJKLMNOPQRSTUVWXYZ>", null
                                                                                              , SpecificationVersion.V02R02, null, null, null, Cardinality.Create("1-5"), null, false), AsList(node.ChildNodes), result
                                                                      );
            Assert.IsFalse(result.IsValid(), "valid");
            foreach (Hl7Error error in result.GetHl7Errors())
            {
                System.Console.Out.WriteLine(error);
            }
        }
Esempio n. 10
0
        public virtual void TestParse()
        {
            XmlNode node = CreateNode("<top>" + "<something>Fred</something>" + "<something>Wilma</something>" + "<something>Betty</something>"
                                      + "</top>");
            BareANY result = new SetElementParser(ParserRegistry.GetInstance()).Parse(ParseContextImpl.Create("SET<ST>", null, SpecificationVersion
                                                                                                              .V02R02, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.MANDATORY, Cardinality.Create("1-5"), null, false),
                                                                                      AsList(node.ChildNodes), null);
            ICollection <string> set = ((SET <ST, string>)result).RawSet();

            Assert.IsNotNull(set, "null");
            Assert.AreEqual(3, set.Count, "size");
            Assert.IsTrue(set.Contains("Fred"), "Fred");
            Assert.IsTrue(set.Contains("Wilma"), "Wilma");
            Assert.IsTrue(set.Contains("Betty"), "Betty");
        }
Esempio n. 11
0
        private BareANY CreateType(ParseContext context, XmlElement element, XmlToModelResult parseResult)
        {
            string        type   = GetParameterizedType(context);
            ElementParser parser = ParserRegistry.GetInstance().Get(type);

            if (parser != null)
            {
                return(parser.Parse(ParseContextImpl.CreateWithConstraints(type, context), Arrays.AsList((XmlNode)element), parseResult));
            }
            else
            {
                parseResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Cannot find a parser for type {0}"
                                                                                                        , type), element));
                return(null);
            }
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        public virtual void TestParse()
        {
            XmlNode node = CreateNode("<top>" + "<something value=\"20000407123059\" />" + "<something value=\"20020628010101\" />" +
                                      "</top>");
            BareANY result = new SetElementParser(ParserRegistry.GetInstance()).Parse(ParseContextImpl.Create("SET<TS>", null, SpecificationVersion
                                                                                                              .V02R02, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.MANDATORY, Cardinality.Create("1-5"), null, false),
                                                                                      AsList(node.ChildNodes), new XmlToModelResult());
            ICollection <PlatformDate> set = ((SET <TS, PlatformDate>)result).RawSet();

            Assert.IsNotNull(set, "null");
            Assert.AreEqual(2, set.Count, "size");
            PlatformDate expectedCalendar = DateUtil.GetDate(2000, 3, 7, 12, 30, 59, 0);

            Assert.IsTrue(set.Contains(expectedCalendar), "first date");
            expectedCalendar = DateUtil.GetDate(2002, 5, 28, 1, 1, 1, 0);
            Assert.IsTrue(set.Contains(expectedCalendar), "second date");
        }
Esempio n. 14
0
        public virtual void TestParse()
        {
            XmlNode node = CreateNode("<top><name><family>Flinstone</family><given>Fred</given></name>" + "<name><family>Flinstone</family><given>Wilma</given></name></top>"
                                      );
            BareANY result = new ListElementParser(ParserRegistry.GetInstance()).Parse(ParseContextImpl.Create("LIST<PN>", null, SpecificationVersion
                                                                                                               .V02R02, null, null, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.MANDATORY, Cardinality.Create("1-5"), null, false),
                                                                                       AsList(node.ChildNodes), this.xmlResult);
            IList <PersonName> list = ((LIST <PN, PersonName>)result).RawList();

            Assert.IsNotNull(list, "null");
            Assert.AreEqual(2, list.Count, "size");
            EntityName fred  = list[0];
            EntityName wilma = list[1];

            Assert.AreEqual("Flinstone", fred.Parts[0].Value);
            Assert.AreEqual("Fred", fred.Parts[1].Value);
            Assert.AreEqual("Flinstone", wilma.Parts[0].Value);
            Assert.AreEqual("Wilma", wilma.Parts[1].Value);
        }
Esempio n. 15
0
        public virtual void TestParse()
        {
            XmlNode node = CreateNode("<top>" + "<something specializationType=\"TEL.EMAIL\" value=\"mailto://Fred\"/>" + "<something specializationType=\"TEL.EMAIL\" value=\"mailto://Wilma\"/>"
                                      + "</top>");
            BareANY result = new ListElementParser(ParserRegistry.GetInstance()).Parse(ParseContextImpl.Create("LIST<TEL.PHONEMAIL>",
                                                                                                               null, SpecificationVersion.V02R02, null, null, null, Cardinality.Create("1-5"), null, false), AsList(node.ChildNodes), null
                                                                                       );
            IList <TelecommunicationAddress> list = ((LIST <TEL, TelecommunicationAddress>)result).RawList();

            Assert.IsNotNull(list, "null");
            Assert.AreEqual(2, list.Count, "size");
            ICollection <string> expectedStrings = new HashSet <string>();

            expectedStrings.Add("Fred");
            expectedStrings.Add("Wilma");
            foreach (TelecommunicationAddress address in list)
            {
                Assert.AreEqual(CeRxDomainTestValues.MAILTO.CodeValue, address.UrlScheme.CodeValue, "urlscheme");
                Assert.IsTrue(expectedStrings.Contains(address.Address), "expected set contains address");
                expectedStrings.Remove(address.Address);
            }
        }
Esempio n. 16
0
        private Diff <PlatformDate> CreateDateDiff(ParseContext context, XmlElement width, XmlToModelResult xmlToModelResult)
        {
            Diff <PlatformDate> result = null;

            if (GetAttributeValue(width, NullFlavorHelper.NULL_FLAVOR_ATTRIBUTE_NAME) != null)
            {
                result = ParseNullWidthNode(width);
            }
            else
            {
                try
                {
                    StandardDataType diffType = StandardDataType.PQ_TIME;
                    ElementParser    parser   = ParserRegistry.GetInstance().Get(diffType);
                    if (parser != null)
                    {
                        ParseContext subContext = ParseContextImpl.Create(diffType.Type, typeof(PhysicalQuantity), Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                                          .POPULATED, Cardinality.Create("1"), context);
                        PhysicalQuantity quantity = (PhysicalQuantity)parser.Parse(subContext, Arrays.AsList((XmlNode)width), xmlToModelResult).BareValue;
                        // though in some PQ cases units can be null, this situation does not seem to make sense for PQ.TIME
                        if (quantity != null && quantity.Quantity != null && quantity.Unit != null)
                        {
                            result = new DateDiff(quantity);
                        }
                    }
                    else
                    {
                        xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Cannot find a parser for " + diffType.Type, width
                                                                  ));
                    }
                }
                catch (XmlToModelTransformationException e)
                {
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, e.Message, width));
                }
            }
            return(result);
        }
Esempio n. 17
0
        public virtual void TestShouldFindSetParser()
        {
            ElementParser elementParser = ParserRegistry.GetInstance().Get("SET<RTO<PQ.DRUG,PQ.TIME>>");

            Assert.IsTrue(elementParser is SetElementParser, "SET");
        }
Esempio n. 18
0
 public virtual void TestShouldFindCeParser()
 {
     Assert.IsTrue(ParserRegistry.GetInstance().Get("CE") is CvElementParser, "CE");
 }
Esempio n. 19
0
 public virtual void TestShouldDefaultToUnqualifiedTypeIfNoSpecificParserExists()
 {
     Assert.IsNotNull(ParserRegistry.GetInstance().Get("II.TOKEN"), "II.TOKEN");
 }
Esempio n. 20
0
 public virtual void TestShouldFindSimpleCase()
 {
     Assert.IsNotNull(ParserRegistry.GetInstance().Get("II"), "II");
 }
Esempio n. 21
0
 public virtual void TestRegistered()
 {
     Assert.IsNotNull(ParserRegistry.GetInstance().Get("IVL.LOW<TS.DATE>"), "parser");
 }
Esempio n. 22
0
 public BagElementParser(ParserRegistry parserRegistry) : base(parserRegistry, false)
 {
 }