Written by

Software Engineer at Holland Hospital
Question Joe Schra · 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!

Comments

Jeffrey Drumm · Oct 25, 2017

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.

0
Joe Schra  Oct 25, 2017 to Jeffrey Drumm

Great thanks Jeffrey! I will take a look at the overview thank you for the direction.

0
Joe Schra  Nov 17, 2017 to Marc Mundt

Thanks Mark,

I am just getting started with Ensemble so forgive me for being naïve...excited to give this a try! 

0
Joe Schra  Nov 17, 2017 to Jeffrey Drumm

Thanks for your follow up Jeff! Hopefully today I can set this up in our TEST environment, I'll let you know the outcome.

0
Joe Schra  Nov 20, 2017 to Jeffrey Drumm

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!

0
Joe Schra  Nov 16, 2017 to Joe Schra

When I am looking at the example

ClassMethodCreateTextMessage()As%Net.MailMessage
{
Setmsg=##class(%Net.MailMessage).%New()
setmsg.From="test@test.com"
Domsg.To.Insert("xxx@xxx.com")
Domsg.Cc.Insert("yyy@yyy.com")
Domsg.Bcc.Insert("zzz@zzz.com")
Setmsg.Subject="subject line here"
Setmsg.IsBinary=0
Setmsg.IsHTML=0
Domsg.TextData.Write("This is the message.")
Quitmsg
}

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

Anyone have any thoughts?

0
Robert Cemper  Nov 16, 2017 to Joe Schra

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
}
0
Joe Schra · Nov 16, 2017

When I am looking at the example

ClassMethodCreateTextMessage()As%Net.MailMessage
{
Setmsg=##class(%Net.MailMessage).%New()
setmsg.From="test@test.com"
Domsg.To.Insert("xxx@xxx.com")
Domsg.Cc.Insert("yyy@yyy.com")
Domsg.Bcc.Insert("zzz@zzz.com")
Setmsg.Subject="subject line here"
Setmsg.IsBinary=0
Setmsg.IsHTML=0
Domsg.TextData.Write("This is the message.")
Quitmsg
}

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

Anyone have any thoughts?

0
John Murray · Nov 16, 2017

Joe, using my DC Moderator superpowers I have removed the "Developer Community FAQ" tag from your post. That tag is intended for FAQs about how to use the DC platform.

0
Marc Mundt · Nov 16, 2017

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)
    ...
0
Marc Mundt · Nov 16, 2017

Moving my comment to an answer

0
Jeffrey Drumm · Nov 16, 2017

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 :)

ClassUser.HL7.Operation.EmailextendsEns.BusinessOperation {

 

ParameterADAPTER = "EnsLib.EMail.OutboundAdapter";

 

PropertyAdapterAsEnsLib.EMail.OutboundAdapter;

 

ParameterINVOCATION = "Queue";

 

MethodSimpleMessage(pInputAsEnsLib.HL7.Message, OutputpOutputAsEns.Response) As%Status

{

    Setemail=##class(%Net.MailMessage).%New()

    Setaddr=pInput.GetValueAt("PID:13.4")

    Doemail.To.Insert(addr)

    Setemail.Subject="The subject of your message"

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

    SettSc=..Adapter.SendMail(email)

    //send an empty response message after message is sent

    SetpOutput=##class(Ens.Response).%New()

    Quit$$$OK

}

 

XDataMessageMap {

<MapItems>

    <MapItemMessageType="EnsLib.HL7.Message">

        <Method>SimpleMessage</Method>

    </MapItem>

</MapItems>

}

 

}

0