web stats
Issue with creating a OBX section of HL7 message - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-09-2011, 11:15 AM
jrohrig jrohrig is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Ohio, USA
Posts: 26
jrohrig is on a distinguished road
Exclamation Issue with creating a OBX section of HL7 message

Hello all,

I am trying to create a HL7 message from a database that I am collecting this data from. I want to create a txt file that will be placed on a server for another software to load. I have been able to use message builders to create everything through OBR section, but need to get this to work. Below I have the code I am using to try to create a reacuring OBX entry.

var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver', 'jdbc:jtds:sqlserver://172.28.1.11:1433/Lab_Interface', 'labinterface', 'li1li2');

var query = "SELECT accession, obrnum, Medlab_order_code, obxnum, OBS_ID, OBS_TXT, OBS_VALUE, OBS_UNITS, REF_RANGE, ABN_FLAG, OBS_RESULT_STATUS, OBS_DATE, result_preformed FROM ORDER_RESULTS WHERE accession = $('accession') and Medlab_order_code = $('Test_Code')";

var results = dbConn.executeCachedQuery(query);
while (results.next()){
var newOBX = new XLM (<OBX/>);
newOBX['OBX.1']['OBX.1.1'] = obxnum;
newOBX['OBX.3']['OBX.3.1'] = OBS_ID;
newOBX['OBX.3']['OBX.3.2'] = OBS_TXT;
newOBX['OBX.5']['OBX.5.1'] = OBS_VALUE;
newOBX['OBX.6']['OBX.6.1'] = OBS_UNITS;
msg.appendChild(newOBX);
}

Again, I just need help trying to get the OBX to repeat. Something simular was given to me by a Mirth employee, but I have been trying to get this to work.

I am also going to attach the channel.
Attached Files
File Type: xml Avatar Import 2.xml (29.8 KB, 24 views)
Reply With Quote
  #2  
Old 11-09-2011, 01:19 PM
panickc panickc is online now
OBX.3 Kenobi
 
Join Date: Dec 2007
Posts: 117
panickc is an unknown quantity at this point
Default

Here's how I do it. This javascript function is the first step in a transformer, then from the 2nd step on down I call the createOBX function multiple times appending OBX's to the template (tmp). The function also returns the new OBX, but I don't use it that way.

Javascript Transformer Step 1:
var obxout= 0;

function createOBX(as_value_type, as_code, as_code_desc, as_code_type, as_value)
{
if (obxout==0)
var newOBX = createSegment('OBX', tmp);
else
var newOBX = createSegmentAfter('OBX', tmp['OBX'][obxout-1]);

obxout++;
newOBX['OBX.1'] = obxout.toString();
newOBX['OBX.2'] = as_value_type;
newOBX['OBX.3']['OBX.3.1'] = as_code;
newOBX['OBX.3']['OBX.3.2'] = as_code_desc;
newOBX['OBX.3']['OBX.3.3'] = as_code_type;
newOBX['OBX.5']['OBX.5.1'] = as_value;
//logger.error("OBX Created:" + SerializerFactory.getHL7Serializer().fromXML(newOB X));
return newOBX;
}



Javascript Step 2:

createOBX(curOBX['OBX.2']['OBX.2.1'].toString(),"ALC_USE", "ALCOHOL USE - drinks per week","RESCOMP",curOBX['OBX.5']['OBX.5.1'].toString()); .
Reply With Quote
  #3  
Old 11-09-2011, 01:34 PM
panickc panickc is online now
OBX.3 Kenobi
 
Join Date: Dec 2007
Posts: 117
panickc is an unknown quantity at this point
Default

Sorry, I see that your sql is in your source, so that fills in the msg.

So for your use, assuming you're using an outbound template (tmp), something like this maybe?:

var obxnum = 0;
while (results.next()){
if (obxnum==0)
var newOBX = createSegment('OBX', tmp);
else
var newOBX = createSegmentAfter('OBX', tmp['OBX'][obxnum-1]);
obxnum++;
newOBX['OBX.1']['OBX.1.1'] = obxnum.toString();
newOBX['OBX.3']['OBX.3.1'] = msg['OBS_ID'].toString();
newOBX['OBX.3']['OBX.3.2'] = msg['OBS_TXT'].toString();
newOBX['OBX.5']['OBX.5.1'] = msg[OBS_VALUE'].toString();
newOBX['OBX.6']['OBX.6.1'] = msg[OBS_UNITS'].toString();
}

Last edited by panickc; 11-09-2011 at 01:43 PM.
Reply With Quote
  #4  
Old 11-11-2011, 09:18 AM
jrohrig jrohrig is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Ohio, USA
Posts: 26
jrohrig is on a distinguished road
Default

Well, I thought this was going to work, but there must be something in the java that I am missing. Here is the step I created based on the above input by panickc.

var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver', 'jdbc:jtds:sqlserver://172.28.1.11:1433/Lab_Interface', 'labinterface', 'li1li2');

var query = "SELECT accession, obrnum, Medlab_order_code, obxnum, OBS_ID, OBS_TXT, OBS_VALUE, OBS_UNITS, REF_RANGE, ABN_FLAG, OBS_RESULT_STATUS, OBS_DATE, result_preformed FROM ORDER_RESULTS WHERE accession = $('accession') and Medlab_order_code = $('Test_Code')";

Code:
var results = dbConn.executeCachedQuery(query);
var obxnum = 0
while (results.next()){
if (obxnum ==0)
var newOBX = createSegment('OBX',tmp);
else
var newOBX = createSegmentAfter('OBX', tmp['OBX'][obxnum-1]);
obxnum++;
newOBX['OBX.1']['OBX.1.1'] = obxnum.toString();
newOBX['OBX.3']['OBX.3.1'] = msg['OBS_ID'].toString();
newOBX['OBX.3']['OBX.3.2'] = msg['OBS_TXT'].toString();
newOBX['OBX.5']['OBX.5.1'] = msg['OBS_VALUE'].toString();
newOBX['OBX.6']['OBX.6.1'] = msg['OBS_UNITS'].toString();
}
I get the attached error message. Any thoughts on what I am doing wrong or missing?
Attached Files
File Type: txt Error.txt (7.1 KB, 31 views)
Reply With Quote
  #5  
Old 11-11-2011, 11:56 AM
panickc panickc is online now
OBX.3 Kenobi
 
Join Date: Dec 2007
Posts: 117
panickc is an unknown quantity at this point
Default

I think it's because of this statement:

var query = "SELECT accession, obrnum, Medlab_order_code, obxnum, OBS_ID, OBS_TXT, OBS_VALUE, OBS_UNITS, REF_RANGE, ABN_FLAG, OBS_RESULT_STATUS, OBS_DATE, result_preformed FROM ORDER_RESULTS WHERE accession = $('accession') and Medlab_order_code = $('Test_Code')";


You have to put the variables, $('accession') and $('Test_Code') outside of the string, like #1 this if they are both character variables in the database or #2 if they are both numeric variables. At least that's how other programming languages work.

#1:
var query = "SELECT accession, obrnum, Medlab_order_code, obxnum, OBS_ID, OBS_TXT, OBS_VALUE, OBS_UNITS, REF_RANGE, ABN_FLAG, OBS_RESULT_STATUS, OBS_DATE, result_preformed FROM ORDER_RESULTS WHERE accession = '" + $('accession') + "' and Medlab_order_code = '" + $('Test_Code') + "' ";

#2:
var query = "SELECT accession, obrnum, Medlab_order_code, obxnum, OBS_ID, OBS_TXT, OBS_VALUE, OBS_UNITS, REF_RANGE, ABN_FLAG, OBS_RESULT_STATUS, OBS_DATE, result_preformed FROM ORDER_RESULTS WHERE accession = " + $('accession') + " and Medlab_order_code = " + $('Test_Code') + " ";

-cp
Reply With Quote
  #6  
Old 11-11-2011, 12:43 PM
jrohrig jrohrig is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Ohio, USA
Posts: 26
jrohrig is on a distinguished road
Default

Well, that still errors, but now I am getting a different detail, please see below. It seems to be getting hung up on the OBX entry.

Code:
[2011-11-11 15:38:00,615]  ERROR (org.mule.impl.DefaultComponentExceptionStrategy:95): Caught exception in Exception Strategy for: 37173726-e577-49d5-b279-69a542faf6ce: org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.webreach.mirth.connectors.jdbc.JdbcConnector@bb3159, endpointUri=jdbc://query, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jdbcEndpoint#-349436542', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionConfig@1e94242, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: org.apache.commons.dbutils.BasicRowProcessor$CaseInsensitiveHashMap
org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.webreach.mirth.connectors.jdbc.JdbcConnector@bb3159, endpointUri=jdbc://query, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jdbcEndpoint#-349436542', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionConfig@1e94242, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: org.apache.commons.dbutils.BasicRowProcessor$CaseInsensitiveHashMap
	at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:64)
	at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:83)
	at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:493)
	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:272)
	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:235)
	at com.webreach.mirth.connectors.jdbc.JdbcMessageReceiver.processMessage(JdbcMessageReceiver.java:168)
	at org.mule.providers.TransactedPollingMessageReceiver$1.doInTransaction(TransactedPollingMessageReceiver.java:98)
	at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:72)
	at org.mule.providers.TransactedPollingMessageReceiver.poll(TransactedPollingMessageReceiver.java:104)
	at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:69)
	at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
	at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
	at java.lang.Thread.run(Unknown Source)Caused by: org.mule.umo.transformer.TransformerException: 
CHANNEL:
	Avatar Import 2
CONNECTOR:
	sourceConnector
SCRIPT SOURCE:
	
LINE NUMBER:
	39
DETAILS:
	TypeError: Cannot read property "OBX.1" from undefined (com.webreach.mirth.server.MirthJavascriptTransformerException)
	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.evaluateScript(JavaScriptTransformer.java:470)
	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:356)
	at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
	at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251)
	at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:61)
	... 13 moreCaused by: com.webreach.mirth.server.MirthJavascriptTransformerException: 
CHANNEL:
	Avatar Import 2
CONNECTOR:
	sourceConnector
SCRIPT SOURCE:
	
LINE NUMBER:
	39
DETAILS:
	TypeError: Cannot read property "OBX.1" from undefined
	at com.webreach.mirth.server.mule.transformers.JavaScriptTransformer.evaluateScript(JavaScriptTransformer.java:460)
	... 20 more
Reply With Quote
  #7  
Old 11-14-2011, 09:00 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 679
Bostad is an unknown quantity at this point
Default

The problem that jumps out at me is that you're expecting multiple OBX's, but in your variable you're not accommodating for them.

Here's how I would do this:

Code:
var i = -1;    //OBX iteration counter

while (results blah blah) {

i++;

var currOBX = createSegment('OBX', msg, i);
/*                                          remember, Mirth does not use segment id's 
                                             to control repeating segments. It treats them
                                             as arrays. So even if your first segment id is
                                             4,000,001, to Mirth it is 0;
*/


msg['OBX'][i]['OBX.1']['OBX.1.1'] = i;

//...and so on

if (i > 0) {
msg['OBX'][i] = msg['OBX'][(i-1)].toString() + currOBX;
}  else {

msg['OBR'] = msg['OBR'].toString() + currOBX;

}

//if you get encoding characters <OBX.1.1>1</OBX1.1> etc. in your output, run the msg['OBX'] string through the serializer first...like this...
// SerializerFactory.getHL7Serializer(false, false, false, true,false).fromXML(msg['OBX'][(i-1)].toString());


/*this is untested and there is some stuff here I haven't tried (but have done some similar things.. so test it thoroughly! */


}
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
hl7coders.wordpress.com

Test all my code suggestions prior to implementation

Last edited by Bostad; 11-14-2011 at 12:08 PM. Reason: forgot the closing code wrapper
Reply With Quote
  #8  
Old 11-17-2011, 12:19 PM
jrohrig jrohrig is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Ohio, USA
Posts: 26
jrohrig is on a distinguished road
Default

Thanks for this option, but I now have a new error message, it looks like it does not like the -1, see message

TypeError: Can not construct XML name from number: -1
at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.evaluateScript(JavaScriptTransform er.java:460)
... 20 more


Here is my entire transformer, which is in the Source as the last transformer under my message builders that are creating the rest of the segments.

Code:
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver', 'jdbc:jtds:sqlserver://172.28.1.11:1433/Lab_Interface', 'labinterface', 'li1li2');

var query = "SELECT accession, obrnum, Medlab_order_code, obxnum, OBS_ID, OBS_TXT, OBS_VALUE, OBS_UNITS, REF_RANGE, ABN_FLAG, OBS_RESULT_STATUS, OBS_DATE, result_preformed  FROM ORDER_RESULTS  WHERE accession = '"+$('accession')+"' and Medlab_order_code = '"+$('Test_Code')+"'";

var results = dbConn.executeCachedQuery(query);
var i=-1
while (results.next()){
var currOBX = createSegment('OBX',msg,i);

msg['OBX'][i]['OBX.1']['OBX.1.1'] = i;
msg['OBX'][i]['OBX.3']['OBX.3.1'] = 'OBS_ID';
msg['OBX'][i]['OBX.3']['OBX.3.2'] = 'OBS_TXT';
msg['OBX'][i]['OBX.5']['OBX.5.1'] = 'OBS_VALUE';
msg['OBX'][i]['OBX.6']['OBX.6.1'] = 'OBS_UNITS';

if (i>0) {
msg['OBX'][i] = msg['OBS'][(i-1)].toString() + currOBX;
} else {
msg['OBR'] = msg['OBR'].toString()+currOBX;
}
}
Reply With Quote
  #9  
Old 11-18-2011, 06:11 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 679
Bostad is an unknown quantity at this point
Default

ah, I forgot to add

Code:
i++;
after the while statement.....sorry
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #10  
Old 11-18-2011, 10:44 AM
jrohrig jrohrig is offline
OBX.1 Kenobi
 
Join Date: Dec 2009
Location: Ohio, USA
Posts: 26
jrohrig is on a distinguished road
Default

Ok, so here is the new error.

[2011-11-18 13:41:00,734] ERROR (org.mule.impl.DefaultComponentExceptionStrategy:9 5): Caught exception in Exception Strategy for: 37173726-e577-49d5-b279-69a542faf6ce: org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.webreach.mirth .connectors.jdbc.JdbcConnector@9f2c4b, endpointUri=jdbc://query, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jdbcEndpoint#1681026586', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionCon fig@4a7faf, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: org.apache.commons.dbutils.BasicRowProcessor$CaseI nsensitiveHashMap
org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.webreach.mirth .connectors.jdbc.JdbcConnector@9f2c4b, endpointUri=jdbc://query, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jdbcEndpoint#1681026586', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionCon fig@4a7faf, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: org.apache.commons.dbutils.BasicRowProcessor$CaseI nsensitiveHashMap
at org.mule.routing.inbound.SelectiveConsumer.isMatch (SelectiveConsumer.java:64)
at org.mule.routing.inbound.InboundMessageRouter.rout e(InboundMessageRouter.java:83)
at org.mule.providers.AbstractMessageReceiver$Default InternalMessageListener.onMessage(AbstractMessageR eceiver.java:493)
at org.mule.providers.AbstractMessageReceiver.routeMe ssage(AbstractMessageReceiver.java:272)
at org.mule.providers.AbstractMessageReceiver.routeMe ssage(AbstractMessageReceiver.java:235)
at com.webreach.mirth.connectors.jdbc.JdbcMessageRece iver.processMessage(JdbcMessageReceiver.java:168)
at org.mule.providers.TransactedPollingMessageReceive r$1.doInTransaction(TransactedPollingMessageReceiv er.java:98)
at org.mule.transaction.TransactionTemplate.execute(T ransactionTemplate.java:72)
at org.mule.providers.TransactedPollingMessageReceive r.poll(TransactedPollingMessageReceiver.java:104)
at org.mule.providers.PollingMessageReceiver.run(Poll ingMessageReceiver.java:69)
at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.runTask(ThreadPoolExecutor. java:650)
at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :675)
at java.lang.Thread.run(Unknown Source)Caused by: org.mule.umo.transformer.TransformerException:
CHANNEL:
Avatar Import 2
CONNECTOR:
sourceConnector
SCRIPT SOURCE:

LINE NUMBER:
44
DETAILS:
TypeError: Cannot call method "toString" of undefined (com.webreach.mirth.server.MirthJavascriptTransfor merException)
at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.evaluateScript(JavaScriptTransform er.java:470)
at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.transform(JavaScriptTransformer.ja va:356)
at org.mule.transformers.AbstractEventAwareTransforme r.doTransform(AbstractEventAwareTransformer.java:4 8)
at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:197)
at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:200)
at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:200)
at org.mule.impl.MuleEvent.getTransformedMessage(Mule Event.java:251)
at org.mule.routing.inbound.SelectiveConsumer.isMatch (SelectiveConsumer.java:61)
... 13 moreCaused by: com.webreach.mirth.server.MirthJavascriptTransform erException:
CHANNEL:
Avatar Import 2
CONNECTOR:
sourceConnector
SCRIPT SOURCE:

LINE NUMBER:
44
DETAILS:
TypeError: Cannot call method "toString" of undefined
at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.evaluateScript(JavaScriptTransform er.java:460)
... 20 more

I have added the 'i++', by the way, you put that in the original message, I just missed it.

Would this be because I don't have my OBR in this javascript, I am doing it through MessageBuilders.

Also, I attached the channel just incase you would like to review.

Thanks.
Attached Files
File Type: xml Avatar Import 2.xml (30.5 KB, 11 views)

Last edited by jrohrig; 11-21-2011 at 06:23 AM.
Reply With Quote
Reply

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 -7. The time now is 06:14 AM.


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