web stats
How to push the data to the new table from mirth using javascript - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2018, 09:15 AM
sreekanth sreekanth is offline
Mirth Newb
 
Join Date: May 2018
Posts: 8
sreekanth is on a distinguished road
Default How to push the data to the new table from mirth using javascript

Hello Everyone,

Can anyone please help me in pushing the data to the table (HL7_ADTS_MIRTHDATA) from mirth using javascript. I tried in many ways but still can't see any data in the table. Please let me know if i made any mistakes in the below code.

Thanks in advance



var sdf1 = java.text.SimpleDateFormat('yyyy-MM-dd');
var sdf2 = java.text.SimpleDateFormat('HH:mm');

var setString = function(ps, i, s) {
if(s != undefined && s != null) {
ps.setString(i, s);
}
else {
ps.setString(i, null);
}
}

var getDate = function(s){
if(s != undefined && s != null) {
try {
return new java.sql.Timestamp(sdf.parse(s.substring(0,8)).get Time());
}
catch(e) {
return null;
}
}
else {
return null;
}

}

var setTimestamp = function(ps, i, s) {
if(s != undefined && s != null && (typeof s) == 'object') {
ps.setTimestamp(i, s);
}
else {
ps.setTimestamp(i, null);
}
}

var insertSequence = function(conn, query, rowId, seq) {
var ps = null;
try {
ps = conn.prepareStatement(query);
for(var i = 0; i < seq.length; i += 1) {
ps.setLong(1, rowId);
ps.setString(2, seq[i]);
ps.execute();
}
}
finally {
if(ps != null) {
ps.close();
}
}
}

var dbConn = null
var ps = null
var s = null
var rs = null
try {

dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sql server://DB Server/Database','user','password');
var conn = dbConn.getConnection();

ps = conn.prepareStatement("INSERT INTO HL7_ADTS_MIRTHDATA (H_MCID, H_ADT_TYPE, H_PAT_CLASS, H_PATIENT_GENDER) VALUES (?, ?, ?, ?)");


setString(ps, 1, $('MessageControlID'));

setString(ps, 2, $('MessageTypeTriggerEvent'));

setString(ps, 3, $('PatientClass'));


setString(ps, 4, $('Gender'));


ps.close();

}
finally {
if(rs != null && rs != undefined) {
rs.close()
}

if(s != null && s != undefined) {
s.close()
}

if(ps != null && ps != undefined) {
ps.close();
}

if(dbConn != null && dbConn != undefined) {
dbConn.close();
}
}
Reply With Quote
  #2  
Old 05-21-2018, 03:19 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 277
AlexNeiva is on a distinguished road
Default

Hello,


replace your DB management code to this one:


Code:
var dbConn;
var result;

try 
{
    var params = new java.util.ArrayList();
    params.add($('MessageControlID'));
    params.add($('MessageTypeTriggerEvent'));
    params.add($('PatientClass'));
    params.add($('Gender'));

    dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sql server://DB Server/Database','user','password');
    
    var query="INSERT INTO HL7_ADTS_MIRTHDATA (H_MCID, H_ADT_TYPE, H_PAT_CLASS, H_PATIENT_GENDER) VALUES (?, ?, ?, ?);";
    
    result = dbConn.executeUpdate(query, params);
    
} finally 
{
    if (dbConn) 
    {
        dbConn.close();
    }
}
__________________
Best Regards,
Alex Neiva
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 -8. The time now is 07:45 PM.


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