Exemplo n.º 1
0
        private bool TryParseSingleEnum <EnumType>(KeyValuePair <string, StringValues> Item, out EnumType EnumValue)
            where EnumType : Enum
        {
            if (!IsParameterValueEmpty(Item))
            {
                CheckSingleParameterForMoreThanOne(Item);
                string Value      = Item.Value[Item.Value.Count - 1];
                string ValueLower = StringSupport.ToLowerFast(Value);
                var    Dic        = StringToEnumMap <EnumType> .GetDictionary();

                if (Dic.ContainsKey(ValueLower))
                {
                    EnumValue = Dic[ValueLower];
                    return(true);
                }
                else
                {
                    this.InvalidParameterList.Add(new InvalidSearchQueryParameter(Item.Key, Value, $"Unable to parse the provided value to an allowed value."));
                }
            }
#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter.
            EnumValue = default;
#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter.
            return(false);
        }
Exemplo n.º 2
0
        public IDtoRootUrlStore SetPrimaryRootUrlStore(string RootUrl)
        {
            RootUrl = StringSupport.ToLowerFast(RootUrl.StripHttp());
            _ServiceBaseUrl ExsistingPrimaryRootURL = this.GetPrimaryPyro_RootUrlStore();

            if (ExsistingPrimaryRootURL != null)
            {
                ExsistingPrimaryRootURL.IsServersPrimaryUrlRoot = false;
            }
            _ServiceBaseUrl ExsistingNonPrimaryRootURL = this.GetPyro_RootUrlStore(RootUrl);

            if (ExsistingNonPrimaryRootURL != null)
            {
                ExsistingNonPrimaryRootURL.IsServersPrimaryUrlRoot = true;
            }
            else
            {
                _ServiceBaseUrl Pyro_RootUrlStore = new _ServiceBaseUrl();
                Pyro_RootUrlStore.IsServersPrimaryUrlRoot = true;
                Pyro_RootUrlStore.Url = RootUrl;
                IPyroDbContext.Set <_ServiceBaseUrl>().Add(Pyro_RootUrlStore);
            }
            this.Save();
            return(this.GetPrimaryRootUrlStore());
        }
        private bool ParseModifierType(ISearchParameterBase SearchParameter, string value)
        {
            var    SearchModifierTypeDic = FhirSearchEnum.GetSearchModifierTypeDictionary();
            string ValueCaseCorrectly    = StringSupport.ToLowerFast(value);

            if (SearchModifierTypeDic.ContainsKey(ValueCaseCorrectly))
            {
                SearchParameter.Modifier = SearchModifierTypeDic[ValueCaseCorrectly];
                return(true);
            }
            else
            {
                string TypedResourceName = value;
                if (value.Contains("."))
                {
                    char[] delimiters = { '.' };
                    TypedResourceName = value.Split(delimiters)[0].Trim();
                }

                Type ResourceType = ModelInfo.GetTypeForFhirType(TypedResourceName);
                if (ResourceType != null && ModelInfo.IsKnownResource(ResourceType))
                {
                    SearchParameter.TypeModifierResource = TypedResourceName;
                    SearchParameter.Modifier             = Hl7.Fhir.Model.SearchParameter.SearchModifierCode.Type;
                    return(true);
                }
                return(false);
            }
        }
Exemplo n.º 4
0
        public virtual void ParseModifier(string parameterName, IResourceTypeSupport IResourceTypeSupport, IKnownResource IKnownResource)
        {
            if (parameterName.Contains(FhirSearchQuery.TermSearchModifierDelimiter))
            {
                string parameterNameModifierPart = parameterName.Split(FhirSearchQuery.TermSearchModifierDelimiter)[1];
                var    SearchModifierTypeDic     = StringToEnumMap <Common.Enums.SearchModifierCode> .GetDictionary();

                string ValueCaseCorrectly = StringSupport.ToLowerFast(parameterNameModifierPart);
                if (SearchModifierTypeDic.ContainsKey(ValueCaseCorrectly))
                {
                    this.Modifier = SearchModifierTypeDic[ValueCaseCorrectly];
                }
                else
                {
                    string TypedResourceName = parameterNameModifierPart;
                    if (parameterNameModifierPart.Contains("."))
                    {
                        char[] delimiters = { '.' };
                        TypedResourceName = parameterNameModifierPart.Split(delimiters)[0].Trim();
                    }

                    if (IKnownResource.IsKnownResource(this.FhirVersionId, TypedResourceName))
                    {
                        Common.Enums.ResourceType?ResourceType = IResourceTypeSupport.GetTypeFromName(TypedResourceName);
                        if (ResourceType != null)
                        {
                            this.TypeModifierResource = ResourceType.Value;
                            this.Modifier             = SearchModifierCode.Type;
                        }
                        else
                        {
                            throw new ApplicationException($"Found a known resource to the FHIR API yet this resource was not found in the Enum list for {typeof(Common.Enums.ResourceType).Name}");
                        }
                    }
                    else
                    {
                        this.InvalidMessage = $"Unable to parse the given search parameter's Modifier: {parameterName}, ";
                        this.IsValid        = false;
                    }
                }
            }
            else
            {
                this.Modifier             = null;
                this.TypeModifierResource = null;
            }

            if (this.Modifier.HasValue)
            {
                SearchModifierCode[] oSupportedModifierArray = SearchQuerySupport.GetModifiersForSearchType(this.SearchParamTypeId);
                if (!oSupportedModifierArray.Any(x => x == this.Modifier.Value))
                {
                    this.InvalidMessage += $"The parameter's modifier: '{this.Modifier.GetCode()}' is not supported by this server for this search parameter type '{this.SearchParamTypeId.GetCode()}', the whole parameter was : '{this.RawValue}', ";
                    this.IsValid         = false;
                }
            }
        }
        /// <summary>
        /// Gets the ServiceBaseUrl Instance if found or creates a new instance if not found
        /// </summary>
        /// <param name="UrlString"></param>
        /// <returns></returns>
        public IDtoRootUrlStore GetAndOrAddService_RootUrlStore(string ServiceRootUrl)
        {
            IDtoRootUrlStore Pyro_RootUrlStore = this.GetPyro_RootUrlStore(ServiceRootUrl);

            if (Pyro_RootUrlStore == null)
            {
                var Pyro_RootUrlStoreDb = new _ServiceBaseUrl();
                Pyro_RootUrlStoreDb.IsServersPrimaryUrlRoot = false;
                Pyro_RootUrlStoreDb.Url = StringSupport.ToLowerFast(ServiceRootUrl.StripHttp());
                Pyro_RootUrlStoreDb     = IPyroDbContext.Set <_ServiceBaseUrl>().Add(Pyro_RootUrlStoreDb);
                this.Save();
                return(Pyro_RootUrlStoreDb);
            }
            else
            {
                return(Pyro_RootUrlStore);
            }
        }
Exemplo n.º 6
0
 private _ServiceBaseUrl GetPyro_RootUrlStore(string ServiceRootUrl)
 {
     ServiceRootUrl = StringSupport.ToLowerFast(ServiceRootUrl.StripHttp());
     return(IPyroDbContext.ServiceBaseUrl.SingleOrDefault(x => x.Url == ServiceRootUrl));
 }