How are the Java classes for resources, used in HAPI FHIR, generated?

For example, is the class org.hl7.fhir.r4.model.Patient auto-generated from patient.xsd? And how? (JAXB/MOXy…)

I would like to generate classes for resources in C++ and I’m curious which approach is currently most reliable. Is postprocessing necessary?

Many thanks!

They are generated from the StructureDefinition resources that are the master definitions for the resources and data types. They are linked from the download page (see ‘package’). I would never try to generate from the xsd’s - they are an information poor representation of the underlying classes

1 Like

Ok, this helps a lot, thank you!

Next I would like to understand how the classes are generated. Which framework is used? (Open source would be great.) Are there more examples of generated code from similar definitions…?

The actual generation is a custom thing. You can see the code that actually does the writing here: https://github.com/HL7/fhir/blob/master/tools/java/org.hl7.fhir.tools.core/src/org/hl7/fhir/tools/implementations/java/JavaResourceGenerator.java

…but that class relies on a bunch of other framework. Bottom line, using the structure definitions is the way to go. It’s not trivial by any means, but they are fairly straightforward to generate code from once you’re used to their patterns.

2 Likes

You could consider using the protobuf-generated code for C++ if you’re happy with using STU3. The proto files have been generated from the FHIR standard, and then C++ (and other language) generation follows the standard protobuf generation.

2 Likes