Project: REST JSON to FHIR JSON Mapping Implementation

Hi @judywawira @sunbiz

I had a discussion with @judywawira to convert the REST API JSON outputs to FHIR JSON output. Just sent me following model.

@judywawira suggest to create a module from scratch that use JSON output of REST module to convert it to the FHIR compatible JSON.

Patient -> Patient REST API JSON Output-> NewModuleConverter JSON to FHIR JSON -> FHIR Patient output

I had look at the rest module of openmrs. There isn’t any service that can obtain the JSON representation. REST module seems it’s defines a representation and then it convert the returning object to JSON representation internally. So we can’t add the module as dependency and access the JSON representation.

Other approach is calling the rest endpoint to get the JSON and then convert it to FHIR compatible resource. But this requires credentials of a user. Would this be a good approach?

Please share your thoughts to achieve this.

Thank you.

Nice. I have one question. The JSON that is been spit out by the REST module depends on the properties of it’s model. For example, the JSON that will be spit out when you request for a patient will depend on the properties of the Patient class. So let’s say a required FHIR field is missing in the JSON spitted out by the REST module, how will this converter handle this?

I think we need to check the FHIR specification of that resource. When I look at it, I notice some properties are mandatory and some aren’t. So we will need to take the decision based on it. May be we can include a default value. what do you think?

I think the best way to approach this, is to think of this as an app that is doing integration testing. So you do not need to write this app, like an OpenMRS module. Instead, think of it as writing a standalone app, which has JUnit tests for each resource transformation.

Each unit test will call an LibreHealth Toolkit REST resource (https://toolkit.librehealth.io/master/ws/rest/v1/resource) which will give you the JSON (if you sent the Accept: application/json header) and then transform it (using something like JOLT - http://bazaarvoice.github.io/jolt/) to a FHIR JSON that can be validated here - http://hl7.org/fhir/validation.html#op . You will POST the transformed JSON to any FHIR server like https://fhirtest.uhn.ca/ and see if the JSON is in the right format.

Of course, you will need user credentials to make the REST calls. But that is just an BasicAuth header when making the REST calls.

@prashadi, I’ve tried to be very conservative with my words here. But please feel free to expand this into a step-by-step process, and ask questions if you think my suggested approach is a quick way to get this done.

2 Likes

Thank you for the information. I’ll proceed with creating standalone application.

@judywawira @sunbiz I have developed JSON to FHIR in [1]. Let me know if it’s fine. [1] https://github.com/kavindya89/librehealth/blob/master/src/main/java/org/librehealth/convert/Main.java

1 Like

You’re on FHIR @prashadi ! Honestly, we need a LOT of familiarization with FHIR here at LH.io to meet our needs. At the same time, I can’t imagine that knowledge of the FHIR schema/api wouldn’t be a very important piece of a medical IT resume.

We need to set everything on FHIR, and collectively, our matches are a bit damp.

Thank you!. I’m new to FHIR and learning about the resources.

I have tried running the code but I keep getting "“peer not authenticated” error

Can anyone help me out because I am also trying to build a small demo to convert Patient JSON based on @sunbiz directives but I get the same “peer not authenticated” error

@lehone it seems like a SSL error. What’s the JDK version you are using? Mine is jdk1.8.0_111/bin/java.

mine is jdk 1.8.0_144

It’s working for me can you try https://stackoverflow.com/questions/23754081/peer-not-authenticated-ssl-certificate-error-usng-defaulthttpclient?

1 Like

Thanks it now works. The problem was with my Internet provider. I changed to another provider and everything now works well.

Hi All,

I completed fhir to librehealth json representation as well.

Following are the outputs

CONVERTED LIBRE HEALTH PATIENT TO FHIR {“resourceType”:“Patient”,“id”:“f19c6540-0058-4bb2-9019-d61dd6afd0ce”,“identifier”:[{“id”:“f625a561-6cef-4e5a-a661-72377641d8d4”,“use”:“usual”,“system”:“Old Identification Number”,“value”:“1234”}],“active”:false,“name”:[{“id”:“9a4df03d-731e-4023-ae88-af7d82f86777”,“family”:“family1”,“given”:[“test1”]}],“gender”:“female”,“birthDate”:“1984-01-01”,“address”:[{“id”:“1bb9664c-da14-4db6-aea6-018046c8841c”,“use”:“home”,“line”:[“Address1”,“Address12”],“city”:“SampleVillege”,“state”:“SampleProvince”,“postalCode”:“7878”,“country”:“SampleCountry”}]}

CONVERTED FHIR PATIENT TO LIBRE HEALTH {“identifiers”:[{“display”:“Old Identification Number=1234”,“links”:[{“ref”:“self”,“uri”:“https://radiology.librehealth.io/lh-toolkit/ws/rest/v1/patient/identifier/f625a561-6cef-4e5a-a661-72377641d8d4"}],“uuid”:“f625a561-6cef-4e5a-a661-72377641d8d4”}],“person”:{“preferredAddress”:{“display”:"",“links”:[{“ref”:“self”,“uri”:“https://radiology.librehealth.io/lh-toolkit/ws/rest/v1/patient/address/1bb9664c-da14-4db6-aea6-018046c8841c”}],“uuid”:“1bb9664c-da14-4db6-aea6-018046c8841c”},“birthdate”:"Sun Jan 01 00:00:00 IST 1984”,“gender”:“F”,“display”:“family1”,“links”:[{“ref”:“self”,“uri”:“https://radiology.librehealth.io/lh-toolkit/ws/rest/v1/patient/person/Patient/f19c6540-0058-4bb2-9019-d61dd6afd0ce"},{“ref”:“ful”,“uri”:“https://radiology.librehealth.io/lh-toolkit/ws/rest/v1/patient/patient/Patient/f19c6540-0058-4bb2-9019-d61dd6afd0ce?v=full”}],“preferredName”:{“display”:“family1”,“links”:[{“ref”:“self”,“uri”:“https://radiology.librehealth.io/lh-toolkit/ws/rest/v1/patient/name/9a4df03d-731e-4023-ae88-af7d82f86777”}],“uuid”:“9a4df03d-731e-4023-ae88-af7d82f86777”},“uuid”:“Patient/f19c6540-0058-4bb2-9019-d61dd6afd0ce”},“display”:“1234-family1”,“links”:[{“ref”:“self”,“uri”:“https://radiology.librehealth.io/lh-toolkit/ws/rest/v1/patient/patient/Patient/f19c6540-0058-4bb2-9019-d61dd6afd0ce”},{}],“uuid”:"Patient/f19c6540-0058-4bb2-9019-d61dd6afd0ce”}

1 Like

Sorry to be slow on this. I finally spent some time reviewing the two attempts that have been made on this thread. I looked at this - https://github.com/kavindya89/librehealth and this - https://github.com/lehone-hp/rest-to-fhir-json-example

Both of those are sort of depending on a model. I like the spec from @lehone, but I think it is still very much hard-coded and will not work as the spec changes. On the other hand, most FHIR servers provide a /validate endpoint. You should use those, and your code should iteratively remember/learn from that validation process.

@lehone, I think you only got the one-way working, because I didnt see FHIR to REST conversion.

@sunbiz Thank you for reviewing the code.

I have used HAPI FHIR library to perform the Librehealth JSON to FHIR conversion. I think this will be good as it provides all the FHIR version support and validations. Hence populating the relevant resource in FHIR specification gives me a advantage of simply convert the model to JSON from a standard library and use particular object for validation. With the library we can convert the required librehealth resources to required FHIR version. I will look at publicly exposed FHIR validation endpoints as well.

Regarding the FHIR to REST, I convert FHIR JSON to its model representation and then used it to build the librehealth format of the resource.

One challenge I encounter was there were no mappings for some attributes.

@sunbiz what should I do next? I will add validations to the resources. I think we need to validate the librehalth format of resource as well.

@prashadi Its good that you are using the HAPI fhir-base and fhir-structures, but I was pointing to this code - https://github.com/kavindya89/librehealth/blob/master/src/main/java/org/librehealth/convert/service/PatientUtil.java This means that for every resource, you have to spend a lot of code to do the mapping. IMO, this is not optimal. I’d like you to think of generic ways in which this can be implemented, such that we can do this mapping outside code, and maybe using external configs?

Sorry about the FHIR to REST conversion, I have been a little bit busy but I will complete it shortly. It is indeed dependent on a model but we will face a problem if the spec change. We will need to look for a way in order to fix that but I posted the converted resource to an FHIR server for validation.

I have added code to perform the reverse json conversion on the Patient resource

I have given this task to modify the module by @judywawira So I want to know about the objective of this task and what technology i can use to complete this work