Sidebar

How can I treat multiple orders as separate messages

0 votes
823 views
asked Sep 13, 2017 by jonathan-l-4690 (210 points)

Hello,

 

I am working on a way for our team to export orders to text for our scheduling team in order to automate a paper process currently in place. I have wrote a script that creates a text file based off of the message coming from Centricity, but it currently can only handle one order/diagnosis at a time. I am confident I can handle the diagnosis piece but I am stumped on how I can separate the multiple orders and run them each through the script separately.

Here is what our message looks like when including multiple orders/diagnoses (this is from a test patient):

MSH|^~\&|LinkLogic-1000-39871-12303|TEST000^PC|SOARCLAB|PC|20170913142300||ORM^O01|1820931774473800|P|2.3.1|||NE|NE
EVN|O01|20170913142300
PID|1|0|71458||Clinical^Ann||19350927|F||2028-9|43 Bewley Rd^^Glasgow^KY^42141||^^^ann.clinical@yahoo.com~(270) 646-9966^^CP~(270) 678-4532^^BP|(270) 670-2340|English|M|||111-11-1112|||D
PV1|1|O|^^^PC||||BMallory
ORC|NW|655422-1|||||||20170913|||rclouse
OBR|1|655422-1||CPT-78300^Bone Scan Limited|||20170913||1||N|||||rclouse|||||||||||^^^^^R
DG1|1||Z85.41^CERVICAL CANCER^I10
DG1|2||I38^VALVULAR HEART DISEASE^I10
DG1|3||C71.9^BRAIN TUMOR^I10
DG1|4||R00.2^FLUTTERING HEART^I10
ORC|NW|655422-2|||||||20170913|||rclouse
OBR|1|655422-2||CPT-77051^CT Abdomen|||20170913||1||N|||||rclouse|||||||||||^^^^^R
NTE|1||What are you trying to rule out? Test
DG1|1||Z85.41^CERVICAL CANCER^I10
DG1|2||I38^VALVULAR HEART DISEASE^I10
DG1|3||C71.9^BRAIN TUMOR^I10
DG1|4||R00.2^FLUTTERING HEART^I10
ORC|NW|655422-3|||||||20170913|||rclouse
OBR|1|655422-3||3076718^Bilirubin Total_BILIT|||20170913||1||N|||||rclouse|||||||||||^^^^^R
NTE|1||CPT-82247  g
DG1|1||Z85.41^CERVICAL CANCER^I10
DG1|2||I38^VALVULAR HEART DISEASE^I10
DG1|3||C71.9^BRAIN TUMOR^I10
DG1|4||R00.2^FLUTTERING HEART^I10
 

Here is the current script I am in the process of writing.

   //Listing the different variables pulled from the HL7
   var ptlastname = source.getNode("PID-5.1");
   var ptfirstname = source.getNode("PID-5.2");
   var birthdate = source.getNode("PID-7");
   var icdcode = source.getNode("DG1-3.3") + "-" + source.getNode("DG1-3.1");
   var diagnosis = source.getNode("DG1-3.2");
   var order = source.getNode("OBR-4.2");
   var ordercode = source.getNode("OBR-4.1");
   var ordercomments = source.getNode("NTE-3");
   var provider = '\'' + source.getNode("OBR-16") + '\'';

   //Bypassing the apostrophe limitation
   var firstquery = 'select FIRSTNAME from USR where LOGINNAME = ' + provider;
   var lastquery = 'select LASTNAME from USR where LOGINNAME = ' + provider;

   //Querying the database to find the providers name
   var provfirst = qie.doSelectQuery('Test-DB', firstquery, true);
   var provlast = qie.doSelectQuery('Test-DB', lastquery, true);

   //Finding the current month
   var d = new Date();
   var month = [];
   month[0] = "January";
   month[1] = "February";
   month[2] = "March";
   month[3] = "April";
   month[4] = "May";
   month[5] = "June";
   month[6] = "July";
   month[7] = "August";
   month[8] = "September";
   month[9] = "October";
   month[10] = "November";
   month[11] = "December";
   var monthlong = month[d.getMonth()];

   //Variables used in the writeFile function - Patient abbreviated to "pt" in order to avoid duplicate variables.
   var ptname = "Patient Name: " + ptlastname + ", " + ptfirstname;
   var ptdob = "Date of Birth: " + StringUtils.substring(birthdate, 5, 6) + "/" + StringUtils.substring(birthdate, 7, 8) + "/" + StringUtils.substring(birthdate, 0, 4);
   var ptorder = "Order: " + order;
   var ptordcode = "Order Code: " + ordercode;
   var ptordercmnt = "Order Instructions: " + ordercomments;
   var ptdiagnosis = "Diagnosis: " + diagnosis + "(" + icdcode + ")";
   var providersig = "Electronically signed by: " + StringUtils.substring(provfirst,9)  + " " + StringUtils.substring(provlast,8);

   //Attempting to generate a file
   try {
      var path = "C:\\Temp\\Qvera\\" + monthlong + "\\" + ptlastname + ", " + ptfirstname + " - " + qie.getSystemDate() + ".txt";
      java.io.File(path, true);
      qie.writeFile(path, ptname + "\r\n" + ptdob + "\r\n" + ptorder + "\r\n" + ptordcode + "\r\n" + ptordercmnt + "\r\n" + ptdiagnosis + "\r\n" + providersig);
   } catch (err) {
      
   }

I thought about using a loop to first try to separate each segment, then run another through the text file creation but so far have came up empty. I am going to continue working on this but thought going ahead and asking the community for advice would be good to try to resolve this issue.

Thanks in advance for any advice/suggestions you can throw my way! 

- Jonathan

1 Answer

+1 vote
 
Best answer

You need to get the ORC groups and then loop through them. Here is a slightly modified shorter script that cycles through the multiple DG1 Segemnts:

//Listing the different variables pulled from the HL7
var ptlastname = source.getNode("PID-5.1");
var ptfirstname = source.getNode("PID-5.2");
var birthdate = source.getNode("PID-7");

//Variables used in the writeFile function - Patient abbreviated to "pt" in order to avoid duplicate variables.
var ptname = "Patient Name: " + ptlastname + ", " + ptfirstname;
var ptdob = "Date of Birth: " + qie.formatDate('M/d/yyyy', birthdate);

var orcGroups = message.getAllNodes('ORC[group=!ORC]');
for (var i = 0; i < orcGroups.length; i++) {
   qie.debug('i: ' + i);
   var orcGroup = qie.parseHL7String(orcGroups[i]);
   
   var provider = '\'' + orcGroup.getNode("OBR-16") + '\'';
   //Bypassing the apostrophe limitation
   var firstquery = 'select FIRSTNAME from USR where LOGINNAME = ' + provider;
   var lastquery = 'select LASTNAME from USR where LOGINNAME = ' + provider;

   //Querying the database to find the providers name
   var provfirst = qie.doSelectQuery('medallies', firstquery, true);
   var provlast = qie.doSelectQuery('medallies', lastquery, true);

   var ptorder = "Order: " + orcGroup.getNode("OBR-4.2");
   var ptordcode = "Order Code: " + orcGroup.getNode("OBR-4.1");
   var ptordercmnt = "Order Instructions: " + orcGroup.getNode("NTE-3");
   var ptdiagnosis = "Diagnosis: ";
   var dg1Segments = orcGroup.getAllNodes('DG1');
   for (var j = 0; j < dg1Segments.length; j++) {
      var dg1Segment = qie.parseHL7String(dg1Segments[j]);
      if (j !== 0) {
         ptdiagnosis += ', ';
      }
      ptdiagnosis += dg1Segment.getNode("DG1-3.2") + "(" + dg1Segment.getNode("DG1-3.3") + "-" + dg1Segment.getNode("DG1-3.1") + ")";
   }
   var providersig = "Electronically signed by: " + StringUtils.substring(provfirst,9)  + " " + StringUtils.substring(provlast,8);

   //Attempting to generate a file
   var path = "C:\\Temp\\Qvera\\" + qie.formatDate('MMMM') + "\\" + ptlastname + ", " + ptfirstname + " - " + qie.getSystemDate() + ".txt";
   try {
      qie.writeFile(path, ptname + "\r\n" + ptdob + "\r\n" + ptorder + "\r\n" + ptordcode + "\r\n" + ptordercmnt + "\r\n" + ptdiagnosis + "\r\n" + providersig, true);
   } catch (err) {
      qie.debug('error1: ' + err);
      try {
         qie.writeFile(path, ptname + "\r\n" + ptdob + "\r\n" + ptorder + "\r\n" + ptordcode + "\r\n" + ptordercmnt + "\r\n" + ptdiagnosis + "\r\n" + providersig, false);
      }catch (err1) {
         qie.debug('error2: ' + err1);
      }
      
   }
}

answered Sep 13, 2017 by brandon-w-8204 (33,170 points)
selected Oct 4, 2017 by jonathan-l-4690
...