Exemple #1
0
        protected override ModelMetadata CreateMetadata(IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            ModelMetadata metadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);

            PropertyEditableAttribute editable = attributes.OfType <PropertyEditableAttribute>().FirstOrDefault();

            if (editable == null)
            {
                editable = PropertyEditableAttribute.Default;
            }
            metadata.AdditionalValues.Add(EditableWhenCreate_Key, editable.WhenCreate);
            metadata.AdditionalValues.Add(EditableWhenEdit_Key, editable.WhenEdit);

            metadata.AdditionalValues.Add(Icon_Prefix, attributes.OfType <IconAttribute>().Select(i => i.File).FirstOrDefault());
            metadata.AdditionalValues.Add(RealSort_Key, attributes.OfType <RealSortAttribute>().Select(s => s.Expression).FirstOrDefault());

            TypeConverterAttribute typeConverterAttribute = attributes.OfType <TypeConverterAttribute>().FirstOrDefault();

            if (typeConverterAttribute != null && typeConverterAttribute.ConverterTypeName != null)
            {
                metadata.AdditionalValues.Add(ConverterTypeName_Key, typeConverterAttribute.ConverterTypeName);
            }

            foreach (var item in attributes.OfType <KeyValueInfoAttribute>())
            {
                metadata.AdditionalValues.Add(KeyValueInfoAttribute_Prefix + item.Key, item.Value);
            }

            DataFormatAttribute dataFormatAttribute = attributes.OfType <DataFormatAttribute>().FirstOrDefault();

            if (dataFormatAttribute != null)
            {
                metadata.EditFormatString         = dataFormatAttribute.EditFormatStringWithBraces;
                metadata.DisplayFormatString      = dataFormatAttribute.DiaplayFormatStringWithBraces;
                metadata.NullDisplayText          = dataFormatAttribute.NullDisplayText;
                metadata.ConvertEmptyStringToNull = dataFormatAttribute.ConvertEmptyStringToNull;
            }

            EnumerationAttribute enumerationAttribute = attributes.OfType <EnumerationAttribute>().FirstOrDefault();

            if (enumerationAttribute != null)
            {
                metadata.AdditionalValues.Add(EnumerationAttribute_Key, enumerationAttribute);
            }

            BoolAttribute boolAttribute = attributes.OfType <BoolAttribute>().FirstOrDefault();

            if (boolAttribute != null)
            {
                metadata.AdditionalValues.Add(BoolAttribute_Key, boolAttribute);
            }

            metadata.AdditionalValues.Add(AllAttribute_Key, attributes);

            return(metadata);
        }
Exemple #2
0
        static AD()
        {
            PartTypeMap = new Dictionary <string, AddressPartType>();

            foreach (FieldInfo fi in typeof(AddressPartType).GetFields())
            {
                if (fi.GetCustomAttributes(typeof(EnumerationAttribute), true).Length > 0)
                {
                    EnumerationAttribute ea = fi.GetCustomAttributes(typeof(EnumerationAttribute), true)[0] as EnumerationAttribute;
                    PartTypeMap.Add(ea.Value, (AddressPartType)fi.GetValue(null));
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Create a value from an Everest enum
        /// </summary>
        /// TODO: Optimize this
        private ValueSet CreateValueFromEverestEnum(Type enumType)
        {
            StructureAttribute structAtt = enumType.GetCustomAttribute <StructureAttribute>();
            var baseUri = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.ToString();

            ValueSet retVal = new ValueSet();

            retVal.Name       = structAtt.Name;
            retVal.Identifier = structAtt.CodeSystem;
            retVal.Id         = retVal.Identifier;
            // Use the company attribute
            var companyAtt = enumType.Assembly.GetCustomAttribute <AssemblyCompanyAttribute>();

            if (companyAtt != null)
            {
                retVal.Publisher = companyAtt.Company;
            }
            var versionAtt = enumType.Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>();

            if (versionAtt != null)
            {
                retVal.Version = versionAtt.InformationalVersion;
            }
            retVal.VersionId = retVal.Version;

            // Date of the assembly file
            if (!String.IsNullOrEmpty(enumType.Assembly.Location) && File.Exists(enumType.Assembly.Location))
            {
                retVal.Date = new SVC.Messaging.FHIR.DataTypes.DateOnly()
                {
                    DateValue = new FileInfo(enumType.Assembly.Location).LastWriteTime
                }
            }
            ;
            retVal.Timestamp = retVal.Date.DateValue.Value;
            retVal.Status    = new SVC.Messaging.FHIR.DataTypes.PrimitiveCode <string>("published");

            // Compose the codes if it has codes from a known code system
            var  enumFields         = enumType.GetFields();
            bool hasRegisteredCodes = Array.Exists(enumFields, (f) =>
            {
                var enumAtt = f.GetCustomAttribute <EnumerationAttribute>();
                if (enumAtt != null)
                {
                    return(ApplicationContext.ConfigurationService.OidRegistrar.FindData(enumAtt.SupplierDomain) != null);
                }
                else
                {
                    return(false);
                }
            }), hasDifferentSuppliers = Array.Exists(enumFields, (f) => {
                var enumAtt = f.GetCustomAttribute <EnumerationAttribute>();
                if (enumAtt != null)
                {
                    return(Array.Exists(enumFields, (fi) =>
                    {
                        var ienumAtt = fi.GetCustomAttribute <EnumerationAttribute>();
                        if (ienumAtt != null)
                        {
                            return ienumAtt.SupplierDomain != enumAtt.SupplierDomain;
                        }
                        return false;
                    }));
                }
                else
                {
                    return(false);
                }
            });

            // Compose or define
            var sysOid = ApplicationContext.ConfigurationService.OidRegistrar.FindData(retVal.Identifier);

            if (sysOid != null)
            {
                retVal.Compose = new ComposeDefinition();
                retVal.Compose.Import.Add(new SVC.Messaging.FHIR.DataTypes.FhirUri(sysOid.Ref));
            }
            else if (hasRegisteredCodes || hasDifferentSuppliers)
            {
                retVal.Compose = new ComposeDefinition();
                // Group like items
                Array.Sort(enumFields, (a, b) =>
                {
                    EnumerationAttribute aAtt = a.GetCustomAttribute <EnumerationAttribute>(),
                    bAtt = b.GetCustomAttribute <EnumerationAttribute>();
                    if ((aAtt == null) ^ (bAtt == null))
                    {
                        return(aAtt == null ? -1 : 1);
                    }
                    else if (aAtt == bAtt)
                    {
                        return(0);
                    }
                    return(aAtt.SupplierDomain.CompareTo(bAtt.SupplierDomain));
                });
                // Build the concept sets
                ConceptSet currentSet = null;
                foreach (var itm in enumFields)
                {
                    EnumerationAttribute enumValue = itm.GetCustomAttribute <EnumerationAttribute>();
                    if (enumValue == null)
                    {
                        continue;
                    }

                    // Extract code system
                    var oidData    = ApplicationContext.ConfigurationService.OidRegistrar.FindData(enumValue.SupplierDomain);
                    Uri codeSystem = oidData == null ? new Uri(String.Format("urn:oid:{0}", enumValue.SupplierDomain)) : oidData.Ref;

                    // add current set and construct
                    if (currentSet == null || !currentSet.System.Value.Equals(codeSystem))
                    {
                        currentSet = new ConceptSet()
                        {
                            System = codeSystem
                        };
                        retVal.Compose.Include.Add(currentSet);
                    }

                    // Now add mnemonic
                    currentSet.Code.Add(new SVC.Messaging.FHIR.DataTypes.PrimitiveCode <string>(enumValue.Value));
                }
            }
            else
            {
                // Create a definition for a valueset
                retVal.Define        = new ValueSetDefinition();
                retVal.Define.System = new Uri(String.Format("{0}/ValueSet/@v3-{1}", baseUri, structAtt.Name));
                foreach (var itm in enumFields)
                {
                    EnumerationAttribute enumValue = itm.GetCustomAttribute <EnumerationAttribute>();
                    if (enumValue == null)
                    {
                        continue;
                    }
                    DescriptionAttribute description = itm.GetCustomAttribute <DescriptionAttribute>();
                    retVal.Define.Concept.Add(new ConceptDefinition()
                    {
                        Code     = new SVC.Messaging.FHIR.DataTypes.PrimitiveCode <string>(enumValue.Value),
                        Abstract = false,
                        Display  = description == null ? itm.Name : description.Description
                    });
                }
            }

            return(retVal);
        }
    }