HLEVAPI ;O-OIFO/LJA - Event Monitor APIs ;02/04/2004 14:42
;;1.6;HEALTH LEVEL SEVEN;**109,161**;Oct 13, 1995;Build 6
;
; Routine Supported APIs...
; -----------------------------------------------------------------
; HLEVAPI START(VAR)
; HLEVAPI CHECKIN
; HLEVAPI CHECKOUT
; HLEVAPI ABORT(STATUS,APPLSTAT)
; HLEVAPI MAILIT
; HLEVAPI VARIABLE
; -----------------------------------------------------------------
; HLEVAPI0 ONOFFM(HLEVIENE)
; -----------------------------------------------------------------
; HLEVAPI1 APPSTAT(STATUS)
; HLEVAPI1 MSGTEXT(GBL)
; HLEVAPI1 RUNDIARY(GBL)
;
;
; Test server code with TEST^HLEVSRV1 (Also HLEVMNU)
; Test monitor code with TEST^HLEVUTI1 (Also HLEVMNU)
;
;
; EVENT CODE
;
VARIABLE(HLEVIENJ,HLVAR) ; Store passed in variables...
; HLVAR can be the name of a variable, like "CT", or it can be
; a list of variables passed by reference.
N VAL,VAR
;
D DEBUG^HLEVAPI2("VARIABLE") ; Debug data created conditionally
;
; Stop all event monitoring to enable on-site debugging...
QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
;
QUIT:$G(^HLEV(776,+$G(HLEVIENJ),0))']"" ;->
;
; Loop thru array...
S VAR=""
F S VAR=$O(HLVAR(VAR)) Q:VAR']"" D
. I $E(VAR,$L(VAR))="*" D QUIT ;->
. . QUIT:VAR="*" ;->
. . D VARSTAR(HLEVIENJ,VAR)
. D STOREIT(HLEVIENJ,VAR,$S($D(@VAR):@VAR,1:"---"),$G(HLVAR(VAR)))
;
Q
;
VARSTAR(HLEVIENJ,VAR) ; Store VAR* variables...
N GBL,LP,REF,ROOT,X,X1
;
KILL ^TMP("HLORDER",$J)
S GBL=$NA(^TMP("HLORDER",$J)),ROOT=$E(GBL,1,$L(GBL)-1)_","
S X=ROOT,X1(VAR)="" D ORDER^%ZOSV
QUIT:'$D(GBL) ;->
;
; $Q thru global...
S LP=GBL
F S LP=$Q(@LP) Q:LP'[ROOT D
. S REF=$P(LP,ROOT,2) QUIT:REF'[")" ;->
. S REF=$P($TR(REF,"""",""),")") QUIT:REF']"" ;->
. I $L(REF)>10 S REF=$E(REF,1,9)_"~"
. D STOREIT(+HLEVIENJ,REF,@LP)
;
Q
;
STOREIT(HLEVIENJ,VAR,VAL,EXPL) ; Store VAR in 776...
N MIEN
S EXPL=$G(EXPL)
S MIEN=$O(^HLEV(776,+HLEVIENJ,52,"B",VAR,0))
I MIEN'>0 S MIEN=$O(^HLEV(776,+HLEVIENJ,52,":"),-1)+1
S ^HLEV(776,+HLEVIENJ,52,+MIEN,0)=VAR_$S(EXPL]"":U_EXPL,1:"")
S ^HLEV(776,+HLEVIENJ,52,+MIEN,52)=VAL
S ^HLEV(776,+HLEVIENJ,52,"B",VAR,MIEN)=""
S MIEN=$O(^HLEV(776,+HLEVIENJ,52,":"),-1)
I MIEN'>0 KILL ^HLEV(776,+HLEVIENJ,52) QUIT ;->
S ^HLEV(776,+HLEVIENJ,52,0)="^776.003A^"_MIEN_U_MIEN
Q
;
STOREVAR ; Update VARIABLE VALUE multiple in 776...
; HLEVIENJ -- req
;
; Stop all event monitoring to enable on-site debugging...
QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
;
N MIEN,VAL,VAR
; Store variable values in 776...
S VAR=""
F S VAR=$O(HLEVAR(VAR)) Q:VAR']"" D
. S VAL=$S($D(@VAR):@VAR,1:"---")
. S MIEN=$O(^HLEV(776,+HLEVIENJ,52,"B",VAR,0))
. I MIEN'>0 S MIEN=$O(^HLEV(776,+HLEVIENJ,52,":"),-1)+1
. S ^HLEV(776,+HLEVIENJ,52,+MIEN,0)=VAR_U_HLEVAR(VAR)
. S ^HLEV(776,+HLEVIENJ,52,+MIEN,52)=VAL
. S ^HLEV(776,+HLEVIENJ,52,"B",VAR,MIEN)=""
S MIEN=$O(^HLEV(776,+HLEVIENJ,52,":"),-1)
I MIEN'>0 KILL ^HLEV(776,+HLEVIENJ,52) QUIT ;->
S ^HLEV(776,+HLEVIENJ,52,0)="^776.003A^"_MIEN_U_MIEN
Q
;
START(VARIABLE) ; Start the whole monitoring process.
; HLEVIENE,HLEVIENJ,HLEVIENM -- req --> HLEVAR()
;
; - Pass in by reference the VARIABLEs being tracked.
;
; >S VAR("VARNAME")="REPORT-VARNAME"
; >D DECLARE("MONITOR-NAME",.VAR)
;
N E,EXPL,I,MIEN,NO,NODE,TXT,VAR
;
D DEBUG^HLEVAPI2("START") ; Debug data created conditionally
;
; Stop all event monitoring to enable on-site debugging...
QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
;
; Check STATUS-EVENT...
QUIT:$P($G(^HLEV(776.999,1,0)),U,6)'="A" ;->
;
; Presets...
S NO=0
KILL HLEVAR
;
; If passed in a variable name directly in VARIABLE
I $G(VARIABLE)]"" F PCE=1:1:$L(VARIABLE,U) D
. S X=$P(VARIABLE,U,+PCE) I X]"" S NO=NO+1,HLEVAR(X)=X
;
; Convert passed in variable to format expected by CHECKIN & CHECKOUT
S VAR=""
F S VAR=$O(VARIABLE(VAR)) Q:VAR']"" D
. S EXPL=VARIABLE(VAR) S:EXPL']"" EXPL=VAR
. S NO=NO+1,HLEVAR(VAR)=EXPL
;
KILL VARIABLE
;
; Make initial DIARY entry...
S TXT="DECLARE called - "_$P($G(^HLEV(776.1,+HLEVIENE,0)),U)
D WPTXT^HLEVUTIL(776,HLEVIENJ,50,776.001,TXT)
;
Q
;
CHECKIN ; Call here to update the EVENT using "your" DECLARE variables...
N D,D0,DA,DI,DIE,DR,NO
;
D DEBUG^HLEVAPI2("CHECKIN") ; Debug data created conditionally
;
; Stop all event monitoring to enable on-site debugging...
QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
;
; Does entry exist?
QUIT:$G(^HLEV(776,+$G(HLEVIENJ),0))']"" ;->
;
D STOREVAR
;
; Fill in zero node...
S DA=+HLEVIENJ,DIE=776
S DR="4///R;6////"_$$NOW^XLFDT
D ^DIE
;
Q
;
ABORT(STATUS,APPLST) ; Call here if job is to be aborted...
N DA,DIE,DR,NOW
;
D DEBUG^HLEVAPI2("ABORT") ; Debug data created conditionally
;
; Stop all event monitoring to enable on-site debugging...
QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
;
; Does entry exist?
QUIT:$G(^HLEV(776,+$G(HLEVIENJ),0))']"" ;->
;
D CHECKIN
;
S DA=+HLEVIENJ,DIE=776
S NOW=$$NOW^XLFDT
S STATUS=$E($$UP^XLFSTR($G(STATUS)_" "))
S STATUS=$S("EFQR"[STATUS:STATUS,1:"E")
S DR="2////"_NOW_";4///"_STATUS_";6////"_NOW
S:$G(APPLST)]"" DR=DR_";5///"_$TR($E(APPLST,1,10),U,"~")
D ^DIE
;
D EVCHKD^HLEVAPI2($G(HLEVIENM),$G(HLEVIENE),$G(HLEVIENJ),STATUS)
;
KILL HLEVAR ; Passed-in user variables...
;
Q
;
CHECKOUT ; Call here to end EVENT using "your" DECLARE variables...
N DA,DIE,DR,NOW
;
D DEBUG^HLEVAPI2("CHECKOUT") ; Debug data created conditionally
;
; Stop all event monitoring to enable on-site debugging...
QUIT:$G(^TMP("HLEVFLAG",$J))["STOP" ;->
;
; Does entry exist?
QUIT:$G(^HLEV(776,+$G(HLEVIENJ),0))']"" ;->
;
D CHECKIN
;
S DA=+HLEVIENJ,DIE=776
S NOW=$$NOW^XLFDT
S DR="2////"_NOW_";4///F;6////"_NOW
D ^DIE
;
D EVCHKD^HLEVAPI2($G(HLEVIENM),$G(HLEVIENE),$G(HLEVIENJ))
;
KILL HLEVAR ; Passed-in user variables...
;
Q
;
MAILIT D MAILIT^HLEVAPI3
Q
;
SENDMAIL(HLEVIENE,HLEVIENJ,XMY) ; Mail info in 776 event monitor's ^(51)...
;
; PARAMETER NOTES
; ---------------------------------------------------------------------
; XMY Pass in XMY by reference.
; XMSUB If XMSUB pre-exists, it will be used.
; XMTEXT The text for the mailman message will come from one of
; three sources:
; (1) If XMTEXT is pre-set, it will be used.
; (2) If XMTEXT is not passed in, then the MAILMAN MESSAGE
; TEXT global ^HLEV(776,IEN,51,#,0) will be used, if it
; exits.
; (3) Otherwise, a generic "message is completed" message
; will be sent.
;
N MGRP,NO,SITE,TEXT,XMDUZ,X,XMZ
;
; If no recipients passed in and no mail group exists, quit...
QUIT:$O(XMY(""))']"" ;->
;
QUIT:$P($G(^HLEV(776.1,+$G(HLEVIENE),0)),U)']"" ;->
QUIT:$P($G(^HLEV(776,+$G(HLEVIENJ),0)),U)']"" ;->
;
; Set up sending...
S XMDUZ=.5
;
; Subject...
S X=$$SITE^VASITE,SITE="HL7 Monitor - "_$P(X,U,2)_"["_$P(X,U,3)_"]"
S XMSUB=$S($G(XMSUB)]"":XMSUB,1:SITE_" - "_$P($G(^HLEV(776.1,+HLEVIENE,0)),U))
;
; Load generic message text...
I $G(XMTEXT)']"" D
. KILL ^TMP($J,"HLMAILMSG")
. D LOADALL^HLEVAPI1(+HLEVIENJ,"HLMAILMSG")
;
; Declare where message is stored...
S XMTEXT=$S($G(XMTEXT)]"":XMTEXT,1:"^TMP("_$J_",""HLMAILMSG"",")
;
D ^XMD
;
I '$D(ZTQUEUED) W !!,"Mail message #",$G(XMZ),"..."
;
I $G(XMZ)>0 D UPDFLDE(+HLEVIENJ,7,XMZ)
;
Q
;
NEWEVENT(HLEVIENE,QTIME) ; Create a new EVENT and pass back IEN...
N DIC,DD,DO,X,Y
;
; Check STATUS-EVENT...return null("") if inactive HL*161
QUIT:$P($G(^HLEV(776.999,1,0)),U,6)'="A" "" ;->
;
S X=$$NOW^XLFDT,DIC="^HLEV(776,",DIC(0)="L"
S DIC("DR")="3////"_HLEVIENE_";4///Q"
I $G(HLEVIENM)>0 S DIC("DR")=DIC("DR")_";9////"_HLEVIENM
I $G(QTIME)]"" S DIC("DR")=DIC("DR")_";10////"_QTIME
D FILE^DICN
;
Q $S(+Y>0:+Y,1:"")
;
UPDFLDE(HLEVIENJ,FLD,VAL) ; Update a specific piece in 776...
N DA,DIE,DR
;
QUIT:$G(^HLEV(776,+$G(HLEVIENJ),0))']"" ;->
;
; Field 50, RUN DIARY...
I FLD=50 D QUIT ;->
. N DIFF,NO,NOW,TIME
. S NO=$O(^HLEV(776,+HLEVIENJ,50,":"),-1)+1
. S ^HLEV(776,+HLEVIENJ,50,0)="^776.001^"_NO_U_NO
. S ^HLEV(776,+HLEVIENJ,50,+NO,0)=$G(VAL)
. ; If FLD=50, update timestamp every 30 seconds...
. ; (This is because many 50 nodes might be updated, one after the
. ; other in a very disk-intensive way.)
. S TIME=$P($G(^HLEV(776,+HLEVIENJ,0)),U,6) ; FM format
. S NOW=$$NOW^XLFDT
. S DIFF=$$FMDIFF^XLFDT(NOW,TIME,2) S:DIFF<0 DIFF=-DIFF
. QUIT:DIFF<30 ;->
. S DA=+HLEVIENJ,DIE=776,DR="6////"_NOW
;
; Fields 401-408...
I FLD?3N&(FLD>400)&(FLD<409) D QUIT ;->
. S ^HLEV(776,+HLEVIENJ,FLD)=VAL
;
; Zero node data...
QUIT:$G(VAL)']"" ;->
S DA=+HLEVIENJ,DIE=776,DR=FLD_"///"_VAL_";6////"_$$NOW^XLFDT
D ^DIE
;
I FLD=2 D EVCHKD^HLEVAPI2($G(HLEVIENM),$G(HLEVIENE),$G(HLEVIENJ))
;
Q
;
EOR ;HLEVAPI - Event Monitor APIs ;5/16/03 14:42
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHLEVAPI 9162 printed Dec 13, 2024@01:57:40 Page 2
HLEVAPI ;O-OIFO/LJA - Event Monitor APIs ;02/04/2004 14:42
+1 ;;1.6;HEALTH LEVEL SEVEN;**109,161**;Oct 13, 1995;Build 6
+2 ;
+3 ; Routine Supported APIs...
+4 ; -----------------------------------------------------------------
+5 ; HLEVAPI START(VAR)
+6 ; HLEVAPI CHECKIN
+7 ; HLEVAPI CHECKOUT
+8 ; HLEVAPI ABORT(STATUS,APPLSTAT)
+9 ; HLEVAPI MAILIT
+10 ; HLEVAPI VARIABLE
+11 ; -----------------------------------------------------------------
+12 ; HLEVAPI0 ONOFFM(HLEVIENE)
+13 ; -----------------------------------------------------------------
+14 ; HLEVAPI1 APPSTAT(STATUS)
+15 ; HLEVAPI1 MSGTEXT(GBL)
+16 ; HLEVAPI1 RUNDIARY(GBL)
+17 ;
+18 ;
+19 ; Test server code with TEST^HLEVSRV1 (Also HLEVMNU)
+20 ; Test monitor code with TEST^HLEVUTI1 (Also HLEVMNU)
+21 ;
+22 ;
+23 ; EVENT CODE
+24 ;
VARIABLE(HLEVIENJ,HLVAR) ; Store passed in variables...
+1 ; HLVAR can be the name of a variable, like "CT", or it can be
+2 ; a list of variables passed by reference.
+3 NEW VAL,VAR
+4 ;
+5 ; Debug data created conditionally
DO DEBUG^HLEVAPI2("VARIABLE")
+6 ;
+7 ; Stop all event monitoring to enable on-site debugging...
+8 ;->
if $GET(^TMP("HLEVFLAG",$JOB))["STOP"
QUIT
+9 ;
+10 ;->
if $GET(^HLEV(776,+$GET(HLEVIENJ),0))']""
QUIT
+11 ;
+12 ; Loop thru array...
+13 SET VAR=""
+14 FOR
SET VAR=$ORDER(HLVAR(VAR))
if VAR']""
QUIT
Begin DoDot:1
+15 ;->
IF $EXTRACT(VAR,$LENGTH(VAR))="*"
Begin DoDot:2
+16 ;->
if VAR="*"
QUIT
+17 DO VARSTAR(HLEVIENJ,VAR)
End DoDot:2
QUIT
+18 DO STOREIT(HLEVIENJ,VAR,$SELECT($DATA(@VAR):@VAR,1:"---"),$GET(HLVAR(VAR)))
End DoDot:1
+19 ;
+20 QUIT
+21 ;
VARSTAR(HLEVIENJ,VAR) ; Store VAR* variables...
+1 NEW GBL,LP,REF,ROOT,X,X1
+2 ;
+3 KILL ^TMP("HLORDER",$JOB)
+4 SET GBL=$NAME(^TMP("HLORDER",$JOB))
SET ROOT=$EXTRACT(GBL,1,$LENGTH(GBL)-1)_","
+5 SET X=ROOT
SET X1(VAR)=""
DO ORDER^%ZOSV
+6 ;->
if '$DATA(GBL)
QUIT
+7 ;
+8 ; $Q thru global...
+9 SET LP=GBL
+10 FOR
SET LP=$QUERY(@LP)
if LP'[ROOT
QUIT
Begin DoDot:1
+11 ;->
SET REF=$PIECE(LP,ROOT,2)
if REF'[")"
QUIT
+12 ;->
SET REF=$PIECE($TRANSLATE(REF,"""",""),")")
if REF']""
QUIT
+13 IF $LENGTH(REF)>10
SET REF=$EXTRACT(REF,1,9)_"~"
+14 DO STOREIT(+HLEVIENJ,REF,@LP)
End DoDot:1
+15 ;
+16 QUIT
+17 ;
STOREIT(HLEVIENJ,VAR,VAL,EXPL) ; Store VAR in 776...
+1 NEW MIEN
+2 SET EXPL=$GET(EXPL)
+3 SET MIEN=$ORDER(^HLEV(776,+HLEVIENJ,52,"B",VAR,0))
+4 IF MIEN'>0
SET MIEN=$ORDER(^HLEV(776,+HLEVIENJ,52,":"),-1)+1
+5 SET ^HLEV(776,+HLEVIENJ,52,+MIEN,0)=VAR_$SELECT(EXPL]"":U_EXPL,1:"")
+6 SET ^HLEV(776,+HLEVIENJ,52,+MIEN,52)=VAL
+7 SET ^HLEV(776,+HLEVIENJ,52,"B",VAR,MIEN)=""
+8 SET MIEN=$ORDER(^HLEV(776,+HLEVIENJ,52,":"),-1)
+9 ;->
IF MIEN'>0
KILL ^HLEV(776,+HLEVIENJ,52)
QUIT
+10 SET ^HLEV(776,+HLEVIENJ,52,0)="^776.003A^"_MIEN_U_MIEN
+11 QUIT
+12 ;
STOREVAR ; Update VARIABLE VALUE multiple in 776...
+1 ; HLEVIENJ -- req
+2 ;
+3 ; Stop all event monitoring to enable on-site debugging...
+4 ;->
if $GET(^TMP("HLEVFLAG",$JOB))["STOP"
QUIT
+5 ;
+6 NEW MIEN,VAL,VAR
+7 ; Store variable values in 776...
+8 SET VAR=""
+9 FOR
SET VAR=$ORDER(HLEVAR(VAR))
if VAR']""
QUIT
Begin DoDot:1
+10 SET VAL=$SELECT($DATA(@VAR):@VAR,1:"---")
+11 SET MIEN=$ORDER(^HLEV(776,+HLEVIENJ,52,"B",VAR,0))
+12 IF MIEN'>0
SET MIEN=$ORDER(^HLEV(776,+HLEVIENJ,52,":"),-1)+1
+13 SET ^HLEV(776,+HLEVIENJ,52,+MIEN,0)=VAR_U_HLEVAR(VAR)
+14 SET ^HLEV(776,+HLEVIENJ,52,+MIEN,52)=VAL
+15 SET ^HLEV(776,+HLEVIENJ,52,"B",VAR,MIEN)=""
End DoDot:1
+16 SET MIEN=$ORDER(^HLEV(776,+HLEVIENJ,52,":"),-1)
+17 ;->
IF MIEN'>0
KILL ^HLEV(776,+HLEVIENJ,52)
QUIT
+18 SET ^HLEV(776,+HLEVIENJ,52,0)="^776.003A^"_MIEN_U_MIEN
+19 QUIT
+20 ;
START(VARIABLE) ; Start the whole monitoring process.
+1 ; HLEVIENE,HLEVIENJ,HLEVIENM -- req --> HLEVAR()
+2 ;
+3 ; - Pass in by reference the VARIABLEs being tracked.
+4 ;
+5 ; >S VAR("VARNAME")="REPORT-VARNAME"
+6 ; >D DECLARE("MONITOR-NAME",.VAR)
+7 ;
+8 NEW E,EXPL,I,MIEN,NO,NODE,TXT,VAR
+9 ;
+10 ; Debug data created conditionally
DO DEBUG^HLEVAPI2("START")
+11 ;
+12 ; Stop all event monitoring to enable on-site debugging...
+13 ;->
if $GET(^TMP("HLEVFLAG",$JOB))["STOP"
QUIT
+14 ;
+15 ; Check STATUS-EVENT...
+16 ;->
if $PIECE($GET(^HLEV(776.999,1,0)),U,6)'="A"
QUIT
+17 ;
+18 ; Presets...
+19 SET NO=0
+20 KILL HLEVAR
+21 ;
+22 ; If passed in a variable name directly in VARIABLE
+23 IF $GET(VARIABLE)]""
FOR PCE=1:1:$LENGTH(VARIABLE,U)
Begin DoDot:1
+24 SET X=$PIECE(VARIABLE,U,+PCE)
IF X]""
SET NO=NO+1
SET HLEVAR(X)=X
End DoDot:1
+25 ;
+26 ; Convert passed in variable to format expected by CHECKIN & CHECKOUT
+27 SET VAR=""
+28 FOR
SET VAR=$ORDER(VARIABLE(VAR))
if VAR']""
QUIT
Begin DoDot:1
+29 SET EXPL=VARIABLE(VAR)
if EXPL']""
SET EXPL=VAR
+30 SET NO=NO+1
SET HLEVAR(VAR)=EXPL
End DoDot:1
+31 ;
+32 KILL VARIABLE
+33 ;
+34 ; Make initial DIARY entry...
+35 SET TXT="DECLARE called - "_$PIECE($GET(^HLEV(776.1,+HLEVIENE,0)),U)
+36 DO WPTXT^HLEVUTIL(776,HLEVIENJ,50,776.001,TXT)
+37 ;
+38 QUIT
+39 ;
CHECKIN ; Call here to update the EVENT using "your" DECLARE variables...
+1 NEW D,D0,DA,DI,DIE,DR,NO
+2 ;
+3 ; Debug data created conditionally
DO DEBUG^HLEVAPI2("CHECKIN")
+4 ;
+5 ; Stop all event monitoring to enable on-site debugging...
+6 ;->
if $GET(^TMP("HLEVFLAG",$JOB))["STOP"
QUIT
+7 ;
+8 ; Does entry exist?
+9 ;->
if $GET(^HLEV(776,+$GET(HLEVIENJ),0))']""
QUIT
+10 ;
+11 DO STOREVAR
+12 ;
+13 ; Fill in zero node...
+14 SET DA=+HLEVIENJ
SET DIE=776
+15 SET DR="4///R;6////"_$$NOW^XLFDT
+16 DO ^DIE
+17 ;
+18 QUIT
+19 ;
ABORT(STATUS,APPLST) ; Call here if job is to be aborted...
+1 NEW DA,DIE,DR,NOW
+2 ;
+3 ; Debug data created conditionally
DO DEBUG^HLEVAPI2("ABORT")
+4 ;
+5 ; Stop all event monitoring to enable on-site debugging...
+6 ;->
if $GET(^TMP("HLEVFLAG",$JOB))["STOP"
QUIT
+7 ;
+8 ; Does entry exist?
+9 ;->
if $GET(^HLEV(776,+$GET(HLEVIENJ),0))']""
QUIT
+10 ;
+11 DO CHECKIN
+12 ;
+13 SET DA=+HLEVIENJ
SET DIE=776
+14 SET NOW=$$NOW^XLFDT
+15 SET STATUS=$EXTRACT($$UP^XLFSTR($GET(STATUS)_" "))
+16 SET STATUS=$SELECT("EFQR"[STATUS:STATUS,1:"E")
+17 SET DR="2////"_NOW_";4///"_STATUS_";6////"_NOW
+18 if $GET(APPLST)]""
SET DR=DR_";5///"_$TRANSLATE($EXTRACT(APPLST,1,10),U,"~")
+19 DO ^DIE
+20 ;
+21 DO EVCHKD^HLEVAPI2($GET(HLEVIENM),$GET(HLEVIENE),$GET(HLEVIENJ),STATUS)
+22 ;
+23 ; Passed-in user variables...
KILL HLEVAR
+24 ;
+25 QUIT
+26 ;
CHECKOUT ; Call here to end EVENT using "your" DECLARE variables...
+1 NEW DA,DIE,DR,NOW
+2 ;
+3 ; Debug data created conditionally
DO DEBUG^HLEVAPI2("CHECKOUT")
+4 ;
+5 ; Stop all event monitoring to enable on-site debugging...
+6 ;->
if $GET(^TMP("HLEVFLAG",$JOB))["STOP"
QUIT
+7 ;
+8 ; Does entry exist?
+9 ;->
if $GET(^HLEV(776,+$GET(HLEVIENJ),0))']""
QUIT
+10 ;
+11 DO CHECKIN
+12 ;
+13 SET DA=+HLEVIENJ
SET DIE=776
+14 SET NOW=$$NOW^XLFDT
+15 SET DR="2////"_NOW_";4///F;6////"_NOW
+16 DO ^DIE
+17 ;
+18 DO EVCHKD^HLEVAPI2($GET(HLEVIENM),$GET(HLEVIENE),$GET(HLEVIENJ))
+19 ;
+20 ; Passed-in user variables...
KILL HLEVAR
+21 ;
+22 QUIT
+23 ;
MAILIT DO MAILIT^HLEVAPI3
+1 QUIT
+2 ;
SENDMAIL(HLEVIENE,HLEVIENJ,XMY) ; Mail info in 776 event monitor's ^(51)...
+1 ;
+2 ; PARAMETER NOTES
+3 ; ---------------------------------------------------------------------
+4 ; XMY Pass in XMY by reference.
+5 ; XMSUB If XMSUB pre-exists, it will be used.
+6 ; XMTEXT The text for the mailman message will come from one of
+7 ; three sources:
+8 ; (1) If XMTEXT is pre-set, it will be used.
+9 ; (2) If XMTEXT is not passed in, then the MAILMAN MESSAGE
+10 ; TEXT global ^HLEV(776,IEN,51,#,0) will be used, if it
+11 ; exits.
+12 ; (3) Otherwise, a generic "message is completed" message
+13 ; will be sent.
+14 ;
+15 NEW MGRP,NO,SITE,TEXT,XMDUZ,X,XMZ
+16 ;
+17 ; If no recipients passed in and no mail group exists, quit...
+18 ;->
if $ORDER(XMY(""))']""
QUIT
+19 ;
+20 ;->
if $PIECE($GET(^HLEV(776.1,+$GET(HLEVIENE),0)),U)']""
QUIT
+21 ;->
if $PIECE($GET(^HLEV(776,+$GET(HLEVIENJ),0)),U)']""
QUIT
+22 ;
+23 ; Set up sending...
+24 SET XMDUZ=.5
+25 ;
+26 ; Subject...
+27 SET X=$$SITE^VASITE
SET SITE="HL7 Monitor - "_$PIECE(X,U,2)_"["_$PIECE(X,U,3)_"]"
+28 SET XMSUB=$SELECT($GET(XMSUB)]"":XMSUB,1:SITE_" - "_$PIECE($GET(^HLEV(776.1,+HLEVIENE,0)),U))
+29 ;
+30 ; Load generic message text...
+31 IF $GET(XMTEXT)']""
Begin DoDot:1
+32 KILL ^TMP($JOB,"HLMAILMSG")
+33 DO LOADALL^HLEVAPI1(+HLEVIENJ,"HLMAILMSG")
End DoDot:1
+34 ;
+35 ; Declare where message is stored...
+36 SET XMTEXT=$SELECT($GET(XMTEXT)]"":XMTEXT,1:"^TMP("_$JOB_",""HLMAILMSG"",")
+37 ;
+38 DO ^XMD
+39 ;
+40 IF '$DATA(ZTQUEUED)
WRITE !!,"Mail message #",$GET(XMZ),"..."
+41 ;
+42 IF $GET(XMZ)>0
DO UPDFLDE(+HLEVIENJ,7,XMZ)
+43 ;
+44 QUIT
+45 ;
NEWEVENT(HLEVIENE,QTIME) ; Create a new EVENT and pass back IEN...
+1 NEW DIC,DD,DO,X,Y
+2 ;
+3 ; Check STATUS-EVENT...return null("") if inactive HL*161
+4 ;->
if $PIECE($GET(^HLEV(776.999,1,0)),U,6)'="A"
QUIT ""
+5 ;
+6 SET X=$$NOW^XLFDT
SET DIC="^HLEV(776,"
SET DIC(0)="L"
+7 SET DIC("DR")="3////"_HLEVIENE_";4///Q"
+8 IF $GET(HLEVIENM)>0
SET DIC("DR")=DIC("DR")_";9////"_HLEVIENM
+9 IF $GET(QTIME)]""
SET DIC("DR")=DIC("DR")_";10////"_QTIME
+10 DO FILE^DICN
+11 ;
+12 QUIT $SELECT(+Y>0:+Y,1:"")
+13 ;
UPDFLDE(HLEVIENJ,FLD,VAL) ; Update a specific piece in 776...
+1 NEW DA,DIE,DR
+2 ;
+3 ;->
if $GET(^HLEV(776,+$GET(HLEVIENJ),0))']""
QUIT
+4 ;
+5 ; Field 50, RUN DIARY...
+6 ;->
IF FLD=50
Begin DoDot:1
+7 NEW DIFF,NO,NOW,TIME
+8 SET NO=$ORDER(^HLEV(776,+HLEVIENJ,50,":"),-1)+1
+9 SET ^HLEV(776,+HLEVIENJ,50,0)="^776.001^"_NO_U_NO
+10 SET ^HLEV(776,+HLEVIENJ,50,+NO,0)=$GET(VAL)
+11 ; If FLD=50, update timestamp every 30 seconds...
+12 ; (This is because many 50 nodes might be updated, one after the
+13 ; other in a very disk-intensive way.)
+14 ; FM format
SET TIME=$PIECE($GET(^HLEV(776,+HLEVIENJ,0)),U,6)
+15 SET NOW=$$NOW^XLFDT
+16 SET DIFF=$$FMDIFF^XLFDT(NOW,TIME,2)
if DIFF<0
SET DIFF=-DIFF
+17 ;->
if DIFF<30
QUIT
+18 SET DA=+HLEVIENJ
SET DIE=776
SET DR="6////"_NOW
End DoDot:1
QUIT
+19 ;
+20 ; Fields 401-408...
+21 ;->
IF FLD?3N&(FLD>400)&(FLD<409)
Begin DoDot:1
+22 SET ^HLEV(776,+HLEVIENJ,FLD)=VAL
End DoDot:1
QUIT
+23 ;
+24 ; Zero node data...
+25 ;->
if $GET(VAL)']""
QUIT
+26 SET DA=+HLEVIENJ
SET DIE=776
SET DR=FLD_"///"_VAL_";6////"_$$NOW^XLFDT
+27 DO ^DIE
+28 ;
+29 IF FLD=2
DO EVCHKD^HLEVAPI2($GET(HLEVIENM),$GET(HLEVIENE),$GET(HLEVIENJ))
+30 ;
+31 QUIT
+32 ;
EOR ;HLEVAPI - Event Monitor APIs ;5/16/03 14:42