DGHTRTX ;ALB/JRC - Home Telehealth HL7 Message Monitoring Routine ;10 January 2005 ; 1/17/14 12:02pm
;;5.3;Registration;**644,859**;Aug 13, 1993;Build 8
;
;This routine when tasked will run at predetermined time intervals
;and check to see if there are any HTH HL7 messages that have not
;received an application acknowledgment. If it finds messages that
;have not received AAs, it will retransmit the HL7 messages up to the
;number of times defined in the "DG HTH # OF RETRANSMITS" parameter.
;If no AA is received after the 5th try an alert is sent to the
;DGHTERR mailgroup. After the 5th try an extended wait time is used
;(12 hours) and the process starts a new.
;
EN ;entry point from tasked option, $O thru home telehealth file
;(#391.31) "HTHNOACK" xref and find messages to retransmit
N MSGID,NODE,STATUS,RECORD,TRANS,TYPE,ERROR,RETRANS,DTIME,XTIME
N DGCOUNT,DGDATE,CNT
S (MSGID,NODE,TRANS,ERROR)="",TYPE=1,CNT=0
K ^TMP($J,"DGHT")
;Get number of allowed retransmissions from parameter file
S RETRANS=$$GET^XPAR("SYS","DG HTH # OF RETRANSMITS")
;Get time interval parameters, convert them to seconds
S DTIME=$$GET^XPAR("SYS","DG HTH DEFAULT WAIT TIME")*60
S XTIME=$$GET^XPAR("SYS","DG HTH EXTENDED WAIT TIME")*60
;Resolve record to update using MSGID cross reference
F S MSGID=$O(^DGHT(391.31,"HTHNOACK",MSGID)) Q:MSGID="" D
.S RECORD=$O(^DGHT(391.31,"D",MSGID,0)) Q:'RECORD
.S TRANS=$O(^DGHT(391.31,"D",MSGID,RECORD,0)) Q:'TRANS
.S NODE=$G(^DGHT(391.31,"HTHNOACK",MSGID,RECORD,TRANS))
.Q:NODE=""
.S DGCOUNT=$P(NODE,U,1),DGDATE=$P(NODE,U,2)
.;Check outgoing message status
.; 0 = message doesn't exist
.; 1 = waiting in queue
.; 1.5 = opening connection
.; 1.7 = awaiting response, # of retries
.; 2 = awaiting application ack
.; 3 = successfully completed
.; 4 = error
.; 8 = being generated
.; 9 = awaiting processing
.S STATUS=+$$MSGSTAT^HLUTIL(MSGID)
.;If status=3 kill xref and quit
.I STATUS=3 D KILLXREF^DGHTXREF(MSGID) Q
.D CHKMSG
I $O(^TMP($J,"DGHT",0)) D MESSAGE K ^TMP($J)
Q
;
RTX ;Retransmit message
N X,DGDATE
S X=$$MSGACT^HLUTIL(MSGID,2)
;Update counter and trans date
S DGDATE=$$NOW^XLFDT()
D SETXREF^DGHTXREF(MSGID,1,1)
Q
;
MESSAGE ;Build bulletin and send to mail group
; Input: Home telehealth patient record
; Output:
;
N MSGTEXT,XMTEXT,XMSUB,XMY,XMCHAN,XMZ,XMDUZ,MSGTYPE,NODE0,NODE1
N RECORD,TNODE
;Get records from ^tmp global
S (RECORD,CNT)=0 F S RECORD=$O(^TMP($J,"DGHT",RECORD)) Q:'RECORD D
.S TRANS=0 F S TRANS=$O(^TMP($J,"DGHT",RECORD,TRANS)) Q:'TRANS D
..S TNODE=^TMP($J,"DGHT",RECORD,TRANS)
..S MSGID=$P(TNODE,U,2),ERROR=$P(TNODE,U,2)
..;Get 0th node and trans nodes
..S NODE0=$G(^DGHT(391.31,RECORD,0))
..S NODE1=$G(^DGHT(391.31,RECORD,"TRAN",TRANS,0)),MSGTYPE=$P(NODE1,U,4)
..S MSGTYPE=$S(MSGTYPE="A":"Sign-up/Activation",MSGTYPE="I":"Inactivation",1:""),CNT=CNT+1
..S MSGTEXT(CNT)="Home Telehealth "_MSGTYPE_" was REJECTED",CNT=CNT+1
..S MSGTEXT(CNT)=" ",CNT=CNT+1
..S MSGTEXT(CNT)="Date: "_$$FMTE^XLFDT($$NOW^XLFDT(),1),CNT=CNT+1
..S MSGTEXT(CNT)="Patient: "_$$GET1^DIQ(2,$P(NODE0,U,2),.01,"E")
..S CNT=CNT+1,MSGTEXT(CNT+1)="Message ID: "_MSGID,CNT=CNT+1
..S MSGTEXT(CNT)="Error Code: "_ERROR,CNT=CNT+1
..S MSGTEXT(CNT)="",CNT=CNT+1
..S MSGTEXT(CNT)="Message ID: "_$P(TNODE,U,1),CNT=CNT+1
..S MSGTEXT(CNT)="Activation Date: "_$$GET1^DIQ(391.31,RECORD,5),CNT=CNT+1
..S MSGTEXT(CNT)="Vendor: "_$$GET1^DIQ(391.31,RECORD,2),CNT=CNT+1
;Send message to mail group
S XMSUB="Home Telehealth Patient "_MSGTYPE_" Reject"
S XMTEXT="MSGTEXT("
S XMY("G.DGHTERR")=""
S XMCHAN=1
S XMDUZ="Home Telehealth Patient "_MSGTYPE
D ^XMD
Q
;
CHKMSG ;Check message for retransmission
N DIFF
S DIFF=$$FMDIFF^XLFDT($$NOW^XLFDT(),DGDATE,2)
I DGCOUNT<RETRANS D Q
.I DIFF>DTIME D RTX I (DGCOUNT+1)=RETRANS D Q
..S ERROR=$S('STATUS:"HL7 MESSAGE DOES NOT EXIST. REQUIRES MANUAL RETRANSMISSION",1:"DEFAULT MAXIMUM RETRANSMISSIONS REACHED")
..S ^TMP($J,"DGHT",RECORD,TRANS)=MSGID_U_ERROR
I DIFF>XTIME S DGCOUNT=0 D RTX Q
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HDGHTRTX 4289 printed Oct 16, 2024@18:44:28 Page 2
DGHTRTX ;ALB/JRC - Home Telehealth HL7 Message Monitoring Routine ;10 January 2005 ; 1/17/14 12:02pm
+1 ;;5.3;Registration;**644,859**;Aug 13, 1993;Build 8
+2 ;
+3 ;This routine when tasked will run at predetermined time intervals
+4 ;and check to see if there are any HTH HL7 messages that have not
+5 ;received an application acknowledgment. If it finds messages that
+6 ;have not received AAs, it will retransmit the HL7 messages up to the
+7 ;number of times defined in the "DG HTH # OF RETRANSMITS" parameter.
+8 ;If no AA is received after the 5th try an alert is sent to the
+9 ;DGHTERR mailgroup. After the 5th try an extended wait time is used
+10 ;(12 hours) and the process starts a new.
+11 ;
EN ;entry point from tasked option, $O thru home telehealth file
+1 ;(#391.31) "HTHNOACK" xref and find messages to retransmit
+2 NEW MSGID,NODE,STATUS,RECORD,TRANS,TYPE,ERROR,RETRANS,DTIME,XTIME
+3 NEW DGCOUNT,DGDATE,CNT
+4 SET (MSGID,NODE,TRANS,ERROR)=""
SET TYPE=1
SET CNT=0
+5 KILL ^TMP($JOB,"DGHT")
+6 ;Get number of allowed retransmissions from parameter file
+7 SET RETRANS=$$GET^XPAR("SYS","DG HTH # OF RETRANSMITS")
+8 ;Get time interval parameters, convert them to seconds
+9 SET DTIME=$$GET^XPAR("SYS","DG HTH DEFAULT WAIT TIME")*60
+10 SET XTIME=$$GET^XPAR("SYS","DG HTH EXTENDED WAIT TIME")*60
+11 ;Resolve record to update using MSGID cross reference
+12 FOR
SET MSGID=$ORDER(^DGHT(391.31,"HTHNOACK",MSGID))
if MSGID=""
QUIT
Begin DoDot:1
+13 SET RECORD=$ORDER(^DGHT(391.31,"D",MSGID,0))
if 'RECORD
QUIT
+14 SET TRANS=$ORDER(^DGHT(391.31,"D",MSGID,RECORD,0))
if 'TRANS
QUIT
+15 SET NODE=$GET(^DGHT(391.31,"HTHNOACK",MSGID,RECORD,TRANS))
+16 if NODE=""
QUIT
+17 SET DGCOUNT=$PIECE(NODE,U,1)
SET DGDATE=$PIECE(NODE,U,2)
+18 ;Check outgoing message status
+19 ; 0 = message doesn't exist
+20 ; 1 = waiting in queue
+21 ; 1.5 = opening connection
+22 ; 1.7 = awaiting response, # of retries
+23 ; 2 = awaiting application ack
+24 ; 3 = successfully completed
+25 ; 4 = error
+26 ; 8 = being generated
+27 ; 9 = awaiting processing
+28 SET STATUS=+$$MSGSTAT^HLUTIL(MSGID)
+29 ;If status=3 kill xref and quit
+30 IF STATUS=3
DO KILLXREF^DGHTXREF(MSGID)
QUIT
+31 DO CHKMSG
End DoDot:1
+32 IF $ORDER(^TMP($JOB,"DGHT",0))
DO MESSAGE
KILL ^TMP($JOB)
+33 QUIT
+34 ;
RTX ;Retransmit message
+1 NEW X,DGDATE
+2 SET X=$$MSGACT^HLUTIL(MSGID,2)
+3 ;Update counter and trans date
+4 SET DGDATE=$$NOW^XLFDT()
+5 DO SETXREF^DGHTXREF(MSGID,1,1)
+6 QUIT
+7 ;
MESSAGE ;Build bulletin and send to mail group
+1 ; Input: Home telehealth patient record
+2 ; Output:
+3 ;
+4 NEW MSGTEXT,XMTEXT,XMSUB,XMY,XMCHAN,XMZ,XMDUZ,MSGTYPE,NODE0,NODE1
+5 NEW RECORD,TNODE
+6 ;Get records from ^tmp global
+7 SET (RECORD,CNT)=0
FOR
SET RECORD=$ORDER(^TMP($JOB,"DGHT",RECORD))
if 'RECORD
QUIT
Begin DoDot:1
+8 SET TRANS=0
FOR
SET TRANS=$ORDER(^TMP($JOB,"DGHT",RECORD,TRANS))
if 'TRANS
QUIT
Begin DoDot:2
+9 SET TNODE=^TMP($JOB,"DGHT",RECORD,TRANS)
+10 SET MSGID=$PIECE(TNODE,U,2)
SET ERROR=$PIECE(TNODE,U,2)
+11 ;Get 0th node and trans nodes
+12 SET NODE0=$GET(^DGHT(391.31,RECORD,0))
+13 SET NODE1=$GET(^DGHT(391.31,RECORD,"TRAN",TRANS,0))
SET MSGTYPE=$PIECE(NODE1,U,4)
+14 SET MSGTYPE=$SELECT(MSGTYPE="A":"Sign-up/Activation",MSGTYPE="I":"Inactivation",1:"")
SET CNT=CNT+1
+15 SET MSGTEXT(CNT)="Home Telehealth "_MSGTYPE_" was REJECTED"
SET CNT=CNT+1
+16 SET MSGTEXT(CNT)=" "
SET CNT=CNT+1
+17 SET MSGTEXT(CNT)="Date: "_$$FMTE^XLFDT($$NOW^XLFDT(),1)
SET CNT=CNT+1
+18 SET MSGTEXT(CNT)="Patient: "_$$GET1^DIQ(2,$PIECE(NODE0,U,2),.01,"E")
+19 SET CNT=CNT+1
SET MSGTEXT(CNT+1)="Message ID: "_MSGID
SET CNT=CNT+1
+20 SET MSGTEXT(CNT)="Error Code: "_ERROR
SET CNT=CNT+1
+21 SET MSGTEXT(CNT)=""
SET CNT=CNT+1
+22 SET MSGTEXT(CNT)="Message ID: "_$PIECE(TNODE,U,1)
SET CNT=CNT+1
+23 SET MSGTEXT(CNT)="Activation Date: "_$$GET1^DIQ(391.31,RECORD,5)
SET CNT=CNT+1
+24 SET MSGTEXT(CNT)="Vendor: "_$$GET1^DIQ(391.31,RECORD,2)
SET CNT=CNT+1
End DoDot:2
End DoDot:1
+25 ;Send message to mail group
+26 SET XMSUB="Home Telehealth Patient "_MSGTYPE_" Reject"
+27 SET XMTEXT="MSGTEXT("
+28 SET XMY("G.DGHTERR")=""
+29 SET XMCHAN=1
+30 SET XMDUZ="Home Telehealth Patient "_MSGTYPE
+31 DO ^XMD
+32 QUIT
+33 ;
CHKMSG ;Check message for retransmission
+1 NEW DIFF
+2 SET DIFF=$$FMDIFF^XLFDT($$NOW^XLFDT(),DGDATE,2)
+3 IF DGCOUNT<RETRANS
Begin DoDot:1
+4 IF DIFF>DTIME
DO RTX
IF (DGCOUNT+1)=RETRANS
Begin DoDot:2
+5 SET ERROR=$SELECT('STATUS:"HL7 MESSAGE DOES NOT EXIST. REQUIRES MANUAL RETRANSMISSION",1:"DEFAULT MAXIMUM RETRANSMISSIONS REACHED")
+6 SET ^TMP($JOB,"DGHT",RECORD,TRANS)=MSGID_U_ERROR
End DoDot:2
QUIT
End DoDot:1
QUIT
+7 IF DIFF>XTIME
SET DGCOUNT=0
DO RTX
QUIT
+8 QUIT