web stats
Hyphen in number string - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 04-28-2014, 03:50 PM
ntaylor ntaylor is offline
What's HL7?
Join Date: Oct 2012
Posts: 5
ntaylor is on a distinguished road
Default Hyphen in number string

I am trying to use Mirth Connect to take information from an HL7 file, and Insert it into a SQL database table.

I setup a Destination with a Connector Type of Database Writer, and am using the javascript code below to write to the database.
The issue I am currently having is that the field I am trying to use is number string containing a hyphen. Whenever I try to insert the value into the nvarchar field in SQL, it is subtracting the numbers on each side of the hyphen, instead of inserting the actual string. For instance the value of my test data is 123-19 but it inserts 104 into the SQL field.

I tried adding .toString at the end of the msg code, but I get an Error stating:
TypeError: Cannot find function ToString in object 123-19.
when I try to process the message.

Can someone please help me figure out what I am doing wrong?
thank you.

var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sql server://','hieuser','hieuser');

//var msg = new XML(SerializerFactory.getHL7Serializer().toXML(con nectorMessage.getEncodedData()));
var msg = new XML(SerializerFactory.getSerializer('HL7V2').toXML (connectorMessage.getEncodedData()));

var test1 = msg['PID']['PID.3']['PID.3.1'];

var result = dbConn.executeUpdate("INSERT INTO DocumentQueue (SourceID, DataTypeID, DocTypeID, ClinicalDate, Summary, DoctorID, FacilityID, DocumentData, FilePath, StatusID) VALUES (" + test1 + ", 0, 0, '', '', 0, 0, '', '', 0)");

Reply With Quote
Old 04-28-2014, 03:56 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road

You're not escaping that "test1" variable correctly when you concatenate the SQL statement.
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.

- How do I foo?
- You just bar.
Reply With Quote
Old 04-28-2014, 09:20 PM
ntaylor ntaylor is offline
What's HL7?
Join Date: Oct 2012
Posts: 5
ntaylor is on a distinguished road

Thank you.
I ended up changing .....VALUES (" + test1 + ", 0.... to .....VALUES ('" + test1 + "', 0..... and it worked.
Reply With Quote

database writer, hyphen, sql, subtract

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 04:46 AM.

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