private ITriggerOutcome ProcessUpdateOrDelete(ITriggerInput TriggerInput)
        {
            //Get any Compartment with the same FhirId
            DtoServiceSearchParameterLight TagSearchParameter = GetTagSearchParameters(TriggerInput.ResourceType.GetLiteral());

            if (TriggerInput.DbTokenIndexList.Any(x => x.ServiceSearchParameterId == TagSearchParameter.Id && x.Code == _ProtectedCoding.Code && x.System == _ProtectedCoding.System))
            {
                //The Resource is protected
                string Message = "Error Message Not Set";
                if (TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Update)
                {
                    Message = $"The {TriggerInput.ResourceType.GetLiteral()} resource instance with Id: {TriggerInput.InboundResourceId} cannot be updated because it is a {_ProtectedCoding.Display}.";
                }
                else if (TriggerInput.CrudOperationType == RestEnum.CrudOperationType.Delete)
                {
                    Message = $"The {TriggerInput.ResourceType.GetLiteral()} resource instance with Id: {TriggerInput.InboundResourceId} cannot be deleted because it is a {_ProtectedCoding.Display}.";
                }
                var ReturnOperationOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.BusinessRule, Message);
                var TriggerOutcome         = new TriggerOutcome();
                TriggerOutcome.Report         = true;
                TriggerOutcome.HttpStatusCode = System.Net.HttpStatusCode.Conflict;
                TriggerOutcome.Resource       = ReturnOperationOutcome;
                return(TriggerOutcome);
            }
            else
            {
                //The resource is not Protected
                return(new TriggerOutcome()
                {
                    Report = false
                });
            }
        }
        private ITriggerOutcome ProcessCreateUpdateOrDelete(ITriggerInput triggerInput)
        {
            if (IGlobalProperties.ServerReadOnlyMode)
            {
                //The Resource is protected
                string Message = $"The FHIR Server is currently in a read only mode. ";
                if (!string.IsNullOrWhiteSpace(IGlobalProperties.ServerReadOnlyModeMessage))
                {
                    Message += $"Administrator's Message: {IGlobalProperties.ServerReadOnlyModeMessage}";
                }

                var ReturnOperationOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Information, OperationOutcome.IssueType.Informational, Message);
                var TriggerOutcome         = new TriggerOutcome();
                TriggerOutcome.Report         = true;
                TriggerOutcome.HttpStatusCode = System.Net.HttpStatusCode.ServiceUnavailable;
                TriggerOutcome.Resource       = ReturnOperationOutcome;
                return(TriggerOutcome);
            }
            else
            {
                //The resource is not Protected
                return(new TriggerOutcome()
                {
                    Report = false
                });
            }
        }
        private ITriggerOutcome ProcessUpdateOrDelete(RestEnum.CrudOperationType crudOperationType, ResourceTriggerService.TriggerRaisedType triggerRaised, string resourceId, FHIRAllTypes resourceType, Resource resource)
        {
            //Get any Compartment with the same FhirId
            var ServiceCompartment = IServiceCompartmentRepository.GetServiceCompartmentByFhirId(resourceId);

            if (ServiceCompartment != null)
            {
                string Message = "Error Message Not Set";
                if (crudOperationType == RestEnum.CrudOperationType.Update)
                {
                    //If so do not allow the update
                    Message = $"The {FHIRAllTypes.CompartmentDefinition.GetLiteral()} resource cannot be updated because it is an active Compartment in the server. " +
                              $"You must first set this compartment to Inactive before you can updated this resource. " +
                              $"To do this you will need to call the server Operation ${FhirOperationEnum.OperationType.xSetCompartmentInActive.GetPyroLiteral()} on this resource instance. " +
                              $"For example '[base]/{FHIRAllTypes.CompartmentDefinition.GetLiteral()}/{resourceId}/${FhirOperationEnum.OperationType.xSetCompartmentInActive.GetPyroLiteral()}' " +
                              $"Once Inactive you will then be able to update this resource in the server. " +
                              $"Caution should be taken as active Compartments affect how users interact with the server and the resources they have access to. " +
                              $"To re-activate the Compartment after updating you must call the Operation ${FhirOperationEnum.OperationType.xSetCompartmentActive.GetPyroLiteral()}. " +
                              $"For example '[base]/{FHIRAllTypes.CompartmentDefinition.GetLiteral()}/{resourceId}/${FhirOperationEnum.OperationType.xSetCompartmentActive.GetPyroLiteral()}' ";
                }
                else if (crudOperationType == RestEnum.CrudOperationType.Delete)
                {
                    Message = $"The {FHIRAllTypes.CompartmentDefinition.GetLiteral()} resource cannot be deleted because it is an active Compartment in the server. " +
                              $"You must first set this compartment to Inactive before you can delete this resource. " +
                              $"To do this you will need to call the server Operation ${FhirOperationEnum.OperationType.xSetCompartmentInActive.GetPyroLiteral()} on this resource instance. " +
                              $"For example '[base]/{FHIRAllTypes.CompartmentDefinition.GetLiteral()}/{resourceId}/${FhirOperationEnum.OperationType.xSetCompartmentInActive.GetPyroLiteral()}' " +
                              $"Once Inactive you will then be able to delete this resource from the server. " +
                              $"Caution should be taken as active Compartments affect how users interact with the server and the resources they have access to.";
                }
                var ReturnOperationOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.BusinessRule, Message);
                var TriggerOutcome         = new TriggerOutcome();
                TriggerOutcome.HttpStatusCode       = System.Net.HttpStatusCode.Conflict;
                TriggerOutcome.TriggerOutcomeResult = TriggerOutcome.TriggerOutcomeType.Report;
                TriggerOutcome.Resource             = ReturnOperationOutcome;
                return(TriggerOutcome);
            }
            else
            {
                //the Compartmentdefinition is not active so can be Updated or deleted, if updating then ensure
                //the active tags are not present and remove if they are
                RemoveActiveCompartmentTag(resource);
            }

            return(new TriggerOutcome()
            {
                TriggerOutcomeResult = TriggerOutcome.TriggerOutcomeType.Contiune
            });
        }