public IResourceServiceOutcome Initialize(OperationClass OperationClass, IRequestMeta RequestMeta, string FhirId)
        {
            if (OperationClass == null)
            {
                throw new NullReferenceException("OperationClass cannot be null.");
            }
            if (IResourceServices == null)
            {
                throw new NullReferenceException("ResourceServices cannot be null.");
            }
            if (RequestMeta == null)
            {
                throw new NullReferenceException("RequestMeta cannot be null.");
            }
            if (RequestMeta.PyroRequestUri == null)
            {
                throw new NullReferenceException("RequestUri cannot be null.");
            }
            if (RequestMeta.RequestHeader == null)
            {
                throw new NullReferenceException("RequestHeaders cannot be null.");
            }
            if (RequestMeta.SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchParameterGeneric cannot be null.");
            }

            ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();



            var ResourceRepository = IRepositorySwitcher.GetRepository(FHIRAllTypes.Patient);



            List <Resource> ResourceList = new List <Resource>();

            if (ResourceList.Count > 0)
            {
                Bundle TransactionBundle  = GenerateTransactionBundle(ResourceList);
                var    CurrentRequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.Bundle.GetLiteral()}/{TransactionBundle.Id}");
                IResourceServiceOutcome ResourceServiceOutcome = IBundleTransactionOperation.Transact(TransactionBundle, CurrentRequestMeta);
                return(ResourceServiceOutcome);
            }


            //  var OutCome = IResourceServices.Put(Res.Id, Res, CurrentRequestMeta);

            //var ResourceRepository = IRepositorySwitcher.GetRepository(FHIRAllTypes.Patient);


            return(ResourceServiceOutcome);
        }
示例#2
0
        public IResourceServiceOutcome GetServersConformanceResource(IRequestMeta RequestMeta)
        {
            if (RequestMeta == null)
            {
                throw new NullReferenceException("RequestMeta can not be null.");
            }
            if (RequestMeta.SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchParameterGeneric can not be null.");
            }

            IResourceServiceOutcome         ServiceOperationOutcome        = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();
            ISearchParameterService         SearchService                  = ISearchParameterServiceFactory.CreateSearchParameterService();
            ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(RequestMeta.SearchParameterGeneric);

            if (SearchParametersServiceOutcome.FhirOperationOutcome != null)
            {
                ServiceOperationOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome;
                ServiceOperationOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode;
                ServiceOperationOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format;
                return(ServiceOperationOutcome);
            }

            var    Conformance            = new CapabilityStatement();
            var    ApplicationReleaseDate = new DateTimeOffset(2017, 10, 17, 6, 00, 00, new TimeSpan(8, 0, 0));
            string ServerName             = "Pyro Server";
            string Https = "https://";

            Conformance.Id               = "metadata";
            Conformance.Url              = $"{Https}{IPrimaryServiceRootCache.GetPrimaryRootUrlFromDatabase().Url}/metadata";
            Conformance.Version          = $"V{IGlobalProperties.ApplicationVersionInfo}";
            Conformance.Meta             = new Meta();
            Conformance.Meta.LastUpdated = ApplicationReleaseDate;
            Conformance.Name             = ServerName;
            Conformance.Status           = PublicationStatus.Active;
            Conformance.Experimental     = true;
            Conformance.Date             = (new FhirDateTime(ApplicationReleaseDate)).Value;
            Conformance.Publisher        = "PyroHealth.net";
            var AngusContactDetail = Common.PyroHealthInformation.PyroHealthContactDetailAngusMillar.GetContactDetail();

            Conformance.Contact = new List <ContactDetail>()
            {
                AngusContactDetail
            };

            Conformance.Description = new Markdown("Conformance statement for the " + ServerName);

            var Australia = new CodeableConcept("urn:iso:std:iso:3166", "AU", "Australia");

            Conformance.Jurisdiction = new List <CodeableConcept>()
            {
                Australia
            };

            Conformance.Purpose = new Markdown("FHIR Server reference implementation");

            Conformance.Copyright = new Markdown("Copyright: PyroHealth.net");
            Conformance.Kind      = CapabilityStatement.CapabilityStatementKind.Instance;

            Conformance.Software             = new CapabilityStatement.SoftwareComponent();
            Conformance.Software.Name        = ServerName;
            Conformance.Software.Version     = IGlobalProperties.ApplicationVersionInfo; //To align with FHIR version only use number no prefix of 'V'
            Conformance.Software.ReleaseDate = (new FhirDateTime(ApplicationReleaseDate)).Value;

            Conformance.Implementation             = new CapabilityStatement.ImplementationComponent();
            Conformance.Implementation.Description = $"{ServerName} is an implementation of a FHIR server supporting V{Hl7.Fhir.Model.ModelInfo.Version} of the specification. This instance is a publicly available testing server and its resource may be cleared at any time.";
            Conformance.Implementation.Url         = $"{Https}{IPrimaryServiceRootCache.GetPrimaryRootUrlFromDatabase().Url}";

            Conformance.FhirVersion   = Hl7.Fhir.Model.ModelInfo.Version; //Must be formated as just the number '3.0.1' as touchstone does not like the V3.0.1
            Conformance.AcceptUnknown = CapabilityStatement.UnknownContentCode.Extensions;

            var ContentFormatList = new List <string>();

            foreach (var mediaType in Hl7.Fhir.Rest.ContentType.XML_CONTENT_HEADERS)
            {
                ContentFormatList.Add(mediaType);
            }
            foreach (var mediaType in Hl7.Fhir.Rest.ContentType.JSON_CONTENT_HEADERS)
            {
                ContentFormatList.Add(mediaType);
            }
            Conformance.Format = ContentFormatList;

            Conformance.Rest = new List <CapabilityStatement.RestComponent>();
            var RestComponent = new CapabilityStatement.RestComponent();

            Conformance.Rest.Add(RestComponent);
            RestComponent.Mode                 = CapabilityStatement.RestfulCapabilityMode.Server;
            RestComponent.Documentation        = $"STU{Hl7.Fhir.Model.ModelInfo.Version.Split('.')[0]} V{Hl7.Fhir.Model.ModelInfo.Version} FHIR Server";
            RestComponent.Security             = new CapabilityStatement.SecurityComponent();
            RestComponent.Security.Description = "No Security has been implemented, server if publicly open";

            RestComponent.Interaction = new List <CapabilityStatement.SystemInteractionComponent>();
            var SystemInteractionComponent = new CapabilityStatement.SystemInteractionComponent();

            RestComponent.Interaction.Add(SystemInteractionComponent);
            SystemInteractionComponent.Code          = CapabilityStatement.SystemRestfulInteraction.Transaction;
            SystemInteractionComponent.Documentation = "Batch Transaction supports all request methods (Delete, POST, PUT, GET) including conditional create/update/delete. Operatons are not supported within Transaction bundles.";

            var CompartmentList = IServiceCompartmentRepository.GetAllServiceCompartments();

            if (CompartmentList != null && CompartmentList.Count > 0)
            {
                var CompartmentUrlList = new List <string>();
                CompartmentList.ForEach(x => CompartmentUrlList.Add(x.Url));
                RestComponent.Compartment = CompartmentUrlList;
            }

            RestComponent.Resource = new List <CapabilityStatement.ResourceComponent>();

            List <DtoServiceSearchParameterHeavy> DtoServiceSearchParameterHeavyList = IServiceSearchParameterService.GetServiceSearchParametersHeavy(false);

            var ResourceTypeList = Enum.GetValues(typeof(ResourceType));

            foreach (ResourceType ResourceType in ResourceTypeList)
            {
                string       CurrentResourceString = ResourceType.GetLiteral();
                FHIRAllTypes?FhirType          = Hl7.Fhir.Model.ModelInfo.FhirTypeNameToFhirType(CurrentResourceString);
                var          ResourceComponent = new CapabilityStatement.ResourceComponent();
                RestComponent.Resource.Add(ResourceComponent);
                ResourceComponent.Type        = ResourceType;
                ResourceComponent.Interaction = new List <CapabilityStatement.ResourceInteractionComponent>()
                {
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.Create
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.Delete
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.Read
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.Update
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.Vread
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.SearchType
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.HistoryInstance
                    },
                    new CapabilityStatement.ResourceInteractionComponent()
                    {
                        Code = CapabilityStatement.TypeRestfulInteraction.HistoryType
                    }
                    //new Conformance.ResourceInteractionComponent() { Code = Conformance.TypeRestfulInteraction.HistoryType},
                };
                ResourceComponent.Versioning        = CapabilityStatement.ResourceVersionPolicy.Versioned;
                ResourceComponent.ReadHistory       = true;
                ResourceComponent.UpdateCreate      = true;
                ResourceComponent.ConditionalCreate = true;
                ResourceComponent.ConditionalRead   = CapabilityStatement.ConditionalReadStatus.FullSupport;
                ResourceComponent.ConditionalUpdate = true;
                ResourceComponent.ConditionalDelete = CapabilityStatement.ConditionalDeleteStatus.Multiple;


                var ReferenceHandlingPolicyList = new List <CapabilityStatement.ReferenceHandlingPolicy?>();
                ReferenceHandlingPolicyList.Add(CapabilityStatement.ReferenceHandlingPolicy.Literal);
                ReferenceHandlingPolicyList.Add(CapabilityStatement.ReferenceHandlingPolicy.Local);
                ResourceComponent.ReferencePolicy = ReferenceHandlingPolicyList;

                List <DtoServiceSearchParameterHeavy> DtoServiceSearchParameterHeavyForResourceList = DtoServiceSearchParameterHeavyList.Where(x => x.Resource == CurrentResourceString || x.Resource == FHIRAllTypes.Resource.GetLiteral()).ToList();

                //List<ServiceSearchParameterHeavy> DtoServiceSearchParameterHeavyForResourceList = ICommonServices.GetServiceSearchParametersHeavyForResource(FhirType.Value.GetLiteral());
                //DtoServiceSearchParameterHeavyForResourceList.AddRange(ICommonServices.GetServiceSearchParametersHeavyForResource(FHIRAllTypes.Resource.GetLiteral()));
                ResourceComponent.SearchParam = new List <CapabilityStatement.SearchParamComponent>();
                List <string> IncludesList    = null;
                List <string> RevIncludesList = null;
                foreach (var SupportedSearchParam in DtoServiceSearchParameterHeavyForResourceList)
                {
                    if (SupportedSearchParam.IsIndexed && SupportedSearchParam.Status == PublicationStatus.Active)
                    {
                        //Include (RevIncludes are below)
                        if (SupportedSearchParam.Type == SearchParamType.Reference)
                        {
                            if (IncludesList == null)
                            {
                                IncludesList = new List <string>();
                            }
                            if (SupportedSearchParam.TargetResourceTypeList.Count > 1)
                            {
                                foreach (var Target in SupportedSearchParam.TargetResourceTypeList)
                                {
                                    IncludesList.Add($"{SupportedSearchParam.Resource}:{SupportedSearchParam.Name}:{Target.ResourceType.GetLiteral()}");
                                }
                            }
                            else
                            {
                                IncludesList.Add($"{SupportedSearchParam.Resource}:{SupportedSearchParam.Name}");
                            }
                        }

                        CapabilityStatement.SearchParamComponent SearchParamComponent = new CapabilityStatement.SearchParamComponent();
                        ResourceComponent.SearchParam.Add(SearchParamComponent);

                        SearchParamComponent.Name       = SupportedSearchParam.Name;
                        SearchParamComponent.Type       = SupportedSearchParam.Type;
                        SearchParamComponent.Definition = SupportedSearchParam.Url;
                        if (!string.IsNullOrWhiteSpace(SupportedSearchParam.Description))
                        {
                            SearchParamComponent.Documentation = SupportedSearchParam.Description;
                        }
                    }
                }
                ResourceComponent.SearchInclude = IncludesList;

                //RevIncludes
                var RevIncludeSearchParameterList = DtoServiceSearchParameterHeavyList.Where(x => x.Type == SearchParamType.Reference && x.TargetResourceTypeList.Any(c => c.ResourceType == ResourceType));
                foreach (var Rev in RevIncludeSearchParameterList)
                {
                    if (RevIncludesList == null)
                    {
                        RevIncludesList = new List <string>();
                    }
                    if (Rev.TargetResourceTypeList.Count > 1)
                    {
                        RevIncludesList.Add($"{Rev.Resource}:{Rev.Name}:{CurrentResourceString}");
                    }
                    else
                    {
                        RevIncludesList.Add($"{Rev.Resource}:{Rev.Name}");
                    }
                }

                ResourceComponent.SearchRevInclude = RevIncludesList;
            }
            ConstructConformanceResourceNarrative(Conformance);

            IDatabaseOperationOutcome DatabaseOperationOutcome = IDatabaseOperationOutcomeFactory.CreateDatabaseOperationOutcome();

            ServiceOperationOutcome.FhirResourceId        = Conformance.Id;
            ServiceOperationOutcome.ResourceVersionNumber = Conformance.Version;
            ServiceOperationOutcome.LastModified          = Conformance.Meta.LastUpdated;
            ServiceOperationOutcome.OperationType         = Common.Enum.RestEnum.CrudOperationType.Read;
            ServiceOperationOutcome.IsDeleted             = false;
            ServiceOperationOutcome.RequestUri            = null;
            ServiceOperationOutcome.ResourceResult        = Conformance;
            ServiceOperationOutcome.FormatMimeType        = SearchParametersServiceOutcome.SearchParameters.Format;
            ServiceOperationOutcome.HttpStatusCode        = System.Net.HttpStatusCode.OK;
            return(ServiceOperationOutcome);
        }
示例#3
0
        public IResourceServiceOutcome Transact(Resource Resource, IRequestMeta RequestMeta)
        {
            if (IResourceServices == null)
            {
                throw new ArgumentNullException("IResourceServices can not be null.");
            }
            if (Resource == null)
            {
                throw new ArgumentNullException("Resource can not be null.");
            }
            if (RequestMeta == null)
            {
                throw new ArgumentNullException("RequestMeta can not be null.");
            }

            _RequestHeader = RequestMeta.RequestHeader ?? throw new ArgumentNullException("RequestHeaders can not be null.");
            _RequestUri    = RequestMeta.PyroRequestUri ?? throw new ArgumentNullException("RequestUri can not be null.");

            _ServiceOperationOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();
            _ServiceOperationOutcome.HttpStatusCode = System.Net.HttpStatusCode.OK;
            Bundle bundle = Resource as Bundle;

            if (bundle == null)
            {
                var Message   = $"The FHIR server's service root endpoint can only accept 'Bundle' resources. Resource received was: {Resource.ResourceType.ToString()}";
                var OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, Message);
                _ServiceOperationOutcome.ResourceResult = OpOutcome;
                _ServiceOperationOutcome.HttpStatusCode = System.Net.HttpStatusCode.Forbidden;
                _ServiceOperationOutcome.OperationType  = Enum.RestEnum.CrudOperationType.Create;
                return(_ServiceOperationOutcome);
            }
            else if (bundle.Type != Bundle.BundleType.Transaction || (bundle.Type != Bundle.BundleType.Transaction && bundle.Type != Bundle.BundleType.Batch))
            {
                var Message   = $"The FHIR server's service root endpoint can only accept Bundle resources of Bundle.type = 'Transaction' or Bundle.type = 'Batch'. Type found was {bundle.Type.ToString()}";
                var OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, Message);
                _ServiceOperationOutcome.ResourceResult = OpOutcome;
                _ServiceOperationOutcome.HttpStatusCode = System.Net.HttpStatusCode.Forbidden;
                _ServiceOperationOutcome.OperationType  = Enum.RestEnum.CrudOperationType.Create;
                return(_ServiceOperationOutcome);
            }
            else
            {
                bundle.Type = Bundle.BundleType.TransactionResponse;
                bundle.Id   = Guid.NewGuid().ToString();
                if (bundle.Meta == null)
                {
                    bundle.Meta = new Meta();
                }
                bundle.Meta.LastUpdated = DateTimeOffset.Now;


                //FHIR Spec: http://build.fhir.org/bundle.html#transaction
                //  If there is no request element, then there SHALL be a resource and the server must infer
                //  whether this is a create or an update from the resource identity supplied.
                //  NO Request Processing
                foreach (var NoRequestEntry in bundle.Entry.Where(x => x.Request == null || !x.Request.Method.HasValue))
                {
                    NoRequestEntry.Request = GenerateRequestComponentForEntry(NoRequestEntry);
                }

                //All entries with a Request, should be all at this point
                var EntryWithRequestList            = bundle.Entry.Where(x => x.Request != null && x.Request.Method.HasValue);
                var EntryWithResourceAndRequestList = EntryWithRequestList.Where(x => x.Resource != null);

                var DeleteEntries = EntryWithRequestList.Where(x => x.Request.Method == Bundle.HTTPVerb.DELETE);
                var POSTEntries   = EntryWithResourceAndRequestList.Where(x => x.Request.Method == Bundle.HTTPVerb.POST);
                var PUTEntries    = EntryWithResourceAndRequestList.Where(x => x.Request.Method == Bundle.HTTPVerb.PUT);
                var GETEntries    = EntryWithRequestList.Where(x => x.Request.Method == Bundle.HTTPVerb.GET);

                try
                {
                    //DELETE Processing
                    for (int i = 0; i < DeleteEntries.Count(); i++)
                    {
                        if (!DeleteProcessing(DeleteEntries.ElementAt(i), i))
                        {
                            return(_ServiceOperationOutcome);
                        }
                    }

                    //Assign new id's for POSTs and then update all POST and PUT entrie referances
                    AssignResourceIdsAndUpdateReferances(POSTEntries, PUTEntries);

                    //POST Processing
                    for (int i = 0; i < POSTEntries.Count(); i++)
                    {
                        if (!PostProcessing(POSTEntries.ElementAt(i), i))
                        {
                            _ServiceOperationOutcome.SuccessfulTransaction = false;
                            return(_ServiceOperationOutcome);
                        }
                    }

                    //PUT Processing
                    for (int i = 0; i < PUTEntries.Count(); i++)
                    {
                        if (!PutProcessing(PUTEntries.ElementAt(i), i))
                        {
                            _ServiceOperationOutcome.SuccessfulTransaction = false;
                            return(_ServiceOperationOutcome);
                        }
                    }

                    //GET Processing
                    for (int i = 0; i < GETEntries.Count(); i++)
                    {
                        if (!GetProcessing(GETEntries.ElementAt(i), i))
                        {
                            _ServiceOperationOutcome.SuccessfulTransaction = false;
                            return(_ServiceOperationOutcome);
                        }
                    }

                    _ServiceOperationOutcome.ResourceResult        = bundle;
                    _ServiceOperationOutcome.HttpStatusCode        = System.Net.HttpStatusCode.OK;
                    _ServiceOperationOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                    _ServiceOperationOutcome.SuccessfulTransaction = true;
                }
                catch (Exception Exec)
                {
                    throw new PyroException(System.Net.HttpStatusCode.InternalServerError, FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message);
                }
            }

            return(_ServiceOperationOutcome);
        }
示例#4
0
        public IResourceServiceOutcome Process(string OperationName, Resource Resource, IRequestMeta RequestMeta)
        {
            if (string.IsNullOrWhiteSpace(OperationName))
            {
                throw new NullReferenceException("OperationName cannot be null.");
            }
            if (Resource == null)
            {
                throw new NullReferenceException("Resource cannot be null.");
            }
            if (RequestMeta == null)
            {
                throw new NullReferenceException("RequestMeta cannot be null.");
            }
            if (RequestMeta.PyroRequestUri == null)
            {
                throw new NullReferenceException("RequestUri cannot be null.");
            }
            if (RequestMeta.RequestHeader == null)
            {
                throw new NullReferenceException("RequestHeaders cannot be null.");
            }
            if (ICommonFactory == null)
            {
                throw new NullReferenceException("ICommonFactory cannot be null.");
            }
            if (RequestMeta.SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchParameterGeneric cannot be null.");
            }

            IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();

            ISearchParameterService         SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
            ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(RequestMeta.SearchParameterGeneric);

            if (SearchParametersServiceOutcome.FhirOperationOutcome != null)
            {
                ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome;
                ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode;
                ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format;
                return(ResourceServiceOutcome);
            }

            var OperationDic = FhirOperationEnum.GetOperationTypeByString();

            if (!OperationDic.ContainsKey(Pyro.Common.Tools.StringSupport.ToLowerFast(OperationName)))
            {
                string Message = $"The resource operation named ${OperationName} is not supported by the server.";
                ResourceServiceOutcome.ResourceResult        = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message);
                ResourceServiceOutcome.FormatMimeType        = SearchParametersServiceOutcome.SearchParameters.Format;
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                ResourceServiceOutcome.SuccessfulTransaction = false;
                return(ResourceServiceOutcome);
            }

            var            Op             = OperationDic[Pyro.Common.Tools.StringSupport.ToLowerFast(OperationName)];
            OperationClass OperationClass = OperationClassFactory.OperationClassList.SingleOrDefault(x => x.Scope == FhirOperationEnum.OperationScope.Resource && x.Type == Op);

            if (OperationClass == null)
            {
                string Message = $"The resource operation named ${OperationName} is not supported by the server as a resource service operation type.";
                ResourceServiceOutcome.ResourceResult        = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message);
                ResourceServiceOutcome.FormatMimeType        = SearchParametersServiceOutcome.SearchParameters.Format;
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                ResourceServiceOutcome.SuccessfulTransaction = false;
                return(ResourceServiceOutcome);
            }

            switch (OperationClass.Type)
            {
            case FhirOperationEnum.OperationType.Validate:
            {
                IFhirValidateOperation FhirValidateOperation = ICommonFactory.CreateFhirValidateOperation();
                return(FhirValidateOperation.ValidateResource(OperationClass, Resource, RequestMeta));
            }

            case FhirOperationEnum.OperationType.xIHISearchOrValidate:
            {
                IIHISearchOrValidateOperation IHISearchOrValidateOperation = ICommonFactory.CreateIHISearchOrValidateOperation();
                return(IHISearchOrValidateOperation.IHISearchOrValidate(OperationClass, Resource, RequestMeta));
            }

            default:
                throw new System.ComponentModel.InvalidEnumArgumentException(OperationClass.Type.GetPyroLiteral(), (int)OperationClass.Type, typeof(FhirOperationEnum.OperationType));
            }
        }
        public IResourceServiceOutcome SetActive(OperationClass OperationClass, IRequestMeta RequestMeta, string FhirId)
        {
            if (OperationClass == null)
            {
                throw new NullReferenceException("OperationClass cannot be null.");
            }
            if (IResourceServices == null)
            {
                throw new NullReferenceException("ResourceServices cannot be null.");
            }
            if (RequestMeta == null)
            {
                throw new NullReferenceException("RequestMeta cannot be null.");
            }
            if (RequestMeta.PyroRequestUri == null)
            {
                throw new NullReferenceException("RequestUri cannot be null.");
            }
            if (RequestMeta.RequestHeader == null)
            {
                throw new NullReferenceException("RequestHeaders cannot be null.");
            }
            if (RequestMeta.SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchParameterGeneric cannot be null.");
            }

            ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();

            Hl7.Fhir.Model.CompartmentDefinition CompartDef = GetCompartmentResource(FhirId);

            if (CompartDef != null)
            {
                if (CompartDef.Status != PublicationStatus.Active)
                {
                    ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                            $"The {ResourceType.CompartmentDefinition.GetLiteral()} resource status must be {PublicationStatus.Active.GetLiteral()}. The resource supplied has a status of {CompartDef.Status.GetLiteral()}.");
                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                    ResourceServiceOutcome.SuccessfulTransaction = true;
                    return(ResourceServiceOutcome);
                }
                if (string.IsNullOrWhiteSpace(CompartDef.Id))
                {
                    ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                            $"The {ResourceType.CompartmentDefinition.GetLiteral()} resource must have a resource id.");
                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                    ResourceServiceOutcome.SuccessfulTransaction = true;
                    return(ResourceServiceOutcome);
                }

                if (CompartDef.Url.StartsWith(HL7OrgUrl) || CompartDef.Url.StartsWith(PyroOrgUrl))
                {
                    DtoServiceCompartment NewServiceCompartment = new DtoServiceCompartment();
                    NewServiceCompartment.CompartmentDefinitionResourceId      = CompartDef.Id;
                    NewServiceCompartment.CompartmentDefinitionResourceVersion = CompartDef.Meta.VersionId;
                    NewServiceCompartment.Code         = CompartDef.Code.GetLiteral();
                    NewServiceCompartment.LastUpdated  = DateTimeOffset.Now;
                    NewServiceCompartment.Name         = CompartDef.Name;
                    NewServiceCompartment.Title        = CompartDef.Title;
                    NewServiceCompartment.Url          = CompartDef.Url;
                    NewServiceCompartment.ResourceList = new List <DtoServiceCompartmentResource>();
                    foreach (var ResourceComponent in CompartDef.Resource)
                    {
                        List <Search.DtoServiceSearchParameterLight> SupportedSerachParamList = IServiceSearchParameterCache.GetSearchParameterForResource(ResourceComponent.Code.GetLiteral());
                        if (ResourceComponent.Param.Count() == 0)
                        {
                            var CompatmentResource = new DtoServiceCompartmentResource()
                            {
                                Code = ResourceComponent.Code.GetLiteral(),
                                // '*' means no paramerter, which means all Resource of this type
                                //are in the compartment.
                                //If there is no 'ResourceComponent' at all then that Resources type and all its instances
                                //are not in the compartment
                                Param = "*"
                            };
                            NewServiceCompartment.ResourceList.Add(CompatmentResource);
                        }

                        foreach (var Param in ResourceComponent.Param)
                        {
                            //The Resource param value equals {def} then thnis shoudl be the same Resource as that of the Compartment its self
                            //in this case there are no search parameters
                            if (Param.ToLower() == "{def}")
                            {
                                if (ResourceComponent.Code.GetLiteral() != CompartDef.Code.GetLiteral())
                                {
                                    ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                                            $"The {ResourceType.CompartmentDefinition.GetLiteral()} resource has a search parameter that has a value of '{{def}}' which should indicate that this Resource is the target of the Compatment it's self, Yet they do not match, Compartment is: '{ResourceComponent.Code.GetLiteral()}' and '{{def}}' parametrer is found for ResourceType {ResourceComponent.Code.GetLiteral()}");
                                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                                    ResourceServiceOutcome.SuccessfulTransaction = true;
                                    return(ResourceServiceOutcome);
                                }
                            }
                            else
                            {
                                var FoundParam = SupportedSerachParamList.SingleOrDefault(x => x.Name == Param.Split('.')[0].Split(':')[0]);
                                if (FoundParam != null)
                                {
                                    if (FoundParam.Type != SearchParamType.Reference)
                                    {
                                        ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                                                $"The {ResourceType.CompartmentDefinition.GetLiteral()} resource has a search parameter that is not a Reference search parameter type. The parameter in question is '{Param}' for the resource '{ResourceComponent.Code.GetLiteral()}'");
                                        ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                                        ResourceServiceOutcome.SuccessfulTransaction = true;
                                        return(ResourceServiceOutcome);
                                    }
                                }
                                else
                                {
                                    ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                                            $"The {ResourceType.CompartmentDefinition.GetLiteral()} resource has a search parameter that is not supported by the server. The parameter in question is '{Param}' for the resource '{ResourceComponent.Code.GetLiteral()}'");
                                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                                    ResourceServiceOutcome.SuccessfulTransaction = true;
                                    return(ResourceServiceOutcome);
                                }

                                var CompatmentResource = new DtoServiceCompartmentResource()
                                {
                                    Code  = ResourceComponent.Code.GetLiteral(),
                                    Param = Param
                                };
                                NewServiceCompartment.ResourceList.Add(CompatmentResource);
                            }
                        }
                    }

                    //Commit or Update the compartment
                    NewServiceCompartment = IServiceCompartmentRepository.UpdateServiceCompartment(NewServiceCompartment);
                    ClearCompartmentCache(NewServiceCompartment.Code);
                    AddCompartmentActiveTag(CompartDef);

                    //Commit CompartmentDefinition with Active tag, disable triggers on doing so as the triggers will block
                    //the update.
                    IRequestMeta RequestMetaUpdateCompartmentDef = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.CompartmentDefinition}/{CompartDef.Id}");
                    //IResourceServices.TriggersActive = false;
                    this.IResourceTriggerService.TriggersActive = false;
                    var IResourceServicesOutcome = IResourceServices.Put(CompartDef.Id, CompartDef, RequestMetaUpdateCompartmentDef);
                    this.IResourceTriggerService.TriggersActive = true;

                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.OK;
                    ResourceServiceOutcome.IsDeleted             = false;
                    ResourceServiceOutcome.OperationType         = RestEnum.CrudOperationType.Update;
                    ResourceServiceOutcome.SuccessfulTransaction = true;
                    return(ResourceServiceOutcome);
                }
                else
                {
                    ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                            $"The {ResourceType.CompartmentDefinition.GetLiteral()} resource url property must start with either: '{HL7OrgUrl}' or '{PyroOrgUrl}'. The resource supplied has a url property of '{CompartDef.Url}'.");
                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                    ResourceServiceOutcome.SuccessfulTransaction = true;
                    return(ResourceServiceOutcome);
                }
            }
            else
            {
                //Not CompartmentDefinition Resource found
                ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported,
                                                                                                        $"The resource id supplied to the ${FhirOperationEnum.OperationType.xSetCompartmentActive.GetPyroLiteral()} operation was not found in the server at: {ResourceType.CompartmentDefinition.GetLiteral()}/{FhirId}");
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.NotFound;
                ResourceServiceOutcome.FhirResourceId        = null;
                ResourceServiceOutcome.LastModified          = null;
                ResourceServiceOutcome.IsDeleted             = null;
                ResourceServiceOutcome.OperationType         = RestEnum.CrudOperationType.Read;
                ResourceServiceOutcome.ResourceVersionNumber = null;
                ResourceServiceOutcome.RequestUri            = RequestMeta.PyroRequestUri.FhirRequestUri;
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.NotFound;
                ResourceServiceOutcome.SuccessfulTransaction = true;
                return(ResourceServiceOutcome);
            }
        }
示例#6
0
        public IResourceServiceOutcome Process(
            string OperationName, Resource Resource, IRequestMeta RequestMeta)
        {
            if (string.IsNullOrWhiteSpace(OperationName))
            {
                throw new NullReferenceException("OperationName cannot be null.");
            }
            if (RequestMeta == null)
            {
                throw new NullReferenceException("RequestMeta cannot be null.");
            }
            if (RequestMeta.PyroRequestUri == null)
            {
                throw new NullReferenceException("PyroRequestUri cannot be null.");
            }
            if (RequestMeta.RequestHeader == null)
            {
                throw new NullReferenceException("RequestHeaders cannot be null.");
            }
            if (RequestMeta.SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchPrameterGeneric cannot be null.");
            }

            IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();

            ISearchParameterService         SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
            ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(RequestMeta.SearchParameterGeneric);

            if (SearchParametersServiceOutcome.FhirOperationOutcome != null)
            {
                ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome;
                ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode;
                ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format;
                return(ResourceServiceOutcome);
            }

            var OperationDic = FhirOperationEnum.GetOperationTypeByString();

            if (!OperationDic.ContainsKey(OperationName))
            {
                string Message = $"The base operation named ${OperationName} is not supported by the server.";
                ResourceServiceOutcome.ResourceResult        = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message);
                ResourceServiceOutcome.FormatMimeType        = SearchParametersServiceOutcome.SearchParameters.Format;
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                ResourceServiceOutcome.SuccessfulTransaction = false;
                return(ResourceServiceOutcome);
            }

            var            Op             = OperationDic[OperationName];
            OperationClass OperationClass = OperationClassFactory.OperationClassList.SingleOrDefault(x => x.Scope == FhirOperationEnum.OperationScope.Base && x.Type == Op);

            if (OperationClass == null)
            {
                string Message = $"The base operation named ${OperationName} is not supported by the server as a service base operation type.";
                ResourceServiceOutcome.ResourceResult        = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message);
                ResourceServiceOutcome.FormatMimeType        = SearchParametersServiceOutcome.SearchParameters.Format;
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                ResourceServiceOutcome.SuccessfulTransaction = false;
                return(ResourceServiceOutcome);
            }

            switch (OperationClass.Type)
            {
            case FhirOperationEnum.OperationType.ServerIndexesDeleteHistoryIndexes:
            {
                IDeleteHistoryIndexesOperation DeleteManyHistoryIndexesService = ICommonFactory.CreateDeleteHistoryIndexesOperation();
                return(DeleteManyHistoryIndexesService.DeleteMany(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource));
            }

            case FhirOperationEnum.OperationType.ServerIndexesSet:
            {
                IServerSearchParameterOperation ServerSearchParameterService = IServerSearchParameterServiceFactory.CreateServerSearchParameterService();
                return(ServerSearchParameterService.ProcessSet(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource));
            }

            case FhirOperationEnum.OperationType.ServerSearchParameterIndexReport:
            {
                IServerSearchParameterOperation ServerSearchParameterService = IServerSearchParameterServiceFactory.CreateServerSearchParameterService();
                return(ServerSearchParameterService.ProcessReport(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource));
            }

            case FhirOperationEnum.OperationType.ServerIndexesIndex:
            {
                IServerSearchParameterOperation ServerSearchParameterService = IServerSearchParameterServiceFactory.CreateServerSearchParameterService();
                return(ServerSearchParameterService.ProcessIndex(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource));
            }

            case FhirOperationEnum.OperationType.ConnectathonAnswer:
            {
                IConnectathonAnswerOperation ConnectathonAnswerService = ICommonFactory.CreateConnectathonAnswerOperation();
                return(ConnectathonAnswerService.Process(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource));
            }

            case FhirOperationEnum.OperationType.ServerResourceReport:
            {
                IResourceReportOperation ServerResourceReportService = ICommonFactory.CreateResourceReportOperation();
                return(ServerResourceReportService.Process(RequestMeta.SearchParameterGeneric));
            }

            default:
                throw new System.ComponentModel.InvalidEnumArgumentException(OperationClass.Type.GetPyroLiteral(), (int)OperationClass.Type, typeof(FhirOperationEnum.OperationType));
            }
        }
        public IResourceServiceOutcome Process(ISearchParameterGeneric SearchParameterGeneric)
        {
            if (SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchParameterGeneric cannot be null.");
            }
            if (IResourceServices == null)
            {
                throw new NullReferenceException("ResourceServices cannot be null.");
            }

            try
            {
                IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();

                ISearchParameterService         SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
                ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(SearchParameterGeneric);
                if (SearchParametersServiceOutcome.FhirOperationOutcome != null)
                {
                    ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome;
                    ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode;
                    ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format;
                    return(ResourceServiceOutcome);
                }

                var ReturnParametersResource = new Parameters();
                ReturnParametersResource.Parameter = new List <Parameters.ParameterComponent>();
                foreach (string ResourceName in ModelInfo.SupportedResources)
                {
                    var ResourceReportParameter = new Parameters.ParameterComponent();
                    ResourceReportParameter.Name = ResourceName;
                    ResourceReportParameter.Part = new List <Parameters.ParameterComponent>();
                    ReturnParametersResource.Parameter.Add(ResourceReportParameter);

                    ResourceType CurrentResourceType = Pyro.Common.Tools.ResourceNameResolutionSupport.GetResourceType(ResourceName);
                    int          TotalCount          = IResourceServices.GetTotalCurrentResourceCount(CurrentResourceType);

                    var TotalCountParameter = new Parameters.ParameterComponent();
                    TotalCountParameter.Name  = $"TotalCount";
                    TotalCountParameter.Value = new FhirDecimal(TotalCount);
                    ResourceReportParameter.Part.Add(TotalCountParameter);

                    if (TotalCount > 0)
                    {
                        DateTimeOffset?LastUpdated = IResourceServices.GetLastCurrentResourceLastUpdatedValue(CurrentResourceType);
                        if (LastUpdated.HasValue)
                        {
                            var LastUpdatedParameter = new Parameters.ParameterComponent();
                            LastUpdatedParameter.Name  = $"LastUpdated";
                            LastUpdatedParameter.Value = new FhirDateTime(LastUpdated.Value);
                            ResourceReportParameter.Part.Add(LastUpdatedParameter);
                        }
                    }
                }

                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.OK;
                ResourceServiceOutcome.ResourceResult        = ReturnParametersResource;
                ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                ResourceServiceOutcome.SuccessfulTransaction = true;
                return(ResourceServiceOutcome);
            }

            catch (Exception Exec)
            {
                throw new Exception("ServerResourceReport exception thrown", Exec);
            }
        }
        public IResourceServiceOutcome DeleteMany(
            IPyroRequestUri RequestUri,
            ISearchParameterGeneric SearchParameterGeneric,
            Resource Resource)
        {
            if (RequestUri == null)
            {
                throw new NullReferenceException("RequestUri cannot be null.");
            }
            if (Resource == null)
            {
                throw new NullReferenceException("Resource cannot be null.");
            }
            if (SearchParameterGeneric == null)
            {
                throw new NullReferenceException("SearchParameterGeneric cannot be null.");
            }
            if (IResourceServices == null)
            {
                throw new NullReferenceException("ResourceServices cannot be null.");
            }

            IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();

            ISearchParameterService         SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
            ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(SearchParameterGeneric);

            if (SearchParametersServiceOutcome.FhirOperationOutcome != null)
            {
                ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode;
                ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome;
                ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format;
                return(ResourceServiceOutcome);
            }

            List <string> _ResourceList = new List <string>();

            if (Resource != null && Resource is Parameters ParametersResource)
            {
                var DeleteAll = ParametersResource.Parameter.SingleOrDefault(x => x.Name.ToLower() == _ParameterName.ToLower() && x.Value is FhirString a && a.Value == "*");
                if (DeleteAll != null)
                {
                    if (ParametersResource.Parameter.Count > 1)
                    {
                        var Op = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Warning, OperationOutcome.IssueType.BusinessRule, $"Operation: ${FhirOperationEnum.OperationType.ServerIndexesDeleteHistoryIndexes.GetPyroLiteral()} can not have a mixture of ResourceType = * and ResourceType = [ResourceName], only one or the other.");
                        ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                        ResourceServiceOutcome.ResourceResult        = Op;
                        ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                        ResourceServiceOutcome.SuccessfulTransaction = false;
                        return(ResourceServiceOutcome);
                    }
                    //Loop through and Delete all resource indexes
                    _ResourceList = ModelInfo.SupportedResources;
                }
                else
                {
                    //Collect from the parameters the Resources to have indexes deleted from
                    _ResourceList = new List <string>();
                    foreach (var Parameter in ParametersResource.Parameter)
                    {
                        if (Parameter.Name.Trim().ToLower() == _ParameterName.ToLower() && Parameter.Value is FhirString ParamValue && ModelInfo.IsKnownResource(ParamValue.Value.Trim()))
                        {
                            _ResourceList.Add(ParamValue.Value.Trim());
                        }
                        else
                        {
                            var Op = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Warning, OperationOutcome.IssueType.BusinessRule, $"Operation: ${FhirOperationEnum.OperationType.ServerIndexesDeleteHistoryIndexes.GetPyroLiteral()} unknown parameter found. Name = {Parameter.Name}, Value = {Parameter.Value}");
                            ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                            ResourceServiceOutcome.ResourceResult        = Op;
                            ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                            ResourceServiceOutcome.SuccessfulTransaction = false;
                            return(ResourceServiceOutcome);
                        }
                    }
示例#9
0
        public IResourceServiceOutcome Process(
            IPyroRequestUri RequestUri,
            ISearchParameterGeneric SearchParameterGeneric,
            Resource Resource)
        {
            IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();
            var IssueList = new List <OperationOutcome.IssueComponent>();

            ISearchParameterService         SearchService = ISearchParameterServiceFactory.CreateSearchParameterService();
            ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(SearchParameterGeneric);

            if (SearchParametersServiceOutcome.FhirOperationOutcome != null)
            {
                ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome;
                ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode;
                ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format;
                return(ResourceServiceOutcome);
            }

            if (Resource is Parameters Parameters)
            {
                if (Parameters.Parameter != null && Parameters.Parameter.Count > 0)
                {
                    if (Parameters.Parameter[0].Name.ToLower() == _ParameterName)
                    {
                        if (Parameters.Parameter[0].Resource != null)
                        {
                            if (Parameters.Parameter[0].Resource is QuestionnaireResponse QuestionnaireResponse)
                            {
                                if (QuestionnaireResponse.Meta == null)
                                {
                                    QuestionnaireResponse.Meta = new Meta();
                                }
                                if (QuestionnaireResponse.Meta.Tag == null)
                                {
                                    QuestionnaireResponse.Meta.Tag = new List <Coding>();
                                }
                                QuestionnaireResponse.Meta.Tag.Add(new Coding("https://pyrohealth.net/fhir/CodeSystem/connectathon-answer", "hidden"));

                                if (QuestionnaireResponse.Id == null || string.IsNullOrWhiteSpace(QuestionnaireResponse.Id))
                                {
                                    IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.QuestionnaireResponse.GetLiteral()}");
                                    ResourceServiceOutcome = this.IResourceServices.Post(QuestionnaireResponse, RequestMeta);
                                }
                                else
                                {
                                    IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.QuestionnaireResponse.GetLiteral()}/{QuestionnaireResponse.Id}");
                                    ResourceServiceOutcome = this.IResourceServices.Put(QuestionnaireResponse.Id, QuestionnaireResponse, RequestMeta);
                                }
                                if (ResourceServiceOutcome.SuccessfulTransaction)
                                {
                                    Parameters ParametersResult = new Parameters();
                                    ParametersResult.Parameter = new List <Parameters.ParameterComponent>();
                                    var Param = new Parameters.ParameterComponent();
                                    Param.Name = "You answers have been submitted.";
                                    ParametersResult.Parameter.Add(Param);
                                    var Param2 = new Parameters.ParameterComponent();
                                    Param2.Name     = FHIRAllTypes.QuestionnaireResponse.GetLiteral();
                                    Param2.Resource = ResourceServiceOutcome.ResourceResult;
                                    ParametersResult.Parameter.Add(Param2);
                                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.OK;
                                    ResourceServiceOutcome.ResourceResult        = ParametersResult;
                                    ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                                    ResourceServiceOutcome.SuccessfulTransaction = true;

                                    IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.QuestionnaireResponse.GetLiteral()}/{_PrimaryQuestionnaireResponseAnswerResourceId}");
                                    var          Answers     = this.IResourceServices.GetRead("AngusA1", RequestMeta);

                                    QuestionnaireResults QuestionnaireResults = QuestionnaireResponseChecker.Check(Answers.ResourceResult as QuestionnaireResponse, QuestionnaireResponse);
                                }
                                else
                                {
                                    Parameters ParametersResult = new Parameters();
                                    ParametersResult.Parameter = new List <Parameters.ParameterComponent>();
                                    var Param = new Parameters.ParameterComponent();
                                    Param.Name = "Oh no, there was an error is submitting your answers.";
                                    ParametersResult.Parameter.Add(Param);
                                    var Param2 = new Parameters.ParameterComponent();
                                    Param2.Name     = FHIRAllTypes.OperationOutcome.GetLiteral();
                                    Param2.Resource = ResourceServiceOutcome.ResourceResult;
                                    ParametersResult.Parameter.Add(Param2);
                                    ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                                    ResourceServiceOutcome.ResourceResult        = ParametersResult;
                                    ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                                    ResourceServiceOutcome.SuccessfulTransaction = false;
                                }
                            }
                            else
                            {
                                IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one parameter with the 'Name' element equal to '{_ParameterName}' where the Resource element is set to a {FHIRAllTypes.QuestionnaireResponse.GetLiteral()} FHIR Resource. The server found here a Resource of type {Parameters.Parameter[0].Resource.ResourceType}."));
                            }
                        }
                        else
                        {
                            IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one Parameter with the Name element equal to '{_ParameterName}' where the Resource element is set to a {FHIRAllTypes.QuestionnaireResponse.GetLiteral()} FHIR Resource. The server found no {FHIRAllTypes.QuestionnaireResponse.GetLiteral()} Resource"));
                        }
                    }
                    else
                    {
                        IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one Parameter with the Name element equal to '{_ParameterName}'."));
                    }
                }
                else
                {
                    IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one Parameter element."));
                }
            }
            else
            {
                IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects a FHIR {FHIRAllTypes.Parameters.GetLiteral()} resource as the call body."));
            }

            if (IssueList.Count > 0)
            {
                var Op = Common.Tools.FhirOperationOutcomeSupport.Generate(IssueList);
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.BadRequest;
                ResourceServiceOutcome.ResourceResult        = Op;
                ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
                ResourceServiceOutcome.SuccessfulTransaction = false;
                return(ResourceServiceOutcome);
            }
            else
            {
                return(ResourceServiceOutcome);
            }
        }