spark icon indicating copy to clipboard operation
spark copied to clipboard

Transactions/Batches containing searches using HTTP POST entries return Parameters instead of search results

Open JeremiahSanders opened this issue 7 months ago • 2 comments

Describe the bug Transactions and batches which contain search entries specifying HTTP POST (i.e., FhirClient's .SearchUsingPost() method) return Parameters objects in the resulting Bundle rather than the results of the search.

If the transaction includes search via HTTP GET, its results will be returned as expected. (I.e., only HTTP POST is affected)

To Reproduce Steps to reproduce the behavior:

  1. Seed a FHIR resource.
  2. Create a TransactionBuilder from your FHIR Client and use its .SearchUsingPost() method to add a FHIR search for the resource just created.
  3. Convert the TransactionBuilder to a Bundle and send it via a FhirClient.
  4. Observe the response Bundle entries. You won't find the resource you were searching for.

Expected behavior Returned Bundle is expected to contain the search results, rather than a saved Parameters resource.

Spark version

  • Version: 2.3.4

Operating system + Database

  • OS: Linux
  • Database: AWS DocumentDB

Container service / Cloud infrastructure:

  • Container service: AWS ECS
  • Cloud provider: AWS
  • Cloud infrastructure: Docker container
  • Database as a service: AWS DocumentDB w/MongoDB compatibility

JeremiahSanders avatar Jul 01 '25 22:07 JeremiahSanders

Can you add a minimal reproduction for this in code

kennethmyhra avatar Jul 02 '25 20:07 kennethmyhra

Sure thing.

Here's the minimal example:

// These must be initialized per your environment.
Uri baseUri;
HttpClient httpClient;
FhirClientSettings settings;

var fhirClient = new FhirClient(baseUri, httpClient, settings);

// Create a sample resource
var patient = await fhirClient.CreateAsync(new Patient { Name = [HumanName.ForFamily("TestSurname").WithGiven("TestGiven")] });
	
// Create search parameters
var nameSearchParams = new SearchParams("name", "TestSurname");
	
// Search in transaction with POST
var withPostRequest = new TransactionBuilder(baseUri).SearchUsingPost(nameSearchParams, nameof(Patient)).ToBundle();
var postResults = await fhirClient.TransactionAsync(withPostRequest);

// Search in transaction with GET
var withGetRequest = new TransactionBuilder(baseUri).Search(nameSearchParams, nameof(Patient)).ToBundle();
var getResults = await fhirClient.TransactionAsync(withGetRequest);

Results:

The with POST transaction returns:

{"resourceType":"Bundle","type":"transaction-response","entry":[{"fullUrl":"https://my_fhir_server_root_path/Parameters/55fc9176-1d25-4769-ace4-e787d8d8803d/_history/1","resource":{"resourceType":"Parameters","id":"55fc9176-1d25-4769-ace4-e787d8d8803d","meta":{"versionId":"1","lastUpdated":"2025-07-03T17:32:36.838+00:00"},"parameter":[{"name":"name","valueString":"TestSurname"}]},"response":{"status":"201 Created","location":"https://my_fhir_server_root_path/Parameters/55fc9176-1d25-4769-ace4-e787d8d8803d/_history/1","etag":"W/\"1\"","lastModified":"2025-07-03T17:32:36.838+00:00"}}]}

While the with GET transaction returns:

{"resourceType":"Bundle","type":"transaction-response","entry":[{"fullUrl":"https://my_fhir_server_root_path/Patient/7f33dfea-8d15-41da-8410-c7642d67b920/_history/1","resource":{"resourceType":"Patient","id":"7f33dfea-8d15-41da-8410-c7642d67b920","meta":{"versionId":"1","lastUpdated":"2025-07-03T17:32:36.015+00:00"},"name":[{"family":"TestSurname","given":["TestGiven"]}]},"response":{"status":"200 OK","location":"https://my_fhir_server_root_path/Patient/7f33dfea-8d15-41da-8410-c7642d67b920/_history/1","etag":"W/\"1\"","lastModified":"2025-07-03T17:32:36.015+00:00"}}]}

For reference, here are the request bodies (as generated by the Hl7.Fhir.R4 FhirClient):

Transaction search using POST request body:

{"resourceType":"Bundle","type":"batch","entry":[{"resource":{"resourceType":"Parameters","parameter":[{"name":"name","valueString":"TestSurname"}]},"request":{"method":"POST","url":"Patient/_search"}}]}

Transaction search using GET request body:

{"resourceType":"Bundle","type":"batch","entry":[{"request":{"method":"GET","url":"Patient?name=TestSurname"}}]}

JeremiahSanders avatar Jul 03 '25 17:07 JeremiahSanders