Beispiel #1
0
        public HttpResponseMessage OperationPostResourceInstanceWithParameters(string ResourceName, string id, string operation, [FromBody] FhirModel.Resource Resource)
        {
            string BaseRequestUri = this.CalculateBaseURI("{ResourceName}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.OperationPostResourceInstanceWithParameters(BaseRequestUri, Request, ResourceName, operation, id, Resource);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #2
0
        public HttpResponseMessage GetHistory(string ResourceName, string id, string vid = "")
        {
            string BaseRequestUri = this.CalculateBaseURI("{ResourceName}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.GetHistory(BaseRequestUri, Request, ResourceName, id, vid);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #3
0
        public HttpResponseMessage PostFormSearch(string ResourceName, [FromBody] FormDataCollection FormDataCollection)
        {
            string BaseRequestUri = this.CalculateBaseURI("{ResourceName}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.PostFormSearch(BaseRequestUri, Request, ResourceName, FormDataCollection.GetAsTupleCollection());

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #4
0
        public HttpResponseMessage ConditionalDelete(string ResourceName)
        {
            string BaseRequestUri = this.CalculateBaseURI("{ResourceName}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.ConditionalDelete(BaseRequestUri, Request, ResourceName);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
 private bool CommitTransactionBundle(Bundle Bundle, string FileName)
 {
     try
     {
         var RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"");
         IBundleTransactionOperation BundleTransactionOperation = IBundleTransactionOperationFactory.CreateBundleTransactionOperation();
         this.IResourceTriggerService.TriggersActive = false;
         IResourceServiceOutcome ResourceServiceOutcome = BundleTransactionOperation.Transact(Bundle, RequestMeta);
         this.IResourceTriggerService.TriggersActive = true;
         if (ResourceServiceOutcome.SuccessfulTransaction)
         {
             return(true);
         }
         else
         {
             string OperationOutcomeMessage = string.Empty;
             if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome OptOut)
             {
                 OptOut.Issue.ForEach(x => OperationOutcomeMessage = OperationOutcomeMessage + " " + x.Details);
             }
             ILog.Error($"Internal Server Error: Transaction bundle from the FHIR specification zip file named: {_ZipFileName}, file '{FileName} did not commit in a single transaction. " +
                        $"The POST bundle transaction reported: HTTP Status: {ResourceServiceOutcome.HttpStatusCode} and the detail: {OperationOutcomeMessage}");
             return(false);
         }
     }
     catch (Exception Exec)
     {
         ILog.Error(Exec, $"Internal Server Error: Could not commit the transaction bundle from the FHIR specification zip file named: {_ZipFileName}, file '{FileName}.");
         return(false);
     }
 }
Beispiel #6
0
        public IResourceServiceOutcome OperationGetResourceInstanceWithParameters(string BaseRequestUri, HttpRequestMessage Request, string ResourceName, string operation, string FhirId)
        {
            using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
            {
                try
                {
                    IRequestServiceRootValidate.Validate(BaseRequestUri);
                    IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set(Request);
                    IFhirResourceInstanceOperationService FhirResourceInstanceOperationService = IFhirResourceInstanceOperationServiceFactory.CreateFhirResourceInstanceOperationService();
                    IResourceServiceOutcome ResourceServiceOutcome = FhirResourceInstanceOperationService.ProcessGet(ResourceName, FhirId, operation, RequestMeta);
                    ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType;
                    if (ResourceServiceOutcome.SuccessfulTransaction)
                    {
                        Transaction.Commit();
                    }
                    else
                    {
                        Transaction.Rollback();
                    }

                    return(ResourceServiceOutcome);
                }
                catch (Exception Exec)
                {
                    Transaction.Rollback();
                    ILog.Error(Exec, $"PyroService.ResourceInstanceOperationWithParameters, Request: {Request.RequestUri.OriginalString}");
                    throw new PyroException(System.Net.HttpStatusCode.InternalServerError,
                                            Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message);
                }
            }
        }
Beispiel #7
0
 public IResourceServiceOutcome Base(string BaseRequestUri, HttpRequestMessage Request, Resource resource)
 {
     using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
     {
         try
         {
             IRequestServiceRootValidate.Validate(BaseRequestUri);
             IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set(Request);
             IBundleTransactionOperation BundleTransactionOperation = IBundleTransactionOperationFactory.CreateBundleTransactionOperation();
             IResourceServiceOutcome     ResourceServiceOutcome     = BundleTransactionOperation.Transact(resource, RequestMeta);
             ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType;
             if (ResourceServiceOutcome.SuccessfulTransaction)
             {
                 Transaction.Commit();
             }
             else
             {
                 Transaction.Rollback();
             }
             return(ResourceServiceOutcome);
         }
         catch (Exception Exec)
         {
             Transaction.Rollback();
             ILog.Error(Exec, $"PyroService.Base, Request: {Request.RequestUri.OriginalString}");
             throw new PyroException(System.Net.HttpStatusCode.InternalServerError,
                                     Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message);
         }
     }
 }
Beispiel #8
0
        public HttpResponseMessage OperationGetBaseWithParameters(string operation)
        {
            string BaseRequestUri = this.CalculateBaseURI("${operation}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.OperationGetBaseWithParameters(BaseRequestUri, Request, operation);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #9
0
        public IResourceServiceOutcome Get(string BaseRequestUri, HttpRequestMessage Request, string ResourceName, string id)
        {
            using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
            {
                try
                {
                    System.Security.Principal.IPrincipal x = System.Threading.Thread.CurrentPrincipal;


                    IRequestServiceRootValidate.Validate(BaseRequestUri);
                    IRequestMeta            RequestMeta            = IRequestMetaFactory.CreateRequestMeta().Set(Request);
                    IResourceServiceOutcome ResourceServiceOutcome = IResourceApiServices.GetRead(id, RequestMeta);
                    ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType;


                    Common.BackgroundTask.Task.ITaskPayloadHiServiceIHISearch Payload = new Common.BackgroundTask.Task.TaskPayloadHiServiceIHISearch("ba58c03b-4ff6-4e86-8883-8851f40fb8f7", "92e74b38-1bb3-4e0c-b056-7ca7c1bd7810");
                    ResourceServiceOutcome.BackgroundTaskList.Add(Payload);

                    Transaction.Commit();
                    return(ResourceServiceOutcome);
                }
                catch (Exception Exec)
                {
                    Transaction.Rollback();
                    ILog.Error(Exec, $"PyroService.Get, Request: {Request.RequestUri.OriginalString}");
                    throw new PyroException(System.Net.HttpStatusCode.InternalServerError,
                                            Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message);
                }
            }
        }
Beispiel #10
0
        public HttpResponseMessage Base([FromBody] FhirModel.Resource resource)
        {
            string BaseRequestUri = this.CalculateBaseURI("");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.Base(BaseRequestUri, Request, resource);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #11
0
        public HttpResponseMessage GetMetadata()
        {
            string BaseRequestUri = this.CalculateBaseURI("metadata");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.Metadata(BaseRequestUri, Request);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
        private IResourceServiceOutcome FinalResourceServiceOutcome(List <OperationOutcome.IssueComponent> IssueList)
        {
            IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();

            //Success is based on the IssueComponent's Severity where True if
            //Severity = null, or not IssueSeverity.Information or IssueSeverity.Warning
            //all other Severity return Success as False
            //Here is the actual API Code:
            //return Severity != null && (Severity.Value == IssueSeverity.Information || Severity.Value == IssueSeverity.Warning);
            if (IssueList.Count == 0)
            {
                ResourceServiceOutcome.ResourceResult    = AllOkOperationOutcome();
                ResourceServiceOutcome.ResourceResult.Id = "allok";
            }
            else
            {
                if (IssueList.Any(x => x.Success == false))
                {
                    ResourceServiceOutcome.ResourceResult    = Common.Tools.FhirOperationOutcomeSupport.Generate(IssueList);;
                    ResourceServiceOutcome.ResourceResult.Id = "validationfail";
                }
                else
                {
                    ResourceServiceOutcome.ResourceResult    = Common.Tools.FhirOperationOutcomeSupport.Generate(IssueList);;
                    ResourceServiceOutcome.ResourceResult.Id = "informationOrWarning";
                }
            }
            ResourceServiceOutcome.SuccessfulTransaction = true;
            ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.OK;
            ResourceServiceOutcome.OperationType         = Enum.RestEnum.CrudOperationType.Update;
            ResourceServiceOutcome.FormatMimeType        = FormatMimeType;
            return(ResourceServiceOutcome);
        }
Beispiel #13
0
        public void Test_HISearchMedicareNumber()
        {
            IResourceServiceOutcomeFactory IResourceServiceOutcomeFactory = CommonTestSetup.TestSetupMocks.GetIResourceServiceOutcomeFactory();
            IPyroFhirUriFactory            IPyroFhirUriFactory            = CommonTestSetup.TestSetupMocks.GetIPyroFhirUriFactory();
            IResourceServices     IResourceServices     = GetIResourceServices();
            IGlobalProperties     IGlobalProperties     = CommonTestSetup.TestSetupMocks.GetIGlobalProperties();
            IHiServiceApi         IHiServiceApi         = GetMokIHiServiceApi();
            IMedicareNumberParser IMedicareNumberParser = new MedicareNumberParser();
            IIndividualHealthcareIdentifierParser IIndividualHealthcareIdentifierParser = new IndividualHealthcareIdentifierParser();
            IDVANumberParser    IDVANumberParser   = new DVANumberParser();
            IRequestMetaFactory RequestMetaFactory = CommonTestSetup.TestSetupMocks.GetIRequestMetaFactory();
            INationalHealthcareIdentifierInfo INationalHealthcareIdentifierInfo = new NationalHealthcareIdentifierInfo();
            IMedicareNumberInfo IMedicareNumberInfo = new MedicareNumberInfo();

            Common.PyroHealthFhirResource.CodeSystems.IPyroFhirServer IPyroFhirServerCodeSystem = new Common.PyroHealthFhirResource.CodeSystems.PyroFhirServer();


            IHISearchOrValidateOperation IHISearchOrValidateOperationService = new IHISearchOrValidateOperation(
                IResourceServiceOutcomeFactory,
                IResourceServices,
                IGlobalProperties,
                IHiServiceApi,
                RequestMetaFactory,
                IMedicareNumberParser,
                IIndividualHealthcareIdentifierParser,
                IDVANumberParser,
                INationalHealthcareIdentifierInfo,
                IMedicareNumberInfo,
                IPyroFhirServerCodeSystem);

            OperationClass OperationClass = new OperationClass()
            {
                Scope = Common.Enum.FhirOperationEnum.OperationScope.Resource,
                Type  = Common.Enum.FhirOperationEnum.OperationType.xIHISearchOrValidate
            };

            //var SearchParameterGeneric = new Common.Search.SearchParameterGeneric();

            var PyroRequestUri = CommonTestSetup.TestSetupMocks.GetIPyroRequestUriFactory().CreateFhirRequestUri();

            PyroRequestUri.FhirRequestUri = CommonTestSetup.TestSetupMocks.GetIPyroRequestUriFactory().CreateFhirRequestUri().FhirRequestUri = new Pyro.Common.Tools.UriSupport.PyroFhirUri(CommonTestSetup.TestSetupMocks.GetIPrimaryServiceRootCache());
            PyroRequestUri.FhirRequestUri.Parse($"{StaticTestData.FhirEndpoint()}/{ResourceType.Patient.GetLiteral()}/{Common.Enum.FhirOperationEnum.OperationType.xIHISearchOrValidate.GetPyroLiteral()}");
            IRequestMeta RequestMeta = RequestMetaFactory.CreateRequestMeta();

            RequestMeta.PyroRequestUri         = PyroRequestUri;
            RequestMeta.RequestHeader          = CommonTestSetup.TestSetupMocks.GetIRequestHeaderFactory().CreateRequestHeader();
            RequestMeta.SearchParameterGeneric = CommonTestSetup.TestSetupMocks.GetISearchParameterGenericFactory().CreateDtoSearchParameterGeneric();

            Parameters ParametersResource = GenerateRequestParametersResource();

            IResourceServiceOutcome ResourceServiceOutcome = IHISearchOrValidateOperationService.IHISearchOrValidate(
                OperationClass,
                ParametersResource,
                RequestMeta
                );

            Assert.NotNull(ResourceServiceOutcome.ResourceResult);
            Assert.AreEqual(ResourceType.Parameters.GetLiteral(), ResourceServiceOutcome.ResourceResult.TypeName);
        }
Beispiel #14
0
        public HttpResponseMessage GetCompartmentSearch(string Compartment, string id, string ResourceName)
        {
            //throw new System.NotImplementedException("Compartment requests are not implemented on this server as yet.");
            string BaseRequestUri = this.CalculateBaseURI("{Compartment}/{id}/{ResourceName}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.CompartmentSearch(BaseRequestUri, Request, Compartment, id, ResourceName);

            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #15
0
        public HttpResponseMessage GetId(string ResourceName, string id)
        {
            string BaseRequestUri = this.CalculateBaseURI("{ResourceName}");
            IResourceServiceOutcome ResourceServiceOutcome = IPyroService.Get(BaseRequestUri, Request, ResourceName, id);

            //Below is only testing at this stage. No real tasks going as yet.
            SignalRHub.BackgroundProcessing.SendTaskList(ResourceServiceOutcome.BackgroundTaskList);
            return(IFhirRestResponse.GetHttpResponseMessage(ResourceServiceOutcome, Request, ResourceServiceOutcome.SummaryType));
        }
Beispiel #16
0
        private bool GetProcessing(Bundle.EntryComponent GetEntry, int GetEntryIndex)
        {
            IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta();

            RequestMeta.Set(GetEntry.Request);
            RequestMeta.RequestHeader.Prefer = _RequestHeader.Prefer;

            IResourceServiceOutcome ResourceServiceOutcome = null;

            if (RequestMeta.SearchParameterGeneric.ParameterList.Count > 0)
            {
                ResourceServiceOutcome = IResourceServices.GetSearch(RequestMeta);
            }
            else
            {
                ResourceServiceOutcome = IResourceServices.GetRead(RequestMeta.PyroRequestUri.FhirRequestUri.ResourceId, RequestMeta);
            }

            if (ResourceServiceOutcome.SuccessfulTransaction)
            {
                GetEntry.FullUrl         = CreateFullUrl(ResourceServiceOutcome);
                GetEntry.Response        = new Bundle.ResponseComponent();
                GetEntry.Response.Status = FormatHTTPStatusCodeAsString(ResourceServiceOutcome.HttpStatusCode);

                if (ResourceServiceOutcome.ResourceResult != null)
                {
                    if (ResourceServiceOutcome.ResourceResult.ResourceType == ResourceType.OperationOutcome)
                    {
                        GetEntry.Response.Outcome = ResourceServiceOutcome.ResourceResult;
                    }
                    else
                    {
                        GetEntry.Resource = ResourceServiceOutcome.ResourceResult;
                    }
                }
                if (ResourceServiceOutcome.LastModified.HasValue)
                {
                    GetEntry.Response.Etag = HttpHeaderSupport.GetEntityTagHeaderValueFromVersion(ResourceServiceOutcome.ResourceVersionNumber).ToString();
                    if (ResourceServiceOutcome.IsDeleted.HasValue && !ResourceServiceOutcome.IsDeleted.Value)
                    {
                        GetEntry.Response.LastModified = ResourceServiceOutcome.LastModified;
                    }
                    GetEntry.Response.Location = FormatResponseLocation(RequestMeta.PyroRequestUri.FhirRequestUri.OriginalString, ResourceServiceOutcome.FhirResourceId, ResourceServiceOutcome.ResourceVersionNumber);
                }
                return(true);
            }
            else
            {
                if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome Op)
                {
                    IdentifieBatchEntityToClient(Op, GetEntry.FullUrl, "GET", GetEntryIndex);
                }
                _ServiceOperationOutcome = ResourceServiceOutcome;
                return(false);
            }
        }
Beispiel #17
0
 private string CreateFullUrl(IResourceServiceOutcome ResourceServiceOutcome)
 {
     //Get Search results will have either a bundle or no resource and do not require FullURLs
     if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult.ResourceType != ResourceType.Bundle)
     {
         return($"{_RequestUri.FhirRequestUri.UriPrimaryServiceRoot.OriginalString}/{ResourceServiceOutcome.ResourceResult.TypeName}/{ResourceServiceOutcome.FhirResourceId}");
         //return $"{ResourceServiceOutcome.RequestUri.UriPrimaryServiceRoot.Scheme}://{ResourceServiceOutcome.ServiceRootUri.OriginalString}/{ResourceServiceOutcome.ResourceResult.TypeName}/{ResourceServiceOutcome.FhirResourceId}";
     }
     return(null);
 }
        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);
        }
Beispiel #19
0
        public Resource ResolveByCanonicalUri(string uri)
        {
            IRequestMeta            RequestMeta            = IRequestMetaFactory.CreateRequestMeta().Set($"{ResourceType.StructureDefinition.GetLiteral()}?url={uri}");
            IResourceServiceOutcome ResourceServiceOutcome = IResourceServices.GetSearch(RequestMeta);

            if (ResourceServiceOutcome.ResourceResult != null && (ResourceServiceOutcome.ResourceResult as Bundle).Entry.Count > 1)
            {
                throw new System.Exception($"More than a single {ResourceType.StructureDefinition.GetLiteral()} instance was found with the Canonical Uri of {uri} at the endpoint {RequestMeta.PyroRequestUri.FhirRequestUri.OriginalString}.");
            }
            else if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is Bundle bundle && bundle.Entry.Count == 1)
            {
                return(bundle.Entry[0].Resource);
            }
        private bool SetSearchParameterServerIndex(string Id)
        {
            string     ResourceName = ResourceType.SearchParameter.GetLiteral();
            Parameters Parameters   = new Parameters();

            Parameters.Parameter = new List <Parameters.ParameterComponent>();
            var ParameterComponent = new Parameters.ParameterComponent();

            Parameters.Parameter.Add(ParameterComponent);
            ParameterComponent.Name = $"{ResourceName}";
            var          Ref             = new ResourceReference();
            IRequestMeta RequestMetaTemp = IRequestMetaFactory.CreateRequestMeta().Set($"{ResourceName}/{Id}");

            Ref.Reference            = $"{RequestMetaTemp.PyroRequestUri.FhirRequestUri.OriginalString}";
            ParameterComponent.Value = Ref;
            string       OperationName = FhirOperationEnum.OperationType.ServerIndexesSet.GetPyroLiteral();
            IRequestMeta RequestMeta   = IRequestMetaFactory.CreateRequestMeta().Set("");

            try
            {
                IFhirBaseOperationService FhirBaseOperationService = IFhirBaseOperationServiceFactory.CreateFhirBaseOperationService();
                IResourceServiceOutcome   ResourceServiceOutcome   = IServerSearchParameterOperation.ProcessSet(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Parameters, true);
                if (ResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(true);
                }
                else
                {
                    string OperationOutcomeMessage = string.Empty;
                    if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome OptOut)
                    {
                        OptOut.Issue.ForEach(x => OperationOutcomeMessage = OperationOutcomeMessage + " " + x.Details.Text);
                        string Message = $"Internal Server Error: Failed to Set SearchParameter Server index calling operation ${OperationName} with the SearchParmeter Resource {RequestMetaTemp.PyroRequestUri.FhirRequestUri.OriginalString} with extra detail: {OperationOutcomeMessage}";
                        ILog.Error(Message);
                        throw new Exception(Message);
                    }
                    else
                    {
                        string Message = $"Internal Server Error: Failed to Set SearchParameter Server index calling operation ${OperationName} with the SearchParmeter Resource {RequestMetaTemp.PyroRequestUri.FhirRequestUri.OriginalString}";
                        ILog.Error(Message);
                        throw new Exception(Message);
                    }
                }
            }
            catch (Exception Exec)
            {
                string Message = $"{Exec.Message},  Internal Server Error: Failed to Set SearchParameter Server index calling operation ${OperationName}";
                ILog.Error(Exec, Message);
                throw new Exception(Message);
            }
        }
Beispiel #21
0
        private IEnumerable <Resource> ResolveResourcesToLoad(IEnumerable <Resource> LoadList)
        {
            List <Resource> UpdatePUTList = new List <Resource>();

            foreach (Resource NewResource in LoadList)
            {
                string ResourceId   = NewResource.Id;
                string ResourceName = NewResource.ResourceType.GetLiteral();

                //This is required for a clean install so that the ServiceBaseURL is set in the database before the next call is made,
                //as the next call is the very first call to the FHIR API yet it uses a relative path which does not work is the database
                //ServiceBaseURL ius not set.
                IRequestServiceRootValidate.Validate(IGlobalProperties.ServiceBaseURL);

                var RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{ResourceName}/{ResourceId}");

                using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
                {
                    try
                    {
                        IResourceServiceOutcome GetResourceServiceOutcome = IResourceServices.GetRead(ResourceId, RequestMeta);
                        if (GetResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.NotFound || GetResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.Gone)
                        {
                            //If the resource is not found in the database then add
                            UpdatePUTList.Add(NewResource);
                        }
                        else if (GetResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK && GetResourceServiceOutcome.ResourceResult != null)
                        {
                            //If the resource is newer than that is the database add
                            DateTimeOffset?DbResourceLastUpdated = GetResourceServiceOutcome.ResourceResult.Meta.LastUpdated;
                            if (NewResource.Meta.LastUpdated.HasValue && DbResourceLastUpdated.HasValue)
                            {
                                if (NewResource.Meta.LastUpdated.Value > DbResourceLastUpdated.Value)
                                {
                                    UpdatePUTList.Add(NewResource);
                                }
                            }
                        }
                        Transaction.Commit();
                    }
                    catch (Exception Exec)
                    {
                        Transaction.Rollback();
                        ILog.Error(Exec, $"ResourceSeeding on Startup, failed to GET {ResourceName} with id of {ResourceId}");
                    }
                }
            }
            return(UpdatePUTList);
        }
Beispiel #22
0
        private bool DeleteProcessing(Bundle.EntryComponent DeleteEntry, int DeleteEntryIndex)
        {
            IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set(DeleteEntry.Request);

            RequestMeta.RequestHeader.Prefer = _RequestHeader.Prefer;
            IResourceServiceOutcome ResourceServiceOutcome = null;

            if (RequestMeta.SearchParameterGeneric.ParameterList.Count > 0)
            {
                ResourceServiceOutcome = IResourceServices.ConditionalDelete(RequestMeta);
            }
            else
            {
                ResourceServiceOutcome = IResourceServices.Delete(RequestMeta.PyroRequestUri.FhirRequestUri.ResourceId, RequestMeta);
            }

            if (ResourceServiceOutcome.SuccessfulTransaction)
            {
                DeleteEntry.Response        = new Bundle.ResponseComponent();
                DeleteEntry.Response.Status = FormatHTTPStatusCodeAsString(ResourceServiceOutcome.HttpStatusCode);
                DeleteEntry.FullUrl         = null;
                if (ResourceServiceOutcome.ResourceResult != null)
                {
                    if (ResourceServiceOutcome.ResourceResult.ResourceType == ResourceType.OperationOutcome)
                    {
                        DeleteEntry.Response.Outcome = ResourceServiceOutcome.ResourceResult;
                    }
                    else
                    {
                        DeleteEntry.Resource = ResourceServiceOutcome.ResourceResult;
                    }
                }
                if (ResourceServiceOutcome.LastModified != null && ResourceServiceOutcome.ResourceVersionNumber != null)
                {
                    DeleteEntry.Response.Etag         = HttpHeaderSupport.GetEntityTagHeaderValueFromVersion(ResourceServiceOutcome.ResourceVersionNumber).ToString();
                    DeleteEntry.Response.LastModified = ResourceServiceOutcome.LastModified;
                }
                return(true);
            }
            else
            {
                if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome Op)
                {
                    IdentifieBatchEntityToClient(Op, DeleteEntry.FullUrl, "DELETE", DeleteEntryIndex);
                }
                _ServiceOperationOutcome = ResourceServiceOutcome;
                return(false);
            }
        }
Beispiel #23
0
 private void CommitResourceList(IEnumerable <Resource> CommitList)
 {
     this.IResourceTriggerService.TriggersActive = false;
     using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
     {
         try
         {
             bool ErrorDetected = false;
             foreach (var NewResource in CommitList)
             {
                 string ResourceId   = NewResource.Id;
                 string ResourceName = NewResource.ResourceType.GetLiteral();
                 var    RequestMeta  = IRequestMetaFactory.CreateRequestMeta().Set($"{ResourceName}/{ResourceId}");
                 IResourceServiceOutcome PutResourceServiceOutcome = IResourceServices.Put(ResourceId, NewResource, RequestMeta);
                 if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.Created)
                 {
                     ILog.Info($"Resource seeding startup task, Created {ResourceName} with id of {ResourceId}.");
                 }
                 else if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK)
                 {
                     ILog.Info($"Resource seeding startup task, Updated {ResourceName} with id of {ResourceId}.");
                 }
                 else
                 {
                     Transaction.Rollback();
                     ILog.Error($"ResourceSeeding on Startup, failed to Create or Update the resource {ResourceName} with the id of {ResourceId}. The entire seeding operation has been rolled back.");
                     ErrorDetected = true;
                     break;
                 }
             }
             if (!ErrorDetected)
             {
                 Transaction.Commit();
             }
         }
         catch (Exception Exec)
         {
             Transaction.Rollback();
             ILog.Error(Exec, $"ResourceSeeding on Startup, PUT operations failed with exception.");
         }
         finally
         {
             this.IResourceTriggerService.TriggersActive = true;
         }
     }
 }
Beispiel #24
0
        public bool UpdateTaskAsStatus(Task.TaskStatus TaskStatus, Task Task)
        {
            try
            {
                //Set the task status only if it has not been updated since we got it from the server, using the IfMatch hearder and the VersionId
                var RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{Task.ResourceType.GetLiteral()}/{Task.Id}");
                RequestMeta.RequestHeader         = IRequestHeaderFactory.CreateRequestHeader();
                RequestMeta.RequestHeader.IfMatch = Common.Tools.HttpHeaderSupport.GetETagString(Task.VersionId);

                //Update the Task Properties
                Task.Status = TaskStatus;
                Task.LastModifiedElement = new FhirDateTime(DateTimeOffset.Now);

                this.IResourceTriggerService.TriggersActive = false;
                IResourceServiceOutcome PutResourceServiceOutcome = IResourceServices.Put(Task.Id, Task, RequestMeta);
                this.IResourceTriggerService.TriggersActive = true;
                if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    Task = PutResourceServiceOutcome.ResourceResult as Task;
                    return(true);
                }
                else if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.Conflict)
                {
                    ILog.Error($"Internal Server Error: UpdateTaskAsStatus failed due to Version Conflict, Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}/_history/{Task.VersionId}.");
                    return(true);
                }
                else if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.Created)
                {
                    ILog.Error($"Internal Server Error: UpdateTaskAsStatus failed due to 201 Create being returned when OK Update was expected, Transaction was rolled back. Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}");
                    return(false);
                }
                else
                {
                    ILog.Error($"Internal Server Error: UpdateTaskAsStatus failed due to unexpected HTTP status code return, code was {PutResourceServiceOutcome.HttpStatusCode.ToString()}. Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}/_history/{Task.VersionId}");
                    return(false);
                }
            }
            catch (Exception Exec)
            {
                ILog.Error(Exec, $"ResourceSeeding on Startup, PUT operations failed with exception. Task reference was: {Task.ResourceType.GetLiteral()}/{Task.Id}/_history/{Task.VersionId}");
                return(false);
            }
        }
Beispiel #25
0
        public IResourceServiceOutcome SetInActive(OperationClass OperationClass, IRequestMeta RequestMeta, string FhirId)
        {
            ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome();
            CompartmentDefinition CompartDef = GetCompartmentResource(FhirId);

            if (CompartDef != null)
            {
                var DbServiceCompartment = IServiceCompartmentRepository.GetServiceCompartmentByFhirId(CompartDef.Id);
                if (DbServiceCompartment != null)
                {
                    IServiceCompartmentRepository.DeleteServiceCompartment(DbServiceCompartment.Code);
                    ClearCompartmentCache(DbServiceCompartment.Code);
                }
                //Regadless of the Compartment being there or not we return NoContent when it is deleted.
                ResourceServiceOutcome.HttpStatusCode        = System.Net.HttpStatusCode.NoContent;
                ResourceServiceOutcome.FhirResourceId        = null;
                ResourceServiceOutcome.LastModified          = null;
                ResourceServiceOutcome.IsDeleted             = null;
                ResourceServiceOutcome.OperationType         = RestEnum.CrudOperationType.Delete;
                ResourceServiceOutcome.ResourceVersionNumber = null;
                ResourceServiceOutcome.RequestUri            = RequestMeta.PyroRequestUri.FhirRequestUri;
                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);
            }
        }
Beispiel #26
0
 public IResourceServiceOutcome PostFormSearch(string BaseRequestUri, HttpRequestMessage Request, string ResourceName, IEnumerable <Tuple <string, string> > FormParameterList)
 {
     using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
     {
         try
         {
             IRequestMeta            RequestMeta            = IRequestMetaFactory.CreateRequestMeta().Set(Request, SearchParams.FromUriParamList(FormParameterList));
             IResourceServiceOutcome ResourceServiceOutcome = IResourceApiServices.GetSearch(RequestMeta);
             ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType;
             Transaction.Commit();
             return(ResourceServiceOutcome);
         }
         catch (Exception Exec)
         {
             Transaction.Rollback();
             ILog.Error(Exec, $"PyroService.PostFormSearch, Request: {Request.RequestUri.OriginalString}");
             throw new PyroException(System.Net.HttpStatusCode.InternalServerError,
                                     Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message);
         }
     }
 }
        private bool AddSearchParameterResourceToServer(SearchParameter SearchParam)
        {
            try
            {
                IResourceTriggerService.TriggersActive = false;
                var RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{SearchParam.TypeName}/{SearchParam.Id}");
                IResourceServiceOutcome ResourceServiceOutcome = IResourceServices.Put(SearchParam.Id, SearchParam, RequestMeta);
                IResourceTriggerService.TriggersActive = true;
                if (ResourceServiceOutcome.SuccessfulTransaction)
                {
                    return(true);
                }
                else
                {
                    string OperationOutcomeMessage = string.Empty;
                    if (ResourceServiceOutcome.ResourceResult != null && ResourceServiceOutcome.ResourceResult is OperationOutcome OptOut)
                    {
                        OptOut.Issue.ForEach(x => OperationOutcomeMessage = OperationOutcomeMessage + " " + x.Details);

                        string Message = $"Internal Server Error: SearchParameter Resource from FHIR specification zip file named: {_ZipFileName}, file 'search-parameters.xml' did not commit to the Fhir Server. " +
                                         $"The PUT failed withHTTP Status: {ResourceServiceOutcome.HttpStatusCode} and the detail: {OperationOutcomeMessage}";
                        ILog.Error(Message);
                        throw new PyroException(System.Net.HttpStatusCode.InternalServerError, OptOut, Message);
                    }
                    else
                    {
                        string Message = $"Internal Server Error: SearchParameter Resource from FHIR specification zip file named: {_ZipFileName}, file 'search-parameters.xml' did not commit to the Fhir Server. " +
                                         $"The PUT failed withHTTP Status: {ResourceServiceOutcome.HttpStatusCode}";
                        ILog.Error(Message);
                        throw new Exception(Message);
                    }
                }
            }
            catch (Exception Exec)
            {
                string Message = $"Internal Server Error: Could not commit the transaction bundle from the FHIR specification zip file named: {_ZipFileName}, file 'search-parameters.xml' SearchParameter Resource entry the Id of '{SearchParam.Id}'.";
                ILog.Error(Exec, Message);
                throw new Exception(Message);
            }
        }
Beispiel #28
0
        private List <Task> GetServerStartupTaskList()
        {
            var    TaskResultList = new List <Task>();
            string SearchQuery    = string.Empty;

            try
            {
                //Get Tasks that are PyroFhirServer 'ServerStartupTask' tasks that have a status of Ready or InProgress or OnHold
                string IdentifierValue = string.Empty;
                foreach (var Id in _TaskIdentifierToRunList)
                {
                    IdentifierValue += $",{IPyroFhirServerCodeSystem.GetSystem()}|{IPyroFhirServerCodeSystem.GetCode(Id)}";
                }
                IdentifierValue = IdentifierValue.TrimStart(',');
                string SearchTaskIdentifier = $"identifier={IdentifierValue}";
                string SearchTaskStatus     = $"status={Task.TaskStatus.Ready.GetLiteral()},{Task.TaskStatus.InProgress.GetLiteral()},{Task.TaskStatus.OnHold.GetLiteral()}";
                SearchQuery = $"{SearchTaskIdentifier}&{SearchTaskStatus}";
                var RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{ResourceType.Task}?{SearchQuery}");

                IResourceServiceOutcome PutResourceServiceOutcome = IResourceServices.GetSearch(RequestMeta);
                if (PutResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK && PutResourceServiceOutcome.SuccessfulTransaction)
                {
                    if (PutResourceServiceOutcome.ResourceResult != null && PutResourceServiceOutcome.ResourceResult is Bundle Bundle)
                    {
                        foreach (var Entry in Bundle.Entry)
                        {
                            if (Entry.Resource != null && Entry.Resource.ResourceType == ResourceType.Task)
                            {
                                TaskResultList.Add(Entry.Resource as Task);
                            }
                        }
                    }
                }
            }
            catch (Exception Exec)
            {
                ILog.Error(Exec, $"Internal Server Error: Unable to load the list of Tasks of Tasks to process on Pyro Server Start-up. Search Query was: {ResourceType.Task.GetLiteral()}?{SearchQuery}");
            }
            return(TaskResultList);
        }
Beispiel #29
0
 public IResourceServiceOutcome CompartmentSearch(string BaseRequestUri, HttpRequestMessage Request, string Compartment, string id, string ResourceName)
 {
     using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
     {
         try
         {
             IRequestServiceRootValidate.Validate(BaseRequestUri);
             IRequestMeta            RequestMeta            = IRequestMetaFactory.CreateRequestMeta().Set(Request);
             IResourceServiceOutcome ResourceServiceOutcome = IResourceApiServices.GetCompartmentSearch(RequestMeta, Compartment, id, ResourceName);
             ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType;
             Transaction.Commit();
             return(ResourceServiceOutcome);
         }
         catch (Exception Exec)
         {
             Transaction.Rollback();
             ILog.Error(Exec, $"PyroService.CompartmentSearch, Request: {Request.RequestUri.OriginalString}");
             throw new PyroException(System.Net.HttpStatusCode.InternalServerError,
                                     Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Exception, Exec.Message), Exec.Message);
         }
     }
 }
Beispiel #30
0
        public void Run(ITaskPayloadHiServiceIHISearch TaskPayloadHiServiceIHISearch)
        {
            using (DbContextTransaction Transaction = IUnitOfWork.BeginTransaction())
            {
                try
                {
                    IRequestMeta            RequestMeta            = IRequestMetaFactory.CreateRequestMeta().Set("Patient/IHIStatusExample");
                    IResourceServiceOutcome ResourceServiceOutcome = IResourceApiServices.GetRead("IHIStatusExample", RequestMeta);
                    ResourceServiceOutcome.SummaryType = RequestMeta.SearchParameterGeneric.SummaryType;

                    Transaction.Commit();


                    ConsoleSupport.TimeStampWriteLine(LogMessageSupport.TaskOutCome(TaskPayloadHiServiceIHISearch, Hl7.Fhir.Model.Task.TaskStatus.Completed));
                }
                catch (Exception Exec)
                {
                    Transaction.Rollback();
                    ConsoleSupport.TimeStampWriteLine(LogMessageSupport.TaskException(TaskPayloadHiServiceIHISearch, Hl7.Fhir.Model.Task.TaskStatus.Failed));
                    ILog.Error(Exec, $"FHIR Task ID: {TaskPayloadHiServiceIHISearch.TaskId}, FHIR Patient ID: {TaskPayloadHiServiceIHISearch.PatientId}");
                }
            }
        }