synthetichealth / synthea

Synthetic Patient Population Simulator
https://synthetichealth.github.io/synthea
Apache License 2.0
2.13k stars 642 forks source link

Generated R4 Bundles Fail Validation #923

Open jmorg85-isc opened 3 years ago

jmorg85-isc commented 3 years ago

Downloading sample R4 bundles from https://synthetichealth.github.io/synthea/ is fantastic, and the generated samples pass FHIR validation without any issues.

Downloading this JAVA tool and generating R4 bundles produces resources that do not pass FHIR validation. My JAVA version is:

java -version openjdk version "15.0.2" 2021-01-19 OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.2+7) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.2+7, mixed mode, sharing)

Example scenario and errors below:

A JSON bundle generated with command... java -jar synthea-with-dependencies.jar Minnesota -p 1000

Abdul218_Hayes766_ec62e6ac-6dba-16a9-e5b3-e81f9c3ae447.txt

...produces validation errors...

MalformedRelativeReference","details":{"text":"The reference value 'Practitioner?identifier=http://hl7.org/fhir/sid/us-npi|9999999049' in property (individual) of Type 'Encounter.participant' is malformed"},"expression":["Encounter.participant[0].individual"]}

MalformedRelativeReference","details":{"text":"The reference value 'Location?identifier=https://github.com/synthetichealth/synthea|5c2014f9-21c0-3952-b9fa-d1c13da056cb' in property (location) of Type 'Encounter.location' is malformed"},"expression":["Encounter.location[0].location"]}

MalformedRelativeReference","details":{"text":"The reference value 'Organization?identifier=https://github.com/synthetichealth/synthea|91ea4431-fdfe-35a2-a773-71658028e5f5' in property (serviceProvider) of Type 'Encounter' is malformed"},"expression":["Encounter.serviceProvider"]}

These are just a few of the errors I am getting from the data out of the generator. I have tried multiple different combinations of settings using a config file. The bundles are all generated with these malformed data values.

Any guidance would be greatly appreciated.

jawalonoski commented 3 years ago

If you want to turn off query-style references, the easiest way to do that is to set exporter.fhir.transaction_bundle = false.

That will make all Bundles have type collection, rather than type transaction, and it will create "normal" style references.

This will also duplicate all the Practitioner, Location, and Organization across all the Bundles -- so you will have duplicate data.

lxbrown commented 3 years ago

@jawalonoski the reported issue is that the syntax

"serviceProvider": {
  "reference": "Organization?identifier=ABC"
}

is not valid per the spec. The "reference" element must contain a literal reference (doc), something like "Organization/42" or "https://github.com/synthetichealth/Organization/42".

It looks like Synthea wants to use logical references (doc) which allow you to use a query-style identifier (not id) to identify a resource. Those need to go in the Reference.identifier element. That'd result in reference objects like the following:

"serviceProvider": {
  "identifier": {
    "system": "https://github.com/synthetichealth/synthea",
    "value": "91ea4431-fdfe-35a2-a773-71658028e5f5"
  }
}
jawalonoski commented 3 years ago

Actually, it is valid per the spec.

Please see https://www.hl7.org/fhir/http.html#trules under the heading "Conditional References" (which I cannot link to directly [no anchor]).

lxbrown commented 3 years ago

Well, you learn something new every day! Thanks for the pointer.

I was just reading the issue where logical references were added and saw your name pop up there too. Seems like even adding them was a bit contentious: https://jira.hl7.org/browse/FHIR-10659

I'll go back to my cave now :)