Пример #1
0
        public void ShouldAddToHl7List()
        {
            Object list = new LISTImpl <ST, String>(typeof(STImpl)).BareValue;

            ListElementUtil.AddElement(list, new STImpl("Betty"));
            Assert.AreEqual(1, ListElementUtil.Count(list), "count");
        }
Пример #2
0
        private void WriteDataType(BeanProperty property, BareANY value, string dataTypeName)
        {
            BareANY field = new DataTypeFieldHelper(property.Bean, property.Name).Get <BareANY>();

            if (field == null)
            {
                //this is required for the case sure when we collapse an association with cardinality > 1
                //into a List of data types. See DevicePrescriptionSummaryQueryCriteriaBean#getRxDispenseIndicator
                if (property.Collection)
                {
                    ListElementUtil.AddElement(property.Get(), value.BareValue);
                }
            }
            else
            {
                value = this.adapterProvider.GetAdapter(dataTypeName, field.GetType()).Adapt(field.GetType(), value);
                if (value.HasNullFlavor())
                {
                    new DataTypeFieldHelper(property.Bean, property.Name).SetNullFlavor(value.NullFlavor);
                }
                if (field is ANYMetaData && value is ANYMetaData)
                {
                    // preserve any meta data (yes, this is not ideal)
                    ((ANYMetaData)field).Language     = ((ANYMetaData)value).Language;
                    ((ANYMetaData)field).DisplayName  = ((ANYMetaData)value).DisplayName;
                    ((ANYMetaData)field).OriginalText = ((ANYMetaData)value).OriginalText;
                    ((ANYMetaData)field).Translations.AddAll(((ANYMetaData)value).Translations);
                }
                ((BareANYImpl)field).BareValue = value.BareValue;
                field.DataType = value.DataType;
            }
        }
Пример #3
0
 internal virtual int GetSingleCollapsedPropertySize()
 {
     if (PropertyCount() != 1)
     {
         throw new MarshallingException(ToString() + " with cardinality changes cannot handle " + PropertyCount() + " collapsed properties"
                                        );
     }
     else
     {
         BeanProperty property = (BeanProperty) new List <BeanProperty>(this.properties.Values)[0];
         object       value    = property.Get();
         if (value == null)
         {
             return(0);
         }
         else
         {
             if (ListElementUtil.IsCollection(value))
             {
                 return(ListElementUtil.Count(value));
             }
             else
             {
                 return(1);
             }
         }
     }
 }
Пример #4
0
        public virtual object GetInitializedReadOnlyAssociation(NamedAndTyped relationshipName)
        {
            object       @object;
            BeanProperty beanProperty = FindBeanProperty(relationshipName);

            if (beanProperty == null)
            {
                @object = null;
            }
            else
            {
                if (!beanProperty.Readable)
                {
                    @object = null;
                }
                else
                {
                    if (ListElementUtil.IsCollection((Type)beanProperty.PropertyType))
                    {
                        //Initialized collections don't count
                        @object = null;
                    }
                    else
                    {
                        @object = beanProperty.Get();
                    }
                }
            }
            return(@object);
        }
Пример #5
0
 private void WriteNonDataType(string relationshipName, BeanProperty property, object @object)
 {
     if (property.Collection)
     {
         if (ListElementUtil.IsCollection(@object))
         {
             ListElementUtil.AddAllElements(property.Get(), @object);
         }
         else
         {
             this.log.Info("Warning mapping HL7 single property to Teal collection. Property=" + relationshipName);
             ListElementUtil.AddElement(property.Get(), @object);
         }
     }
     else
     {
         if (property.Writable)
         {
             if (@object != null)
             {
                 property.Set(@object);
             }
         }
         else
         {
             throw new MarshallingException("Cannot write to " + property.Name + " of " + this.sorter.GetBean().GetType());
         }
     }
 }
Пример #6
0
 protected virtual bool IsEmptyCollection(V value)
 {
     if (ListElementUtil.IsCollection(value))
     {
         return(ListElementUtil.IsEmpty(value));
     }
     return(false);
 }
Пример #7
0
        public void ShouldGetElementFromHl7List()
        {
            IList <String> list = new LISTImpl <ST, String>(typeof(STImpl)).RawList();

            list.Add("Fred");
            list.Add("Barney");
            list.Add("Wilma");

            Assert.AreEqual("Barney", ListElementUtil.GetElement(list, 1), "element");
        }
Пример #8
0
        public void ShouldGetElementFromLinkedSet()
        {
            LinkedSet <String> list = new LinkedSet <String>();

            list.Add("Fred");
            list.Add("Barney");
            list.Add("Wilma");

            Assert.AreEqual("Barney", ListElementUtil.GetElement(list, 1), "element");
        }
Пример #9
0
        public void ShouldGetElementFromArrayList()
        {
            ArrayList list = new ArrayList();

            list.Add("Fred");
            list.Add("Barney");
            list.Add("Wilma");

            Assert.AreEqual("Barney", ListElementUtil.GetElement(list, 1), "element");
        }
Пример #10
0
 private AssociationBridge CreateAssociationBridge(Relationship relationship, RelationshipSorter sorter, Interaction interaction
                                                   , MessagePartHolder currentMessagePart, BridgeContext context)
 {
     if (sorter.IsCollapsedRelationship(relationship))
     {
         if (relationship.Cardinality.Multiple)
         {
             return(CreateCollectionRelationshipBridge(relationship, sorter, interaction));
         }
         else
         {
             RelationshipSorter collapsedSorter = sorter.GetAsRelationshipSorter(relationship);
             PartBridge         bridge          = CreatePartBridge(collapsedSorter, interaction, GetMessagePart(interaction, relationship, collapsedSorter
                                                                                                                .GetBean()), new BridgeContext(true, context.GetOriginalIndex()), false);
             return(new AssociationBridgeImpl(relationship, bridge));
         }
     }
     else
     {
         object       o        = sorter.Get(relationship);
         BeanProperty property = (BeanProperty)o;
         object       value    = property.Get();
         if (relationship.Cardinality.Multiple && value is IEnumerable)
         {
             this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to collection property " +
                            Describer.Describe(sorter.GetBeanType(), property));
             return(CreateCollectionOfCompositeBeanBridges(property.Name, relationship, (IEnumerable)value, interaction));
         }
         else
         {
             if (context.IsIndexed() && property.Collection)
             {
                 this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to index " + context.GetIndex
                                    () + " of collection property " + Describer.Describe(sorter.GetBeanType(), property));
                 object elementValue = ListElementUtil.GetElement(value, context.GetIndex());
                 // use the indexed object's part instead
                 MessagePartHolder part = GetMessagePart(interaction, relationship, elementValue);
                 return(new AssociationBridgeImpl(relationship, CreatePartBridgeFromBean(property.Name + "[" + context.GetIndex() + "]", elementValue
                                                                                         , interaction, part)));
             }
             else
             {
                 this.log.Debug("Association " + Describer.Describe(currentMessagePart, relationship) + " maps to property " + Describer.Describe
                                    (sorter.GetBeanType(), property));
                 // Bug 13050 - should handle a single cardinality relationship if mapped to a collection
                 if (ListElementUtil.IsCollection(value))
                 {
                     value = ListElementUtil.IsEmpty(value) ? null : ListElementUtil.GetElement(value, 0);
                 }
                 MessagePartHolder part = GetMessagePart(interaction, relationship, value);
                 return(new AssociationBridgeImpl(relationship, CreatePartBridgeFromBean(property.Name, value, interaction, part)));
             }
         }
     }
 }
Пример #11
0
        public void ShouldAddToHl7RawList()
        {
            IList <String> list = new LISTImpl <ST, String>(typeof(STImpl)).RawList();

            list.Add("Fred");
            list.Add("Barney");
            list.Add("Wilma");

            ListElementUtil.AddElement(list, "Betty");
            Assert.AreEqual(4, list.Count, "count");
            Assert.IsTrue(list.Contains("Betty"));
        }
Пример #12
0
        public virtual BareANY GetHl7Value(int index)
        {
            object list = this.property == null ? null : new DataTypeFieldHelper(property.Bean, property.Name).Get <object>();

            if (this.property.Collection && ListElementUtil.Count(list) < index)
            {
                return((BareANY)ListElementUtil.GetElement(list, index));
            }
            else
            {
                return(null);
            }
        }
Пример #13
0
 internal static bool IsEmpty(object value)
 {
     if (value == null)
     {
         return(true);
     }
     else
     {
         if (ListElementUtil.IsCollection(value))
         {
             return(0 == ListElementUtil.Count(value));
         }
         else
         {
             return(false);
         }
     }
 }
Пример #14
0
 private bool Hl7ValueHasContent(BareANY hl7Value)
 {
     if (hl7Value.BareValue != null)
     {
         // there's a value; if it's a list, check if it is empty
         if (ListElementUtil.IsCollection(hl7Value.BareValue))
         {
             return(!ListElementUtil.IsEmpty(hl7Value.BareValue));
         }
         else
         {
             return(true);
         }
     }
     else
     {
         // contains no value, but perhaps has a null flavor
         return(hl7Value.HasNullFlavor());
     }
 }
Пример #15
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));
        }
Пример #16
0
        public void ShouldDetectCollection()
        {
            IList <String> list = new List <String>();

            Assert.IsTrue(ListElementUtil.IsCollection(list), "is list");
        }
Пример #17
0
        public void ShouldDetectCollectionOnCollapsedType()
        {
            IList <PersonName> list = new RawListWrapper <PN, PersonName>(new List <PN>(), typeof(PNImpl));

            Assert.IsTrue(ListElementUtil.IsCollection(list), "is list");
        }