1

I am trying to merge two FHIR patient resources using the C# Firely SDK.

Unfortunately, this always fails with an error

Invalid request. Query parameter sourcePatientId is missing

although it is provided.

Does someone know what I am doing wrong?

Using the same endpoint and parameters in Postman works.

string baseURL = "...";
string targetPatientID = "123-234-5";
string sourcePatientID = "1234-4321-1";

FhirClientsettings settings = new(); // added some headers for auth, etc.
FhirClient client = new(baseURL, settings);

var parameters = new Parameters
{
    { "sourcePatientId", new FhirString(patSource) },
    { "targetPatientId", new FhirString(patTarget) }
};

var uri = new Uri($"{baseUrl}/Patient/$merge", UriKind.Absolute);
Resource mergeResult = await client.OperationAsync(uri, parameters);
1
  • Use Fiddler to debug the HTTP request your C# app is sending, compare that to what the Postman console shows. Commented Sep 22 at 13:36

1 Answer 1

1

The request Patient/$merge needs the parameters added to the URI.

The used method (OperationAsync) turns the parameters into a body and does not add them to the URI. To handle this the following implementation can be used:

var mergeURI = new Uri($"{baseURL}Patient/$merge?sourcePatientId={patSource}&targetPatientId={patTarget}", UriKind.Absolute);
// the empty parameters are needed otherwise it will throw a nullreference exception
Resource mergeResult = await client.OperationAsync(mergeURI, []);

The empty list has to be added to prevent a nullReferenceException

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.