Why do I get errors when creating a patient using HL7 and REST?

I have OpenMRS 2.2 standalone version installed on my system

Question: Hi! Has anyone been able to create a patient in OpenMRS using HL7 messages (rest calls). Could you please post an example? I have been trying to do this for more than a week now…but I keep getting HL7 encoding errors!

POST /openmrs-standalone/remotecommunication/postHl7.form?source=LOCAL&sourceKey=test&hl7Message=MSH|^~\&|FORMENTRY|AMRS|HL7LISTENER|AMRS|20150723110101||ADT^A28|AMRS20150723110101|P|2.5|1|||||||| EVN|A28|20150723110101|||1 PID|||1003D1^^^OpenMRS ID||ANKITHA^SAKHAIRE||19650529|F|||70-1C-8^02^Kakinada^Andhra||||||||||||||||20371|^^||N&username=admin&password=Admin123 HTTP/1.1
Host: 192.168.1.25:8081
Authorization: Basic base64.encode(admin:Admin123)
Content-Type: application/json
Cache-Control: no-cache

My HL7 Message:

MSH|^~\&|FORMENTRY|AMRS|HL7LISTENER|AMRS|20150723110101||ADT^A28|AMRS20150723110101|P|2.5|1|||||||| EVN|A28|20150723110101|||1 PID|||1003D1^^^OpenMRS ID||ANKITHA^SAKHAIRE||19650529|F|||70-1C-8^02^Kakinada^Andhra||||||||||||||||20371|^^||N&username=admin&password=Admin123 HTTP/1.1

Doubts: Do I need to encode the separation betweeen the segments as \r or \r\n? Also, there is a space in OpenMRS ID…do I need to encode it or can I leave it like that? Is the format of my HL7 message correct (to create a patient in OpneMRS)

This link contains the the error logs:

http://pastebin.com/9vzNJ2GQ

Thanks in advance!

1 Like

Sharing an example of the HL7 message you are sending, together with a link to the error log, would be helpful.

@dkayiwa: Ya sure! This link contains the POST request and the error log: http://pastebin.com/9vzNJ2GQ

Please have a look at it and help me rectify this!

Thank you!

With Daniel’s help I could resolve this issue. This is the HL7 message I could send successfully from OpenMRS rest test api: Type: POST URI: http://localhost:8081/openmrs-standalone/ws/rest/v1/hl7 Body Content: {“hl7”:“MSH|^~\&|FORMENTRY|LOCAL|HL7LISTENER|LOCAL|20091123101300^0|HUP|ADT^A28^ADT_A05|9166768|P|2.5|1|||AL||ASCII\r\nEVN|A28|20091123101300|||1\r\nPID|||1003C3^^^OpenMRS ID||Patient^Demo^OldId||20011114|M|||20371^02^2400^724||||||724^Y||||||02|||11|20371|724^DEUT^N||N”}

Thanks! :slight_smile:

1 Like