private IEnumerable <Resource> GetListAsOf20180507()
        {
            List <Resource> ResourceList    = new List <Resource>();
            string          TaskId          = "PyroServerInitialize20180507";
            var             RequestTaskMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.Task.GetLiteral()}/{TaskId}");
            var             OutCome         = IResourceServices.GetRead(TaskId, RequestTaskMeta);

            if (OutCome.ResourceResult == null)
            {
                var TaskRes = new Task();
                TaskRes.Id   = TaskId;
                TaskRes.Meta = new Meta()
                {
                    Tag = new List <Coding>()
                    {
                        new Coding()
                        {
                            Code   = PyroHealthInformation.PyroServerCodeSystem.Codes.Protected.GetPyroLiteral(),
                            System = PyroHealthInformation.PyroServerCodeSystem.System,
                        }
                    }
                };
            }


            return(ResourceList);
        }
Пример #2
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);
                }
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        private bool ProcessCompartmentDefinition(string ResourceId)
        {
            //First Get the CompartmentDefinition resource
            //Request: GET [base]/CompartmentDefinition/pyro-patient
            var GetRequestMeta         = IRequestMetaFactory.CreateRequestMeta().Set(ResourceType.CompartmentDefinition, $"{ResourceId}");
            var ResourceServiceOutcome = IResourceServices.GetRead(ResourceId, GetRequestMeta);

            if (ResourceServiceOutcome.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                if (ResourceServiceOutcome.ResourceResult is CompartmentDefinition Def)
                {
                    //Check if it is already an Active Compartment
                    var ActiveCoding = IPyroFhirServerCodeSystem.GetCoding(Common.PyroHealthFhirResource.CodeSystems.PyroFhirServer.Codes.ActiveCompartment);
                    if (Def.Meta.Tag.Any(x => x.System == ActiveCoding.System && x.Code == ActiveCoding.Code))
                    {
                        //If it is then set to Active (Note: On server start we will have bypassed the Protected Resource check so need to InActivate and then Activate it to make sure the
                        //Compartment is set correctly against the loaded Resource in the database table [_ServiceCompartment])
                        //It is highly likley that this never occurs unless this task run on server that already has Compartments set, first time installs this would never happen.
                        //Request: GET [base]/CompartmentDefinition/pyro-patient/x-set-compartment-inactive
                        var GetInActivateRequestMeta            = IRequestMetaFactory.CreateRequestMeta().Set(ResourceType.CompartmentDefinition, $"{ResourceId}/${FhirOperationEnum.OperationType.xSetCompartmentInActive.GetPyroLiteral()}");
                        var ResourceServiceOutcomeGetOpInActive = IFhirResourceInstanceOperationService.ProcessGet(ResourceType.CompartmentDefinition.GetLiteral(), ResourceId, FhirOperationEnum.OperationType.xSetCompartmentInActive.GetPyroLiteral(), GetInActivateRequestMeta);
                        //Note: When a Compartment is made InActive it returns 204 NoContent to indicate it has been made InActive
                        if (ResourceServiceOutcomeGetOpInActive.HttpStatusCode == System.Net.HttpStatusCode.NoContent)
                        {
                            return(SetCompatmentAsActive(ResourceId));
                        }
                        else
                        {
                            ILog.Warn($"The resource CompartmentDefinition/{ResourceId} was marked as an Active compartment yet the server was not able to set the compartment to InActive inorder to update it. The HTTP status returned was: {ResourceServiceOutcome.HttpStatusCode.ToString()}");
                            return(false);
                        }
                    }
                    else
                    {
                        //The Compartment is not set as Active so we can just Activate it
                        //Note: ToDo: Do we actualy check that a Compartment code i.e 'Patient' is not set twice by two seperate resources?
                        return(SetCompatmentAsActive(ResourceId));
                    }
                }
                else
                {
                    ILog.Warn($"Unable to cast FHIR resource returned by get CompartmentDefinition/{ResourceId} to a CompartmentDefinition resource.");
                    return(false);
                }
            }
            else
            {
                ILog.Warn($"Unable to get the CompartmentDefinition resource inorder to set the Compartment on server startup. The resource was CompartmentDefinition/{ResourceId}. The HTTP status returned was: {ResourceServiceOutcome.HttpStatusCode.ToString()} ");
                return(false);
            }
        }
Пример #5
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);
        }
Пример #6
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}");
                }
            }
        }