web stats
Basic Transformer Question - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2011, 10:46 AM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default Basic Transformer Question

Hi, I am very new to Mirth and have a lot to learn. I really appreciate how helpful the people on this forum have been thus far. Thank you all!

I am trying to create a channel that will receive HL7v2.* files from a laboratory and store the lab results into a MySQL table. Thus far, I've been able to create transformers for patientID, last name, first name, etc and store those in a table, no problem.

However, I'm not sure how to store the actual lab values. There could be only one or two results - or there could be many. How do I create variables for each of an unknown number of fields (Sodium, Potassium, WBC, etc) and their corresponding values? Or can I create arrays of all of the field names and field values? If so, how would I store such an array into a db?
Reply With Quote
  #2  
Old 07-18-2011, 10:52 AM
fonix fonix is offline
OBX.1 Kenobi
 
Join Date: Jun 2011
Posts: 31
fonix is on a distinguished road
Default

I think one of your first steps is to make sure you are allowing repeated fields. With Mirth Connect open, click Channels > Your channel, and make sure you are on the Summary page. Click Set Data Types and then Properties for (I think) your input. Make sure "Parse Field Repetitions" is checked.

This is something I had trouble with at one point, and without it checked I was getting all my repeated fields crammed into 1.

Someone else should be able to further help you, but try using a template on the input that has everything in it, that way it will try and map the fields if they're there.

Last edited by fonix; 07-18-2011 at 10:52 AM. Reason: spelling
Reply With Quote
  #3  
Old 07-18-2011, 11:58 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

This is more a db design question I think.

I've never worked with My SQL, only Oracle and SQL Server. I don't know how it handles cross-table relationships.

If this were my project I'd have a patient table, a test table containing the various tests that would come across the interface, and a results table.

The results table, naturally is where you store your results. It would need a many to one relationship with both the patient and the tests tables and would need at least 3 fields.

Pt ID, Test ID, and Result

You could then write as many or as few results per patient into the table as required.

Hopefully this isn't too convoluted. If you need clarification feel free to ask, I'll try and be as helpful as I can.
Reply With Quote
  #4  
Old 07-18-2011, 12:41 PM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default

Actually, I'm pretty confident about the design of the db - it looks a lot like what you laid out. My question was: how do I get at the values of the results in order to store them?

For example: In the transformer I have patientID mapped to msg['PID']['PID.3']['PID.3.1'].toString(). This works because there is only one instance of ['PID']. However, each result address looks like msg['OBX'][3]['OBX.7']['OBX.7.1'].toString(). The [3] signifies that this is the third result value.

There will be some unknown number of results. Therefore I need to pull msg['OBX'][X]['OBX.7']['OBX.7.1'].toString() where X goes from 1 to whatever number or results there are.

Right now I'm trying pull all the values as an array by mapping a variable to msg['OBX']['OBX.7']['OBX.7.1'].toString() (notice, no number). That may or may not work - I'm experimenting

Last edited by DimitriA; 07-21-2011 at 09:31 AM. Reason: changed OBR's to OBX's
Reply With Quote
  #5  
Old 07-18-2011, 12:47 PM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Oh! Sorry...I do that sometimes..

This should point you in the right direction..

Code:
for each(seg in msg.children()) {
	if(seg.name() == "OBR") {

}
}
You have to reference your fields using this format seg['OBR.2']['OBR.2.2']
Reply With Quote
  #6  
Old 07-18-2011, 04:07 PM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default

Great!

Sorry for the newbie question but uh . . . where do I put that?

It looks like JavaScript, so do I put it in Destinations?
Reply With Quote
  #7  
Old 07-19-2011, 05:48 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

Don't worry about sounding like a newbie....go back and read my original posts when I started with Mirth...you'll feel better

You need to build a transformer on the destination you want this to work on.

Copy a sample message to your clipboard.

Go to the destination and click "Transformers" on the left hand side of your window.

Click "Add New Step"

When the new step comes up, double click on "Message Builder" and select Javascript from the pulldown

Copy the code into the window and make the necessary modifications.

Go to Templates and paste your message in the inbound template. Click on Message Tree and you'll see if you have access to it parsed into nodes.

When you want to manipulate or read a node, all you have to do is drag it into your code.

Remember that when you drag it, it will always be msg['SEG']['SEG.1']['SEG.1.1'].toString()

.."SEG" being the segment.

If you're using this in the for each loop, you need to replace msg['SEG'] with just seg (exactly those letter seg)
Reply With Quote
  #8  
Old 07-20-2011, 09:16 AM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default

Bostad,

Thank you so much for the clear and thorough explanation!

However I'm stumped on the last part: how do I get at the values in the 'for each' loop?

I tried setting the name of a previous Step (resultValue) that was of type Mapper equal to the node like this:
Code:
for each(seg in msg.children())
{
	if(seg.name() == "OBX")
	{
		 $('resultValue') = seg['OBX.5']['OBX.5.1'].toString();
	}
}
Unfortunately, that gave me errors both when resultValue already had a Mapping and when it didn't. Any ideas?
Reply With Quote
  #9  
Old 07-21-2011, 04:59 PM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default

Never mind I got it.

For anyone else:

Code:
var resultVal = new Array();
var counter = 0;

for each (mOBX in msg..OBX) 
{

	resultVal[counter] = mOBX['OBX.5']['OBX.5.1'].toString();
	counter += 1;
}

channelMap.put("resultVal",resultVal);
Reply With Quote
  #10  
Old 07-22-2011, 03:32 PM
edvanbaak edvanbaak is offline
Mirth Newb
 
Join Date: Aug 2010
Posts: 23
edvanbaak is on a distinguished road
Default

Thanks for posting the answer.
Reply With Quote
Reply

Tags
database writer, mirth, transformer, transformer mapping

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 08:32 PM.


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