Exemple #1
0
        private void ExtractReferenceTypes(PropertyInfo prop, FhirPropertyInfo target)
        {
            var attReferenceAttribute = prop.GetCustomAttribute <ReferencesAttribute>(false);

            if (attReferenceAttribute != null)
            {
                target.IsReference = true;
                target.AllowedTypes.AddRange(attReferenceAttribute.Resources.Select(r => _fhirModel.GetTypeForResourceName(r)).Where(at => at != null));
            }
        }
Exemple #2
0
        private static void ExtractDataChoiceTypes(PropertyInfo prop, FhirPropertyInfo target)
        {
            var attFhirElement = prop.GetCustomAttribute <FhirElementAttribute>(false);

            if (attFhirElement != null)
            {
                target.PropertyName  = attFhirElement.Name;
                target.IsFhirElement = true;
                if (attFhirElement.Choice == ChoiceType.DatatypeChoice ||
                    attFhirElement.Choice == ChoiceType.ResourceChoice)
                {
                    var attChoiceAttribute = prop.GetCustomAttribute <AllowedTypesAttribute>(false);
                    //CK: Nasty workaround because Element.Value is specified wit AllowedTypes(Element) instead of the list of exact types.
                    //TODO: Solve this, preferably in the Hl7.Api
                    if (prop.DeclaringType == typeof(Extension) && prop.Name == "Value")
                    {
                        target.AllowedTypes.AddRange(
                            new List <Type>
                        {
                            typeof(Integer),
                            typeof(FhirDecimal),
                            typeof(FhirDateTime),
                            typeof(Date),
                            typeof(Instant),
                            typeof(FhirString),
                            typeof(FhirUri),
                            typeof(FhirBoolean),
                            typeof(Code),
                            typeof(Markdown),
                            typeof(Base64Binary),
                            typeof(Coding),
                            typeof(CodeableConcept),
                            typeof(Attachment),
                            typeof(Identifier),
                            typeof(Quantity),
                            typeof(Hl7.Fhir.Model.Range),
                            typeof(Period),
                            typeof(Ratio),
                            typeof(HumanName),
                            typeof(Address),
                            typeof(ContactPoint),
                            typeof(Timing),
                            typeof(Signature),
                            typeof(ResourceReference)
                        });
                    }
                    else if (attChoiceAttribute != null)
                    {
                        target.AllowedTypes.AddRange(attChoiceAttribute.Types);
                    }
                }
            }
        }
Exemple #3
0
        private void ExtractDataChoiceTypes(PropertyInfo prop, FhirPropertyInfo target)
        {
            var attFhirElement = prop.GetCustomAttribute <FhirElementAttribute>(false);

            if (attFhirElement != null)
            {
                target.PropertyName  = attFhirElement.Name;
                target.IsFhirElement = true;
                if (attFhirElement.Choice == ChoiceType.DatatypeChoice || attFhirElement.Choice == ChoiceType.ResourceChoice)
                {
                    var attChoiceAttribute = prop.GetCustomAttribute <AllowedTypesAttribute>(false);
                    if (attChoiceAttribute != null)
                    {
                        target.AllowedTypes.AddRange(attChoiceAttribute.Types);
                    }
                }
            }
        }
Exemple #4
0
        internal FhirPropertyInfo CreateFhirPropertyInfo(PropertyInfo prop)
        {
            var result = new FhirPropertyInfo();

            result.PropertyName = prop.Name;
            result.PropInfo     = prop;
            result.AllowedTypes = new List <Type>();

            ExtractDataChoiceTypes(prop, result);

            ExtractReferenceTypes(prop, result);

            if (!result.AllowedTypes.Any())
            {
                result.AllowedTypes.Add(prop.PropertyType);
            }
            return(result);
        }
        internal FhirPropertyInfo CreateFhirPropertyInfo(PropertyInfo prop)
        {
            var result = new FhirPropertyInfo();

            result.PropertyName = prop.Name;
            result.PropInfo     = prop;
            result.AllowedTypes = new List <Type>();

            ExtractDataChoiceTypes(prop, result);

            ExtractReferenceTypes(prop, result);

            if (!result.AllowedTypes.Any())
            {
                result.AllowedTypes.Add(prop.PropertyType);
            }

            result.TypedNames = result.AllowedTypes.Select(at => result.PropertyName + findFhirTypeInfo(fti => fti.FhirType == at)?.TypeName.FirstUpper() ?? at.Name).ToList();

            return(result);
        }
        /// <summary>
        /// Find info about the property with the name <paramref name="propertyName"/> in the resource of type <paramref name="fhirType"/>.
        /// Can also be called for the resourceTypeName instead of the Type, <see cref="findPropertyInfo(string, string)"/>.
        /// </summary>
        /// <param name="fhirType">Type of resource that should contain a property with the supplied name.</param>
        /// <param name="propertyName">Name of the property within the resource type.</param>
        /// <returns><see cref="FhirPropertyInfo"/> for the specified property. Null if not present.</returns>
        public FhirPropertyInfo findPropertyInfo(Type fhirType, string propertyName)
        {
            FhirPropertyInfo propertyInfo = null;

            if (fhirType.IsGenericType)
            {
                propertyInfo = findFhirTypeInfo(new Predicate
                                                <FhirTypeInfo>(r => r.FhirType.Name == fhirType.Name))?
                               .findPropertyInfo(propertyName);
                if (propertyInfo != null)
                {
                    propertyInfo.PropInfo = fhirType.GetProperty(propertyInfo.PropInfo.Name);
                }
            }
            else
            {
                propertyInfo = findFhirTypeInfo(new Predicate
                                                <FhirTypeInfo>(r => r.FhirType == fhirType))?
                               .findPropertyInfo(propertyName);
            }

            return(propertyInfo);
        }
Exemple #7
0
        private void ExtractDataChoiceTypes(PropertyInfo prop, FhirPropertyInfo target)
        {
            var attFhirElement = prop.GetCustomAttribute<FhirElementAttribute>(false);
            if (attFhirElement != null)
            {
                target.PropertyName = attFhirElement.Name;
                target.IsFhirElement = true;
                if (attFhirElement.Choice == ChoiceType.DatatypeChoice || attFhirElement.Choice == ChoiceType.ResourceChoice)
                {
                    var attChoiceAttribute = prop.GetCustomAttribute<AllowedTypesAttribute>(false);
                    if (attChoiceAttribute != null)
                    {
                        target.AllowedTypes.AddRange(attChoiceAttribute.Types);
                    }
                }

            }
        }
Exemple #8
0
 private void ExtractReferenceTypes(PropertyInfo prop, FhirPropertyInfo target)
 {
     var attReferenceAttribute = prop.GetCustomAttribute<ReferencesAttribute>(false);
     if (attReferenceAttribute != null)
     {
         target.IsReference = true;
         target.AllowedTypes.AddRange(attReferenceAttribute.Resources.Select(r => _fhirModel.GetTypeForResourceName(r)).Where(at => at != null));
     }
 }
Exemple #9
0
        internal FhirPropertyInfo CreateFhirPropertyInfo(PropertyInfo prop)
        {
            var result = new FhirPropertyInfo();
            result.PropertyName = prop.Name;
            result.PropInfo = prop;
            result.AllowedTypes = new List<Type>();

            ExtractDataChoiceTypes(prop, result);

            ExtractReferenceTypes(prop, result);

            if (!result.AllowedTypes.Any())
            {
                result.AllowedTypes.Add(prop.PropertyType);
            }
            return result;
        }