web stats
Create JSON from HL7 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2018, 10:26 AM
gojoshi gojoshi is offline
OBX.1 Kenobi
 
Join Date: Jul 2013
Posts: 35
gojoshi is on a distinguished road
Default HL7 to JSON

]Hello Everyone,

looking for a good way to take OBX3.1 and OBX3.2 and add them to a JSON. So basically I need to make the JSON elements based on the OBX segments. There could by any number of OBX segments..

Example, with the following OBX segments, I would need to create the below JSON object..


Example OBX segments:

OBX|1|CWE|123^Text1^LN||
OBX|2|CWE|456^Text2^LN||
OBX|3|NM|789^Text3^LN|||

JSON Needed:

JSON_Elements
[
{
“value1”: “Canned Comment”,
“value2”: “123”,
“value3”: “Text1”
},
{
“value1”: “Canned Comment”,
“value2": “456”,
“value3”: “Text2”
},
{
“value1”: “Canned Comment”,
“value2": “789”,
“value3”: “Text3”
},
]

Last edited by gojoshi; 12-19-2018 at 04:37 AM.
Reply With Quote
  #2  
Old 12-19-2018, 05:44 AM
bhesler bhesler is offline
Mirth Newb
 
Join Date: Jul 2015
Posts: 11
bhesler is on a distinguished road
Default

I think the below code should give you what are looking for.

var encountersObject = [];

//Loop through all PV1 Seigments
for (i=0; i < msg['PV1'].length(); i++) {
//Build Allergies Sub Object
encountersSubObject = {code:{}};

//Encounters.Code Begin
encountersSubObject.code.code = msg['PV1'][i]['PV1.2']['PV1.2.1'].toString();
encountersSubObject.code.originalText = msg['PV1'][i]['PV1.2']['PV1.2.1'].toString();
encountersSubObject.code.displayName = msg['PV1'][i]['PV1.2']['PV1.2.2'].toString();
}
Reply With Quote
  #3  
Old 12-19-2018, 09:32 AM
gojoshi gojoshi is offline
OBX.1 Kenobi
 
Join Date: Jul 2013
Posts: 35
gojoshi is on a distinguished road
Default

Hey bhesler thank you for the response..

Since there are usually multiple OBX segments, I came up with something a little different. It seems to work for me:

var empJSON = {}


for each (seg in msg.children()) {
if (seg.name().toString() == "OBX") {
if (seg['OBX.3']['OBX.3.1'].toString() == "ABC")
{
empJSON.username = "empJSON.username";
empJSON.icon_url = "empJSON.icon_url";
empJSON.text = "empJSON.text";
}
}
}
Reply With Quote
  #4  
Old 12-19-2018, 12:28 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 774
agermano is on a distinguished road
Default

Not sure if your requirements changed, but this is how to solve the original question.

Code:
var obxJson = [];
for each (var obx in msg.OBX) {
    obxJson.push({
        value1: 'Canned Comment',
        value2: obx['OBX.3']['OBX.3.1'].toString(),
        value3: obx['OBX.3']['OBX.3.2'].toString()
    });
}
Reply With Quote
Reply

Tags
hl7, hl7 conversion, hl7v2, json, mirth

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 03:22 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation