Question
· Oct 24, 2017

Use EnsLib.EMail.OutboundAdapter based on patient email in PID 13-4

Hello All,

I am looking to send out an email based on a patient's discharge where PID13-4 contains their email. We are currently using something similar with an Email.OutboundAdapter. However, in our current scenario we have a hard coded email in place as the recipient (as this is for order notification to a pager).  In the scenario in question, I would need PID13-4 to populate as the recipient of the email.  Does anyone have an example of something similar, or a suggestion on where to start?

Thanks!

Discussion (12)3
Log in or sign up to continue

There's a pretty good description of what needs to be done in the overview here. It describes, and offers examples of,  methods for composing and sending an email in a Business Operation based on this adapter. The primary decisions you'll need to make are whether it will be a simple text-based email vs. a multi-part message, what type of message object will trigger it, and the method to call for delivery when that message type is received.

Jeffrey this works!

I will be making variations on this as we have 49 unique locations to populate automatically in the body of the email message.  However, my test went through.  To come full circle, if anyone else is looking for something like this... We are sending out "How are we doing surveys" after a clinical appointment with our Hospital and outpatient services. Based on a patient email, and the location in which they were seen, they will receive the survey (embedded in a URL).

Thanks!

When I am looking at the example

ClassMethod CreateTextMessage() As %Net.MailMessage
{
Set msg = ##class(%Net.MailMessage).%New()
set msg.From = "test@test.com"
Do msg.To.Insert("xxx@xxx.com")
Do msg.Cc.Insert("yyy@yyy.com")
Do msg.Bcc.Insert("zzz@zzz.com")
Set msg.Subject="subject line here"
Set msg.IsBinary=0
Set msg.IsHTML=0
Do msg.TextData.Write("This is the message.")

Quit msg
}

My biggest hurdle is finding a way for the message to insert PID-13-4 (email address) into the "Do msg.To.Insert___"

Anyone have any thoughts?

I assume you know where you get your email address from.
The rest is straight COS and your code my look like this


set myEmail=.......      ;wherever you get it from your PID-13-4
set msg=..CreateTextMessage(myEmail)   
ClassMethod CreateTextMessage(toMail) As %Net.MailMessage
{
 Set msg = ##class(%Net.MailMessage).%New()
 Set msg.From = "test@test.com"
 Do msg.To.Insert(toMail)
 Do msg.Cc.Insert("yyy@yyy.com")
 Do msg.Bcc.Insert("zzz@zzz.com")
 Set msg.Subject="subject line here"
 Set msg.IsBinary=0
 Set msg.IsHTML=0
 Do msg.TextData.Write("This is the message.") 
 Quit msg
}

When I am looking at the example

ClassMethod CreateTextMessage() As %Net.MailMessage
{
Set msg = ##class(%Net.MailMessage).%New()
set msg.From = "test@test.com"
Do msg.To.Insert("xxx@xxx.com")
Do msg.Cc.Insert("yyy@yyy.com")
Do msg.Bcc.Insert("zzz@zzz.com")
Set msg.Subject="subject line here"
Set msg.IsBinary=0
Set msg.IsHTML=0
Do msg.TextData.Write("This is the message.")

Quit msg
}

My biggest hurdle is finding a way for the message to insert PID-13-4 (email address) into the "Do msg.To.Insert___"

Anyone have any thoughts?

Hi Joe,

I assume that CreateTextMessage is being called from a custom Business Operation similar to what's outlined in this chapter.

If you are passing an HL7 message to the Business Operation, and your operation's message map looks like this:

XData MessageMap
{
<MapItems>
  <MapItem MessageType="EnsLib.HL7.Message">
    <Method>SendEmail</Method>
  </MapItem>
  ...
</MapItems>
}

...then your SendEmail method can use the GetValueAt() method of the EnsLib.HL7.Message object to retrieve a field value using the same syntax that you use in DTL. Have a look at the docs for EnsLib.HL7.Message and specifically GetValueAt.

It would look something like this:

Method SendEmail(myMessage As EnsLib.HL7.Message, Output pResp As ResponseClass) As %Status {
    set myEmail=myMessage.GetValueAt("PID:13(1).4")
    set msg=..CreateTextMessage(myEmail)
    ...

So, putting it all together ...

NOTE: This is NOT production-ready code. There's no error handling or input validation. You get to add that stuff yourself :)

Class User.HL7.Operation.Email extends Ens.BusinessOperation {

 

Parameter ADAPTER = "EnsLib.EMail.OutboundAdapter";

 

Property Adapter As EnsLib.EMail.OutboundAdapter;

 

Parameter INVOCATION = "Queue";

 

Method SimpleMessage(pInput As EnsLib.HL7.Message, Output pOutput As Ens.Response) As %Status

{

    Set email=##class(%Net.MailMessage).%New()

    Set addr = pInput.GetValueAt("PID:13.4")

    Do email.To.Insert(addr)

    Set email.Subject="The subject of your message"

    Do email.TextData.Write("This is the body of your message.")

    Set tSc=..Adapter.SendMail(email)

    //send an empty response message after message is sent

    Set pOutput=##class(Ens.Response).%New()

    Quit $$$OK

}

 

XData MessageMap {

<MapItems>

    <MapItem MessageType="EnsLib.HL7.Message">

        <Method>SimpleMessage</Method>

    </MapItem>

</MapItems>

}

 

}