コード例 #1
0
        public DtoServiceCompartment UpdateServiceCompartment(DtoServiceCompartment DtoServiceCompartment)
        {
            _ServiceCompartment ServiceCompartment = IMapper.Map <_ServiceCompartment>(DtoServiceCompartment);

            DeleteServiceCompartment(ServiceCompartment.Code);
            ServiceCompartment = IPyroDbContext.Set <_ServiceCompartment>().Add(ServiceCompartment);
            this.Save();
            return(IMapper.Map <DtoServiceCompartment>(ServiceCompartment));
        }
コード例 #2
0
        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);
            }
        }