public PyroSearchParameters GetSearchParameters(string Compartment, string CompartmentId, string ResourceName) { //I need to check that Compartment and ResourceName are actual FHIR Resource Types, the two lines //below do that and throw Pyro Exception if they are not. FHIRAllTypes CompartmentType = ResourceNameResolutionSupport.GetResourceFhirAllType(Compartment); FHIRAllTypes ResourceNameType = ResourceNameResolutionSupport.GetResourceFhirAllType(ResourceName); //Now to contruct the Container search parameters, these are cached from the database Conatiner Resource DtoServiceCompartmentResourceCached ServiceCompartmentResource = IServiceCompartmentCache.GetServiceCompartmentResourceForCompartmentCodeAndResource(Compartment, ResourceName); string ConatinerSerachString = string.Empty; if (ServiceCompartmentResource != null) { var CompartmentParamQuery = new List <string>(); foreach (var CompartmentSearchParameter in ServiceCompartmentResource.ParamList) { if (CompartmentSearchParameter.Param == "*") { // if the param="*" then all instances of this Resource Type are in the container and there are no // actualy parameters that it needs to be restricted by. So the ConatinerSerachString remains as empty string. break; } else { CompartmentParamQuery.Add($"{CompartmentSearchParameter.Param}:{Compartment}={CompartmentId}"); } } ConatinerSerachString = String.Join("&", CompartmentParamQuery.ToArray()); } else { DtoServiceCompartmentCached ServiceCompartment = IServiceCompartmentCache.GetServiceCompartmentForCompartmentCode(Compartment); if (ServiceCompartment == null) { string Message = $"No active {Compartment} Compartment exist in this server. Perhaps you could create one using a {FHIRAllTypes.CompartmentDefinition.GetLiteral()} resource and the resource instance ${Pyro.Common.Enum.FhirOperationEnum.OperationType.xSetCompartmentActive} Operation. " + $"For example: '[base]/{FHIRAllTypes.CompartmentDefinition.GetLiteral()}/[id]/${Pyro.Common.Enum.FhirOperationEnum.OperationType.xSetCompartmentActive}' "; var OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported, Message); throw new PyroException(System.Net.HttpStatusCode.BadRequest, OpOutcome, Message); } else { string Message = $"The {Compartment} Compartment defined by the {FHIRAllTypes.CompartmentDefinition.GetLiteral()} with the resource id of '{ServiceCompartment.CompartmentDefinitionResourceId}' does not allow access to any {ResourceName} resource type instances."; var OpOutcome = FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Fatal, OperationOutcome.IssueType.NotSupported, Message); throw new PyroException(System.Net.HttpStatusCode.BadRequest, OpOutcome, Message); } } ISearchParameterGeneric ContainerSearchParameterGeneric = ISearchParameterGenericFactory.CreateDtoSearchParameterGeneric().Parse(ConatinerSerachString); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome ContainerSearchParametersServiceOutcome = SearchService.ProcessSearchParameters(ContainerSearchParameterGeneric, SearchParameterService.SearchParameterServiceType.Resource, ResourceNameType, null); return(ContainerSearchParametersServiceOutcome.SearchParameters); }
public IResourceServiceOutcome GetServersConformanceResource(IRequestMeta RequestMeta) { if (RequestMeta == null) { throw new NullReferenceException("RequestMeta can not be null."); } if (RequestMeta.SearchParameterGeneric == null) { throw new NullReferenceException("SearchParameterGeneric can not be null."); } IResourceServiceOutcome ServiceOperationOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome(); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(RequestMeta.SearchParameterGeneric); if (SearchParametersServiceOutcome.FhirOperationOutcome != null) { ServiceOperationOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome; ServiceOperationOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode; ServiceOperationOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; return(ServiceOperationOutcome); } var Conformance = new CapabilityStatement(); var ApplicationReleaseDate = new DateTimeOffset(2017, 10, 17, 6, 00, 00, new TimeSpan(8, 0, 0)); string ServerName = "Pyro Server"; string Https = "https://"; Conformance.Id = "metadata"; Conformance.Url = $"{Https}{IPrimaryServiceRootCache.GetPrimaryRootUrlFromDatabase().Url}/metadata"; Conformance.Version = $"V{IGlobalProperties.ApplicationVersionInfo}"; Conformance.Meta = new Meta(); Conformance.Meta.LastUpdated = ApplicationReleaseDate; Conformance.Name = ServerName; Conformance.Status = PublicationStatus.Active; Conformance.Experimental = true; Conformance.Date = (new FhirDateTime(ApplicationReleaseDate)).Value; Conformance.Publisher = "PyroHealth.net"; var AngusContactDetail = Common.PyroHealthInformation.PyroHealthContactDetailAngusMillar.GetContactDetail(); Conformance.Contact = new List <ContactDetail>() { AngusContactDetail }; Conformance.Description = new Markdown("Conformance statement for the " + ServerName); var Australia = new CodeableConcept("urn:iso:std:iso:3166", "AU", "Australia"); Conformance.Jurisdiction = new List <CodeableConcept>() { Australia }; Conformance.Purpose = new Markdown("FHIR Server reference implementation"); Conformance.Copyright = new Markdown("Copyright: PyroHealth.net"); Conformance.Kind = CapabilityStatement.CapabilityStatementKind.Instance; Conformance.Software = new CapabilityStatement.SoftwareComponent(); Conformance.Software.Name = ServerName; Conformance.Software.Version = IGlobalProperties.ApplicationVersionInfo; //To align with FHIR version only use number no prefix of 'V' Conformance.Software.ReleaseDate = (new FhirDateTime(ApplicationReleaseDate)).Value; Conformance.Implementation = new CapabilityStatement.ImplementationComponent(); Conformance.Implementation.Description = $"{ServerName} is an implementation of a FHIR server supporting V{Hl7.Fhir.Model.ModelInfo.Version} of the specification. This instance is a publicly available testing server and its resource may be cleared at any time."; Conformance.Implementation.Url = $"{Https}{IPrimaryServiceRootCache.GetPrimaryRootUrlFromDatabase().Url}"; Conformance.FhirVersion = Hl7.Fhir.Model.ModelInfo.Version; //Must be formated as just the number '3.0.1' as touchstone does not like the V3.0.1 Conformance.AcceptUnknown = CapabilityStatement.UnknownContentCode.Extensions; var ContentFormatList = new List <string>(); foreach (var mediaType in Hl7.Fhir.Rest.ContentType.XML_CONTENT_HEADERS) { ContentFormatList.Add(mediaType); } foreach (var mediaType in Hl7.Fhir.Rest.ContentType.JSON_CONTENT_HEADERS) { ContentFormatList.Add(mediaType); } Conformance.Format = ContentFormatList; Conformance.Rest = new List <CapabilityStatement.RestComponent>(); var RestComponent = new CapabilityStatement.RestComponent(); Conformance.Rest.Add(RestComponent); RestComponent.Mode = CapabilityStatement.RestfulCapabilityMode.Server; RestComponent.Documentation = $"STU{Hl7.Fhir.Model.ModelInfo.Version.Split('.')[0]} V{Hl7.Fhir.Model.ModelInfo.Version} FHIR Server"; RestComponent.Security = new CapabilityStatement.SecurityComponent(); RestComponent.Security.Description = "No Security has been implemented, server if publicly open"; RestComponent.Interaction = new List <CapabilityStatement.SystemInteractionComponent>(); var SystemInteractionComponent = new CapabilityStatement.SystemInteractionComponent(); RestComponent.Interaction.Add(SystemInteractionComponent); SystemInteractionComponent.Code = CapabilityStatement.SystemRestfulInteraction.Transaction; SystemInteractionComponent.Documentation = "Batch Transaction supports all request methods (Delete, POST, PUT, GET) including conditional create/update/delete. Operatons are not supported within Transaction bundles."; var CompartmentList = IServiceCompartmentRepository.GetAllServiceCompartments(); if (CompartmentList != null && CompartmentList.Count > 0) { var CompartmentUrlList = new List <string>(); CompartmentList.ForEach(x => CompartmentUrlList.Add(x.Url)); RestComponent.Compartment = CompartmentUrlList; } RestComponent.Resource = new List <CapabilityStatement.ResourceComponent>(); List <DtoServiceSearchParameterHeavy> DtoServiceSearchParameterHeavyList = IServiceSearchParameterService.GetServiceSearchParametersHeavy(false); var ResourceTypeList = Enum.GetValues(typeof(ResourceType)); foreach (ResourceType ResourceType in ResourceTypeList) { string CurrentResourceString = ResourceType.GetLiteral(); FHIRAllTypes?FhirType = Hl7.Fhir.Model.ModelInfo.FhirTypeNameToFhirType(CurrentResourceString); var ResourceComponent = new CapabilityStatement.ResourceComponent(); RestComponent.Resource.Add(ResourceComponent); ResourceComponent.Type = ResourceType; ResourceComponent.Interaction = new List <CapabilityStatement.ResourceInteractionComponent>() { new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.Create }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.Delete }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.Read }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.Update }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.Vread }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.SearchType }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.HistoryInstance }, new CapabilityStatement.ResourceInteractionComponent() { Code = CapabilityStatement.TypeRestfulInteraction.HistoryType } //new Conformance.ResourceInteractionComponent() { Code = Conformance.TypeRestfulInteraction.HistoryType}, }; ResourceComponent.Versioning = CapabilityStatement.ResourceVersionPolicy.Versioned; ResourceComponent.ReadHistory = true; ResourceComponent.UpdateCreate = true; ResourceComponent.ConditionalCreate = true; ResourceComponent.ConditionalRead = CapabilityStatement.ConditionalReadStatus.FullSupport; ResourceComponent.ConditionalUpdate = true; ResourceComponent.ConditionalDelete = CapabilityStatement.ConditionalDeleteStatus.Multiple; var ReferenceHandlingPolicyList = new List <CapabilityStatement.ReferenceHandlingPolicy?>(); ReferenceHandlingPolicyList.Add(CapabilityStatement.ReferenceHandlingPolicy.Literal); ReferenceHandlingPolicyList.Add(CapabilityStatement.ReferenceHandlingPolicy.Local); ResourceComponent.ReferencePolicy = ReferenceHandlingPolicyList; List <DtoServiceSearchParameterHeavy> DtoServiceSearchParameterHeavyForResourceList = DtoServiceSearchParameterHeavyList.Where(x => x.Resource == CurrentResourceString || x.Resource == FHIRAllTypes.Resource.GetLiteral()).ToList(); //List<ServiceSearchParameterHeavy> DtoServiceSearchParameterHeavyForResourceList = ICommonServices.GetServiceSearchParametersHeavyForResource(FhirType.Value.GetLiteral()); //DtoServiceSearchParameterHeavyForResourceList.AddRange(ICommonServices.GetServiceSearchParametersHeavyForResource(FHIRAllTypes.Resource.GetLiteral())); ResourceComponent.SearchParam = new List <CapabilityStatement.SearchParamComponent>(); List <string> IncludesList = null; List <string> RevIncludesList = null; foreach (var SupportedSearchParam in DtoServiceSearchParameterHeavyForResourceList) { if (SupportedSearchParam.IsIndexed && SupportedSearchParam.Status == PublicationStatus.Active) { //Include (RevIncludes are below) if (SupportedSearchParam.Type == SearchParamType.Reference) { if (IncludesList == null) { IncludesList = new List <string>(); } if (SupportedSearchParam.TargetResourceTypeList.Count > 1) { foreach (var Target in SupportedSearchParam.TargetResourceTypeList) { IncludesList.Add($"{SupportedSearchParam.Resource}:{SupportedSearchParam.Name}:{Target.ResourceType.GetLiteral()}"); } } else { IncludesList.Add($"{SupportedSearchParam.Resource}:{SupportedSearchParam.Name}"); } } CapabilityStatement.SearchParamComponent SearchParamComponent = new CapabilityStatement.SearchParamComponent(); ResourceComponent.SearchParam.Add(SearchParamComponent); SearchParamComponent.Name = SupportedSearchParam.Name; SearchParamComponent.Type = SupportedSearchParam.Type; SearchParamComponent.Definition = SupportedSearchParam.Url; if (!string.IsNullOrWhiteSpace(SupportedSearchParam.Description)) { SearchParamComponent.Documentation = SupportedSearchParam.Description; } } } ResourceComponent.SearchInclude = IncludesList; //RevIncludes var RevIncludeSearchParameterList = DtoServiceSearchParameterHeavyList.Where(x => x.Type == SearchParamType.Reference && x.TargetResourceTypeList.Any(c => c.ResourceType == ResourceType)); foreach (var Rev in RevIncludeSearchParameterList) { if (RevIncludesList == null) { RevIncludesList = new List <string>(); } if (Rev.TargetResourceTypeList.Count > 1) { RevIncludesList.Add($"{Rev.Resource}:{Rev.Name}:{CurrentResourceString}"); } else { RevIncludesList.Add($"{Rev.Resource}:{Rev.Name}"); } } ResourceComponent.SearchRevInclude = RevIncludesList; } ConstructConformanceResourceNarrative(Conformance); IDatabaseOperationOutcome DatabaseOperationOutcome = IDatabaseOperationOutcomeFactory.CreateDatabaseOperationOutcome(); ServiceOperationOutcome.FhirResourceId = Conformance.Id; ServiceOperationOutcome.ResourceVersionNumber = Conformance.Version; ServiceOperationOutcome.LastModified = Conformance.Meta.LastUpdated; ServiceOperationOutcome.OperationType = Common.Enum.RestEnum.CrudOperationType.Read; ServiceOperationOutcome.IsDeleted = false; ServiceOperationOutcome.RequestUri = null; ServiceOperationOutcome.ResourceResult = Conformance; ServiceOperationOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; ServiceOperationOutcome.HttpStatusCode = System.Net.HttpStatusCode.OK; return(ServiceOperationOutcome); }
public IResourceServiceOutcome Process(string OperationName, Resource Resource, IRequestMeta RequestMeta) { if (string.IsNullOrWhiteSpace(OperationName)) { throw new NullReferenceException("OperationName cannot be null."); } if (Resource == null) { throw new NullReferenceException("Resource 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 (ICommonFactory == null) { throw new NullReferenceException("ICommonFactory cannot be null."); } if (RequestMeta.SearchParameterGeneric == null) { throw new NullReferenceException("SearchParameterGeneric cannot be null."); } IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome(); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(RequestMeta.SearchParameterGeneric); if (SearchParametersServiceOutcome.FhirOperationOutcome != null) { ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome; ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode; ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; return(ResourceServiceOutcome); } var OperationDic = FhirOperationEnum.GetOperationTypeByString(); if (!OperationDic.ContainsKey(Pyro.Common.Tools.StringSupport.ToLowerFast(OperationName))) { string Message = $"The resource operation named ${OperationName} is not supported by the server."; ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message); ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } var Op = OperationDic[Pyro.Common.Tools.StringSupport.ToLowerFast(OperationName)]; OperationClass OperationClass = OperationClassFactory.OperationClassList.SingleOrDefault(x => x.Scope == FhirOperationEnum.OperationScope.Resource && x.Type == Op); if (OperationClass == null) { string Message = $"The resource operation named ${OperationName} is not supported by the server as a resource service operation type."; ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message); ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } switch (OperationClass.Type) { case FhirOperationEnum.OperationType.Validate: { IFhirValidateOperation FhirValidateOperation = ICommonFactory.CreateFhirValidateOperation(); return(FhirValidateOperation.ValidateResource(OperationClass, Resource, RequestMeta)); } case FhirOperationEnum.OperationType.xIHISearchOrValidate: { IIHISearchOrValidateOperation IHISearchOrValidateOperation = ICommonFactory.CreateIHISearchOrValidateOperation(); return(IHISearchOrValidateOperation.IHISearchOrValidate(OperationClass, Resource, RequestMeta)); } default: throw new System.ComponentModel.InvalidEnumArgumentException(OperationClass.Type.GetPyroLiteral(), (int)OperationClass.Type, typeof(FhirOperationEnum.OperationType)); } }
public IResourceServiceOutcome Process( string OperationName, Resource Resource, IRequestMeta RequestMeta) { if (string.IsNullOrWhiteSpace(OperationName)) { throw new NullReferenceException("OperationName cannot be null."); } if (RequestMeta == null) { throw new NullReferenceException("RequestMeta cannot be null."); } if (RequestMeta.PyroRequestUri == null) { throw new NullReferenceException("PyroRequestUri cannot be null."); } if (RequestMeta.RequestHeader == null) { throw new NullReferenceException("RequestHeaders cannot be null."); } if (RequestMeta.SearchParameterGeneric == null) { throw new NullReferenceException("SearchPrameterGeneric cannot be null."); } IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome(); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(RequestMeta.SearchParameterGeneric); if (SearchParametersServiceOutcome.FhirOperationOutcome != null) { ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome; ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode; ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; return(ResourceServiceOutcome); } var OperationDic = FhirOperationEnum.GetOperationTypeByString(); if (!OperationDic.ContainsKey(OperationName)) { string Message = $"The base operation named ${OperationName} is not supported by the server."; ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message); ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } var Op = OperationDic[OperationName]; OperationClass OperationClass = OperationClassFactory.OperationClassList.SingleOrDefault(x => x.Scope == FhirOperationEnum.OperationScope.Base && x.Type == Op); if (OperationClass == null) { string Message = $"The base operation named ${OperationName} is not supported by the server as a service base operation type."; ResourceServiceOutcome.ResourceResult = Common.Tools.FhirOperationOutcomeSupport.Create(Hl7.Fhir.Model.OperationOutcome.IssueSeverity.Error, Hl7.Fhir.Model.OperationOutcome.IssueType.NotSupported, Message); ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } switch (OperationClass.Type) { case FhirOperationEnum.OperationType.ServerIndexesDeleteHistoryIndexes: { IDeleteHistoryIndexesOperation DeleteManyHistoryIndexesService = ICommonFactory.CreateDeleteHistoryIndexesOperation(); return(DeleteManyHistoryIndexesService.DeleteMany(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource)); } case FhirOperationEnum.OperationType.ServerIndexesSet: { IServerSearchParameterOperation ServerSearchParameterService = IServerSearchParameterServiceFactory.CreateServerSearchParameterService(); return(ServerSearchParameterService.ProcessSet(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource)); } case FhirOperationEnum.OperationType.ServerSearchParameterIndexReport: { IServerSearchParameterOperation ServerSearchParameterService = IServerSearchParameterServiceFactory.CreateServerSearchParameterService(); return(ServerSearchParameterService.ProcessReport(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource)); } case FhirOperationEnum.OperationType.ServerIndexesIndex: { IServerSearchParameterOperation ServerSearchParameterService = IServerSearchParameterServiceFactory.CreateServerSearchParameterService(); return(ServerSearchParameterService.ProcessIndex(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource)); } case FhirOperationEnum.OperationType.ConnectathonAnswer: { IConnectathonAnswerOperation ConnectathonAnswerService = ICommonFactory.CreateConnectathonAnswerOperation(); return(ConnectathonAnswerService.Process(RequestMeta.PyroRequestUri, RequestMeta.SearchParameterGeneric, Resource)); } case FhirOperationEnum.OperationType.ServerResourceReport: { IResourceReportOperation ServerResourceReportService = ICommonFactory.CreateResourceReportOperation(); return(ServerResourceReportService.Process(RequestMeta.SearchParameterGeneric)); } default: throw new System.ComponentModel.InvalidEnumArgumentException(OperationClass.Type.GetPyroLiteral(), (int)OperationClass.Type, typeof(FhirOperationEnum.OperationType)); } }
public IResourceServiceOutcome Process(ISearchParameterGeneric SearchParameterGeneric) { if (SearchParameterGeneric == null) { throw new NullReferenceException("SearchParameterGeneric cannot be null."); } if (IResourceServices == null) { throw new NullReferenceException("ResourceServices cannot be null."); } try { IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome(); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(SearchParameterGeneric); if (SearchParametersServiceOutcome.FhirOperationOutcome != null) { ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome; ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode; ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; return(ResourceServiceOutcome); } var ReturnParametersResource = new Parameters(); ReturnParametersResource.Parameter = new List <Parameters.ParameterComponent>(); foreach (string ResourceName in ModelInfo.SupportedResources) { var ResourceReportParameter = new Parameters.ParameterComponent(); ResourceReportParameter.Name = ResourceName; ResourceReportParameter.Part = new List <Parameters.ParameterComponent>(); ReturnParametersResource.Parameter.Add(ResourceReportParameter); ResourceType CurrentResourceType = Pyro.Common.Tools.ResourceNameResolutionSupport.GetResourceType(ResourceName); int TotalCount = IResourceServices.GetTotalCurrentResourceCount(CurrentResourceType); var TotalCountParameter = new Parameters.ParameterComponent(); TotalCountParameter.Name = $"TotalCount"; TotalCountParameter.Value = new FhirDecimal(TotalCount); ResourceReportParameter.Part.Add(TotalCountParameter); if (TotalCount > 0) { DateTimeOffset?LastUpdated = IResourceServices.GetLastCurrentResourceLastUpdatedValue(CurrentResourceType); if (LastUpdated.HasValue) { var LastUpdatedParameter = new Parameters.ParameterComponent(); LastUpdatedParameter.Name = $"LastUpdated"; LastUpdatedParameter.Value = new FhirDateTime(LastUpdated.Value); ResourceReportParameter.Part.Add(LastUpdatedParameter); } } } ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.OK; ResourceServiceOutcome.ResourceResult = ReturnParametersResource; ResourceServiceOutcome.OperationType = Enum.RestEnum.CrudOperationType.Update; ResourceServiceOutcome.SuccessfulTransaction = true; return(ResourceServiceOutcome); } catch (Exception Exec) { throw new Exception("ServerResourceReport exception thrown", Exec); } }
private ISearchParametersServiceOutcome ParseUrlSearchParameters(ISearchParameterGeneric SearchParameterGeneric, FhirOperation.OperationClass OperationClass) { ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); return(SearchService.ProcessOperationSearchParameters(SearchParameterGeneric, SearchParameterService.SearchParameterServiceType.Base | SearchParameterService.SearchParameterServiceType.Operation, OperationClass)); }
public IResourceServiceOutcome DeleteMany( IPyroRequestUri RequestUri, ISearchParameterGeneric SearchParameterGeneric, Resource Resource) { if (RequestUri == null) { throw new NullReferenceException("RequestUri cannot be null."); } if (Resource == null) { throw new NullReferenceException("Resource cannot be null."); } if (SearchParameterGeneric == null) { throw new NullReferenceException("SearchParameterGeneric cannot be null."); } if (IResourceServices == null) { throw new NullReferenceException("ResourceServices cannot be null."); } IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome(); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(SearchParameterGeneric); if (SearchParametersServiceOutcome.FhirOperationOutcome != null) { ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode; ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome; ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; return(ResourceServiceOutcome); } List <string> _ResourceList = new List <string>(); if (Resource != null && Resource is Parameters ParametersResource) { var DeleteAll = ParametersResource.Parameter.SingleOrDefault(x => x.Name.ToLower() == _ParameterName.ToLower() && x.Value is FhirString a && a.Value == "*"); if (DeleteAll != null) { if (ParametersResource.Parameter.Count > 1) { var Op = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Warning, OperationOutcome.IssueType.BusinessRule, $"Operation: ${FhirOperationEnum.OperationType.ServerIndexesDeleteHistoryIndexes.GetPyroLiteral()} can not have a mixture of ResourceType = * and ResourceType = [ResourceName], only one or the other."); ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.ResourceResult = Op; ResourceServiceOutcome.OperationType = Enum.RestEnum.CrudOperationType.Update; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } //Loop through and Delete all resource indexes _ResourceList = ModelInfo.SupportedResources; } else { //Collect from the parameters the Resources to have indexes deleted from _ResourceList = new List <string>(); foreach (var Parameter in ParametersResource.Parameter) { if (Parameter.Name.Trim().ToLower() == _ParameterName.ToLower() && Parameter.Value is FhirString ParamValue && ModelInfo.IsKnownResource(ParamValue.Value.Trim())) { _ResourceList.Add(ParamValue.Value.Trim()); } else { var Op = Common.Tools.FhirOperationOutcomeSupport.Create(OperationOutcome.IssueSeverity.Warning, OperationOutcome.IssueType.BusinessRule, $"Operation: ${FhirOperationEnum.OperationType.ServerIndexesDeleteHistoryIndexes.GetPyroLiteral()} unknown parameter found. Name = {Parameter.Name}, Value = {Parameter.Value}"); ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.ResourceResult = Op; ResourceServiceOutcome.OperationType = Enum.RestEnum.CrudOperationType.Update; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } }
public IResourceServiceOutcome Process( IPyroRequestUri RequestUri, ISearchParameterGeneric SearchParameterGeneric, Resource Resource) { IResourceServiceOutcome ResourceServiceOutcome = IResourceServiceOutcomeFactory.CreateResourceServiceOutcome(); var IssueList = new List <OperationOutcome.IssueComponent>(); ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); ISearchParametersServiceOutcome SearchParametersServiceOutcome = SearchService.ProcessBaseSearchParameters(SearchParameterGeneric); if (SearchParametersServiceOutcome.FhirOperationOutcome != null) { ResourceServiceOutcome.ResourceResult = SearchParametersServiceOutcome.FhirOperationOutcome; ResourceServiceOutcome.HttpStatusCode = SearchParametersServiceOutcome.HttpStatusCode; ResourceServiceOutcome.FormatMimeType = SearchParametersServiceOutcome.SearchParameters.Format; return(ResourceServiceOutcome); } if (Resource is Parameters Parameters) { if (Parameters.Parameter != null && Parameters.Parameter.Count > 0) { if (Parameters.Parameter[0].Name.ToLower() == _ParameterName) { if (Parameters.Parameter[0].Resource != null) { if (Parameters.Parameter[0].Resource is QuestionnaireResponse QuestionnaireResponse) { if (QuestionnaireResponse.Meta == null) { QuestionnaireResponse.Meta = new Meta(); } if (QuestionnaireResponse.Meta.Tag == null) { QuestionnaireResponse.Meta.Tag = new List <Coding>(); } QuestionnaireResponse.Meta.Tag.Add(new Coding("https://pyrohealth.net/fhir/CodeSystem/connectathon-answer", "hidden")); if (QuestionnaireResponse.Id == null || string.IsNullOrWhiteSpace(QuestionnaireResponse.Id)) { IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.QuestionnaireResponse.GetLiteral()}"); ResourceServiceOutcome = this.IResourceServices.Post(QuestionnaireResponse, RequestMeta); } else { IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.QuestionnaireResponse.GetLiteral()}/{QuestionnaireResponse.Id}"); ResourceServiceOutcome = this.IResourceServices.Put(QuestionnaireResponse.Id, QuestionnaireResponse, RequestMeta); } if (ResourceServiceOutcome.SuccessfulTransaction) { Parameters ParametersResult = new Parameters(); ParametersResult.Parameter = new List <Parameters.ParameterComponent>(); var Param = new Parameters.ParameterComponent(); Param.Name = "You answers have been submitted."; ParametersResult.Parameter.Add(Param); var Param2 = new Parameters.ParameterComponent(); Param2.Name = FHIRAllTypes.QuestionnaireResponse.GetLiteral(); Param2.Resource = ResourceServiceOutcome.ResourceResult; ParametersResult.Parameter.Add(Param2); ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.OK; ResourceServiceOutcome.ResourceResult = ParametersResult; ResourceServiceOutcome.OperationType = Enum.RestEnum.CrudOperationType.Update; ResourceServiceOutcome.SuccessfulTransaction = true; IRequestMeta RequestMeta = IRequestMetaFactory.CreateRequestMeta().Set($"{FHIRAllTypes.QuestionnaireResponse.GetLiteral()}/{_PrimaryQuestionnaireResponseAnswerResourceId}"); var Answers = this.IResourceServices.GetRead("AngusA1", RequestMeta); QuestionnaireResults QuestionnaireResults = QuestionnaireResponseChecker.Check(Answers.ResourceResult as QuestionnaireResponse, QuestionnaireResponse); } else { Parameters ParametersResult = new Parameters(); ParametersResult.Parameter = new List <Parameters.ParameterComponent>(); var Param = new Parameters.ParameterComponent(); Param.Name = "Oh no, there was an error is submitting your answers."; ParametersResult.Parameter.Add(Param); var Param2 = new Parameters.ParameterComponent(); Param2.Name = FHIRAllTypes.OperationOutcome.GetLiteral(); Param2.Resource = ResourceServiceOutcome.ResourceResult; ParametersResult.Parameter.Add(Param2); ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.ResourceResult = ParametersResult; ResourceServiceOutcome.OperationType = Enum.RestEnum.CrudOperationType.Update; ResourceServiceOutcome.SuccessfulTransaction = false; } } else { IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one parameter with the 'Name' element equal to '{_ParameterName}' where the Resource element is set to a {FHIRAllTypes.QuestionnaireResponse.GetLiteral()} FHIR Resource. The server found here a Resource of type {Parameters.Parameter[0].Resource.ResourceType}.")); } } else { IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one Parameter with the Name element equal to '{_ParameterName}' where the Resource element is set to a {FHIRAllTypes.QuestionnaireResponse.GetLiteral()} FHIR Resource. The server found no {FHIRAllTypes.QuestionnaireResponse.GetLiteral()} Resource")); } } else { IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one Parameter with the Name element equal to '{_ParameterName}'.")); } } else { IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects the {FHIRAllTypes.Parameters.GetLiteral()} resource to have one Parameter element.")); } } else { IssueList.Add(Pyro.Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.Invalid, $"The ${_OperationName} expects a FHIR {FHIRAllTypes.Parameters.GetLiteral()} resource as the call body.")); } if (IssueList.Count > 0) { var Op = Common.Tools.FhirOperationOutcomeSupport.Generate(IssueList); ResourceServiceOutcome.HttpStatusCode = System.Net.HttpStatusCode.BadRequest; ResourceServiceOutcome.ResourceResult = Op; ResourceServiceOutcome.OperationType = Enum.RestEnum.CrudOperationType.Update; ResourceServiceOutcome.SuccessfulTransaction = false; return(ResourceServiceOutcome); } else { return(ResourceServiceOutcome); } }
//Old Method for chaining, not in use public ISearchParameterBase CreateSearchParameter_OLD(DtoServiceSearchParameterLight DtoSupportedSearchParametersResource, Tuple <string, string> Parameter) { ISearchParameterBase oSearchParameter = InitalizeSearchParameter(DtoSupportedSearchParametersResource.Type); string ParameterName = Parameter.Item1; string ParameterValue = Parameter.Item2; oSearchParameter.Id = DtoSupportedSearchParametersResource.Id; oSearchParameter.Resource = DtoSupportedSearchParametersResource.Resource; oSearchParameter.Name = DtoSupportedSearchParametersResource.Name; oSearchParameter.TargetResourceTypeList = DtoSupportedSearchParametersResource.TargetResourceTypeList; oSearchParameter.RawValue = ParameterName + _ParameterNameParameterValueDilimeter + ParameterValue; _RawSearchParameterAndValueString = oSearchParameter.RawValue; if (!ParseModifier(ParameterName, oSearchParameter)) { oSearchParameter.IsValid = false; oSearchParameter.InvalidMessage = $"Unable to parse the given search parameter's Modifier: {ParameterName}', "; } if (ParameterName.Contains(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR)) { //This is a resourceReferance with a Chained parameter, resolve that chained parameter to a search parameter here (is a recursive call). var SearchParameterGeneric = ISearchParameterGenericFactory.CreateDtoSearchParameterGeneric(); SearchParameterGeneric.ParameterList = new List <Tuple <string, string> >(); var x = ParameterName.Substring(ParameterName.IndexOf(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR) + 1, (ParameterName.Length - ParameterName.IndexOf(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR) - 1)); var ChainedSearchParam = new Tuple <string, string>(x, ParameterValue); SearchParameterGeneric.ParameterList.Add(ChainedSearchParam); FHIRAllTypes?TypeModifierResource = null; if (oSearchParameter.Modifier.HasValue && oSearchParameter.Modifier.Value == SearchParameter.SearchModifierCode.Type && !string.IsNullOrWhiteSpace(oSearchParameter.TypeModifierResource)) { //var ChainedSearchParam = new Tuple<string, string>(ParameterName.Split(Hl7.Fhir.Rest.SearchParams.SEARCH_CHAINSEPARATOR)[1], ParameterValue); TypeModifierResource = ModelInfo.FhirTypeNameToFhirType(oSearchParameter.TypeModifierResource).Value; } else { // If the chained reference has no Type modifier then their must be only one Target resource for the parameter! // The FHIR spec does allow the server to try and resolve resources for many resource targets in this case. Yet, the server must // reject the search if Resource instances are returned across more then one of the types for the search parameter. // This seams like a very fragile rule and would also be hard to implement given the current framework. // Therefore I am making a design decision that if more that one target resource is available for the given search // parameter and the user does not specify which by supplying a Type modifier, then I will reject the search parameter. if (oSearchParameter.TargetResourceTypeList != null && oSearchParameter.TargetResourceTypeList.Count == 1) { TypeModifierResource = ModelInfo.FhirTypeNameToFhirType(oSearchParameter.TargetResourceTypeList[0].ResourceType.GetLiteral()).Value; } else { if (oSearchParameter.TargetResourceTypeList != null && oSearchParameter.TargetResourceTypeList.Count > 1) { oSearchParameter.IsValid = false; oSearchParameter.InvalidMessage = $"The chained search parameter '{oSearchParameter.RawValue}' has no Type modifier specifying the target resource for the parameter and the parameter in use has many possible target resources. The search parameter must specify a target resource using the type modifier. For example '[base]/DiagnosticReport?subject:Patient.name=peter' where Patient is the Type modifier."; } else { throw new FormatException($"Server error: chained search parameter did not resolve to any target resource types. Parameter was: '{oSearchParameter.RawValue}' "); } } } ISearchParameterService SearchService = ISearchParameterServiceFactory.CreateSearchParameterService(); //oSearchParameter.ChainedSearchParameterList.Add(SearchService.ProcessResourceSearchParameters(SearchParameterGeneric, SearchParameterService.SearchParameterServiceType.Resource, TypeModifierResource.Value)); } else { if (oSearchParameter.Type == SearchParamType.Reference) { (oSearchParameter as SearchParameterReferance).AllowedReferanceResourceList = ServiceSearchParameterFactory.GetSearchParameterTargetResourceList(oSearchParameter); } if (!oSearchParameter.TryParseValue(ParameterValue)) { oSearchParameter.IsValid = false; } } return(oSearchParameter); }