Esempio n. 1
0
 public IRequestMeta Set(HttpRequestMessage Request)
 {
     this.PyroRequestUri = IPyroRequestUriFactory.CreateFhirRequestUri();
     this.PyroRequestUri.FhirRequestUri.Parse(Request.RequestUri.OriginalString);
     this.RequestHeader          = IRequestHeaderFactory.CreateRequestHeader().Parse(Request.Headers);
     this.SearchParameterGeneric = ISearchParameterGenericFactory.CreateDtoSearchParameterGeneric().Parse(Request.GetSearchParams());
     return(this);
 }
        public PyroSearchParameters GetSearchParameters(string Compartment, string CompartmentId, string ResourceName)
        {
            //I need to check that Compartment and ResourceName are actual FHIR Resource Types, the two lines
            //below do that and throw Pyro Exception if they are not.
            FHIRAllTypes CompartmentType  = ResourceNameResolutionSupport.GetResourceFhirAllType(Compartment);
            FHIRAllTypes ResourceNameType = ResourceNameResolutionSupport.GetResourceFhirAllType(ResourceName);

            //Now to contruct the Container search parameters, these are cached from the database Conatiner Resource
            DtoServiceCompartmentResourceCached ServiceCompartmentResource = IServiceCompartmentCache.GetServiceCompartmentResourceForCompartmentCodeAndResource(Compartment, ResourceName);
            string ConatinerSerachString = string.Empty;

            if (ServiceCompartmentResource != null)
            {
                var CompartmentParamQuery = new List <string>();
                foreach (var CompartmentSearchParameter in ServiceCompartmentResource.ParamList)
                {
                    if (CompartmentSearchParameter.Param == "*")
                    {
                        // if the param="*" then all instances of this Resource Type are in the container and there are no
                        // actualy parameters that it needs to be restricted by. So the ConatinerSerachString remains as empty string.
                        break;
                    }
                    else
                    {
                        CompartmentParamQuery.Add($"{CompartmentSearchParameter.Param}:{Compartment}={CompartmentId}");
                    }
                }
                ConatinerSerachString = String.Join("&", CompartmentParamQuery.ToArray());
            }
            else
            {
                DtoServiceCompartmentCached ServiceCompartment = IServiceCompartmentCache.GetServiceCompartmentForCompartmentCode(Compartment);
                if (ServiceCompartment == null)
                {
                    string Message = $"No active {Compartment} Compartment exist in this server. Perhaps you could create one using a {FHIRAllTypes.CompartmentDefinition.GetLiteral()} resource and the resource instance ${Pyro.Common.Enum.FhirOperationEnum.OperationType.xSetCompartmentActive} Operation. " +
                                     $"For example: '[base]/{FHIRAllTypes.CompartmentDefinition.GetLiteral()}/[id]/${Pyro.Common.Enum.FhirOperationEnum.OperationType.xSetCompartmentActive}' ";
                    var OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported, Message);
                    throw new PyroException(System.Net.HttpStatusCode.BadRequest, OpOutcome, Message);
                }
                else
                {
                    string Message   = $"The {Compartment} Compartment defined by the {FHIRAllTypes.CompartmentDefinition.GetLiteral()} with the resource id of '{ServiceCompartment.CompartmentDefinitionResourceId}' does not allow access to any {ResourceName} resource type instances.";
                    var    OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported, Message);
                    throw new PyroException(System.Net.HttpStatusCode.BadRequest, OpOutcome, Message);
                }
            }

            ISearchParameterGeneric         ContainerSearchParameterGeneric = ISearchParameterGenericFactory.CreateDtoSearchParameterGeneric().Parse(ConatinerSerachString);
            ISearchParameterService         SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
            ISearchParametersServiceOutcome ContainerSearchParametersServiceOutcome = SearchService.ProcessSearchParameters(ContainerSearchParameterGeneric, SearchParameterService.SearchParameterServiceType.Resource, ResourceNameType, null);

            return(ContainerSearchParametersServiceOutcome.SearchParameters);
        }
Esempio n. 3
0
        //Old Method for chaining, not in use
        public ISearchParameterBase CreateSearchParameter_OLD(DtoServiceSearchParameterLight DtoSupportedSearchParametersResource, Tuple <string, string> Parameter)
        {
            ISearchParameterBase oSearchParameter = InitalizeSearchParameter(DtoSupportedSearchParametersResource.Type);

            string ParameterName  = Parameter.Item1;
            string ParameterValue = Parameter.Item2;

            oSearchParameter.Id       = DtoSupportedSearchParametersResource.Id;
            oSearchParameter.Resource = DtoSupportedSearchParametersResource.Resource;
            oSearchParameter.Name     = DtoSupportedSearchParametersResource.Name;
            oSearchParameter.TargetResourceTypeList = DtoSupportedSearchParametersResource.TargetResourceTypeList;
            oSearchParameter.RawValue         = ParameterName + _ParameterNameParameterValueDilimeter + ParameterValue;
            _RawSearchParameterAndValueString = oSearchParameter.RawValue;
            if (!ParseModifier(ParameterName, oSearchParameter))
            {
                oSearchParameter.IsValid        = false;
                oSearchParameter.InvalidMessage = $"Unable to parse the given search parameter's Modifier: {ParameterName}', ";
            }

            if (ParameterName.Contains(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR))
            {
                //This is a resourceReferance with a Chained parameter, resolve that chained parameter to a search parameter here (is a recursive call).
                var SearchParameterGeneric = ISearchParameterGenericFactory.CreateDtoSearchParameterGeneric();
                SearchParameterGeneric.ParameterList = new List <Tuple <string, string> >();

                var x = ParameterName.Substring(ParameterName.IndexOf(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR) + 1, (ParameterName.Length - ParameterName.IndexOf(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR) - 1));
                var ChainedSearchParam = new Tuple <string, string>(x, ParameterValue);

                SearchParameterGeneric.ParameterList.Add(ChainedSearchParam);

                FHIRAllTypes?TypeModifierResource = null;

                if (oSearchParameter.Modifier.HasValue &&
                    oSearchParameter.Modifier.Value == SearchParameter.SearchModifierCode.Type &&
                    !string.IsNullOrWhiteSpace(oSearchParameter.TypeModifierResource))
                {
                    //var ChainedSearchParam = new Tuple<string, string>(ParameterName.Split(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR)[1], ParameterValue);
                    TypeModifierResource = ModelInfo.FhirTypeNameToFhirType(oSearchParameter.TypeModifierResource).Value;
                }
                else
                {
                    // If the chained reference has no Type modifier then their must be only one Target resource for the parameter!
                    // The FHIR spec does allow the server to try and resolve resources for many resource targets in this case. Yet, the server must
                    // reject the search if Resource instances are returned across more then one of the types for the search parameter.
                    // This seams like a very fragile rule and would also be hard to implement given the current framework.
                    // Therefore I am making a design decision that if more that one target resource is available for the given search
                    // parameter and the user does not specify which by supplying a Type modifier, then I will reject the search parameter.

                    if (oSearchParameter.TargetResourceTypeList != null && oSearchParameter.TargetResourceTypeList.Count == 1)
                    {
                        TypeModifierResource = ModelInfo.FhirTypeNameToFhirType(oSearchParameter.TargetResourceTypeList[0].ResourceType.GetLiteral()).Value;
                    }
                    else
                    {
                        if (oSearchParameter.TargetResourceTypeList != null && oSearchParameter.TargetResourceTypeList.Count > 1)
                        {
                            oSearchParameter.IsValid        = false;
                            oSearchParameter.InvalidMessage = $"The chained search parameter '{oSearchParameter.RawValue}' has no Type modifier specifying the target resource for the parameter and the parameter in use has many possible target resources. The search parameter must specify a target resource using the type modifier. For example '[base]/DiagnosticReport?subject:Patient.name=peter' where Patient is the Type modifier.";
                        }
                        else
                        {
                            throw new FormatException($"Server error: chained search parameter did not resolve to any target resource types. Parameter was: '{oSearchParameter.RawValue}' ");
                        }
                    }
                }
                ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
                //oSearchParameter.ChainedSearchParameterList.Add(SearchService.ProcessResourceSearchParameters(SearchParameterGeneric, SearchParameterService.SearchParameterServiceType.Resource, TypeModifierResource.Value));
            }
            else
            {
                if (oSearchParameter.Type == SearchParamType.Reference)
                {
                    (oSearchParameter as SearchParameterReferance).AllowedReferanceResourceList = ServiceSearchParameterFactory.GetSearchParameterTargetResourceList(oSearchParameter);
                }

                if (!oSearchParameter.TryParseValue(ParameterValue))
                {
                    oSearchParameter.IsValid = false;
                }
            }
            return(oSearchParameter);
        }