Exemple #1
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
                                                                                                                  ));
        }
Exemple #2
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
             ("\"");
     }
 }
Exemple #3
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));
        }
Exemple #4
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));
        }
Exemple #5
0
 private void HandleNullFlavor(CodedTypeR2 <Code> codedType, IDictionary <string, string> result, BareANY bareAny, FormatContext
                               context)
 {
     if (bareAny != null && bareAny.HasNullFlavor())
     {
         result.PutAll(CreateNullFlavorAttributes(bareAny.NullFlavor));
     }
     else
     {
         if (codedType == null)
         {
             Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel();
             Cardinality cardinality = context.GetCardinality();
             if (conformanceLevel == null || ConformanceLevelUtil.IsPopulated(conformanceLevel, cardinality))
             {
                 result.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES);
             }
         }
     }
 }
Exemple #6
0
 public virtual void VisitAttribute(AttributeBridge tealBean, Relationship relationship, ConstrainedDatatype constraints,
                                    TimeZoneInfo dateTimeZone, TimeZoneInfo dateTimeTimeZone)
 {
     PushPropertyPathName(DeterminePropertyName(tealBean.GetPropertyName(), relationship), false);
     if (relationship.Structural)
     {
         string propertyPath = BuildPropertyPath();
         if (tealBean.GetValue() != null)
         {
             HandleNotAllowedAndIgnored(relationship, propertyPath);
         }
         // TODO - CDA - TM - may need to handle constraints for structural attributes
         new VisitorStructuralAttributeRenderer(relationship, tealBean.GetValue()).Render(CurrentBuffer().GetStructuralBuilder(),
                                                                                          propertyPath, this.result);
         AddNewErrorsToList(CurrentBuffer().GetWarnings());
     }
     else
     {
         bool hasProperty = !StringUtils.IsEmpty(tealBean.GetPropertyName());
         if (hasProperty)
         {
             RenderNonStructuralAttribute(tealBean, relationship, constraints, dateTimeZone, dateTimeTimeZone);
         }
         else
         {
             if (ConformanceLevelUtil.IsMandatoryOrPopulated(relationship))
             {
                 IDictionary <string, string> attributes = null;
                 if (ConformanceLevelUtil.IsPopulated(relationship))
                 {
                     attributes = new Dictionary <string, string>();
                     attributes["nullFlavor"] = "NI";
                 }
                 string placeholderXml = XmlRenderingUtils.CreateStartElement(relationship.Name, attributes, GetIndent(), true, true);
                 CurrentBuffer().GetChildBuilder().Append(placeholderXml);
             }
         }
     }
     this.propertyPathNames.Pop();
 }
Exemple #7
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));
        }
Exemple #8
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);
            }
        }
Exemple #9
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);
     }
 }
Exemple #10
0
 private bool IsSomethingToRender(PartBridge tealBean, Relationship relationship)
 {
     return(!tealBean.IsEmpty() || ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                      ) || tealBean.HasNullFlavor());
 }
Exemple #11
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]));
         }
     }
 }