public async Task <SearchResult> GetSearchResult(IVonkContext context) { Log.Information("Handling Csv"); _ = await Task.FromResult(true); var(_, args, _) = context.Parts(); foreach (var arg in args) { if (arg.ArgumentValue.Contains("/$csv")) { arg.ArgumentValue = arg.ArgumentValue.Remove (arg.ArgumentValue.Length - 5); } } // FIXME: double check this // if (!response.Success()) throw new ArgumentException("Server returned 404. Please check query"); var searchResult = await _searchRepository.Search(context.Arguments, SearchOptions.Latest(context.ServerBase, context.Request.Interaction, context.InformationModel)); return(searchResult); }
private async Task <(bool found, IEnumerable <IResource> resolvedResources)> ResourceHasPatientReference(IVonkContext vonkContext, string resourceType, string propertyName, string patientId) { var searchArgs = new ArgumentCollection( new Argument(ArgumentSource.Internal, ArgumentNames.resourceType, resourceType) { MustHandle = true }, new Argument(ArgumentSource.Internal, propertyName, $"Patient/{patientId}") { MustHandle = true } ); var options = SearchOptions.Latest(vonkContext.ServerBase, vonkContext.Request.Interaction, vonkContext.InformationModel); var searchResult = await _searchRepository.Search(searchArgs, options); if (searchResult == null || searchResult.TotalCount == 0) { return(false, null); } return(searchResult.TotalCount > 0, searchResult); }
public async Task EverythingOperationGETReturn200OnSuccess() { // Create VonkContext for $everything (GET / Instance level) var testContext = new VonkTestContext(VonkInteraction.instance_custom); // Setup Patient resource var patient = CreateTestPatientNoReferences(); string patientStr = FhirAsJsonString(patient); var account = CreateTestAccountForPatient(); var searchOptions = SearchOptions.Latest(testContext.ServerBase, testContext.Request.Interaction, testContext.InformationModel); var patSearchResult = new SearchResult(new List <IResource>() { patient }, 1, 1); var searchArgs = new ArgumentCollection( new Argument(ArgumentSource.Internal, ArgumentNames.resourceType, patient.GetResourceTypeIndicator()) { MustHandle = true }, new Argument(ArgumentSource.Internal, ArgumentNames.resourceId, $"{patient.Id}") { MustHandle = true } ); _searchMock.Setup(repo => repo.Search(searchArgs, searchOptions)).ReturnsAsync(patSearchResult); var acctsearchResult = new SearchResult(new List <IResource>() { account }, 1, 1); searchArgs = new ArgumentCollection( new Argument(ArgumentSource.Internal, ArgumentNames.resourceType, account.GetResourceTypeIndicator()) { MustHandle = true }, new Argument(ArgumentSource.Internal, "subject", $"Patient/{patient.Id}") { MustHandle = true } ); _searchMock.Setup(repo => repo.Search(searchArgs, searchOptions)).ReturnsAsync(acctsearchResult); testContext.Arguments.AddArguments(new[] { new Argument(ArgumentSource.Path, ArgumentNames.resourceType, "Patient"), new Argument(ArgumentSource.Path, ArgumentNames.resourceId, "test") }); testContext.TestRequest.CustomOperation = "everything"; testContext.TestRequest.Method = "GET"; // Execute $everything await _everythingService.PatientInstanceGET(testContext); // Check response status testContext.Response.HttpResult.Should().Be(StatusCodes.Status200OK, "$everything should succeed with HTTP 200 - OK on test patient"); testContext.Response.Payload.Should().NotBeNull(); var bundleType = testContext.Response.Payload.SelectText("type"); bundleType.Should().Be("searchset", "Bundle.type should be set to 'searchset'"); var bundle = testContext.Response.Payload.ToPoco <Bundle>(); bundle.Entry.Count.Should().Be(1); bundle.Entry[0].Resource.ResourceType.Should().Be(ResourceType.Patient); string bundleStr = FhirAsJsonString(testContext.Response.Payload); }