Пример #1
0
        public virtual void Render(StringBuilder builder, string propertyPath, Hl7Errors errors)
        {
            Relationship r = this.relationship;

            if (r.HasFixedValue())
            {
                FormatFixedValue(builder, r);
            }
            else
            {
                object value = GetValue();
                // structural attributes should never have a conformance of populated, and should never have a nullFlavor (no need to check these cases)
                if (value == null && ConformanceLevelUtil.IsMandatory(r) && r.HasDefaultValue())
                {
                    FormatDefaultValue(builder, r);
                }
                else
                {
                    if (value != null)
                    {
                        FormatValue(builder, r, value);
                    }
                    else
                    {
                        if (ConformanceLevelUtil.IsMandatory(this.relationship))
                        {
                            string   errorMessage = "Relationship " + r.Name + " is mandatory (and not a fixed or default value), but no value is specified";
                            Hl7Error error        = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage, propertyPath);
                            errors.AddHl7Error(error);
                        }
                    }
                }
            }
        }
Пример #2
0
        public virtual NullFlavor ParseNullNode()
        {
            string     attributeValue = GetAttributeValue(node, NULL_FLAVOR_ATTRIBUTE_NAME);
            NullFlavor nullFlavor     = CodeResolverRegistry.Lookup <NullFlavor>(attributeValue);

            if (ConformanceLevelUtil.IsMandatory(this.conformanceLevel, null))
            {
                xmlToModelResult.AddHl7Error(Hl7Error.CreateMandatoryAttributeIsNullError(NodeUtil.GetLocalOrTagName((XmlElement)node), GetAttributeValue
                                                                                              (node, NULL_FLAVOR_ATTRIBUTE_NAME), (XmlElement)node));
            }
            else
            {
                //      RM #15431 - strictly speaking, nullFlavors are not allowed for REQUIRED fields. However, jurisdictions often ignore this restriction.
                //      FIXME:  TM (see RM18424) - once MB has error levels implemented, this can be reinstated as a warning
                //		} else if (this.conformanceLevel != null && this.conformanceLevel == ConformanceLevel.REQUIRED) {
                //			xmlToModelResult.addHl7Error(Hl7Error.createRequiredAttributeIsNullError(
                //					NodeUtil.getLocalOrTagName((Element) node),
                //					getAttributeValue(node, NULL_FLAVOR_ATTRIBUTE_NAME),
                //					(Element) node));
                if (this.isAssociation && !StringUtils.Equals(GetAttributeValue(node, NULL_FLAVOR_XSI_NIL_ATTRIBUTE_NAME), "true"))
                {
                    if (!Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(Ca.Infoway.Messagebuilder.Marshalling.HL7.Parser.NullFlavorHelper
                                                                                            .MB_SUPPRESS_XSI_NIL_ON_NULLFLAVOR)))
                    {
                        xmlToModelResult.AddHl7Error(Hl7Error.CreateNullFlavorMissingXsiNilError(NodeUtil.GetLocalOrTagName((XmlElement)node), (XmlElement
                                                                                                                                                )node));
                    }
                }
            }
            return(nullFlavor);
        }
Пример #3
0
 private bool IsIndicator(Hl7Source source, Relationship relationship)
 {
     if (relationship.TemplateRelationship || relationship.Choice || relationship.Structural)
     {
         return(false);
     }
     return(IsFullyFixedType(relationship, source) && !ConformanceLevelUtil.IsMandatory(relationship));
 }
Пример #4
0
        protected virtual bool IsMandatoryOrPopulated(FormatContext context)
        {
            Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformance = context.GetConformanceLevel();
            Cardinality cardinality = context.GetCardinality();

            return(ConformanceLevelUtil.IsMandatory(conformance, cardinality) || ConformanceLevelUtil.IsPopulated(conformance, cardinality
                                                                                                                  ));
        }
Пример #5
0
 private void FormatDefaultValue(StringBuilder builder, Relationship relationship)
 {
     // suppress rendering of required or optional fixed values
     if (ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship))
     {
         builder.Append(" ").Append(relationship.Name).Append("=\"").Append(XmlStringEscape.Escape(relationship.DefaultValue)).Append
             ("\"");
     }
 }
Пример #6
0
 private void ProcessPartValue(PartBridge child, Interaction interaction, AssociationBridge relationshipBridge, Visitor visitor
                               )
 {
     if (child.IsEmpty() && !ConformanceLevelUtil.IsMandatory(relationshipBridge.GetRelationship()))
     {
     }
     else
     {
         ProcessAllRelationships(child, interaction, visitor);
     }
 }
Пример #7
0
 private void ValidateMandatoryAttributesExist(Hl7Source source, XmlElement element)
 {
     foreach (Relationship relationship in GetMessagePart(source).Relationships)
     {
         if (relationship.Structural && ConformanceLevelUtil.IsMandatory(relationship) && !element.HasAttribute(relationship.Name))
         {
             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.SYNTAX_ERROR, System.String.Format("Attribute {0} missing ({1})"
                                                                                                         , relationship.Name, XmlDescriber.DescribeSingleElement(element)), element));
         }
     }
 }
Пример #8
0
        private AssociationBridge CreateCollectionOfCompositeBeanBridges(string propertyName, Relationship relationship, IEnumerable
                                                                         value, Interaction interaction)
        {
            IList <PartBridge> list = new List <PartBridge>();

            foreach (object @object in value)
            {
                list.Add(CreatePartBridgeFromBean(propertyName, @object, interaction, GetMessagePart(interaction, relationship, @object))
                         );
            }
            // bug 13240 - if empty collection and pop/mand, add a placeholder bridge - this will output a nullflavor element, and a warning for mandatory
            if (list.IsEmpty() && (ConformanceLevelUtil.IsPopulated(relationship) || ConformanceLevelUtil.IsMandatory(relationship)))
            {
                list.Add(CreatePartBridgeFromBean(propertyName, null, interaction, GetMessagePart(interaction, relationship, value)));
            }
            return(new AssociationBridgeImpl(relationship, list));
        }
Пример #9
0
        private AssociationBridge CreateCollectionRelationshipBridge(Relationship relationship, RelationshipSorter sorter, Interaction
                                                                     interaction)
        {
            RelationshipSorter association = sorter.GetAsRelationshipSorter(relationship);
            List <PartBridge>  list        = new List <PartBridge>();
            int length = association.GetSingleCollapsedPropertySize();

            for (int i = 0; i < length; i++)
            {
                list.Add(CreatePartBridge(association, interaction, GetMessagePart(interaction, relationship, null), new BridgeContext(true
                                                                                                                                       , i), false));
            }
            // bug 13240 - if empty collection and pop/mand, add a placeholder bridge - this will output a nullflavor element, and a warning for mandatory
            if (list.IsEmpty() && (ConformanceLevelUtil.IsPopulated(relationship) || ConformanceLevelUtil.IsMandatory(relationship)))
            {
                list.Add(CreatePartBridgeFromBean(string.Empty, null, interaction, GetMessagePart(interaction, relationship, null)));
            }
            return(new AssociationBridgeImpl(relationship, list));
        }
Пример #10
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            string result = string.Empty;

            if (hl7Value != null)
            {
                V value = ExtractBareValue(hl7Value);
                Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel();
                Cardinality cardinality = context.GetCardinality();
                if (hl7Value.HasNullFlavor())
                {
                    result = CreateElement(context, CreateNullFlavorAttributes(hl7Value.NullFlavor), indentLevel, true, true);
                    if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                    {
                        CreateMissingMandatoryWarning(context);
                    }
                }
                else
                {
                    if (value == null || IsEmptyCollection(value))
                    {
                        if (conformanceLevel == null || IsMandatoryOrPopulated(context))
                        {
                            if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                            {
                                result = CreateElement(context, AbstractPropertyFormatter.EMPTY_ATTRIBUTE_MAP, indentLevel, true, true);
                                CreateMissingMandatoryWarning(context);
                            }
                            else
                            {
                                result = CreateElement(context, AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES, indentLevel, true, true);
                            }
                        }
                    }
                    else
                    {
                        result = FormatNonNullDataType(context, hl7Value, indentLevel);
                    }
                }
            }
            return(result);
        }
Пример #11
0
        private bool IsIndicator(Relationship relationship)
        {
            bool result = (!ConformanceLevelUtil.IsMandatory(relationship) && !relationship.Choice && relationship.Type != null && !relationship
                           .Structural);

            if (result)
            {
                string      type        = relationship.Type;
                MessagePart messagePart = this.service.GetMessagePart(this.version, type);
                foreach (Relationship innerRelationship in messagePart.Relationships)
                {
                    if (!innerRelationship.HasFixedValue())
                    {
                        result = false;
                        break;
                    }
                }
            }
            return(result);
        }
Пример #12
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            bool isAny = false;
            CD   cd    = null;

            if (hl7Value is CD)
            {
                cd = (CD)hl7Value;
            }
            else
            {
                isAny = true;
                // bypass some validations
                cd = ConvertAnyToCd(hl7Value);
            }
            StringBuilder result = new StringBuilder();

            if (cd != null)
            {
                HandleConstraints(cd.Value, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult());
                // don't bother validating if we don't have anything to validate
                if (cd.HasNullFlavor() || HasValue(cd, context))
                {
                    Hl7Errors     errors  = context.GetModelToXmlResult();
                    VersionNumber version = context.GetVersion();
                    string        type    = context.Type;
                    bool          isCne   = context.GetCodingStrength() == CodingStrength.CNE;
                    bool          isCwe   = context.GetCodingStrength() == CodingStrength.CWE;
                    // we can't lookup a code supplied in an ANY datatype as we don't know the domain
                    // a "reverse" lookup of domain type by code/codesystem could be possible, but difficult to implement to be 100% correct (MB does not track code systems)
                    if (!isAny)
                    {
                        if (cd.Value != null && cd.Value.CodeValue != null)
                        {
                            ValidateCodeExists(cd.Value, context.GetDomainType(), version, context.IsCda(), context.GetPropertyPath(), errors);
                        }
                    }
                    string codeAsString = (cd.Value != null ? cd.Value.CodeValue : null);
                    CD_VALIDATION_UTILS.ValidateCodedType(cd, codeAsString, isCwe, isCne, false, context.IsFixed(), type, version, null, context
                                                          .GetPropertyPath(), errors);
                }
                IDictionary <string, string> attributes = new Dictionary <string, string>();
                Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel();
                Cardinality cardinality = context.GetCardinality();
                if (cd.HasNullFlavor())
                {
                    if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                    {
                        LogMandatoryError(context);
                    }
                    else
                    {
                        attributes.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor));
                    }
                }
                else
                {
                    if (!HasValue(cd, context))
                    {
                        if (conformanceLevel == null || IsMandatoryOrPopulated(context))
                        {
                            if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                            {
                                LogMandatoryError(context);
                            }
                            else
                            {
                                attributes.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES);
                            }
                        }
                    }
                }
                // Codes can have other attributes in map even if has NullFlavor
                attributes.PutAll(GetAttributeNameValuePairs(context, cd.Value, hl7Value));
                bool hasChildContent = HasChildContent(cd, context);
                if (hasChildContent || (!attributes.IsEmpty() || ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)))
                {
                    result.Append(CreateElement(context, attributes, indentLevel, !hasChildContent, !hasChildContent));
                    if (hasChildContent)
                    {
                        CreateChildContent(cd, result);
                        result.Append("</").Append(context.GetElementName()).Append(">");
                        result.Append(SystemUtils.LINE_SEPARATOR);
                    }
                }
            }
            return(result.ToString());
        }
Пример #13
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override string ParseNonNullNode(ParseContext context, XmlNode node, BareANY dataType, Type returnType, XmlToModelResult
                                                   xmlToModelResult)
        {
            XmlElement element = (XmlElement)node;

            if (StandardDataType.ST.Type.Equals(context.Type) && HasLanguageAttribute(element))
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute is not allowed for ST element types ({0})"
                                                                                                             , XmlDescriber.DescribeSingleElement(element)), element));
            }
            else
            {
                if (StandardDataType.ST_LANG.Type.Equals(context.Type) && !HasLanguageAttribute(element))
                {
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute is required for ST.LANG element types ({0})"
                                                                                                                 , XmlDescriber.DescribeSingleElement(element)), element));
                }
                else
                {
                    if (StandardDataType.ST_LANG.Type.Equals(context.Type) && HasLanguageAttribute(element) && !LanguageSupported(element))
                    {
                        xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute is not one of the supported types ({0})"
                                                                                                                     , XmlDescriber.DescribeSingleElement(element)), element));
                    }
                }
            }
            string result         = null;
            int    childNodeCount = node.ChildNodes.Count;

            if (childNodeCount == 0)
            {
                if (ConformanceLevelUtil.IsMandatory(context.GetConformance(), context.GetCardinality()))
                {
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The string value should not be empty ({0})"
                                                                                                                 , XmlDescriber.DescribeSingleElement(element)), element));
                }
                // this is an empty node, return empty string (null should have a null flavor attribute)
                result = AbstractSingleElementParser <string> .EMPTY_STRING;
            }
            else
            {
                if (childNodeCount == 1)
                {
                    XmlNode childNode = node.FirstChild;
                    if (childNode.NodeType != System.Xml.XmlNodeType.Text && childNode.NodeType != System.Xml.XmlNodeType.CDATA)
                    {
                        // RM18422 - decided to allow for CDATA section within ST datatypes (other datatypes - AD, ON, PN, SC, TN - still restrict to TEXT only)
                        throw new XmlToModelTransformationException("Expected ST node to have a text node");
                    }
                    if (childNode.NodeType == System.Xml.XmlNodeType.CDATA)
                    {
                        ((ST)dataType).IsCdata = true;
                    }
                    result = childNode.Value;
                }
                else
                {
                    throw new XmlToModelTransformationException("Expected ST node to have at most one child");
                }
            }
            if (context.GetLength() != null && result.Length > context.GetLength())
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The specified string (\"{0}\") exceeds the maximum length of {1}.  The string has been truncated."
                                                                                                             , Truncate(result, 50), context.GetLength()), element));
                result = StringUtils.Left(result, context.GetLength());
            }
            if (StandardDataType.ST_LANG.Type.Equals(context.Type))
            {
                string language = ((XmlElement)node).GetAttribute("language");
                // this cast is safe - it will always be an STImpl due to the doCreateDataTypeInstance() method
                ((STImpl)dataType).Language = StringUtils.TrimToNull(language);
            }
            return(result);
        }
Пример #14
0
        private void RenderNonStructuralAttribute(AttributeBridge tealBean, Relationship relationship, ConstrainedDatatype constraints
                                                  , TimeZoneInfo dateTimeZone, TimeZoneInfo dateTimeTimeZone)
        {
            string            propertyPath = BuildPropertyPath();
            BareANY           hl7Value     = tealBean.GetHl7Value();
            string            type         = DetermineActualType(relationship, hl7Value, this.result, propertyPath);
            PropertyFormatter formatter    = this.formatterRegistry.Get(type);

            if (formatter == null)
            {
                throw new RenderingException("Cannot support properties of type " + type);
            }
            else
            {
                string xmlFragment = string.Empty;
                try
                {
                    BareANY any = null;
                    bool    isMandatoryOrPopulated = ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                                        );
                    if (relationship.HasFixedValue())
                    {
                        // suppress rendering fixed values for optional or required
                        if (isMandatoryOrPopulated)
                        {
                            any = (BareANY)DataTypeFactory.CreateDataType(relationship.Type, this.isCda && this.isR2);
                            object fixedValue = NonStructuralHl7AttributeRenderer.GetFixedValue(relationship, version, this.isR2, this.result, propertyPath
                                                                                                );
                            ((BareANYImpl)any).BareValue = fixedValue;
                        }
                    }
                    else
                    {
                        any = hl7Value;
                        any = this.adapterProvider.GetAdapter(any != null ? any.GetType() : null, type).Adapt(type, any);
                    }
                    // TODO - CDA - TM - implement default value handling
                    //					boolean valueNotProvided = (any.getBareValue() == null && !any.hasNullFlavor());
                    //					if (valueNotProvided && relationship.hasDefaultValue() && isMandatoryOrPopulated) {
                    //						// FIXME - CDA - TM - this doesn't work - will have a class cast exception (put Object convert(Object/String?) on ANY, implement trivial in ANYImpl, implement where necessary?)
                    //
                    //						any.setBareValue(relationship.getDefaultValue());
                    //					}
                    if (hl7Value != null && Hl7ValueHasContent(hl7Value))
                    {
                        HandleNotAllowedAndIgnored(relationship, propertyPath);
                    }
                    FormatContext context = Ca.Infoway.Messagebuilder.Marshalling.FormatContextImpl.Create(this.result, propertyPath, relationship
                                                                                                           , version, dateTimeZone, dateTimeTimeZone, constraints, this.isCda);
                    if (!StringUtils.Equals(type, relationship.Type))
                    {
                        context = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(type, true, context);
                    }
                    xmlFragment += formatter.Format(context, any, GetIndent());
                    // if relationship specifies a namespace, need to add it to xml
                    if (StringUtils.IsNotBlank(xmlFragment) & StringUtils.IsNotBlank(relationship.Namespaze))
                    {
                        xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "<" + relationship.Name + " ", "<" + relationship
                                                                                   .Namespaze + ":" + relationship.Name + " ");
                        xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "<" + relationship.Name + ">", "<" + relationship
                                                                                   .Namespaze + ":" + relationship.Name + ">");
                        xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "</" + relationship.Name + ">", "</" + relationship
                                                                                   .Namespaze + ":" + relationship.Name + ">");
                    }
                }
                catch (ModelToXmlTransformationException e)
                {
                    Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, e.Message, propertyPath);
                    this.result.AddHl7Error(hl7Error);
                }
                RenderNewErrorsToXml(CurrentBuffer().GetChildBuilder());
                CurrentBuffer().GetChildBuilder().Append(xmlFragment);
            }
        }
Пример #15
0
 public virtual void VisitAssociationStart(PartBridge part, Relationship relationship)
 {
     if (IsSomethingToRender(part, relationship))
     {
         bool   validationWarning = false;
         string warningMessage    = null;
         PushPropertyPathName(DeterminePropertyName(part.GetPropertyName(), relationship), part.IsCollapsed());
         string propertyPath   = BuildPropertyPath();
         string xmlElementName = DetermineXmlName(part, relationship);
         if (StringUtils.IsNotBlank(relationship.Namespaze))
         {
             xmlElementName = relationship.Namespaze + ":" + xmlElementName;
         }
         this.buffers.Push(new XmlRenderingVisitor.Buffer(this, xmlElementName, this.buffers.Count));
         AddChoiceAnnotation(part, relationship);
         if (part.IsEmpty() && (ConformanceLevelUtil.IsPopulated(relationship) || part.HasNullFlavor()))
         {
             // MBR-319 - some clients want xsi:nil suppressed
             string nf = Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(NullFlavorHelper.MB_SUPPRESS_XSI_NIL_ON_NULLFLAVOR
                                                                                            )) ? NULL_FLAVOR_FORMAT_FOR_ASSOCIATIONS_NO_XSI_NIL : NULL_FLAVOR_FORMAT_FOR_ASSOCIATIONS;
             CurrentBuffer().GetStructuralBuilder().Append(System.String.Format(nf, GetNullFlavor(part).CodeValue));
         }
         else
         {
             if (part.IsEmpty() && ConformanceLevelUtil.IsMandatory(relationship) && !IsTrivial(part))
             {
                 // some errors are due to "null" parts MB has inserted to create structural XML; don't log errors on these
                 validationWarning = !part.IsNullPart() && !part.IsCollapsed();
                 warningMessage    = "Mandatory association has no data.";
                 if (!validationWarning)
                 {
                     CurrentBuffer().AddWarning(warningMessage + " (" + propertyPath + ")");
                 }
             }
             else
             {
                 if (ConformanceLevelUtil.IsIgnored(relationship))
                 {
                     validationWarning = true;
                     warningMessage    = System.String.Format(ConformanceLevelUtil.IsIgnoredNotAllowed() ? ConformanceLevelUtil.ASSOCIATION_IS_IGNORED_AND_CANNOT_BE_USED
                                                          : ConformanceLevelUtil.ASSOCIATION_IS_IGNORED_AND_WILL_NOT_BE_USED, relationship.Name);
                 }
                 else
                 {
                     if (ConformanceLevelUtil.IsNotAllowed(relationship))
                     {
                         validationWarning = true;
                         warningMessage    = System.String.Format(ConformanceLevelUtil.ASSOCIATION_IS_NOT_ALLOWED, relationship.Name);
                     }
                 }
             }
         }
         if (validationWarning)
         {
             // store error within error collection
             this.result.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, warningMessage, propertyPath));
         }
         AddNewErrorsToList(CurrentBuffer().GetWarnings());
         RenderRealmCodes(part);
     }
 }
Пример #16
0
 private bool IsSomethingToRender(PartBridge tealBean, Relationship relationship)
 {
     return(!tealBean.IsEmpty() || ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                      ) || tealBean.HasNullFlavor());
 }
Пример #17
0
 private void ValidateNonstructuralFixedValue(Relationship relationship, BareANY value, Hl7Source source, IList <XmlNode> nodes
                                              )
 {
     if (relationship.HasFixedValue())
     {
         bool valueProvided = (value != null && value.BareValue != null);
         bool valid         = valueProvided || (!ConformanceLevelUtil.IsMandatory(relationship) && !ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                                     ));
         // optional and required fixed values do not have to provide a value, but if they do they must conform to specified value
         if (valueProvided)
         {
             if ("BL".Equals(relationship.Type) && value is BL)
             {
                 string valueAsString = ((BL)value).Value.ToString();
                 valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
             }
             else
             {
                 if ("ST".Equals(relationship.Type) && value is ST)
                 {
                     string valueAsString = ((ST)value).Value.ToString();
                     valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
                 }
                 else
                 {
                     if ("INT.POS".Equals(relationship.Type) && value is INT)
                     {
                         string valueAsString = ((INT)value).Value.ToString();
                         valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
                     }
                     else
                     {
                         if (relationship.CodedType)
                         {
                             if (source.IsR2())
                             {
                                 if (GenericClassUtil.IsInstanceOfANY(value))
                                 {
                                     object value2 = GenericClassUtil.GetValueFromANY(value);
                                     Code   code   = value2 == null ? null : CodedTypeR2Helper.GetCode(value2);
                                     valid = (code != null && code.CodeValue != null && StringUtils.Equals(relationship.FixedValue, code.CodeValue));
                                 }
                             }
                             else
                             {
                                 if (value is CD)
                                 {
                                     Code code = ((CD)value).Value;
                                     valid = (code.CodeValue != null && StringUtils.Equals(relationship.FixedValue, code.CodeValue));
                                 }
                             }
                         }
                         else
                         {
                             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.SYNTAX_ERROR, "Non-structural fixed-value attribute '" + relationship
                                                                         .Name + "' was of unexpected type '" + relationship.Type + "'", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
                         }
                     }
                 }
             }
         }
         if (!valid)
         {
             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED, "Fixed-value attribute '" + relationship
                                                         .Name + "' must have value '" + relationship.FixedValue + "'", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
         }
     }
 }
Пример #18
0
        private PartBridge CreatePartBridge(RelationshipSorter sorter, Interaction interaction, MessagePartHolder currentMessagePart
                                            , BridgeContext context, bool nullPart)
        {
            IList <BaseRelationshipBridge> relationships = new List <BaseRelationshipBridge>();

            foreach (Relationship relationship in currentMessagePart.GetRelationships())
            {
                object o = sorter.Get(relationship);
                if (relationship.Attribute && relationship.HasFixedValue())
                {
                    relationships.Add(new FixedValueAttributeBeanBridge(relationship, (BareANY)null));
                }
                else
                {
                    if (relationship.Attribute)
                    {
                        if (o == null)
                        {
                            CreateWarningIfPropertyIsNotMapped(sorter, currentMessagePart, relationship);
                            relationships.Add(new AttributeBridgeImpl(relationship, null));
                        }
                        else
                        {
                            if (context.IsIndexed())
                            {
                                CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                                object field = sorter.GetField(relationship);
                                if (ListElementUtil.IsCollection(field))
                                {
                                    relationships.Add(new CollapsedAttributeBridge(((BeanProperty)o).Name, relationship, ListElementUtil.GetElement(field, context
                                                                                                                                                    .GetIndex())));
                                }
                                else
                                {
                                    throw new MarshallingException("Expected relationship " + relationship.Name + " on " + sorter + " to resolve to a List because we think it's a collapsed "
                                                                   + " attribute");
                                }
                            }
                            else
                            {
                                CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                                relationships.Add(CreateAttributeBridge(relationship, (BeanProperty)o, sorter, currentMessagePart));
                            }
                        }
                    }
                    else
                    {
                        if (IsIndicator(relationship))
                        {
                            CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                            relationships.Add(CreateIndicatorAssociationBridge(relationship, sorter, interaction, context, (BeanProperty)o));
                        }
                        else
                        {
                            if (o == null)
                            {
                                CreateWarningIfPropertyIsNotMapped(sorter, currentMessagePart, relationship);
                                if (ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship))
                                {
                                    relationships.Add(new AssociationBridgeImpl(relationship, CreateNullPartBridge(relationship, interaction)));
                                }
                            }
                            else
                            {
                                CreateWarningIfConformanceLevelIsNotAllowed(relationship);
                                relationships.Add(CreateAssociationBridge(relationship, sorter, interaction, currentMessagePart, context));
                            }
                        }
                    }
                }
            }
            //		if (sorter.getPropertyName() == null || sorter.getPropertyName().equals("null")) {
            //			System.out.println("not correct");
            //		}
            return(new PartBridgeImpl(sorter.GetPropertyName(), sorter.GetBean(), currentMessagePart.GetName(), relationships, context
                                      .IsCollapsed(), nullPart));
        }
Пример #19
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override string ParseNonNullNode(ParseContext context, XmlNode node, BareANY dataType, Type returnType, XmlToModelResult
                                                   xmlToModelResult)
        {
            XmlElement element = (XmlElement)node;

            // could have language (if so, must be nonblank); don't know if language only restricted to certain types
            // must have text (NF would have been processed elsewhere)
            // TM: incoming xml should have mediaType=\"text/plain\" and representation=\"TXT\", but not currently validating this
            if (HasLanguageAttribute(element) && GetLanguage(element) == null)
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("For ST, the language attribute, if provided, can not be blank."
                                                                                                             , XmlDescriber.DescribeSingleElement(element)), element));
            }
            string result         = null;
            int    childNodeCount = node.ChildNodes.Count;

            if (childNodeCount == 0)
            {
                if (ConformanceLevelUtil.IsMandatory(context.GetConformance(), context.GetCardinality()))
                {
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The string value should not be empty ({0})"
                                                                                                                 , XmlDescriber.DescribeSingleElement(element)), element));
                }
                // this is an empty node, return empty string (null should have a null flavor attribute)
                result = AbstractSingleElementParser <string> .EMPTY_STRING;
            }
            else
            {
                if (childNodeCount == 1)
                {
                    XmlNode childNode = node.FirstChild;
                    if (childNode.NodeType != System.Xml.XmlNodeType.Text && childNode.NodeType != System.Xml.XmlNodeType.CDATA)
                    {
                        // RM18422 - decided to allow for CDATA section within ST datatypes (other datatypes - AD, ON, PN, SC, TN - still restrict to TEXT only)
                        throw new XmlToModelTransformationException("Expected ST node to have a text node");
                    }
                    if (childNode.NodeType == System.Xml.XmlNodeType.CDATA)
                    {
                        ((ST)dataType).IsCdata = true;
                    }
                    result = childNode.Value;
                }
                else
                {
                    throw new XmlToModelTransformationException("Expected ST node to have at most one child");
                }
            }
            if (context.GetLength() != null && result.Length > context.GetLength())
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The specified string (\"{0}\") exceeds the maximum length of {1}.  The string has been truncated."
                                                                                                             , Truncate(result, 50), context.GetLength()), element));
                result = StringUtils.Left(result, context.GetLength());
            }
            if (HasLanguageAttribute(element))
            {
                string language = GetLanguage(node);
                // this cast is safe - it will always be an STImpl due to the doCreateDataTypeInstance() method
                ((STImpl)dataType).Language = language;
            }
            return(result);
        }