Friday, June 17, 2016

Order/Observation Parsing

Here is a quick script I wrote to parse order and observation groups in Mirth Connect. This is very generic and requires tweaking for each application, but it's a good place to start if you're trying to keep track of multiple orders within a message.
The script iterates through the message and can easily be set to gather the message segments into an object or array for further processing.
Feel free to use this script as you like. 

/*
Script Purpose: Organize and compile order and observation segment groups

::Possible Group Organizations::
[orc]-->obr --> (obx) --> (nte) --> (obx)... [spm]
|  |       |-> (obx) --> (nte)... [spm]
|  |-> (nte) --> (obx) --> (nte)... [spm]
|->obr ...
[orc] ...
*/

//get number of ORC messages
var orcmsg = msg["ORC"].length();
var ordGroup = 0; // track order groups
var obvGroup = 0; // track observation groups
var keeper = false; // help prevent grabbing unassociated NTE segments

if(orcmsg==1){ //only one ORC segment exists in the message
//begin looping through the message
var orcFound = false;
for each (seg in msg.children()){
if(seg.name().toString()=="ORC"){
//load ORC info 
orcFound = true;
}
else if(seg.name().toString()=="OBR" && orcFound){
ordGroup = seg["OBR.1"]["OBR.1.1"].toString();
obvGroup = 0; // reset observation group number
keeper = true; // make sure we don't include stray NTE segments
//load OBR info
}
else if(seg.name().toString()=="OBX" && orcFound){
obvGroup++;
keeper = true;
//load OBX info
}
else if(seg.name().toString()=="NTE" && orcFound && keeper){
//load NTE info
}
else if(seg.name().toString()=="SPM" && orcFound){
//Load SPM info
}
else{ //unaccounted segment handling
keeper = false;
}
}
}
else if(orcmsg>=2){ 
//begin looping through the message
var orcFound = false;
for each (seg in msg.children()){
if(seg.name().toString()=="ORC"){
//load ORC info 
orcFound = true;
keeper = false;
}
else if(seg.name().toString()=="OBR" && orcFound){
ordGroup = seg["OBR.1"]["OBR.1.1"].toString();
obvGroup = 0; // reset observation group number
keeper = true; // make sure we ignore stray NTE segments
//load OBR info
}
else if(seg.name().toString()=="OBX" && orcFound){
obvGroup++;
keeper = true;
//load OBX info
}
else if(seg.name().toString()=="NTE" && orcFound && keeper){
//load NTE info
}
else if(seg.name().toString()=="SPM" && orcFound){
//Load SPM info
}
else{ //unaccounted segment handling
keeper = false;
}
}
}
else{/* Message contains no Common Order segment (ORC) */}

I take no responsibility for any damage caused by using this script. This is meant to be used as a tool to assist in development of Mirth Connect Channels, and comes with no warranty of any kind. 

No comments:

Post a Comment