web stats
translating - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-11-2019, 08:06 AM
dforesman dforesman is offline
Mirth Newb
 
Join Date: Mar 2016
Posts: 16
dforesman is on a distinguished road
Default translating

Mirth Version 3.6.1

I am in the process of correcting CCDs that are being generated by an EMR that we are unable to modify. So far I am able to return the correct information. However after it is stored in the variable xml_final it returns with decoded html entities and I am having a heck of a time keeping them encoded when inserting back into the XML.

I have tried return a variation of return message.replace() like below:
var messg=message;
messg=messg.replace('&lt;','<');
messg=messg.replace('&gt;','>');
messg=messg.replace('
','');
return messg;

I understand it is happening due to my query however when I write the data to a file (see bottom of code) it spits out with the correct encoded entities.

Any help or guidance is appreciated. Please note the SQL Queries and such have been scrubbed.

Code:
var prob_cnt;
var xml_build;
var xml_build2;
var xml_final;
var num_records;
var crs = new Packages.com.sun.rowset.CachedRowSetImpl();

var pt_mrn = msg['recordTarget']['patientRole']['id']['@extension'].toString();

channelMap.put('pt_mrn', validate(pt_mrn, pt_mrn, new Array()));

//first grab row count
var dbConn;	
var dbConn = db_connect_stuffs;
var sql = "select COUNT(rownum) cnt FROM some_table WHERE things=stuff";
	prob_cnt = dbConn.executeCachedQuery(sql);
	
if (prob_cnt.next()) {
num_records = prob_cnt.getString(1);

} 
//validating count from query
channelMap.put('prob_cnt', validate(num_records, num_records, new Array()));

for (i = 1; i <= num_records; i++) {
//return problem description
		var sql2 = "SELECT prob_description FROM some_table";	
		var prob_description =  dbConn.executeCachedQuery(sql2); 

		while (prob_description.next()) {
		prob_desc = prob_description.getString(1).trim();
			}
//return onset date		
		var sql3 = "SELECT prob_onsetdt FROM some_table";
		var prob_onsetdate =  dbConn.executeCachedQuery(sql3); 
	
		while (prob_onsetdate.next()) {
		var prob_onsetdt = prob_onsetdate.getString(1).trim();
			}
//used for validation
		//channelMap.put('prob_description'+parseFloat(i), validate(prob_desc, prob_desc, new Array()));
		//channelMap.put('prob_onsetdate'+parseFloat(i), validate(prob_onsetdt, prob_onsetdt, new Array()));

		var xml_build_prob_list='\r\n								<tr>\r\n									<td>\r\n										<content ID="problemDescription'+i+'">'+prob_desc+'</content>\r\n									</td>\r\n									<td>'+prob_onsetdt+'</td>\r\n									<td>\r\n										<content ID="problemStatus'+i+'">Active</content>\r\n									</td>\r\n									<td/>\r\n								</tr>';
		//dynamically build the xml so it can be put back into the CCD
		if(i==1){
			xml_final= xml_build_prob_list;
		}
		else{
			xml_final= xml_final+xml_build_prob_list;
		}



}
//this was used to validate the elements and values are being written properly

/*
		 var Filename =  'prob_'+$('mod_filename');
				//Validating filename
		        channelMap.put('Filename',Filename);
			var Directory = 'D:/PP_CCD/Sent/'
				//validating file path
				channelMap.put('Directory',Directory);
			var string=xml_final;
			FileToWrite = java.io.File(Directory+'/'+Filename);
			org.apache.commons.io.FileUtils.writeStringToFile(FileToWrite, string, true);
			channelMap.put('xml_build', validate(xml_final, xml_final, new Array()));
			*/

//update node with new value
msg['component']['structuredBody']['component'][1]['section']['text']['table']['tbody']=xml_final;

Last edited by dforesman; 01-11-2019 at 08:09 AM.
Reply With Quote
  #2  
Old 01-12-2019, 07:10 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 718
agermano is on a distinguished road
Default

The issue is that you are building your xml as a string, and then assigning that string to an xml node. It will automatically escape the string for you. What you need to do is actually build an xml object.

Code:
// initialize empty XMLList to hold the final table rows
xml_final = new XMLList();
for (i = 1; i <= num_records; i++) {
//return problem description
		var sql2 = "SELECT prob_description FROM some_table";	
		var prob_description =  dbConn.executeCachedQuery(sql2); 

		while (prob_description.next()) {
		prob_desc = prob_description.getString(1).trim();
			}
//return onset date		
		var sql3 = "SELECT prob_onsetdt FROM some_table";
		var prob_onsetdate =  dbConn.executeCachedQuery(sql3); 
	
		while (prob_onsetdate.next()) {
		var prob_onsetdt = prob_onsetdate.getString(1).trim();
			}
//used for validation
		//channelMap.put('prob_description'+parseFloat(i), validate(prob_desc, prob_desc, new Array()));
		//channelMap.put('prob_onsetdate'+parseFloat(i), validate(prob_onsetdt, prob_onsetdt, new Array()));

        // create xml table row
        var desc_id =  'problemDescription' + i;
        var status_id =  'problemStatus' + i;
        var xml_build_prob_list =
            <tr>
                <td>
                    <content ID={desc_id}>{prob_desc}</content>
                </td>
                <td>{prob_onsetdt}</td>
                <td>
                    <content ID={status_id}>Active</content>
                </td>
                <td/>
            </tr>;
        // add row to final list
        xml_final += xml_build_prob_list;
}
Reply With Quote
  #3  
Old 01-17-2019, 06:28 AM
dforesman dforesman is offline
Mirth Newb
 
Join Date: Mar 2016
Posts: 16
dforesman is on a distinguished road
Default

Thank you agermano that worked, I did not think of it like that.

Now I feel a little silly..
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 04:24 AM.


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