HealthShare 2 Slack Business Operation

This will be a stretch to be useful, but it was sorta fun.  If you just so happen to have a use case to make your HealthShare productions talk to a Slack channel, this is the Business Operation for you.

In Slack, it is a dead simple process to enable an incoming web hook:

  • Name It
  • Give it an Icon or Emoji
  • Declare a Channel to Interact With

One you supplies those, it spits out a URL that you can go to town posting to your channel using that endpoint.

To demonstrate this, I whooped up a small Production that accepted HL7 via a Business Service, and routed the message to the Slack Business Operation which ended up using Data from the HL7 Message to Post to the Channel as A Bot.  And since this year's InterSystems Global Summit has introduced Slack to its participants, I reached out to the good Paul Gomez at InterSystems who runs Slack for the conference it to let me interact with an incoming web hook there to view the final result.

Head over to the #developer-sandbox out on the Global Summit Slack and check it out.

  

Here is the Code:

Include Ensemble

Class GS2016.Operations.HTTPSLACKOperation Extends Ens.BusinessOperation
{

/* 

   Coded while on a call with Comcast (A Time Warner Company).
   Fun with Slack from HealthShare @ GS2016
   Ron Sweeney, Integration Required (GS Slack @sween)
   
*/
Parameter INVOCATION = "Queue";

Property SlackURL As %String(MAXLEN = 1000);

Property SlackSSL As %String;

Property SlackPort As %String;

Property SlackServer As %String;

Parameter SETTINGS = "SlackURL,SlackSSL,SlackPort,SlackServer";

Method SendSlackChannel(pInput As EnsLib.HL7.Message, Output pResponse As %String) As %Status
{
    Set tSC = $$$OK
    
    // Open the inbound HL7 Object
    
    // Set DocType on Message so we can Nav the Virtual Properties
    Set:pInput.DocType="" pInput.DocType = "2.3.1:ADT_A01"

    // Set values from what is in the HL7 Message
    Set tFirstName = pInput.GetValueAt("PID:5.2")
    Set tLastName = pInput.GetValueAt("PID:5.1")
    Set tMessageType = pInput.GetValueAt("MSH:9")
    Set tPatientId =  pInput.GetValueAt("PID:2")
    
    // Post This apparently, from the Slack Help Page on Incoming Web Hooks
    /*
    {
    "text": "New Help Ticket Received:",
    "attachments": [
        {
            "title": "App hangs on reboot",
            "title_link": "http://domain.com/ticket/123456",
            "text": "If I restart my computer without quitting your app, it stops the reboot sequence.\nhttp://domain.com/ticket/123456",
        }
     ]
    }
    */
    
    Set tHttpRequest = ##class(%Net.HttpRequest).%New()
     
     Set tHttpRequest.Server = ..SlackServer
     Set tHttpRequest.Port = ..SlackPort
     
     // This is from the Webhook Generated from Slack
     Set tURL = ..SlackURL
     
     // You need to build an SSL configuration for, Use Firefox or ask me how
    Set tHttpRequest.Https = 1
    Set tHttpRequest.SSLConfiguration = ..SlackSSL
    
    Set tRequestStream = ##class(%GlobalBinaryStream).%New()
    
    // Going out Cheap Here, and not creating an object
    Set tPayLoad = ""
    Set tPayLoad = tPayLoad_"{"
    Set tPayLoad = tPayLoad_"""text"": ""HL7 Message Received: "_tLastName_", "_tFirstName_""","
    Set tPayLoad = tPayLoad_"""attachments"": ["
    Set tPayLoad = tPayLoad_"{"
    Set tPayLoad = tPayLoad_"""title"": ""Integration Type: "_tMessageType_""","
    Set tPayLoad = tPayLoad_"""title_link"": ""http://integration.health.com"","
    Set tPayLoad = tPayLoad_"""text"": ""PatientID: "_tPatientId_""""
    Set tPayLoad = tPayLoad_"}"
    Set tPayLoad = tPayLoad_"]"
    Set tPayLoad = tPayLoad_"}"
    
    $$$LOGINFO(tPayLoad)
    Do tRequestStream.Write(tPayLoad)    
    Set tHttpRequest.EntityBody = tRequestStream
    
    Do tHttpRequest.Post(tURL)
    
    Set tResponse = tHttpRequest.HttpResponse.Data.Read()
    
    Set pResponse = tResponse
    $$$LOGINFO("Slack Response: "_tResponse)
    
    
    Quit tSC
}

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

}

 

 

  • + 8
  • 0
  • 398
  • 3

Comments

Ron! It's just great! Put the code on Github/Gist?

And would you please make online demo of it? ) I mean slack conference with channel from Ensemble? 

Ha, this post really made me laugh out loud. But I do see use cases for this kind of an integration. If you use slack for issue tracking you can easily create  a channel where all Ensemble issues are automatically posted. Inactive Business Services, thrown errors, etc. If Slack is part of your company culture, this is a simple and nice enhancement to your workflow.