I need to grab a file that matches an Accession# in an incoming HL7 message. So say I get a message with an accession# of 123.....I then need to find the file with the matching 123 in the file name and send that file out. Any ideas on how to do this with javascript?
Announcement
Collapse
No announcement yet.
Receiving a HL7 message and then sending a file
Collapse
X
-
Originally posted by atibbits View PostI need to grab a file that matches an Accession# in an incoming HL7 message. So say I get a message with an accession# of 123.....I then need to find the file with the matching 123 in the file name and send that file out. Any ideas on how to do this with javascript?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.
-
-
Well let me run this by you..the HL7 message I receive contains the file path and I am wondering if I can just use that in combination with the FileUtils? Could I extract the path in OBX5 and open the file and send it? Otherwise I was going to just extract the accession number and go out then match that to the file I need to send?
Here is a sample message:
MSH|^~\&|Xcelera|SRHC|RAD|SRHC|20131108103248||ORM ^R01|00020420131108103248|P|2.2||||||8859/1
PID|||M000000273||CAR^SHINEY^||19651123|F|||456 GRAND AVE^^SALINA^KS^67401^||(785)827-9877|||||V00000007161
OBR|1|330.001||NICL^2DECHO^2D ECHOCARDIOGRAM (COMPLETE)|||201311081025|201311081032||||||||KAUC U^KAUER^CURTIS^D^^^MD^003319||||||20131108103231|| CUS|F|||||||^^^||||||||1
OBX|1|RP|Adult|1|file://///Xceltestsvr/ReportStorage/330.001SRHC_C0273_Adult{1}_11_08_13_1025a.pdf||||| |F
Comment
-
-
Originally posted by atibbits View PostWell let me run this by you..the HL7 message I receive contains the file path and I am wondering if I can just use that in combination with the FileUtils? Could I extract the path in OBX5 and open the file and send it? Otherwise I was going to just extract the accession number and go out then match that to the file I need to send?
Here is a sample message: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.
Comment
-
-
One more question.....how do I send out the file after I read it in? It is the only thing I need to send. I am somehow going to have to use a file writer because I have to change the file name going out. Is that where you were talking about store the contents in a map variable?
Comment
-
-
Originally posted by atibbits View PostOne more question.....how do I send out the file after I read it in? It is the only thing I need to send. I am somehow going to have to use a file writer because I have to change the file name going out. Is that where you were talking about store the contents in a map variable?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.
Comment
-
-
Do you have any examples of how to use the FileUtils to call my path? I am having some trouble with this because I have not used this much. Is this even close??:
var filePath='my file path';
var folder = new Packages.java.io.File(filePath);
var listOfFiles = folder.listFiles();
globalMap.put('file', folder)
var obx5=msg['OBX']['OBX.5']['OBX.5.1'].toString();
var filePath=obx5;Last edited by atibbits; 12-11-2013, 12:53 PM.
Comment
-
-
I think you're on the right path:
I used an HL7 with this OBX segment: OBX|1|RP|Adult|1|C:\\Users\\Eduardo\\Desktop\\test .txt||||| |F
and ran the following:
//get file info
var sourceFilePath = msg['OBX']['OBX.5']['OBX.5.1'].toString();
var sourceFile = new java.io.File(sourceFilePath);
//read file
var byteArray = org.apache.commons.io.FileUtils.readFileToByteArra y(sourceFile);
//write file
var destFilePath = "C:\\Users\\Eduardo\\Desktop\\test2.txt"
var destFile = new java.io.File(destFilePath);
org.apache.commons.io.FileUtils.writeByteArrayToFi le(destFile, byteArray);
It looks like you want to send the file out but that should be the same idea. You might also want to check if the file exists.
Comment
-
-
Originally posted by eduardoa View PostI think you're on the right path:
I used an HL7 with this OBX segment: OBX|1|RP|Adult|1|C:\\Users\\Eduardo\\Desktop\\test .txt||||| |F
and ran the following:
//get file info
var sourceFilePath = msg['OBX']['OBX.5']['OBX.5.1'].toString();
var sourceFile = new java.io.File(sourceFilePath);
//read file
var byteArray = org.apache.commons.io.FileUtils.readFileToByteArra y(sourceFile);
//write file
var destFilePath = "C:\\Users\\Eduardo\\Desktop\\test2.txt"
var destFile = new java.io.File(destFilePath);
org.apache.commons.io.FileUtils.writeByteArrayToFi le(destFile, byteArray);
It looks like you want to send the file out but that should be the same idea. You might also want to check if the file exists.
Thanks Eduardo! I think I am really close, but I cannot seem to figure out my file path. I keep getting a file does not exist error, but the file really does exist. The file exists on a shared file on a different server. Do i need to have permissions written in here somewhere or should it work since it is a shared file? I think I need to do smb since I am on Unix? Is there a way to do this? Here is my test message:
Code:MSH|^~\&|Xcelera|SRHC|RAD|SRHC|20131108102858||ORM^R01|00019420131108102858|P|2.2||||||8859/1 PID|||M000000074||OD^JAMES^||19600510|M|||132 GRAND^^SALINA^KS^67401^||(785)827-9877|||||V00000007096 OBR|1|332.001||NICL^CONGECHOC^ECHO CONGENITAL ANOM COMPLETE|||201311081025|201311081028||||||||BATTDA^BATTIN^DAVID^L^^^MD^020962||||||20131108102819||CUS|F|||||||^^^||||||||1 OBX|1|RP|Adult|1|file://///Xceltestsvr/ReportStorage/332.001SRHC_O0074_Adult{1}_11_08_13_1025a.pdf||||||F
I decided to test with a test file path before I start using what is in OBX.5. I wanted to get the format correct first.
Here is the code I am using:
Code://get file info var sourceFilePath = 'file:\\\\xceltestsvr\ReportStorage\332.001SRHC_O0074_Adult%7B1%7D_11_08_13_1025a.pdf'; var sourceFile = new java.io.File(sourceFilePath); //read file var byteArray = org.apache.commons.io.FileUtils.readFileToByteArray(sourceFile); //write file var destFilePath = "\\home\\appsadmin\\mirthtest\\XCELERA_COLDFEED_test.pdf" var destFile = new java.io.File(destFilePath); org.apache.commons.io.FileUtils.writeByteArrayToFile(destFile, byteArray);
Here is my error:
Code:ERROR-300: Transformer error ERROR MESSAGE: Error evaluating transformer com.mirth.connect.server.MirthJavascriptTransformerException: CHANNEL: RESULTS_from_xcelera_echo_pdf_7148 CONNECTOR: SEND FILE WITH JAVASCRIPT TEST SCRIPT SOURCE: SOURCE CODE: 99: //get file info 100: var sourceFilePath = 'file:\\\\xceltestsvr\\ReportStorage\\332.001SRHC_O0074_Adult%7B1%7D_11_08_13_1025a.pdf'; 101: var sourceFile = new java.io.File(sourceFilePath); 102: 103: //read file 104: var byteArray = org.apache.commons.io.FileUtils.readFileToByteArray(sourceFile); 105: 106: //write file 107: var destFilePath = "\\home\\appsadmin\\mirthtest\\XCELERA_COLDFEED_test.pdf" 108: var destFile = new java.io.File(destFilePath); LINE NUMBER: 104 DETAILS: Wrapped java.io.FileNotFoundException: File 'file:\\xceltestsvr\ReportStorage\332.001SRHC_O0074_Adult%7B1%7D_11_08_13_1025a.pdf' does not exist
Last edited by atibbits; 12-12-2013, 07:57 AM.
Comment
-
-
I am pretty convinced I am going to need to access these files with smb, but everything I have to tried with smb is not working. I have tried the format:
smb://Domain/User/Password@ip address/directory/file name.pdf
It is still not working. Are you able to read files in smb with javascript? I am trying to eventually use the path that is provided in OBX.5 (see above posts) , but I cannot access it quite yet.
Comment
-
Comment