예제 #1
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);
        }
예제 #2
0
        private ParseContext HandleSpecializationType(ParseContext context, XmlNode node, XmlToModelResult xmlToModelResult)
        {
            string specializationType = GetSpecializationType(node);

            if (specializationType == null)
            {
                // TM - RedMine issue 492 - there is some concern over MBT forcing a specialization type for abstract TS type TS_FULLDATEWITHTIME
                //    - I'm relaxing this validation for the time being (the formatter currently ignores specialization type completely)
                //    - (update: perhaps the real issue is that this was an IVL<TS.FULLDATEWITHTIME> and MB has a bug where inner types can't have specializationType set??)
                // TM - 16/10/2012 - should be able to set specialization type now (need to specify IVL_FULL_DATE_TIME as the specialization type for IVL<TS.FULLDATEWITHTIME>, for example)
                //                 - in a cowardly move, I have allowed for a system property to bypass this validation error
                if (Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(TsDateFormats.ABSTRACT_TS_IGNORE_SPECIALIZATION_TYPE_ERROR_PROPERTY_NAME
                                                                                       )))
                {
                }
                else
                {
                    // do nothing - fall back to parsing through all allowable date formats for TS.FULLDATEWITHTIME
                    xmlToModelResult.AddHl7Error(Hl7Error.CreateMissingMandatoryAttributeError(AbstractElementParser.SPECIALIZATION_TYPE, (XmlElement
                                                                                                                                           )node));
                }
            }
            else
            {
                if (IsValidSpecializationType(specializationType))
                {
                    context = ParseContextImpl.Create(specializationType, context);
                }
                else
                {
                    // log error - fall back to parsing through all allowable date formats for TS.FULLDATEWITHTIME
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Invalid specialization type " + specializationType
                                                              + " (" + XmlDescriber.DescribeSingleElement((XmlElement)node) + ")", (XmlElement)node));
                }
            }
            return(context);
        }