Version Converters
Beginning in HAPI FHIR 2.3, a new module called hapi-fhir-converter
has been added to the project. This is an experimental feature so use it with caution!
This feature allows automated conversion from earlier versions of the FHIR structures to a later version.
The following page shows some basic examples. Please get in touch if you are able to contribute better examples!
To use the hapi-fhir-converter
module, import the following dependency into your project pom.xml (or equivalent)
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-converter</artifactId>
<version>${project.version}</version>
</dependency>
The following example shows a conversion from a hapi-fhir-structures-hl7org-dstu2
structure to a hapi-fhir-structures-dstu3
structure.
// Create an input resource to convert
org.hl7.fhir.dstu2.model.Observation input = new org.hl7.fhir.dstu2.model.Observation();
input.setEncounter(new org.hl7.fhir.dstu2.model.Reference("Encounter/123"));
// Convert the resource
org.hl7.fhir.dstu3.model.Observation output =
(Observation) VersionConvertorFactory_10_30.convertResource(input);
String context = output.getContext().getReference();
The following example shows a conversion from a hapi-fhir-structures-dstu2.1
structure to a hapi-fhir-structures-dstu3
structure.
// Create a resource to convert
org.hl7.fhir.dstu2016may.model.Questionnaire input = new org.hl7.fhir.dstu2016may.model.Questionnaire();
input.setTitle("My title");
// Convert the resource
org.hl7.fhir.dstu3.model.Questionnaire output =
(Questionnaire) VersionConvertorFactory_14_30.convertResource(input);
String context = output.getTitle();