web stats
Convert/extract X12(270) into parameters and store them into Database - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-09-2012, 03:52 AM
nikhilb nikhilb is offline
Mirth Newb
 
Join Date: May 2012
Posts: 19
nikhilb is on a distinguished road
Default Convert/extract X12(270) into parameters and store them into Database

Hi,
I am new to Mirth.
I want to create a channel such that it will accept X12(270) message and extract/convert it into form of parameters and then store/insert those parameters into database.

Can we do like , convert X12(270) message into XML and then by writing custom javascript extract params from it and then insert those params into database ?

Could anyone pl help me on this . If anyone has similar example, then pl provide me or let me know the steps.

Thanks,
nikhil.
Reply With Quote
  #2  
Old 07-09-2012, 04:14 AM
ami199102 ami199102 is offline
OBX.2 Kenobi
 
Join Date: May 2012
Location: India
Posts: 70
ami199102 is on a distinguished road
Thumbs up x12(270)

HI Nikhil,

step 1: Create a channel
step 2: Goto Source tab and choose edit transformer.
step 3: In the Inbound Message Template choose data type as X12 and insert your sample X12(270) message format.
step 4: choose "Message Trees" and now you can view a tree containing all the data.
step 5: create mappers and drag the value from the Message Tree and map it with the local variable.
step 6: In the destination side use Java Script Writer to write those values inside your database.
__________________
Amarnath. K
http://amarnathks.wordpress.com
Reply With Quote
  #3  
Old 07-09-2012, 05:39 AM
JoshMc JoshMc is offline
OBX.2 Kenobi
 
Join Date: Jun 2009
Location: Nashville, TN
Posts: 95
JoshMc is on a distinguished road
Default

With an X12 transaction, it can be a bit tricky to use the message tree to map. I wrote my own parser for an X12 271transaction. (270 should be very similar)
Code:
var eligStatus = "";
var currentHL = "";
var currentEB = "";
var transactionDate = "";
var transactionID = "";
var currentEB01 = "";
var currentEB02 = "";
var currentEB03 = "";
var extraPayorLoop = false;
var otherInsurance = "";
var eligStartDate = "";
var eligEndDate = "";
var planCode = "";
var subFname = "";
var subLname = "";
var subMname = "";
var subSfx = "";
var subPolicyNumber = "";
var patFname = "";
var patLname = "";
var patMname = "";
var patSfx = "";
var patPolicyNumber = "";
var subDOB = "";
var subGender = "";
var patDOB = "";
var patGender = "";
var acct = "";
var mrn = "";


for each (seg in msg.children()) {
	switch(seg.name().toString())
	{

	case "AAA":
		if (eligStatus != "1" && eligStatus != "6") {
			eligStatus = seg['AAA.03']['AAA.03.1'].toString();
			}
		break;

	case "HL":

		currentHL = seg['HL.01']['HL.01.1'].toString();
		break;

	case "ISA":
		transactionID = seg['ISA.13']['ISA.13.1'].toString();	
		break;
	
	case "GS":
		transactionDate = FormatDate(seg['GS.04']['GS.04.1'].toString(), 'yyyymmdd');
		break;

	case "EB":
		currentEB = seg['EB.01']['EB.01.1'].toString();
		currentEB01 = seg['EB.01']['EB.01.1'].toString();
		currentEB02 = seg['EB.02']['EB.02.1'].toString();
		currentEB03 = seg['EB.03']['EB.03.1'].toString();
		if (seg['EB.01']['EB.01.1'].toString() == "1") {
			eligStatus = "1";
		}
		if (seg['EB.01']['EB.01.1'].toString() == "6" && eligStatus !="1") {
			eligStatus = "6";
		}
		break;

	case "REF":
		if (seg['REF.01']['REF.01.1'].toString() == "EA") {
			mrn = seg['REF.02']['REF.02.1'].toString();
		}
		if (seg['REF.01']['REF.01.1'].toString() == "EJ") {
			acct = seg['REF.02']['REF.02.1'].toString();
		}
		break;

	case "NM1":
		if (currentHL == 1) {
			if (seg['NM1.01']['NM1.01.1'].toString() == "PR" && seg['NM1.02']['NM1.02.1'].toString() == "2") {
				planCode = seg['NM1.09']['NM1.09.1'].toString();
			} 
		}
		if (currentHL == 3) {
			if (seg['NM1.01']['NM1.01.1'].toString() == "IL") {
				subFname = seg['NM1.04']['NM1.04.1'].toString();
				subLname = seg['NM1.03']['NM1.03.1'].toString();
				subMname = seg['NM1.05']['NM1.05.1'].toString();
				subSfx = seg['NM1.06']['NM1.06.1'].toString();		
			}
			if (seg['NM1.08']['NM1.08.1'].toString() == "MI") {
					subPolicyNumber = seg['NM1.09']['NM1.09.1'];
			}
		}
		if (currentHL==4) 
		{
			if (seg['NM1.01']['NM1.01.1'].toString() == "03") 
				{
				patFname = seg['NM1.04']['NM1.04.1'].toString();
				patLname = seg['NM1.03']['NM1.03.1'].toString();
				patMname = seg['NM1.05']['NM1.05.1'].toString();
				patSfx = seg['NM1.06']['NM1.06.1'].toString();				
				if (seg['NM1.08']['NM1.08.1'].toString() == "MI") {
					patPolicyNumber = seg['NM1.09']['NM1.09.1'];
				}
			}
		}
		if (extraPayorLoop == true){
			if (currentEB01 == "R" && currentEB03 =="88") {
				otherInsurance = "";
			} else 
				{ 
					otherInsurance = seg['NM1.03']['NM1.03.1'].toString();
				}	
		}
		break;

	case "DTP":
		if (seg['DTP.03']['DTP.03.1'].toString() == "357") {
			eligStartDate = FormatDate(seg['DTP.03']['DTP.03.1'].toString(),'yyyymmdd');
		}
		if (seg['DTP.03']['DTP.03.1'].toString() == "356") {
			eligStartDate = FormatDate(seg['DTP.03']['DTP.03.1'].toString(),'yyyymmdd');
		}
		


		if (currentEB == 1) {
			if 	(eligStartDate.length == 0 && seg['DTP.02']['DTP.02.1'].toString() == "D8") 
			{
				eligStartDate = FormatDate(seg['DTP.03']['DTP.03.1'].toString(),'yyyymmdd');
			}
			if (seg['DTP.02']['DTP.02.1'].toString() == "RD8") 
			{
				if 	(eligStartDate.length ==0) 
				{
				
				eligStartDate = SplitData(seg['DTP.03']['DTP.03.1'].toString(),'-',0);
				eligStartDate = FormatDate(eligStartDate, 'yyyymmdd');
				
				eligEndDate = SplitData(seg['DTP.03']['DTP.03.1'].toString(),'-',1);
				eligEndDate = FormatDate(eligEndDate, 'yyyymmdd');
				}
			}
			if (seg['DTP.01']['DTP.01.1'].toString() == "357") {
				eligEndDate = FormatDate(seg['DTP.03']['DTP.03.1'].toString(),'yyyymmdd');
			}
		}
		break;

	case "DMG":
		if (currentHL == 3) {
			subDOB = seg['DMG.02']['DMG.02.1'].toString();
			//logger.error('SUB DOB: ' + subDOB);
			subGender = seg['DMG.03']['DMG.03.1'].toString();
		}

		if (currentHL == 4) {
			patDOB = seg['DMG.02']['DMG.02.1'].toString();
			//logger.error('Pat DOB: ' + patDOB);
			patGender = seg['DMG.03']['DMG.03.1'].toString();
		}
		break;

	case "LS":
		extraPayorLoop = true;
		break;
	
	case "LE":
		extraPayorLoop = false;
		break;

	default:

	} // end of switch statement
} //end of for each loop

if (patFname.toString() == "" && patLname.toString() == "" && patMname.toString() == "") {
	patFname = subFname;
	patLname = subLname;
	patMname = subMname;
	patSfx = subSfx;
}	

if (patDOB == "" || patDOB == null) { 
	patDOB = subDOB; 
}

if (patGender == "" || patGender == null) {
	patGender = subGender;
}


channelMap.put('transactionID', transactionID);
channelMap.put('acct', acct);
channelMap.put('mrn', mrn);
channelMap.put('transactionDate', transactionDate);
channelMap.put('eligStatus', eligStatus);
channelMap.put('planCode', planCode);
channelMap.put('subFname', subFname);
channelMap.put('subLname', subLname);
channelMap.put('subMname', subMname);
channelMap.put('subSfx', subSfx);
channelMap.put('subDOB', subDOB);
channelMap.put('subGender', subGender);
channelMap.put('subPolicyNumber', subPolicyNumber);
channelMap.put('patPolicyNumber', patPolicyNumber);
channelMap.put('patFname', patFname);
channelMap.put('patLname', patLname);
channelMap.put('patMname', patMname);
channelMap.put('patSfx', patSfx);
channelMap.put('patGender', patGender);
channelMap.put('patDOB', patDOB);
channelMap.put('otherInsurance', otherInsurance);
channelMap.put('eligStartDate', eligStartDate);
channelMap.put('eligEndDate', eligEndDate);
These mappings show up in your destination mappings and you can drag/drop those into your SQL builder.
Reply With Quote
  #4  
Old 07-09-2012, 11:03 PM
nikhilb nikhilb is offline
Mirth Newb
 
Join Date: May 2012
Posts: 19
nikhilb is on a distinguished road
Default

Thanks a lot for the reply.

I have done with mappings now. I have assigned params from message tree to variables like
var isa = msg['ISA']['ISA.01']['ISA.01.1'].toString(); Is it correct?
What will be the next step to insert these varibales into database ?
Do i need to write javascript under destinations tab by selecting connector type as 'javascript writer' ?
Could you pl provide me sample javascriprt code for database insert with the transformed data obetained from mappings ?

Waiting for ur replies !

Thanks a lot,
Nikhil.
Reply With Quote
  #5  
Old 07-10-2012, 02:30 AM
nikhilb nikhilb is offline
Mirth Newb
 
Join Date: May 2012
Posts: 19
nikhilb is on a distinguished road
Default Still not getting

One more thing. For the channel I have selected 'file reader' as connector type under source tab. In that I have given path to the .txt file which contains X12 message. For destination , I am using 'database writer' as connector type with mysql DB and with Use javascript as 'yes'.
This is my javascript code :
var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('com.mysql.jdbc.Driver','localhost','root','');
var result = dbConn.executeUpdate("INSERT INTO messages (id,source, receiver) VALUES (1,'"+$(source)+"', '"+$(receiver)+"')");
dbConn.close();

$(source) and $(receiver) are two variables created from channel mappings(edit transformer screen) as suggested by Amarnath.
I have created database 'mirthdata' in mysql on localhost into which I have one table 'messages'.
I am attaching some screenshots for reference.
I am not getting what datatypes i need to select for source connector and is my javascript for DB insert is correct ?

I want read X12 from file as input to channel and extract that X12 and insert params into database.
Please help me out with this. Am I following the right steps ?
I think I am missing something.

Thanks,
nikhil.
Attached Images
File Type: jpg mirth_data_types.jpg (25.1 KB, 51 views)
File Type: jpg source.jpg (36.3 KB, 61 views)
File Type: jpg destination.jpg (44.9 KB, 60 views)
File Type: jpg transformer_with_msg_template.jpg (42.2 KB, 64 views)
File Type: jpg transformer_with_msg_tree.jpg (38.0 KB, 57 views)
Reply With Quote
  #6  
Old 07-10-2012, 04:41 AM
JoshMc JoshMc is offline
OBX.2 Kenobi
 
Join Date: Jun 2009
Location: Nashville, TN
Posts: 95
JoshMc is on a distinguished road
Default

That should pretty much work. Although, you don't need to use javascript in your database writer (if you don't want to). You can simply check 'No' under 'Use JavaScript' and fill in the parameters as appropriate in the text boxes provided. You only have to write your INSERT statement and you can use the generate button for that and use the query builder built-in.

I generally only use javascript in the SQL Writer if I'm executing a stored procedure or function. Your way should work though just the same (provided your syntax is good).
Reply With Quote
Reply

Tags
database, parameters, x12

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 01:21 AM.


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