Exemplo n.º 1
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;
                }
            }
        }
Exemplo n.º 2
0
 public static bool ValidatePreFix(Bug.Common.Enums.SearchParamType SearchParamType, SearchComparator?Prefix)
 {
     if (Prefix.HasValue)
     {
         return(Array.Exists(SearchQuerySupport.GetPrefixListForSearchType(SearchParamType), item => item == Prefix.Value));
     }
     else
     {
         return(true);
     }
 }