Building an API based on FHIR resources


I am a dot net software developer tasked to build an API to allow third parties to get a subset of our clinical data set based on FHIR resources. I am using the FHIR DOTNET library but I am having issues in understanding this…

Can I build a new empty patient? And then adding resources to it and producing a JSON and XML output for third party to GET my data? I have not downloaded yet the library but from all seen examples seems like the library connect to a test FHIR server to get a patient object with an ID.

In my case I would need to do something like Patient MdwPatient = new Patient(); Patient.identifier = blah blah… Patient.Gender = blah blah… Patient.Save() or simiral to produce JSON output

Any help will be appreciated.



Can you build a new empty patient?

Sure, just do

var p = new Patient();

and start filling out the fields, just like you described.

Then do

var jsonstring = FhirSerializer.SerializeToJson(p);

You’d get your Json output. If you want to send your patient to servers, you don’t have to do that serialization yourself, and you could just use a FhirClient to send data, as described here:

Looking for integration project specialists. I am working with a healthcare blockchain start-up. We are looking to speak with integration specialists who can help out with getting a handle on integrating a narrow data set( 10 -15) elements with user data from Cerner Etc. systems.

We want to pull data from a full EHR system and pop it into a FHiR compliant structure/base that can also be a resource. We are looking at putting the de-identified data onto a blockchain to create a research commons along with a few other interesting use cases.

happy to skype/call with those interested in learning more and helping us size up this and other integrations.


I managed to create a whole bundle; my problem is that when I do
RetJson = FhirSerializer.SerializeResourceToJson(myBundle);

the JSON returned is not formatted; do I have to create my own formatter or FHIR DOT NET can do this?

You mean formatted as in “formatted with tabs and spaces” aka “pretty print”, so it’s nicely laid out? There’s currently only one way to do that, and that is to use the other serialize overload:

    public static void SerializeResource(Resource resource, JsonWriter writer, SummaryType summary = SummaryType.False)

Here, you pass in a JsonWriter yourself (which comes from the library, the underlying json API that we use):

StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);

using (JsonWriter writer = new JsonTextWriter(sw))
      writer.Formatting = Formatting.Indented;
       SerializeResource(yourResource, writer);

var jsonstring = sb.ToString();

It’s a bit of a hassle, I admit, so I added a new suggestion to the library here:

Thanks Ewout,

that is very useful