Solved

query mssql Database with mirth

Posted on 2010-11-09
5
5,536 Views
Last Modified: 2012-05-10
I'm not very good at the programming aspect of my job.  Can someone look at this code and tell me where I'm screwing up?

I think I'm screwing up at tmp[blahblahblah] = result(1);

I know the field i'm grabbing from is a text field..
//DatabaseConnection
//see http://svn.sourceforge.net/viewvc/mirth/trunk/server/src/com/webreach/mirth/server/util/DatabaseConnection.java?view=markup 
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://10.0.0.55:1433/raypax','username','password');


//the query
var AccNum = msg['tag00080050']['@tag'].toString();
var expression = "SELECT REPORT_TEXT FROM PACS_T_REPORT_TEXT WHERE EXAM_KEY = '" + AccNum + "';";  


//CachedRowSetImpl
//see http://developers.sun.com/prodtech/javatools/jscreator/reference/docs/apis/rowset/com/sun/rowset/CachedRowSetImpl.html
var result = dbConn.executeCachedQuery(expression); 

//go to the first result
result.next();
//get the value from the first colum as an integer

tmp['OBX']['OBX.5']['OBX.5.1'] = result(1);


result.close(); 
dbConn.close();

Open in new window

0
Comment
Question by:mwolfe83
  • 4
5 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 34096795
tmp[blah] =  result.getInt(1);
0
 

Author Comment

by:mwolfe83
ID: 34097006
Here is the error that it returned:
DETAILS:
Wrapped java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0

DETAILS:	Wrapped java.sql.SQLException: Invalid column index
	at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.evaluateScript(JavaScriptTransformer.java:451)
	at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:349)
	at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
	at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
	at org.mule.impl.MuleEvent.getTransformedMessage(MuleEvent.java:251)
	at com.mirth.connect.server.controllers.DefaultMessageObjectController.getMessageObjectFromEvent(DefaultMessageObjectController.java:737)
	at com.mirth.connect.connectors.file.FileMessageDispatcher.doDispatch(FileMessageDispatcher.java:52)
	at com.mirth.connect.connectors.file.FileMessageDispatcher.doSend(FileMessageDispatcher.java:129)
	at org.mule.providers.AbstractMessageDispatcher.send(AbstractMessageDispatcher.java:164)
	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:191)
	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:130)
	at org.mule.routing.outbound.AbstractOutboundRouter.send(AbstractOutboundRouter.java:85)
	at org.mule.routing.outbound.FilteringMulticastingRouter.route(FilteringMulticastingRouter.java:61)
	at org.mule.routing.outbound.OutboundMessageRouter$1.doInTransaction(OutboundMessageRouter.java:78)
	at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:48)
	at org.mule.routing.outbound.OutboundMessageRouter.route(OutboundMessageRouter.java:82)
	at org.mule.impl.model.DefaultMuleProxy.onCall(DefaultMuleProxy.java:247)
	at org.mule.impl.model.seda.SedaComponent.doSend(SedaComponent.java:209)
	at org.mule.impl.model.AbstractComponent.sendEvent(AbstractComponent.java:277)
	at org.mule.impl.MuleSession.sendEvent(MuleSession.java:201)
	at org.mule.routing.inbound.InboundMessageRouter.send(InboundMessageRouter.java:176)
	at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:143)
	at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487)
	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266)
	at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225)
	at com.mirth.connect.connectors.dimse.DICOMMessageReceiver$MirthStorageSCP.onCStoreRQ(DICOMMessageReceiver.java:193)
	at com.mirth.connect.connectors.dimse.DICOMMessageReceiver$MirthStorageSCP.cstore(DICOMMessageReceiver.java:211)
	at org.dcm4che2.net.DicomServiceRegistry.process(DicomServiceRegistry.java:238)
	at org.dcm4che2.net.NetworkApplicationEntity.perform(NetworkApplicationEntity.java:1158)
	at org.dcm4che2.net.Association.onDimseRQ(Association.java:971)
	at org.dcm4che2.net.PDUDecoder.decodeDIMSE(PDUDecoder.java:530)
	at org.dcm4che2.net.Association.onPDataTF(Association.java:948)
	at org.dcm4che2.net.State$Sta6.receivedPDataTF(State.java:239)
	at org.dcm4che2.net.Association.receivedPDataTF(Association.java:944)
	at org.dcm4che2.net.PDUDecoder.nextPDU(PDUDecoder.java:231)
	at org.dcm4che2.net.Association.run(Association.java:850)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Invalid column index
	at com.sun.rowset.CachedRowSetImpl.checkIndex(Unknown Source)
	at com.sun.rowset.CachedRowSetImpl.getInt(Unknown Source)
	at sun.reflect.GeneratedMethodAccessor297.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:247)
	at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:66)
	at org.mozilla.javascript.gen._32060774_24ea_4354_80c5_4a9ac4ceca47_340._c_doTransform_13(32060774-24ea-4354-80c5-4a9ac4ceca47:31)
	at org.mozilla.javascript.gen._32060774_24ea_4354_80c5_4a9ac4ceca47_340.call(32060774-24ea-4354-80c5-4a9ac4ceca47)
	at org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRuntime.java:108)
	at org.mozilla.javascript.gen._32060774_24ea_4354_80c5_4a9ac4ceca47_340._c_script_0(32060774-24ea-4354-80c5-4a9ac4ceca47:42)
	at org.mozilla.javascript.gen._32060774_24ea_4354_80c5_4a9ac4ceca47_340.call(32060774-24ea-4354-80c5-4a9ac4ceca47)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3157)
	at org.mozilla.javascript.gen._32060774_24ea_4354_80c5_4a9ac4ceca47_340.call(32060774-24ea-4354-80c5-4a9ac4ceca47)
	at org.mozilla.javascript.gen._32060774_24ea_4354_80c5_4a9ac4ceca47_340.exec(32060774-24ea-4354-80c5-4a9ac4ceca47)
	at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.evaluateScript(JavaScriptTransformer.java:395)
	... 36 more

Open in new window

0
 

Author Comment

by:mwolfe83
ID: 34101941
After looking deeper into the archives of this forum, I found a post that seemed to get me a little closer. Now I am running into a LocalMap.put problem. It says the object is not defined. Any Ideas?
var AccNum = msg['tag00080050']['@tag'].toString();


//using stored procedure in javascript

var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sql server://10.0.0.55:1433/raypax', 'username', 'password');
var expression = 'select EXAM_KEY,REPORT_TEXT from PACS_T_REPORT_TEXT where EXAM_KEY= 10131' ;//here REPORT_TEXT is blob column
var result = dbConn.executeCachedQuery(expression);

result.next();
var xray = result.getClob(2);
var strOut = new java.lang.StringBuffer();
var aux = new java.lang.String();

// RTF data conversion

var kit = new Packages.javax.swing.text.rtf.RTFEditorKit()
var doc = new Packages.javax.swing.text.DefaultStyledDocument();
kit.read(xray.getAsciiStream(), doc, 0);

var text=doc.getText(0,doc.getLength());
// The data in Text Format

localMap.put('xray',text);

tmp['OBX']['OBX.5']['OBX.5.1'] = xray
0

dbConn.close(); 

Open in new window

0
 

Accepted Solution

by:
mwolfe83 earned 0 total points
ID: 34106797
Fixed it.  Man, that was rough.  I guess it would help if I knew ANY programming...


var accession;
var rptBody; //holds report text from PACS_T_REPORT_TEXT.REPORT_TEXT
accession = msg['tag00080050']['@tag'].toString();

//connect to DB
var dbConn = DatabaseConnectionFactory.createDatabaseConnection
('oracle.jdbc.driver.OracleDriver','jdbcracle:th in:@10.0.1.13:1521:RAYPAX1', 'pacs', 'pacs');

//query for report body
var SQL = "select REPORT_TEXT from PACS_T_REPORT_TEXT where EXAM_KEY= '" + accession + "'";
var result = dbConn.executeCachedQuery(SQL);
result.first();
try
{
var rptBody = result.getClob("REPORT_TEXT");
logger.error(rptBody);
var clobLength = rptBody.length();
var rptBodyFull = rptBody.getSubString(1,clobLength)
logger.error(rptBodyFull);


} catch (e) {
rptBody = "Exception retreiving report. No Report Found";
}
channelMap.put('rptBody',rptBody);

tmp['OBX']['OBX.5']['OBX.5.1'] = (rptBodyFull);


dbConn.close();

Open in new window

0
 

Author Closing Comment

by:mwolfe83
ID: 34134706
I figured it out on my own after living on the mirthcorp forum.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question