Written by

Applications Development Consultant at The Ohio State University, Wexner Medical Center
Question Jonathan Anglin · Jan 28, 2020

Multiple Emails from EnsLib.EMail.OutboundAdapter

I'm trying to tie IRIS (2019.1) into our Concord Fax cloud-based email-to-fax workflow. We have some sites that require a fax be sent to multiple locations based upon certain data (ie Radiology and Emergency departments). Unfortunately, CC-ing does not work with Concord Fax so I need a way to send the email, change the recipient, and then send it again if certain criteria are met. Is this possible? Do I need to duplicate and rename the method, calling the second one in the MessageMap?

Here's what my code currently looks like:

 

Code

 
/// Sends reports to the cloud-based Concord fax service.
Class LH.Util.ORUToConcord Extends Ens.BusinessOperation
{
  Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";
  Parameter INVOCATION = "Queue";
  Method SendSimpleMessage(pRequest As EnsLib.HL7.Message, Output pResponse As Ens.Response) As %Status
{
set = ##class(%Net.MailMessage).%New()//get variables from HL7 message:
set siteCode = pRequest.GetValueAt("MSH:4")
set patientClass = pRequest.GetValueAt("PV1:2.1")
set patientID = pRequest.GetValueAt("PID:3")
set patientLName = pRequest.GetValueAt("PID:5.1")
set patientFName = pRequest.GetValueAt("PID:5.2")
set patientMName = pRequest.GetValueAt("PID:5.3")
set patientDOB = pRequest.GetValueAt("PID:7")
set patientGender = pRequest.GetValueAt("PID:8")
set accNum = pRequest.GetValueAt("ORC:3")
set procCode = pRequest.GetValueAt("OBR:4.1")
set procDesc = pRequest.GetValueAt("OBR:4.2")
set DOS = pRequest.GetValueAt("OBR:7")
set opFirst = pRequest.GetValueAt("OBR:16.3")
set opLast = pRequest.GetValueAt("OBR:16.2")
set resultStatus = pRequest.GetValueAt("OBR:25")
set reasonFE = pRequest.GetValueAt("OBR:31.1")
set priLName = pRequest.GetValueAt("OBR:32.1.2")
set priFName = pRequest.GetValueAt("OBR:32.1.3")
set dt = pRequest.GetValueAt("OBR:32.3") 
 
//convert the dictated datetime (dt) into human-readable format
set dictatedDate = $e(dt,1,8)
set dictatedTime = $e(dt,9,10)_":"_$e(dt,11,12) 
 
//set variables based on the result status:
if resultStatus = "P" {
  set m.Subject = "Preliminary report for "_accNum
  set title = "PRELIMINARY REPORT"
}
if resultStatus = "F" {
  set m.Subject = "Final report for "_accNum
  set title = "FINAL REPORT"
}
if resultStatus = "S" {
  set m.Subject = "Final report for "_accNum
  set title = "FINAL REPORT"
}
if resultStatus = "A" {
  set m.Subject = "Addended report for "_accNum
  set title = "ADDENDUM"
}
//set variables based upon the site:
do m.To.Insert("8005551212@concordsend.com")
set header = "site address and phone number"
 
//regardless of site:
set m.From = siteCode_"Fax@domain.com" 
 
//used for iterating through the OBX segments
set obxCount = pRequest.GetValueAt("OBX(*)")
set = 1 
 
set m.IsHTML = 1
set m.IsBinary = 0
set m.IsMultiPart = 1
set m.MultiPartType = "related"
do m.Headers.SetAt("inline","Content-Disposition")
 
//html part
#dim text as %Net.MailMessagePart
text = m.AttachNewMessage()
text.IsHTML = 1
text.IsBinary = 0
text.IsMultiPart = 0
  
do text.TextData.Write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>")
do text.TextData.Write("<html><head><meta http-equiv='content-type' content='text/html; charset=ISO-8859-1'>")
do text.TextData.Write("</head><body text='#666666' bgcolor='#ffffff' margin-left='50px'>")
//Concord cannot process an image as indicated below.
//Converting to BASE64 also fails. Kept in case of emailing instead of fax
//do text.TextData.Write("<p style='text-align:center'><img src='cid:myImage.png' /><br />"_header_"</p>")
do text.TextData.Write("<p style='text-align:center'><strong>"_title_"</strong></p>")
do text.TextData.Write("<p>Patient: "_patientLName_", "_patientFName_" "_patientMName_"<br />")
do text.TextData.Write("MRN: "_patientID_"<br />")
do text.TextData.Write("DOB: "_$ZD($ZDATEH(patientDOB,5))_"<br />")
do text.TextData.Write("Sex: "_patientGender_"<br /><br />")
do text.TextData.Write("Ordering Provider: "_opFirst_" "_opLast_"<br /><br />")
do text.TextData.Write("Study Date: "_DOS_"<br />")
do text.TextData.Write("Accession #: "_accNum_"<br />")
do text.TextData.Write("Procedure Code: "_procCode_"<br />")
do text.TextData.Write("Procedure: "_procDesc_"<br />")
do text.TextData.Write("Reason For Study: "_reasonFE_"</p><p>")
for{  do text.TextData.Write(pRequest.GetValueAt("OBX("_x_"):5")_"<br />")
  set = x+1
  quit:x=obxCount
}
do text.TextData.Write("</p><p>Dictated on: "_$ZD($ZDATEH(dictatedDate,5))_" "_dictatedTime_"<br />")
do text.TextData.Write("Interpreted by: "_priFName_" "_priLName_"</p>")
do text.TextData.Write("</body></html>")
  
// Image Message Part (only works for email, not faxing so use cover sheets instead)
/*
set part = m.AttachNewMessage()
set part.IsBinary = 1
set part.IsMultiPart = 0
set part.FileName = "myImage.png"do part.BinaryData.LinkToFile("/mnt/install/irisUsrFiles/"_siteCode_".png")
do part.Headers.SetAt("inline","Content-Disposition")
do part.Headers.SetAt("<myImage.png>","Content-ID")
*/   
  set status = ..Adapter.SendMail(m)
        
  $system.OBJ.DisplayError(status)
  status,!
  
  return status
} 
XData MessageMap
{
<MapItems>
    <MapItem MessageType="EnsLib.HL7.Message">
        <Method>SendSimpleMessage</Method>
    </MapItem>
</MapItems>
}
}

 

Comments

Eduard Lebedyuk · Jan 29, 2020

Have you tried sending the message to several recipients directly? Not CC but TO:

do m.To.Insert("mail1@domain.com")
do m.To.Insert("mail2@domain.com")

Or you can send the same email object to several recipients one by one:

for to = "mail1@domain.com", "mail2@domain.com" {
    do m.To.Clear()
    do m.To.Insert(to)
    set status = ..Adapter.SendMail(m)
    do:$$$ISERR(status) $system.OBJ.DisplayError(status)
}
0
Jonathan Anglin  Jan 29, 2020 to Eduard Lebedyuk

I did try an additional "To" that failed. However I just did it again and it worked. I assumed it failed because Concord Fax did not support it, but I must have had something else incorrect that has since then been fixed.  Thank you for the sanity-check!

0