private string BuildAndReturnQueryFilterAsJsonString(ResourceType resourceType, string searchParameter, string query) { var bsonSerializerRegistry = new BsonSerializerRegistry(); bsonSerializerRegistry.RegisterSerializationProvider(new BsonSerializationProvider()); var resourceTypeAsString = resourceType.GetLiteral(); var criterium = Criterium.Parse(query); criterium.SearchParameters.AddRange(ModelInfo.SearchParameters.Where(p => p.Resource == resourceTypeAsString && p.Name == searchParameter)); var filter = criterium.ToFilter(resourceType.GetLiteral()); var jsonFilter = filter?.Render(null, bsonSerializerRegistry)?.ToJson(); return(jsonFilter); }
private bool CheckResourceEndpointMatchesResourceToBeValidated(ResourceType ResourceType, IPyroRequestUri RequestUri) { if (RequestUri.FhirRequestUri.ResourseName != ResourceType.GetLiteral()) { var OpOutComeIssue = Common.Tools.FhirOperationOutcomeSupport.CreateIssue(OperationOutcome.IssueSeverity.Error, OperationOutcome.IssueType.NotSupported, $"The Resource endpoint of the request URL does not match the Resource provided to be validated in the request body. URL Resource: {RequestUri.FhirRequestUri.ResourseName}, Request body Resource: {ResourceType.GetLiteral()}"); IssueList.Add(OpOutComeIssue); return(false); } return(true); }
private void CleanUpByIdentifier(ResourceType ResourceType) { // give the call a while to execute (particularly while debugging). Hl7.Fhir.Rest.FhirClient clientFhir = new Hl7.Fhir.Rest.FhirClient(StaticTestData.FhirEndpoint(), false); clientFhir.Timeout = 1000 * 1000; //--- Clean Up --------------------------------------------------------- //Clean up by deleting all Test Patients SearchParams sp = new SearchParams().Where($"identifier={StaticTestData.TestIdentiferSystem}|"); try { clientFhir.Delete(ResourceType.GetLiteral(), sp); } catch (Exception Exec) { Assert.True(false, $"Exception thrown on clean up delete of resource {ResourceType.GetLiteral()}: " + Exec.Message); } }
/// <summary> /// Set the ResourceType i.e "Patient" and then ad a request string i.e "?family=Millar" /// </summary> /// <param name="ResourceType"></param> /// <param name="RequestString"></param> /// <returns></returns> public IRequestMeta Set(ResourceType ResourceType, string RequestString) { if (RequestString.StartsWith("/")) { RequestString.TrimStart('/'); } this.PyroRequestUri = IPyroRequestUriFactory.CreateFhirRequestUri(); CreateAndParsePyroRequestUri($"{ResourceType.GetLiteral()}/{RequestString}"); this.RequestHeader = IRequestHeaderFactory.CreateRequestHeader(); this.SearchParameterGeneric = ISearchParameterGenericFactory.CreateDtoSearchParameterGeneric().Parse(this.PyroRequestUri.FhirRequestUri.Query); return(this); }
public void Test_ORSearchParameterReferance_ResourceAndId_Positive() { //Arrange IPyroFhirUriFactory PyroFhirUriFactory = TestSetupMocks.GetIPyroFhirUriFactory(); SearchParameterReferance SearchParameterReferance = new SearchParameterReferance(PyroFhirUriFactory); SearchParameterReferance.Id = 10; SearchParameterReferance.Expression = "Not Required For Test"; SearchParameterReferance.AllowedReferanceResourceList = new List <string>() { ResourceType.Patient.GetLiteral(), ResourceType.Group.GetLiteral(), }; string TestResourceId = "MyResID1"; string TestResourceId2 = "MyResID2"; ResourceType TestResourceType = ResourceType.Patient; ResourceType TestResourceType2 = ResourceType.Group; string TestResourceName = TestResourceType.GetLiteral(); string TestResourceName2 = TestResourceType2.GetLiteral(); //Looks like: Patient/MyResId string TestParameter = $"{TestResourceName}/{TestResourceId},{TestResourceName2}/{TestResourceId2}"; //Act bool Result = SearchParameterReferance.TryParseValue(TestParameter); //Assert Assert.IsTrue(Result, "Parse retruned False, expected True"); Assert.AreEqual(SearchParameterReferance.ValueList.Count, 2, "To many Values returned for parse"); Assert.IsFalse(SearchParameterReferance.ValueList[0].IsMissing, "IsMissing should be False"); Assert.IsNull(SearchParameterReferance.ChainedSearchParameter, "ChainedSearchParameter should be null"); Assert.IsTrue(SearchParameterReferance.HasLogicalOrProperties, "HasLogicalOrProperties should be False"); Assert.IsNull(SearchParameterReferance.InvalidMessage, "InvalidMessage should be Null"); Assert.IsFalse(SearchParameterReferance.IsChained, "IsChained should be False"); Assert.IsTrue(SearchParameterReferance.IsValid, "IsValid should be True"); Assert.IsNull(SearchParameterReferance.Modifier, "Modifier should be NUll"); Assert.IsNull(SearchParameterReferance.TypeModifierResource, "RawValue does not match parameter"); Assert.IsNotNull(SearchParameterReferance.ValueList[0].FhirRequestUri, "FhirRequestUri can not be Null"); Assert.AreEqual(SearchParameterReferance.ValueList[0].FhirRequestUri.ResourceType, TestResourceType, "FhirRequestUri.ResourceType should be Patient"); Assert.AreEqual(SearchParameterReferance.ValueList[0].FhirRequestUri.ResourseName, TestResourceName, "FhirRequestUri.ResourceName should be Patient"); Assert.AreEqual(SearchParameterReferance.ValueList[0].FhirRequestUri.ResourceId, TestResourceId, "FhirRequestUri.ResourceName should be Patient"); Assert.IsNotNull(SearchParameterReferance.ValueList[1].FhirRequestUri, "FhirRequestUri can not be Null"); Assert.AreEqual(SearchParameterReferance.ValueList[1].FhirRequestUri.ResourceType, TestResourceType2, "FhirRequestUri.ResourceType should be Patient"); Assert.AreEqual(SearchParameterReferance.ValueList[1].FhirRequestUri.ResourseName, TestResourceName2, "FhirRequestUri.ResourceName should be Patient"); Assert.AreEqual(SearchParameterReferance.ValueList[1].FhirRequestUri.ResourceId, TestResourceId2, "FhirRequestUri.ResourceName should be Patient"); }
static void Main(string[] args) { var SearchParamTool = new SearchParameterTools(); var CompartemntDefTool = new CompartmentDefiinitionTools(); List <CompartmentDefinition> CompartmentDefList = CompartemntDefTool.GetDefinitionList(); foreach (var Compartment in CompartmentDefList) { ResourceType ResType = GetResourceTypeForCompartmentCode(Compartment.Code.Value); Console.WriteLine($"Compartment: {ResType.GetLiteral()}"); Console.WriteLine($"==========================================================="); if (ResType == ResourceType.AuditEvent) { } //List<SearchParameter> CompartmentSearchParameterList = SearchParamTool.GetSearchParameterDefinitionListForResource(ResType); foreach (var ResComponent in Compartment.Resource) { Console.WriteLine($"Resource: {ResComponent.Code.GetLiteral()}"); List <SearchParameter> SearchParameterForResourceList = SearchParamTool.GetSearchParameterDefinitionListForResource(ResComponent.Code.Value); foreach (string Param in ResComponent.Param) { var SearchParameter = SearchParameterForResourceList.SingleOrDefault(x => x.Name == Param); if (SearchParameter != null) { Console.WriteLine($"Search Param: {SearchParameter.Name}"); if (SearchParameter.Type == SearchParamType.Reference) { if (SearchParameter.Target != null) { if (SearchParameter.Target.Count() > 1) { if (SearchParameter.Target.Contains(ResType)) { } } else { } } } } } } } }
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 static FHIRAllTypes GetResourceFhirAllType(ResourceType ResourceType) { return(ResourceNameResolutionSupport.GetResourceFhirAllType(ResourceType.GetLiteral())); }
/// <inheritdoc/> public ResourceReference ToResourceReference() { _resourceReference ??= new ResourceReference($"{ResourceType.GetLiteral()}/{ResourceId}"); return(_resourceReference); }