Issue with Exchanging Encounter and Observational Data Between CHT and OpenMRS

We are currently working on the openmrs-mediator branch of the CHT interoperability repository. While demographic data is being successfully exchanged between CHT and OpenMRS, we are encountering challenges with the exchange of programmatic/encounter and observational data.
We have followed the official documentation and made the required changes in the base_settings.json file. However, the data captured in OpenMRS is not being transferred as expected.
We’d appreciate any guidance on the next steps to resolve this. Thank you.

cc: @sanjay @SanghArsha_PyakuRel @Santosh_Paudel

Hi @gaarimasharma - thanks so much for posting your question. It’s exciting to hear about the CHT Interop repository being put to use - yay!!

The first place I would look would be the logs of the different services. For example, in my local test deployment, I see the following services running:

$ docker ps --format "{{.Status}}\t{{.Names}}"
Up 5 minutes	openhim-console
Up 5 minutes	chis-interop-nginx-1
Up 5 minutes	openhim-core
Up 5 minutes	hapi-fhir
Up 5 minutes	mediator
Up 5 minutes	chis-interop-api-1
Up 5 minutes	chis-interop-sentinel-1
Up 5 minutes	chis-interop-healthcheck-1
Up 5 minutes	chis-interop-couchdb-1
Up 5 minutes	openhim-mongo
Up 5 minutes	hapi-db
Up 5 minutes	chis-interop-haproxy-1

Looking at the logs of the mediator, I can see it’s having issues connecting:

docker logs mediator

> mediator@1.0.0 start
> node ./dist/index.js

2025-01-23 19:14:29 INFO: Server listening on port 6000 
/app/dist/src/utils/openhim.js:7
        throw new Error(`Mediator Registration Failed: Reason ${err}`);
        ^

Error: Mediator Registration Failed: Reason Error: connect ECONNREFUSED 172.20.0.12:8080
    at registerMediatorCallback (/app/dist/src/utils/openhim.js:7:15)
    at /app/node_modules/openhim-mediator-utils/register.js:16:14
    at Request._callback (/app/node_modules/openhim-mediator-utils/auth.js:21:7)
    at self.callback (/app/node_modules/request/request.js:185:22)
    at Request.emit (node:events:517:28)
    at Request.onRequestError (/app/node_modules/request/request.js:877:8)
    at ClientRequest.emit (node:events:517:28)
    at TLSSocket.socketErrorListener (node:_http_client:501:9)
    at TLSSocket.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)

See if you you can find relevant log entries that point you toward which part of the system is failing to work as expected.

Keep us posted - we’d love to help!

Hi @gaarimasharma can you give some more details about

However, the data captured in OpenMRS is not being transferred as expected.
What is expected and what is actually happening?

@mrjones @twier Thank you for your responses and suggestions.

We reviewed the mediator logs but were unable to pinpoint the exact issue.
To provide additional context and seek further assistance; so far, the configuration has been completed to the point where demographic data created in OpenMRS is successfully synced to the CHT. This involved working on the address template in OpenMRS and creating a similar hierarchy in the CHT to synchronize demographic data and hierarchy. Additionally, a programmatic ANC form was created in both OpenMRS and CHT.
However, while configuring the programmatic ANC data transfer, the data captured in OpenMRS is not mapping correctly to the variables in the CHT reports. For example, indicator data in OpenMRS is supposed to appear as corresponding variables in the CHT reports, but this mapping is failing, resulting in incomplete or incorrect report generation in the CHT.

I’ve included the logs below.

Here is the current state of my Docker containers:

 ⠿ Container chis-interop-openmrs-referenceapplication-mysql-1  Running                                                                                                                                0.0s
 ⠿ Container openhim-mongo                                      Running                                                                                                                                0.0s
 ⠿ Container hapi-db                                            Running                                                                                                                                0.0s
 ⠿ Container hapi-fhir                                          Running                                                                                                                                0.0s
 ⠿ Container openhim-core                                       Running                                                                                                                                0.0s
 ⠿ Container chis-interop-openmrs-1                             Running                                                                                                                                0.0s
 ⠿ Container chis-interop-configurator-1                        Started                                                                                                                                0.2s
 ⠿ Container openhim-console                                    Running                                                                                                                                0.0s
 ⠿ Container mediator                                           Running

And here is the logs of the mediator:

2025-01-24 07:13:15 INFO: Comparing Encounter 
2025-01-24 07:13:15 INFO: Incoming: d7bfea96-bf8b-4ee4-99fc-82a99a6c5592,77218673-57cc-40da-be78-c1a82efc5acd 
2025-01-24 07:13:15 INFO: Outgoing:  
2025-01-24 07:13:15 INFO: Sending Encounter d7bfea96-bf8b-4ee4-99fc-82a99a6c5592 to FHIR 
2025-01-24 07:13:15 INFO: Replacing Patient/9cc6471e-8fe4-4125-9100-42a3ddc704cc with 9cc6471e-8fe4-4125-9100-42a3ddc704cc for d7bfea96-bf8b-4ee4-99fc-82a99a6c5592 
2025-01-24 07:13:15 INFO: Sending Encounter d7bfea96-bf8b-4ee4-99fc-82a99a6c5592 to CHT 
2025-01-24 07:13:16 ERROR: Not sending encounter which is incomplete 77218673-57cc-40da-be78-c1a82efc5acd 
2025-01-24 07:14:11 INFO: Comparing Patient 
2025-01-24 07:14:11 INFO: Incoming:  
2025-01-24 07:14:11 INFO: Outgoing: 114b9bd4-e3eb-4c14-a004-a79b78ee1232,9417e1bc-7eaa-40e7-9e25-8381d125906e 
2025-01-24 07:14:11 INFO: Sending Patient 114b9bd4-e3eb-4c14-a004-a79b78ee1232 to OpenMRS 
2025-01-24 07:14:11 INFO: Sending Patient 9417e1bc-7eaa-40e7-9e25-8381d125906e to OpenMRS 
2025-01-24 07:14:13 ERROR: Request failed with status code 413 AxiosError: Request failed with status code 413
    at settle (/app/node_modules/axios/dist/node/axios.cjs:1859:12)
    at BrotliDecompress.handleStreamEnd (/app/node_modules/axios/dist/node/axios.cjs:2723:11)
    at BrotliDecompress.emit (node:events:529:35)
    at endReadableNT (node:internal/streams/readable:1400:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2025-01-24 07:14:15 ERROR: Request failed with status code 422 AxiosError: Request failed with status code 422
    at settle (/app/node_modules/axios/dist/node/axios.cjs:1859:12)
    at BrotliDecompress.handleStreamEnd (/app/node_modules/axios/dist/node/axios.cjs:2723:11)
    at BrotliDecompress.emit (node:events:529:35)
    at endReadableNT (node:internal/streams/readable:1400:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2025-01-24 07:14:16 INFO: Comparing Encounter 
2025-01-24 07:14:16 INFO: Incoming: 77218673-57cc-40da-be78-c1a82efc5acd 
2025-01-24 07:14:16 INFO: Outgoing:  
2025-01-24 07:14:16 ERROR: Not sending encounter which is incomplete 77218673-57cc-40da-be78-c1a82efc5acd 
2025-01-24 07:15:11 INFO: Comparing Patient 
2025-01-24 07:15:11 INFO: Incoming:  
2025-01-24 07:15:11 INFO: Outgoing: 114b9bd4-e3eb-4c14-a004-a79b78ee1232,9417e1bc-7eaa-40e7-9e25-8381d125906e 
2025-01-24 07:15:11 INFO: Sending Patient 114b9bd4-e3eb-4c14-a004-a79b78ee1232 to OpenMRS 
2025-01-24 07:15:11 INFO: Sending Patient 9417e1bc-7eaa-40e7-9e25-8381d125906e to OpenMRS 
2025-01-24 07:15:13 ERROR: Request failed with status code 413 AxiosError: Request failed with status code 413

Despite tweaking the configurations based on the documentation, it seems we might be overlooking something. Any guidance or suggestions would be greatly appreciated!

thanks @gaarimasharma looks like there are several issues.
Sending patient 114b9bd4-e3eb-4c14-a004-a79b78ee1232 to OpenMRS is getting error 413 which is Request Entity Too Large. I haven’t seen this before and wouldn’t expect a normal Patient payload to be unusually large.
Then 9417e1bc-7eaa-40e7-9e25-8381d125906e is getting 422 Unprocessable Entity which means it is being rejected by OpenMRS.

For both of these, there may be more details either in the OpenHIM transactions page or the OpenMRS logs; for the 413 we can see if the size of the payload is normal or not and debug further from there, and for the 422 we can see the response from OpenMRS to see why it might have been rejected.

Then, for the Encounter 77218673-57cc-40da-be78-c1a82efc5acd The error message is Not sending encounter which is incomplete. This means that the encounter in OpenMRS has no end date; to prevent update chatter while the visit in OpenMRS is still in progress, the mediator doesn’t send Encounters that don’t have any end date.
Ending the visit in OpenMRS and re-syncing it should trigger the update.

Getting everything working together can be tricky; especially for OpenMRS->CHT data. if you’d like to schedule a call to debug in real time (and post the results back on this thread) I’m available via DM or slack.

3 Likes

@twier that would indeed be very helpful. Our team will reach out to you via Slack to schedule a call and debug this together. Once we’ve resolved it, we’ll make sure to update this thread with the solution.

Thanks again for your support!

cc: @Santosh_Paudel @SanghArsha_PyakuRel

1 Like