Stream: implementers
Topic: Golang FHIR Models
Alexander Kiel (Nov 28 2019 at 11:21):
I'm looking for a golang library which gives me structs for each resource and enums for each valueset. I found google/fhir which implements protobufs for all FHIR resources but brings the parsers/printers and models only for Java and C++. I found intervention-engine/fhir-golang-generator which looks outdated. @Chris Moesel Do you have any news on this?
Paul Church (Nov 28 2019 at 15:35):
We have a golang implementation inside Google that will eventually be added to the google/fhir repo as a 3rd language option. Not sure when that will happen though, there are some inconsistencies vs. the C++ implementation that need to be resolved.
Alexander Kiel (Dec 01 2019 at 07:53):
@Paul Church That sounds good. It will include structs which work with json.Unmarshal/json.Marshal?
Chris Moesel (Dec 02 2019 at 01:07):
Hi @Alexander Kiel -- we developed the fhir-golang-generator
for our Intervention Engine research project which is no longer under active development. You can see the resulting models in our (also defunct) FHIR Server. The FHIR server was forked by @Eugene Lubarsky -- but I think he took a different approach to handling the models (see models2).
The fhir-golang-generator
was based on the approach of generating models as part of the Java build process. I don't know if that approach is still supported or encouraged; if I were to do it again today, I'd just generate from the StructureDefinitions. If it is supported, you might be able to rebase the code on the newer FHIR source, but I expect a lot has changed; so I kind of doubt it would work well... That said, I don't think we did anything super complex for the models -- so it might not be too hard to just do something simple like that based on the StructureDefinitions...
Chris Moesel (Dec 02 2019 at 01:08):
Just saw @Paul Church's reply. If Google will be releasing that soon(ish), then it certainly seems worth the wait!
Paul Church (Dec 02 2019 at 15:48):
@Alexander Kiel The structs are just the protobuf definitions - Marshal(proto.Message) returns []byte, Unmarshal([]byte) returns proto.Message. All of the resources and valueset enums are produced by the proto compiler - you could get those today with a bazel target.
Alexander Kiel (Dec 02 2019 at 15:55):
@Paul Church Meanwhile, I have written a generator which generates structs like for Patient. The generator can be found in the same repo.
Are the protobuf definitions different? Sorry I haven't worked with protobuf before. Apart of my implementation, I would rather use official models but I need JSON serialization.
Paul Church (Dec 02 2019 at 16:22):
The protobuf compiler for each language generates a set of structs / classes / other language appropriate constructs, given the protobuf definitions. So the published protos by themselves are usable as a FHIR data model in plenty of languages - but serializing to/from interoperable FHIR JSON is the gap filled by the parser. Without that, the data model is of limited use. You could use protobuf serialization to bridge over to C++ or Java and then use the JSON parsers we released for those languages, but that's a roundabout way of getting somewhere.
Alexander Kiel (Dec 02 2019 at 17:11):
Ok I understand. Is a native Go JSON parser planned?
Paul Church (Dec 02 2019 at 17:17):
Yes, that's what's in implementation I mentioned - a golang JSON parser/serializer and some associated support code.
Alexander Kiel (Dec 02 2019 at 17:20):
Ok thanks. I'll wait until it becomes available.
Richard Stanley (May 03 2020 at 17:20):
Hi. I’m just expressing interest in the Go and Python parsers for google/fhir and curious if any folks in the community would share an update.
Paul Church (May 03 2020 at 23:01):
We have a golang implementation of the parser inside Google that will likely be open sourced at some point. Haven't heard anything about python.
Last updated: Apr 12 2022 at 19:14 UTC