An open API service indexing awesome lists of open source software.

https://github.com/rahulsom/fhir-protobuf

Unofficial FHIR Protobuf Parser
https://github.com/rahulsom/fhir-protobuf

fhir healthcare java protobuf3

Last synced: 6 months ago
JSON representation

Unofficial FHIR Protobuf Parser

Awesome Lists containing this project

README

          

= FHIR Protobuf

Experimental FHIR parser that serializes to Protobuf.
See https://gist.github.com/rahulsom/598cd37924197d6ee2526483a3d539d2[this] to see motivation.

WARNING: **This is not an official FHIR format.**
This was written before google open sourced their implementation of https://github.com/google/fhir[fhir protocol buffers].
Based on what we've seen on the mailing lists, it appears that the google implementation will be adopted as an official standard.

== Features

* [x] Parse and Create Protobufs using Protobuf DSL
* [x] Parse and Create Protobuf's JSON using Protobuf DSL
* [x] Convert Standard JSON to Protobuf JSON
* [x] Convert Protobuf JSON to Standard JSON

== Usage

Download the library you need from Maven

[cols="1,3"]
|===

a| Types

image::https://maven-badges.herokuapp.com/maven-central/com.github.rahulsom/fhir-protobuf-types/badge.svg[link=https://maven-badges.herokuapp.com/maven-central/com.github.rahulsom/fhir-protobuf-types]
| Contains types for parsing Protobuf binary and JSON formats.

a|Translate

image::https://maven-badges.herokuapp.com/maven-central/com.github.rahulsom/fhir-protobuf-translate/badge.svg[link=https://maven-badges.herokuapp.com/maven-central/com.github.rahulsom/fhir-protobuf-translate]
| Supports translation of FHIR JSON to Protobuf JSON and back. Depends on _Types_.

|===

Once released, the artifact will ba available on Maven Central.
Until then, snapshots can be downloaded from https://oss.sonatype.org/content/repositories/snapshots/com/github/rahulsom/fhir-protobuf/[Sonatype OSS].

To create a practitioner
[source,java]
----
Practitioner practitioner = Practitioner.newBuilder().
setId("Practitioner_1").
addName(HumanName.newBuilder().
addGiven("Bob").
setFamily("Kelso")).
setGender(Practitioner_gender.Practitioner_gender_male).
addIdentifier(Identifier.newBuilder().
setSystem("https://stmarys.com/practitioners").
setValue("BK001")).
build();
----

To serialize to Protobuf Binary Format

[source,java]
----
byte[] protobufByteArray = practitioner.toByteArray();
----

To parse from Protobuf Binary Format

[source,java]
----
Practitioner practitionerFromBinary = Practitioner.parseFrom(protobufByteArray);
----

To serialize to Protobuf Json Format

[source,java]
----
String protobufJson = JsonFormat.printer().print(practitioner);
----

To parseFrom Protobuf Json Format

[source,java]
----
Practitioner.Builder jsonPractitionerBuilder = Practitioner.newBuilder();
JsonFormat.parser().merge(protobufJson, jsonPractitionerBuilder);
Practitioner practitionerFromJson = jsonPractitionerBuilder.build();
----

To translate FHIR Json to Protobuf Json

[source,java]
----
String protoJson = Converter.fromFhirJson(fhirJsonAsString);
----

To translate Protobuf Json to FHIR Json

[source,java]
----
String fhirJson = Converter.toFhirJson(protoJson);
----