Using ChatGPT to generate FHIR test data

Creating test data is a pain. It’s grunt work and it’s a time sink. All the hype aside, ChatGPT is great at creating sample FHIR data.

But you need to be very precise in your instructions, otherwise it will create resources that don’t make sense.

Let’s say you’re looking for test data that includes a number of interconnected resources. You may want to test some code related to Encounters and Appointments.

Here’s a starting prompt:

“Create sample FHIR resources for Patient, Practitioner, Encounter, Appointment and Observation. Ensure that all resources are connected, such that a single Patient has at least one Encounter, Appointment, and Observation. Ensure the Observation is connected to the Encounter and to the Patient. Ensure that references between resources go in the correct direction, as defined by the FHIR specification.”

Tell it exactly what you want. Tell it to get the resource references correct, otherwise it will be ‘creative’ and add references for Encounters and Observations to the Patient resource.

When the results come back, tailor it some more to your requirements.

“Ensure that all resource IDs are unique GUIDs and do not include the resource type as part of the ID. Ensure that the Patient resource contains a numeric MRN identifier. Make the Observation a blood pressure reading.”

And more.

“Add a Condition resource that was diagnosed at the same Encounter for the same Patient. Populate the code, severity, category and bodysite of the Condition.”

Review the results.

In the data created for me, ChatGPT was smart enough to recognize the previous BP Observation of 120 / 80 and create a Condition of mild hypertension (apparently 120 / 80 just barely makes the cut).

Think about how much time it used to take to create sample data for testing and development, and how incomplete that data was. ChatGPT does it better and faster, but the devil is in the instructions.

Be precise. Fine tune the results with new instructions again and again until it gets it right. And always be aware that it has a tendency to be creative.

Try ChatGPT yourself



Sign up to “The Tuesday FHIR Sessions” and receive an email every Tuesday where I go deep on a single FHIR topic.