web stats
Mirth Community - View Single Post - EDI X12 837 File Parse Error Mirth Connect 3.0
View Single Post
  #6  
Old 02-11-2015, 11:01 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

I'm surprised that no has been willing to post a sample channel for this. It seems to be in demand right now.

I've been able to (with MIRTH Support) create a source transformer that parses the 837 file into nice XML segments. This code will break the entire file into "chunks" of HLs. ie a chuck for the HL 20, HL 22 and so forth.


// Create XML to makes things easier
var claims = <claims></claims>;
var sub_section = null;
var first_hl = msg['HL'][0].childIndex();

for(i=first_hl; i<msg.children().length(); i++){

var claim_child_name = msg.child(i).name().toString();

if(claim_child_name == "HL")
{
//then you have a new claim
if(i!=first_hl){
claim.appendChild(sub_section);
claims.appendChild(claim);
}
var claim = <claim></claim>;
sub_section = claim;
}

//The rest are sub sections of HL
else if(claim_child_name == "SBR")
{
if(sub_section!=claim){
claim.appendChild(sub_section);
}
sub_section = <SBR></SBR>;
}

else if(claim_child_name == "NM1")
{
if(sub_section!=claim){
claim.appendChild(sub_section);
}
sub_section = <NM1></NM1>;
}
else if(claim_child_name == "LX")
{
if(sub_section!=claim){
claim.appendChild(sub_section);
}
sub_section = <LX></LX>;
}

if(sub_section == null)
{
//Then there's a subsection that's
//not SBR, NM1, or LX
claim.appendChild(msg.child(i));
}
else
{
sub_section.appendChild(msg.child(i));
}
}

claim.appendChild(sub_section);
claims.appendChild(claim);
channelMap.put("claims", claims);

for(h=0; h<claims.children().length(); h++){

//Create a blank HL7 XML
var HL7_message = <HL7Message></HL7Message>;
//Append an MSH segment to the HL7 XML
HL7_message.appendChild(new XML(SerializerFactory.getSerializer('HL7V2').toXML ('MSH|^~\&|company|company|company|company|'+dateS tring+'||ADT^A01||P|2.5|')));

var h20 = <h20/>;
try{h20['h20.1']['h20.1.1'] = claims['claim'][claimsCount]['NM1'][0]['NM1'][1]['NM1.01']['NM1.01.1'].toString();}catch(err){h20['h20.1']['h20.1.1'] = '';}

try{h20['h20.1']['h20.1.1'] = claims['claim'][claimsCount]['HL']['HL.01']['HL.01.1'].toString(); }catch(err){h20['h20.1']['h20.1.1'] = '';}
try{h20['h20.2']['h20.2.1'] = claims['claim'][claimsCount]['HL']['HL.02']['HL.02.1'].toString(); }catch(err){h20['h20.2']['h20.2.1'] = '';}
try{h20['h20.3']['h20.3.1'] = claims['claim'][claimsCount]['HL']['HL.03']['HL.03.1'].toString(); }catch(err){h20['h20.3']['h20.3.1'] = '';}
try{h20['h20.4']['h20.4.1'] = claims['claim'][claimsCount]['HL']['HL.04']['HL.04.1'].toString(); }catch(err){h20['h20.4']['h20.4.1'] = '';}
try{h20['h20.5']['h20.5.1'] = claims['claim'][claimsCount]['NM1'][0]['NM1'][1]['NM1.01']['NM1.01.1'].toString(); }catch(err){h20['h20.5']['h20.5.1'] = '';}
try{h20['h20.6']['h20.6.1'] = claims['claim'][claimsCount]['NM1'][0]['N3']['N3.01']['N3.01.1'].toString(); }catch(err){h20['h20.6']['h20.6.1'] = '';}
try{h20['h20.7']['h20.7.1'] = claims['claim'][claimsCount]['NM1'][0]['N4']['N4.01']['N4.01.1'].toString(); }catch(err){h20['h20.7']['h20.7.1'] = '';}
try{h20['h20.7']['h20.7.2'] = claims['claim'][claimsCount]['NM1'][0]['N4']['N4.02']['N4.02.1'].toString(); }catch(err){h20['h20.7']['h20.7.2'] = '';}
try{h20['h20.7']['h20.7.3'] = claims['claim'][claimsCount]['NM1'][0]['N4']['N4.03']['N4.03.1'].toString(); }catch(err){h20['h20.7']['h20.7.3'] = '';}
try{h20['h20.8']['h20.8.1'] = claims['claim'][claimsCount]['NM1'][0]['REF']['REF.01']['REF.01.1'].toString(); }catch(err){h20['h20.8']['h20.8.1'] = '';}
try{h20['h20.9']['h20.9.1'] = claims['claim'][claimsCount]['NM1'][0]['REF']['REF.02']['REF.02.1'].toString(); }catch(err){h20['h20.9']['h20.9.1'] = '';}
try{h20['h20.10']['h20.10.1'] = claims['claim'][claimsCount]['NM1'][1]['N3']['N3.01']['N3.01.1'].toString(); }catch(err){h20['h20.10']['h20.10.1'] = '';}
try{h20['h20.11']['h20.11.1'] = claims['claim'][claimsCount]['NM1'][1]['N4']['N4.01']['N4.01.1'].toString(); }catch(err){h20['h20.11']['h20.11.1'] = '';}
try{h20['h20.11']['h20.11.2'] = claims['claim'][claimsCount]['NM1'][1]['N4']['N4.02']['N4.02.1'].toString(); }catch(err){h20['h20.11']['h20.11.2'] = '';}
try{h20['h20.11']['h20.11.3'] = claims['claim'][claimsCount]['NM1'][1]['N4']['N4.03']['N4.03.1'].toString(); }catch(err){h20['h20.11']['h20.11.3'] = '';}
HL7_message.appendChild(h20);

router.routeMessage("HL7_file_creation", SerializerFactory.getSerializer('HL7V2').fromXML(H L7_message));

}

}
Reply With Quote