Пример #1
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);
        }
Пример #2
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);
         }
     }
 }