Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: MHV7R4

MHV7R4.m

Go to the documentation of this file.
  1. MHV7R4 ;WAS/GPM - HL7 RECEIVER FOR SECURE MESSAGING QRY^A19 ; [3/23/08 9:32pm]
  1. ;;1.0;My HealtheVet;**5**;Aug 23, 2005;Build 24
  1. ;;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. Q
  1. ;
  1. QRYA19 ;Process QRY^A19 messages from the MHVSM QRY-A19 Subscriber protocol
  1. ;
  1. ; This routine and subroutines assume that all VistA HL7 environment
  1. ; variables are properly initialized and will produce a fatal error
  1. ; if they are missing.
  1. ;
  1. ; The message will be checked to see if it is a valid query.
  1. ; If not a negative acknowledgement will be sent. If the query is an
  1. ; immediate mode or synchronous query, the realtime request manager
  1. ; is called to handle the query. This means the query will be
  1. ; processed and a response generated immediately.
  1. ; In the future deferred mode queries may be filed in a database for
  1. ; later processing, or transmission.
  1. ;
  1. ; Input:
  1. ; HL7 environment variables
  1. ;
  1. ; Output:
  1. ; Processed query or negative acknowledgement
  1. ; If handled real-time the query response is generated
  1. ;
  1. N MSGROOT,QRY,XMT,ERR,RNAME
  1. S (QRY,XMT,ERR)=""
  1. ; Inbound query messages are small enough to be held in a local.
  1. ; The following lines commented out support use of global and are
  1. ; left in case use a global becomes necessary.
  1. ;S MSGROOT="^TMP(""MHV7"",$J)"
  1. ;K @MSGROOT
  1. S MSGROOT="MHV7MSG"
  1. N MHV7MSG
  1. D LOADXMT^MHV7U(.XMT) ;Load inbound message information
  1. ;
  1. S RNAME="SM "_XMT("MESSAGE TYPE")_"-"_XMT("EVENT TYPE")_" RECEIVER"
  1. D LOG^MHVUL2(RNAME,"BEGIN","S","TRACE")
  1. ;
  1. D LOADMSG^MHV7U(MSGROOT)
  1. D LOG^MHVUL2("LOAD",MSGROOT,"I","DEBUG")
  1. ;
  1. D PARSEMSG^MHV7U(MSGROOT,.HL)
  1. D LOG^MHVUL2("PARSE",MSGROOT,"I","DEBUG")
  1. ;
  1. I '$$VALIDMSG(MSGROOT,.QRY,.XMT,.ERR) D Q
  1. . D LOG^MHVUL2("MSG CHECK","INVALID^"_ERR,"S","ERROR")
  1. . D XMIT^MHV7T(.QRY,.XMT,ERR,"",.HL)
  1. D LOG^MHVUL2("MSG CHECK","VALID","S","TRACE")
  1. ;
  1. ; Immediate Mode
  1. ; Deferred mode queries are not supported at this time
  1. D REALTIME^MHVRQI(.QRY,.XMT,.HL)
  1. ;
  1. D LOG^MHVUL2(RNAME,"END","S","TRACE")
  1. D RESET^MHVUL2 ;Clean up TMP used by logging
  1. ;K @MSGROOT
  1. ;
  1. Q
  1. ;
  1. VALIDMSG(MSGROOT,QRY,XMT,ERR) ;Validate message
  1. ;
  1. ; Messages handled: QRY^A19 - Demographics
  1. ;
  1. ; Old style query messages must contain QRD and QRF segments.
  1. ; Any additional segments are ignored.
  1. ;
  1. ; The following sequences are required
  1. ; QRD(1)* - Query Date/Time
  1. ; QRD(2)* - Query Format Code
  1. ; QRD(3) - Query Priority
  1. ; QRD(4) - Query ID
  1. ; QRD(8) - Who Subject Filter
  1. ; QRD(9)* - What Subject Filter
  1. ; QRD(10) - What Dept. Data Code
  1. ; QRF(1)* - Where Subject Filter
  1. ; * required by HL7 standard but not used by MHV
  1. ; Name fields in Who Subject Filter also not used
  1. ;
  1. ; The following sequences are optional
  1. ; QRD(7) - Quantity Limited Request
  1. ; QRF(2) - When Data Start Date/Time
  1. ; QRF(3) - When Data End Date/Time
  1. ;
  1. ; Input:
  1. ; MSGROOT - Root of array holding message
  1. ; XMT - Transmission parameters
  1. ;
  1. ; Output:
  1. ; QRY - Query Array
  1. ; XMT - Transmission parameters
  1. ; ERR - segment^sequence^field^code^ACK type^error text
  1. ;
  1. N MSH,QRD,QRF,ICN,DFN,SSN,I,ID,REQTYPE,PRI,REQID,TYPE,FROMDT,TODT,SEGTYPE,CNT,FAMILY,GIVEN,MIDDLE,SUFFIX,FORMAT,WHAT,WHERE,OCNT,QTY,QDATE,UNIT
  1. K QRY,ERR
  1. S ERR=""
  1. ;
  1. ; Set up basics for responding to message.
  1. ;-----------------------------------------
  1. S QRY("MID")=XMT("MID") ;Message ID
  1. S QRY("QRD")=""
  1. S QRY("QRF")=""
  1. ;
  1. ; Validate message is a well-formed old style query message.
  1. ;-----------------------------------------------------------
  1. ; Must have MSH first followed by QRD, and QRF in any order.
  1. ; Any other segments are ignored.
  1. ;
  1. I $G(@MSGROOT@(1,0))="MSH" M MSH=@MSGROOT@(1)
  1. E S ERR="MSH^1^^100^AE^Missing MSH segment" Q 0
  1. ;
  1. S CNT=2,OCNT=0
  1. F Q:'$D(@MSGROOT@(CNT)) D S CNT=CNT+1
  1. . S SEGTYPE=$G(@MSGROOT@(CNT,0))
  1. . I SEGTYPE="QRD" M QRD=@MSGROOT@(CNT),QRY("QRD")=QRD Q
  1. . I SEGTYPE="QRF" M QRF=@MSGROOT@(CNT),QRY("QRF")=QRF Q
  1. . Q
  1. ;
  1. I '$D(QRD) S ERR="QRD^1^^100^AE^Missing QRD segment" Q 0
  1. I '$D(QRF) S ERR="QRF^1^^100^AE^Missing QRF segment" Q 0
  1. ;
  1. ; Validate required fields and query parameters
  1. ;------------------------------------------------------
  1. S QDATE=$G(QRD(1)) ;Query Date/Time
  1. S FORMAT=$G(QRD(2)) ;Query Format Code
  1. S PRI=$G(QRD(3)) ;Query Priority
  1. S REQID=$G(QRD(4)) ;Query ID - Request ID
  1. S QTY=$G(QRD(7,1,1)) ;Quantity Limited Request
  1. S UNIT=$G(QRD(7,1,2)) ;Quantity Units
  1. S WHAT=$G(QRD(9,1,1)) ;What Subject Filter
  1. S REQTYPE=$G(QRD(10)) ;What Dept. Data Code - Request Type
  1. S WHERE=$G(QRF(1)) ;Where Subject Filter
  1. S FROMDT=$G(QRF(2)) ;When Data Start Date/Time - From Date
  1. S TODT=$G(QRF(3)) ;When Data End Date/Time - To Date
  1. ;
  1. I QDATE="" S ERR="QRD^1^1^101^AE^Missing Query Date/Time" Q 0
  1. I '$$VALIDDT^MHV7RU(.QDATE) S ERR="QRD^1^1^102^AE^Invalid Query Date/Time" Q 0
  1. ;
  1. I FORMAT="" S ERR="QRD^1^2^101^AE^Missing Query Format Code" Q 0
  1. I FORMAT'="R" S ERR="QRD^1^2^102^AE^Invalid Query Format Code" Q 0
  1. ;
  1. I PRI="" S ERR="QRD^1^3^101^AE^Missing Query Priority" Q 0
  1. I ",D,I,"'[(","_PRI_",") S ERR="QRD^1^3^102^AE^Invalid Query Priority" Q 0
  1. S QRY("PRI")=PRI
  1. ;
  1. I REQID="" S ERR="QRD^1^4^101^AE^Missing Request ID" Q 0
  1. S QRY("REQID")=REQID
  1. ;
  1. I QTY'?0.N S ERR="QRD^1^7^102^AE^Invalid Quantity" Q 0
  1. S QRY("QTY")=+QTY
  1. S XMT("MAX SIZE")=+QTY
  1. ;
  1. I QTY,UNIT'="CH" S ERR="QRD^1^7^102^AE^Invalid Units" Q 0
  1. ;
  1. I WHAT="" S ERR="QRD^1^9^101^AE^Missing What Subject Filter" Q 0
  1. ;
  1. I REQTYPE="" S ERR="QRD^1^10^101^AE^Missing Request Type" Q 0
  1. I '$$VALRTYPE^MHV7RU(REQTYPE,.QRY,.ERR) S ERR="QRD^1^10^"_ERR Q 0
  1. ;
  1. I '$$VALIDWHO^MHV7RUS(.QRD,.QRY,.ERR) Q 0
  1. ;
  1. I WHERE="" S ERR="QRF^1^1^101^AE^Missing Where Subject Filter" Q 0
  1. ;
  1. I '$$VALIDDT^MHV7RU(.FROMDT) S ERR="QRF^1^2^102^AE^Invalid From Date" Q 0
  1. S QRY("FROM")=FROMDT
  1. I '$$VALIDDT^MHV7RU(.TODT) S ERR="QRF^1^3^102^AE^Invalid To Date" Q 0
  1. I TODT'="",TODT<FROMDT S ERR="QRF^1^3^102^AE^To Date precedes From Date" Q 0
  1. S QRY("TO")=TODT
  1. ;
  1. ; Get HL7 delimiters to be used in the response message
  1. ; Some extractors call APIs that require delimiters to be passed
  1. S QRY("DELIM")=XMT("DELIM")
  1. I XMT("MODE")="A" S QRY("DELIM")=$$DELIM^MHV7U(XMT("PROTOCOL"))
  1. ;
  1. Q 1
  1. ;