Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

query mssql Database with mirth

Posted on 2010-11-09
5
Medium Priority
?
5,916 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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