ConnectR Post Proc Script

From Galen Healthcare Solutions - Allscripts TouchWorks EHR Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Scenario

In an EHR-inbound microbiology results interface, messages received by the vendor need to be reformatted to enable proper processing.

Approach

Utilization of a post-processing script can facilitate re-formatting of the HL7 message. The target system would then pass the output to another source system such that the message can be processed through a normal inbound interface (HL7->stored procedure).

First define a post-proc script within ConnectR with the desired logic. In the example shown below, the ConnectR VBScript reformats the micro OBX records into a custom MOBX report SSH.

Function PostProcess(sOriginalMessage, sMappedMessage)
On Error Resume Next
PostProcessSS = sMappedMessage
   Dim OBX
   Dim LastNbr
   Dim MOBXLabel()
   Dim MOBXDesc()
   EOLChar = vbCr
   'EOLChar = vbCrLf  'testing

   LastNbr = ""
   LastORG = ""
   Erase MOBXLabel
   Erase MOBXDesc
   
   Dim AbnormalFlag(10)
   Dim AbnormalDesc(10)
   
   AbnormalFlag(0) = "S"
   AbnormalFlag(1) = "R"
  AbnormalFlag(2) = "N"
   AbnormalFlag(3) = "I"
   AbnormalDesc(0) = "     S     "
   AbnormalDesc(1) = "     R     "
   AbnormalDesc(2) = " "
    AbnormalDesc(3) = "     I     "
    AbnormalFlag(4) = "Rx"
    AbnormalDesc(4) = "     Rx     "

   
   LabelMax = 0
   '*
   '*  Strip unwanted control chars
   '*
    sMappedMessage = Replace(sMappedMessage, Chr(11), "")
    sMappedMessage = Replace(sMappedMessage, Chr(28), "")
    SEGArray = Split(sMappedMessage, Chr(13), -1)      '* Create Array based on remaining CR

    SEGCnt = UBound(SEGArray) - 2    ' Account for Null and end of array
    ReDim MOBXLabel(SEGCnt)  'Dynamic Array
    ReDim MOBXDesc(SEGCnt)   'Dynamic Array

    OBSCnt = 0
    For xx = 0 To SEGCnt
      TextStreamIn = SEGArray(xx)
      OBS = Split(TextStreamIn, "|", -1) ' Break into an OBX Array
      If OBS(0) = "OBR" Then
            OBR15append = ""
            If OBS(1) = "1" Then
                inText = "ORDER PROC: "
                sArray = Split(OBS(15) & "^^^^^^", "^")
                If sArray(0) <> "" Then OBR15append = ";  " & sArray(0) & ", " & sArray(3)
           Else
                OBSCnt = OBSCnt + 1  ' Add a blank Line
                Call ResizeArray(MOBXLabel, MOBXDesc, NEWCnt) 'resize Dynamic Array
                MOBXLabel(OBSCnt) = ""
                MOBXDesc(OBSCnt) = ""
                inText = "ORGANISM: "
            End If
            
            OBSCnt = OBSCnt + 1
            Call Labeling(inText, LabelMax)
            MOBXLabel(OBSCnt) = inText
            inText = OBS(4)
            Call ParseV3(inText)
            MOBXDesc(OBSCnt) = inText & OBR15append
            
       End If  ' End OBR
       
      If OBS(0) = "NTE" Then

            oText = OBS(3) & "\.br\"

            NLine = Split(oText, "\.br\", -1)  'force an array
            NLCnt = UBound(NLine) - 1
            Call ResizeArray(MOBXLabel, MOBXDesc, NLCnt + 1) 'Dynamic Array

            For nlx = 0 To NLCnt
                inText = " "
                OBSCnt = OBSCnt + 1
                Call Labeling(inText, LabelMax)
                MOBXLabel(OBSCnt) = inText
                inText = NLine(nlx)
                MOBXDesc(OBSCnt) = inText
            Next

            'OBSCnt = OBSCnt + 1  'Blank Line
            'MOBXLabel(OBSCnt) = ""
            'MOBXLabel(OBSCnt) = ""
       End If  ' End NTE
        
        If OBS(0) = "OBX" Then
            
         'Format Text line
            inText = OBS(3)
            If inText = "ORGANISM" Then inText = inText & " #" & OBS(4)
            Call Labeling(inText, LabelMax)
            Label = inText
            ABNormal = ""
            If OBS(2) = "ST" And OBS(8) <> "" Then
                ABNormal = " "
                       Call TextCheck(OBS(8), lpos, AbnormalFlag)
                If lpos >= 0 Then ABNormal = AbnormalDesc(lpos) & "   "
            End If
            oText = OBS(5)
            
            NewLine = InStr(oText, "\.br\")  ' Check for new line to trigger additional segiments
            If NewLine Then
                NLine = Split(oText, "\.br\", -1)
                oText = NLine(0)  '  Reset oText to first Value
                NEWCnt = UBound(NLine)
                Call ResizeArray(MOBXLabel, MOBXDesc, NEWCnt) 'Dynamic Array
            Else
                inText = oText
                Call ParseV2(inText)
                oText = inText
            End If
            OBSCnt = OBSCnt + 1
            MOBXLabel(OBSCnt) = Label
            MOBXDesc(OBSCnt) = MOBXDesc(OBSCnt) & " " & ABNormal & oText

            If NewLine Then
              NlineCnt = UBound(NLine)
              For Nlinex = 1 To NlineCnt
                  OBSCnt = OBSCnt + 1
                  MOBXLabel(OBSCnt) = Label
                  MOBXDesc(OBSCnt) = MOBXDesc(OBSCnt) & " " & NLine(Nlinex)
              Next
                    
            End If

            
        End If   ' OBX end if
    Next
    '
    ' Build out routine
    '
    OutPutMessage = Chr(11)
    For x = 0 To SEGCnt
       OutPutMessage = OutPutMessage & SEGArray(x) & EOLChar
    Next
    '
    ' Add New MOBX segiments to end of file
    '
    For x = 1 To (OBSCnt)
    
            LabelLen = Len(MOBXLabel(x))
            LabelSpace = LabelMax - LabelLen
            FormatText = "MOBX|" & x & "|" & MOBXLabel(x) & Space(LabelSpace) & LTrim(MOBXDesc(x))
            OutPutMessage = OutPutMessage & FormatText & EOLChar

    Next
    OutPutMessage = OutPutMessage & Chr(28) & Chr(13)

PostProcess = OutPutMessage

End Function

'=====================
' ==Called Subroutines
'=====================

Sub TextCheck(text2find, pos, inArray)
txtDelim = "|"
textString = Join(inArray, txtDelim)
pos = UBound(Split(Mid(textString, 1, InStr(textString, text2find)), txtDelim))
End Sub

Sub Labeling(inText, LabelMax)

Call ParseV2(inText)
Label = inText & ":"
If Len(Label) + 2 > LabelMax Then LabelMax = Len(Label) + 2  'Find longest label length
inText = Label

End Sub

Sub ParseV2(inText)
pos3 = InStr(inText, "^")
inText = mid(intext,(Instr(intext,"^"))+1,InStr(Mid(intext,pos3+1),"^")-1)
'inText = Mid(inText, pos3 + 1, Len(inText))
'pos2 = instr (intext, "^")
'intx = Mid(inText, 1, pos2 -1)
'intext = intx
End Sub

Sub ParseV3(inText)
pos3 = InStr(inText, "^")
inText = mid(intext,(Instr(intext,"^"))+1,InStr(Mid(intext,pos3+1),"^")-1)

End Sub

Sub ResizeArray(MOBXLabel, MOBXDesc, sizeIncrease)
CurCnt = UBound(MOBXDesc)
ReDim Preserve MOBXLabel(sizeIncrease + CurCnt)  'Dynamic Array
ReDim Preserve MOBXDesc(sizeIncrease + CurCnt)   'Dynamic Array
                
End Sub

Next modify the interface mapping to select a Script Type of "Post Script" and specify the script to be the one just created as shown below: CxRPostProcScript.jpg