Esempio n. 1
0
        public virtual void TestSimpleWithOperator()
        {
            Interval <Int32?> ivl    = IntervalFactory.CreateSimple <Int32?>(5, SetOperator.EXCLUDE);
            string            result = this.formatter.Format(GetContext("name"), new IVLImpl <QTY <Int32?>, Interval <Int32?> >(ivl));

            AssertXml("result", "<name operator=\"E\" value=\"5\"/>", result);
        }
Esempio n. 2
0
        public virtual void TestIntervalSimple()
        {
            Interval <PlatformDate> interval = IntervalFactory.CreateSimple <PlatformDate>(ParseDate("2006-12-25"));
            string result = this.formatter.Format(GetContext("name"), new IVLImpl <QTY <PlatformDate>, Interval <PlatformDate> >(interval
                                                                                                                                 ));

            Assert.IsFalse(this.result.IsValid());
            Assert.AreEqual(1, this.result.GetHl7Errors().Count);
            // must have 2 of width/low/high
            AssertXml("result", "<name value=\"20061225\"/>", result);
        }
Esempio n. 3
0
        private Interval <PlatformDate> CreateSimpleValueInterval()
        {
            PlatformDate value = DateUtil.GetDate(2013, 11, 7);

            return(IntervalFactory.CreateSimple(value));
        }
Esempio n. 4
0
        protected override Interval <T> ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                         , XmlToModelResult xmlToModelResult)
        {
            // go back and revert TS.FULLDATEWITHTIME validation check? (is there anything to revert?)
            context = HandleSpecializationType(context, node, xmlToModelResult);
            Interval <T> result = null;
            XmlElement   low    = (XmlElement)GetNamedChildNode(node, "low");
            XmlElement   high   = (XmlElement)GetNamedChildNode(node, "high");
            XmlElement   center = (XmlElement)GetNamedChildNode(node, "center");
            XmlElement   width  = (XmlElement)GetNamedChildNode(node, "width");

            ValidateCorrectElementsProvided(low != null, high != null, center != null, width != null, (XmlElement)node, context, xmlToModelResult
                                            );
            BareANY  lowAny     = low == null ? null : CreateType(context, low, xmlToModelResult);
            object   lowType    = lowAny == null ? null : lowAny.BareValue;
            BareANY  highAny    = high == null ? null : CreateType(context, high, xmlToModelResult);
            object   highType   = highAny == null ? null : highAny.BareValue;
            BareANY  centerAny  = center == null ? null : CreateType(context, center, xmlToModelResult);
            object   centerType = centerAny == null ? null : centerAny.BareValue;
            BareDiff widthType  = width == null ? null : CreateDiffType(context, width, xmlToModelResult);

            DoOtherValidations(lowAny, highAny, centerAny, widthType, (XmlElement)node, context, xmlToModelResult);
            if (lowAny != null && highAny != null)
            {
                result = IntervalFactory.CreateLowHigh <T>((T)lowType, (T)highType, lowAny.NullFlavor, highAny.NullFlavor);
            }
            else
            {
                if (lowAny != null && widthType != null)
                {
                    result = IntervalFactory.CreateLowWidth <T>((T)lowType, (Diff <T>)widthType, lowAny.NullFlavor);
                }
                else
                {
                    if (highAny != null && widthType != null)
                    {
                        result = IntervalFactory.CreateWidthHigh <T>((Diff <T>)widthType, (T)highType, highAny.NullFlavor);
                    }
                    else
                    {
                        if (centerAny != null && widthType != null)
                        {
                            result = IntervalFactory.CreateCentreWidth <T>((T)centerType, (Diff <T>)widthType, centerAny.NullFlavor);
                        }
                        else
                        {
                            if (centerAny != null && lowAny != null)
                            {
                                result = IntervalFactory.CreateLowCentre <T>((T)lowType, (T)centerType, lowAny.NullFlavor, centerAny.NullFlavor);
                            }
                            else
                            {
                                if (centerAny != null && highAny != null)
                                {
                                    result = IntervalFactory.CreateCentreHigh <T>((T)centerType, (T)highType, centerAny.NullFlavor, highAny.NullFlavor);
                                }
                                else
                                {
                                    if (lowAny != null)
                                    {
                                        result = IntervalFactory.CreateLow <T>((T)lowType, lowAny.NullFlavor);
                                    }
                                    else
                                    {
                                        if (highAny != null)
                                        {
                                            result = IntervalFactory.CreateHigh <T>((T)highType, highAny.NullFlavor);
                                        }
                                        else
                                        {
                                            if (centerAny != null)
                                            {
                                                result = IntervalFactory.CreateCentre <T>((T)centerType, centerAny.NullFlavor);
                                            }
                                            else
                                            {
                                                if (widthType != null)
                                                {
                                                    result = IntervalFactory.CreateWidth <T>((Diff <T>)widthType);
                                                }
                                                else
                                                {
                                                    if (low == null && high == null && center == null && width == null)
                                                    {
                                                        // only treat this as a "simple" interval if no other interval elements were provided (even if they were in error)
                                                        // try to parse a "simple" interval; this does not seem a valid approach for MR2009, MR2007, or CeRx (perhaps allowed within the XSDs?)
                                                        object type = CreateType(context, (XmlElement)node, xmlToModelResult).BareValue;
                                                        if (type == null)
                                                        {
                                                            xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.SYNTAX_ERROR, "\"Simple interval node: " + XmlDescriber.DescribePath
                                                                                                          (node) + " does not allow a null value\"", (XmlElement)node));
                                                        }
                                                        else
                                                        {
                                                            result = IntervalFactory.CreateSimple <T>((T)type);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 5
0
        protected override Interval <T> ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                         , XmlToModelResult xmlToModelResult)
        {
            Interval <T> result = null;
            XmlElement   low    = (XmlElement)GetNamedChildNode(node, "low");
            XmlElement   high   = (XmlElement)GetNamedChildNode(node, "high");
            XmlElement   center = (XmlElement)GetNamedChildNode(node, "center");
            XmlElement   width  = (XmlElement)GetNamedChildNode(node, "width");

            ValidateCorrectElementsProvided(low != null, high != null, center != null, width != null, (XmlElement)node, context, xmlToModelResult
                                            );
            BareANY  lowAny        = low == null ? null : CreateType(context, low, xmlToModelResult, false);
            object   lowType       = ExtractValue(lowAny);
            Boolean? lowInclusive  = ExtractInclusive(context, low, xmlToModelResult);
            BareANY  highAny       = high == null ? null : CreateType(context, high, xmlToModelResult, false);
            object   highType      = ExtractValue(highAny);
            Boolean? highInclusive = ExtractInclusive(context, high, xmlToModelResult);
            BareANY  centerAny     = center == null ? null : CreateType(context, center, xmlToModelResult, false);
            object   centerType    = ExtractValue(centerAny);
            BareDiff widthType     = width == null ? null : CreateDiffType(context, width, xmlToModelResult);

            if (lowAny != null && highAny != null)
            {
                result = IntervalFactory.CreateLowHigh <T>((T)lowType, (T)highType, lowAny.NullFlavor, highAny.NullFlavor);
            }
            else
            {
                if (lowAny != null && widthType != null)
                {
                    result = IntervalFactory.CreateLowWidth <T>((T)lowType, (Diff <T>)widthType, lowAny.NullFlavor);
                }
                else
                {
                    if (highAny != null && widthType != null)
                    {
                        result = IntervalFactory.CreateWidthHigh <T>((Diff <T>)widthType, (T)highType, highAny.NullFlavor);
                    }
                    else
                    {
                        if (centerAny != null && widthType != null)
                        {
                            result = IntervalFactory.CreateCentreWidth <T>((T)centerType, (Diff <T>)widthType, centerAny.NullFlavor);
                        }
                        else
                        {
                            if (centerAny != null && lowAny != null)
                            {
                                result = IntervalFactory.CreateLowCentre <T>((T)lowType, (T)centerType, lowAny.NullFlavor, centerAny.NullFlavor);
                            }
                            else
                            {
                                if (centerAny != null && highAny != null)
                                {
                                    result = IntervalFactory.CreateCentreHigh <T>((T)centerType, (T)highType, centerAny.NullFlavor, highAny.NullFlavor);
                                }
                                else
                                {
                                    if (lowAny != null)
                                    {
                                        result = IntervalFactory.CreateLow <T>((T)lowType, lowAny.NullFlavor);
                                    }
                                    else
                                    {
                                        if (highAny != null)
                                        {
                                            result = IntervalFactory.CreateHigh <T>((T)highType, highAny.NullFlavor);
                                        }
                                        else
                                        {
                                            if (centerAny != null)
                                            {
                                                result = IntervalFactory.CreateCentre <T>((T)centerType, centerAny.NullFlavor);
                                            }
                                            else
                                            {
                                                if (widthType != null)
                                                {
                                                    result = IntervalFactory.CreateWidth <T>((Diff <T>)widthType);
                                                }
                                                else
                                                {
                                                    if (low == null && high == null && center == null && width == null)
                                                    {
                                                        // only treat this as a "simple" interval if no other interval elements were provided (even if they were in error)
                                                        // try to parse a "simple" interval
                                                        BareANY simpleAny = CreateType(context, (XmlElement)node, xmlToModelResult, true);
                                                        object  type      = ExtractValue(simpleAny);
                                                        if (type == null)
                                                        {
                                                            xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.SYNTAX_ERROR, "\"Simple interval node: " + XmlDescriber.DescribePath
                                                                                                          (node) + " does not allow a null value\"", (XmlElement)node));
                                                        }
                                                        else
                                                        {
                                                            result = IntervalFactory.CreateSimple <T>((T)type, ((ANYMetaData)simpleAny).Operator);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (result != null)
            {
                result.LowInclusive  = lowInclusive;
                result.HighInclusive = highInclusive;
            }
            return(result);
        }