Ejemplo n.º 1
0
        public FhirModel(Dictionary <Type, string> csTypeToFhirTypeNameMapping, IEnumerable <SearchParamDefinition> searchParameters, List <Type> enums)
        {
            LoadSearchParameters(searchParameters);
            _csTypeToFhirTypeName = csTypeToFhirTypeNameMapping;
            _fhirTypeNameToCsType = _csTypeToFhirTypeName.ToLookup(pair => pair.Value, pair => pair.Key).ToDictionary(group => group.Key, group => group.FirstOrDefault());

            _enumMappings = new List <EnumMapping>();
            foreach (var enumType in enums)
            {
                if (EnumMapping.IsMappableEnum(enumType))
                {
                    _enumMappings.Add(EnumMapping.Create(enumType));
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadAssembly(Assembly fhirAssembly)
        {
            _csTypeToFhirTypeName = new Dictionary <Type, string>();
            _fhirTypeNameToCsType = new Dictionary <string, Type>();
            _enumMappings         = new List <EnumMapping>();

            foreach (Type fhirType in fhirAssembly.GetTypes())
            {
                if (typeof(Resource).IsAssignableFrom(fhirType)) //It is derived of Resource, so it is a Resource type.
                {
                    var fhirTypeAtt = fhirType.GetCustomAttribute <FhirTypeAttribute>();
                    var obsoleteAtt = fhirType.GetCustomAttribute <ObsoleteAttribute>();
                    //CK: Also check for obsolete. Example was Query, which was derived from Parameters, and therefore had the same name ("Parameters").
                    if (fhirTypeAtt != null && fhirTypeAtt.IsResource && (obsoleteAtt == null || !obsoleteAtt.IsError))
                    {
                        if (_csTypeToFhirTypeName.Keys.Contains(fhirType))
                        {
                            Debug.WriteLine("Double import: " + fhirType.FullName);
                        }
                        else
                        {
                            _csTypeToFhirTypeName.Add(fhirType, fhirTypeAtt.Name);
                        }
                        if (_fhirTypeNameToCsType.Keys.Contains(fhirTypeAtt.Name))
                        {
                            Debug.WriteLine("Double import: " + fhirType.FullName);
                        }
                        else
                        {
                            _fhirTypeNameToCsType.Add(fhirTypeAtt.Name, fhirType);
                        }
                    }
                }
                else if (EnumMapping.IsMappableEnum(fhirType))
                {
                    _enumMappings.Add(EnumMapping.Create(fhirType));
                }
            }
        }