FHIR bundle in JSON #2503
-
Hello. I want to use this library to read a FHIR bundle in JSON from a RESTFul service. Let me know, please. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you can read a string from file or have an in-memory string and parse it to a Bundle object first, before you do what you would like after the REST call. Another option is to use one of the publicly available FHIR test servers. Here's an example reading a Bundle from file and parsing it: using Hl7.Fhir.ElementModel;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using System.Text.Json;
void Test() {
JsonSerializerOptions options = new JsonSerializerOptions().ForFhir();
string jsonInput = File.ReadAllText("bundle.json");
Bundle bundle = JsonSerializer.Deserialize<Bundle>(jsonInput, options);
foreach (var entry in bundle.Entry)
{ // do something with the entry }
} or use a test server: using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
void Test() {
FhirClient client = new FhirClient("https://server.fire.ly/R4");
SearchParams searchParams = new SearchParams().Where("name=Everyman");
Bundle searchResult = client.Search<Patient>(searchParams);
foreach (var entry in searchResult.Entry)
{ // do something with the entry }
} |
Beta Was this translation helpful? Give feedback.
Yes, you can read a string from file or have an in-memory string and parse it to a Bundle object first, before you do what you would like after the REST call. Another option is to use one of the publicly available FHIR test servers.
Here's an example reading a Bundle from file and parsing it:
or…