SCDXHLDR ;ALB/JLU;Ambulatory care event handler;4/30/96
;;5.3;Scheduling;**44,99,126,66,132,245,1015**;5/1/96;Build 21
;This routine is the Ambulatory care event handler. It will hang on
;the Scheduling event driver and monitor the types of events. When a
;check out, edit to a check out or deletion of a check out occurs this
;routine will update the Transmitted outpatient encounter file.
;IHS/ANMC/LJF 6/16/2000 added quit-IHS does not transmit to Austin
;
EN ;Main entry point
Q:$$IHS^BDGF ;IHS
;
I $D(SDSTPAMB) G ENQ ;this will stop the logging of events.
I '$D(SDAMEVT) G ENQ
I SDAMEVT'>4!(SDAMEVT>9) G ENQ ;check out, add/edit and add/edit change
N SDOE,SDPROC,SDBEFORE,SDAFTER,EVTDT,CLINIC,XMIT
S SDPROC=0
F S SDPROC=$O(^TMP("SDEVT",$J,SDHDL,SDPROC)) Q:'SDPROC I SDPROC'=4 DO
.S SDOE=0
.F S SDOE=$O(^TMP("SDEVT",$J,SDHDL,SDPROC,"SDOE",SDOE)) Q:'SDOE DO
..K XMIT
..D NOW^%DTC S EVTDT=%
..S SDAFTER=$G(^TMP("SDEVT",$J,SDHDL,SDPROC,"SDOE",SDOE,0,"AFTER"))
..S SDBEFORE=$G(^("BEFORE")) ;naked reference from previous line
..;
..;Screen out test patients
..S DFN=$S((SDAFTER'=""):$P(SDAFTER,U,2),(SDBEFORE'=""):$P(SDBEFORE,U,2),1:0)
..I DFN Q:$$TESTPAT^VADPT(DFN)
..;
..; screen out non counts
..I SDAFTER]"" S CLINIC=$P(SDAFTER,U,4) Q:$$NONCNT($P(SDAFTER,U,4))
..I SDBEFORE]"" S CLINIC=$P(SDBEFORE,U,4) Q:$$NONCNT($P(SDBEFORE,U,4))
..;
..; handling of delete encounters and check outs
..I SDAFTER]"",SDBEFORE]"",SDAFTER'=SDBEFORE,'$$COMPL(SDAFTER) D LOAD("DELETE",SDOE,EVTDT,SDBEFORE) Q ;DELETION OF A CHECK OUT
..I SDBEFORE]"",SDAFTER']"",SDPROC=2,'+$P(SDBEFORE,U,6) D LOAD("DELETE",SDOE,EVTDT,SDBEFORE) Q ;delete of a stand alone add/edit
..I SDBEFORE]"",SDAFTER']"",SDPROC=2,+$P(SDBEFORE,U,6) Q ;delete of add/edit from an appt. IT HAS ALREADY BEEN MARKED
..;;;I SDBEFORE]"",SDAFTER']"",SDPROC=2,+$P(SDBEFORE,U,6) D LOAD("EDIT",SDOE,EVTDT,SDBEFORE) Q ;THIS IS FROM ABOVE. KEPT FOR REFERENCE
..;
..;screen out not checked out encounters
..I '$S(SDAFTER]"":$$COMPL(SDAFTER),SDBEFORE]"":$$COMPL(SDBEFORE),1:0) Q
..;
..;any loads or edits
..I SDBEFORE]"",SDAFTER]"" D LOAD("EDIT",SDOE,EVTDT) ;edit of C/O
..I SDBEFORE']"",SDAFTER]"" D LOAD("ADD",SDOE,EVTDT) ;new encounter at C/O
..Q
.Q
;
ENQ ;
Q
;
NONCNT(IEN) ;this function determines if the clinic is non count or not
;INPUT IEN the poitner to the hospital location.
;OUTPUT 1 if a non count
; 0 if not a non count
I '$D(IEN) S ANS=0 G NONCNTQ
I 'IEN S ANS=0 G NONCNTQ
S ANS=$S($P(^SC(IEN,0),U,17)="Y":1,1:0)
NONCNTQ Q ANS
;
COMPL(NODE) ;this function call returns whether or not the check out
;process is complete or not. 1 for complete 0 for not
;
Q $S(+$P(NODE,U,7):1,1:0)
;
LOAD(ACTION,IEN,EVTDT,NODE) ;
;ACTION is what type of action caused this event
;IEN is the pointer to the outpatient encounter file
;EVTDT is the date this action occured
;NODE is the zero node of the outpatient encounter file
;
N EVNT,PAR
;
I ACTION'="DELETE" DO
.I $D(^SCE(IEN,0)) S PAR=$P(^SCE(IEN,0),U,6)
.E S PAR=$P(NODE,U,6)
.S IEN=$S(+PAR:PAR,1:IEN)
.S EVNT=$S(ACTION="ADD":1,1:2)
.S XMIT=$$FINDXMIT^SCDXFU01(IEN)
.I 'XMIT S XMIT=$$CRTXMIT^SCDXFU01(IEN,"",EVTDT)
.I +XMIT>0 D STREEVNT^SCDXFU01(XMIT,EVNT,EVTDT),XMITFLAG^SCDXFU01(XMIT,0)
.Q
;
I ACTION="DELETE" DO
.N DELENT,TRANENT,DELENCT,PAR,NTNEED
.S PAR=$P(NODE,U,6)
.S IEN=$S(+PAR:PAR,1:IEN)
.;
.;Encounter never transmitted to or accepted by NPCD
.I (('$$XMITED^SCDXFU03(IEN))&('$$ACCEPTED^SCDXFU03(IEN))) S NTNEED=""
.;Another parent encounter has same Visit ID (i.e. duplicate encounter)
.I ($$VIDCNT^SCDXFU03($P(NODE,"^",20),IEN)) S NTNEED=""
.;
.S DELENT=$$CRTDEL^SCDXFU02($P(NODE,U,1),$P(NODE,U,2),EVTDT,NODE)
.I DELENT<0 S DELENT=$$DELXMIT^SCDXFU03(IEN,1) Q
.;
.S XMIT=$$CRTXMIT^SCDXFU01(IEN,DELENT,EVTDT)
.I XMIT<0 S DELENT=$$DELXMIT^SCDXFU03(IEN,1) Q
.;
.;Delete entry in transmission file (409.73) - not needed
.I $D(NTNEED) S DELENT=$$DELXMIT^SCDXFU03(DELENT,2) Q
.;
.D XMITFLAG^SCDXFU01(XMIT,0)
.Q
Q
;
VALIDATE(XMIT,CLINIC) ;this entry point performs the validation at check out.
;
;INPUT - XMIT this is the IEN of an entry in the transmit file 409.73
S XMIT=+$G(XMIT)
S CLINIC=+$G(CLINIC)
I XMIT<1!(CLINIC<1) G VALQ
N VAL
S VAL=$$VALWL^SCMSVUT2(+$G(CLINIC))
I VAL<1 G VALQ
I 'SDMODE,'$D(ZTQUEUED),'$D(VALQUIET) W !!,"Performing Ambulatory Care Validation Checks.",!
S ERR=$$VALIDATE^SCMSVUT2(XMIT)
I SDMODE!($D(ZTQUEUED))!($D(VALQUIET)) G VALQ
I ERR<1 DO G VALQ
.W !,"No validation errors found!"
.Q
S DIR(0)="Y"
S DIR("B")="YES"
S DIR("A")="Do you wish to correct the validation errors"
D ^DIR
K DIR
I Y<1 G VALQ
;
D ENP^SCENI0(XMIT)
;
VALQ Q
;
FINAL(VISIT,PXKVST) ;
;INPUT VISIT - the IEN of the visit at hand.
;
Q:$D(SDIEMM)
Q:'$D(VISIT)
Q:VISIT=""
Q:$D(VALSTP)
Q:$D(^TMP("PXKSAVE",$J))
N ENC,CLN,XMT,SDMODE
S ENC=0
F S ENC=$O(^SCE("AVSIT",VISIT,ENC)) Q:ENC="" I $P(^SCE(ENC,0),U,6)="" Q
I ENC="" Q
Q:'$D(^SCE(ENC,0))
Q:'$$COMPL(^SCE(ENC,0))
S CLN=$P(^SCE(ENC,0),U,4)
S XMT=+$O(^SD(409.73,"AENC",ENC,0))
I 'XMT Q
S SDMODE=0
D TERM
D VALIDATE(XMT,CLN)
Q
;
TERM ;this is to reset the io variables for lsitman to function properly
;when coming from PCE.
N X
S X="IORVON;IORVOFF;IOIL;IOSTBM;IOSC;IORC;IOEDEOP;IOINHI;IOINORM;IOUON;IOUOFF;IOBON;IOBOFF;IOSGR0"
;;;S X="IORVON;IORVOFF;IOSC;IORC;IOEDEOP;IOINHI;IOINORM;IOUON;IOUOFF;IOBON;IOBOFF;IOSGR0"
D ENDR^%ZISS
Q
;
OK() ;
I SDAMEVT=6,SDBEFORE="",SDAFTER]"" Q 0
Q 1
;
SCDXHLDR ;ALB/JLU;Ambulatory care event handler;4/30/96
+1 ;;5.3;Scheduling;**44,99,126,66,132,245,1015**;5/1/96;Build 21
+2 ;This routine is the Ambulatory care event handler. It will hang on
+3 ;the Scheduling event driver and monitor the types of events. When a
+4 ;check out, edit to a check out or deletion of a check out occurs this
+5 ;routine will update the Transmitted outpatient encounter file.
+6 ;IHS/ANMC/LJF 6/16/2000 added quit-IHS does not transmit to Austin
+7 ;
EN ;Main entry point
+1 ;IHS
IF $$IHS^BDGF
QUIT
+2 ;
+3 ;this will stop the logging of events.
IF $DATA(SDSTPAMB)
GOTO ENQ
+4 IF '$DATA(SDAMEVT)
GOTO ENQ
+5 ;check out, add/edit and add/edit change
IF SDAMEVT'>4!(SDAMEVT>9)
GOTO ENQ
+6 NEW SDOE,SDPROC,SDBEFORE,SDAFTER,EVTDT,CLINIC,XMIT
+7 SET SDPROC=0
+8 FOR
SET SDPROC=$ORDER(^TMP("SDEVT",$JOB,SDHDL,SDPROC))
IF 'SDPROC
QUIT
IF SDPROC'=4
Begin DoDot:1
+9 SET SDOE=0
+10 FOR
SET SDOE=$ORDER(^TMP("SDEVT",$JOB,SDHDL,SDPROC,"SDOE",SDOE))
IF 'SDOE
QUIT
Begin DoDot:2
+11 KILL XMIT
+12 DO NOW^%DTC
SET EVTDT=%
+13 SET SDAFTER=$GET(^TMP("SDEVT",$JOB,SDHDL,SDPROC,"SDOE",SDOE,0,"AFTER"))
+14 ;naked reference from previous line
SET SDBEFORE=$GET(^("BEFORE"))
+15 ;
+16 ;Screen out test patients
+17 SET DFN=$SELECT((SDAFTER'=""):$PIECE(SDAFTER,U,2),(SDBEFORE'=""):$PIECE(SDBEFORE,U,2),1:0)
+18 IF DFN
IF $$TESTPAT^VADPT(DFN)
QUIT
+19 ;
+20 ; screen out non counts
+21 IF SDAFTER]""
SET CLINIC=$PIECE(SDAFTER,U,4)
IF $$NONCNT($PIECE(SDAFTER,U,4))
QUIT
+22 IF SDBEFORE]""
SET CLINIC=$PIECE(SDBEFORE,U,4)
IF $$NONCNT($PIECE(SDBEFORE,U,4))
QUIT
+23 ;
+24 ; handling of delete encounters and check outs
+25 ;DELETION OF A CHECK OUT
IF SDAFTER]""
IF SDBEFORE]""
IF SDAFTER'=SDBEFORE
IF '$$COMPL(SDAFTER)
DO LOAD("DELETE",SDOE,EVTDT,SDBEFORE)
QUIT
+26 ;delete of a stand alone add/edit
IF SDBEFORE]""
IF SDAFTER']""
IF SDPROC=2
IF '+$PIECE(SDBEFORE,U,6)
DO LOAD("DELETE",SDOE,EVTDT,SDBEFORE)
QUIT
+27 ;delete of add/edit from an appt. IT HAS ALREADY BEEN MARKED
IF SDBEFORE]""
IF SDAFTER']""
IF SDPROC=2
IF +$PIECE(SDBEFORE,U,6)
QUIT
+28 ;;;I SDBEFORE]"",SDAFTER']"",SDPROC=2,+$P(SDBEFORE,U,6) D LOAD("EDIT",SDOE,EVTDT,SDBEFORE) Q ;THIS IS FROM ABOVE. KEPT FOR REFERENCE
+29 ;
+30 ;screen out not checked out encounters
+31 IF '$SELECT(SDAFTER]"":$$COMPL(SDAFTER),SDBEFORE]"":$$COMPL(SDBEFORE),1:0)
QUIT
+32 ;
+33 ;any loads or edits
+34 ;edit of C/O
IF SDBEFORE]""
IF SDAFTER]""
DO LOAD("EDIT",SDOE,EVTDT)
+35 ;new encounter at C/O
IF SDBEFORE']""
IF SDAFTER]""
DO LOAD("ADD",SDOE,EVTDT)
+36 QUIT
End DoDot:2
+37 QUIT
End DoDot:1
+38 ;
ENQ ;
+1 QUIT
+2 ;
NONCNT(IEN) ;this function determines if the clinic is non count or not
+1 ;INPUT IEN the poitner to the hospital location.
+2 ;OUTPUT 1 if a non count
+3 ; 0 if not a non count
+4 IF '$DATA(IEN)
SET ANS=0
GOTO NONCNTQ
+5 IF 'IEN
SET ANS=0
GOTO NONCNTQ
+6 SET ANS=$SELECT($PIECE(^SC(IEN,0),U,17)="Y":1,1:0)
NONCNTQ QUIT ANS
+1 ;
COMPL(NODE) ;this function call returns whether or not the check out
+1 ;process is complete or not. 1 for complete 0 for not
+2 ;
+3 QUIT $SELECT(+$PIECE(NODE,U,7):1,1:0)
+4 ;
LOAD(ACTION,IEN,EVTDT,NODE) ;
+1 ;ACTION is what type of action caused this event
+2 ;IEN is the pointer to the outpatient encounter file
+3 ;EVTDT is the date this action occured
+4 ;NODE is the zero node of the outpatient encounter file
+5 ;
+6 NEW EVNT,PAR
+7 ;
+8 IF ACTION'="DELETE"
Begin DoDot:1
+9 IF $DATA(^SCE(IEN,0))
SET PAR=$PIECE(^SCE(IEN,0),U,6)
+10 IF '$TEST
SET PAR=$PIECE(NODE,U,6)
+11 SET IEN=$SELECT(+PAR:PAR,1:IEN)
+12 SET EVNT=$SELECT(ACTION="ADD":1,1:2)
+13 SET XMIT=$$FINDXMIT^SCDXFU01(IEN)
+14 IF 'XMIT
SET XMIT=$$CRTXMIT^SCDXFU01(IEN,"",EVTDT)
+15 IF +XMIT>0
DO STREEVNT^SCDXFU01(XMIT,EVNT,EVTDT)
DO XMITFLAG^SCDXFU01(XMIT,0)
+16 QUIT
End DoDot:1
+17 ;
+18 IF ACTION="DELETE"
Begin DoDot:1
+19 NEW DELENT,TRANENT,DELENCT,PAR,NTNEED
+20 SET PAR=$PIECE(NODE,U,6)
+21 SET IEN=$SELECT(+PAR:PAR,1:IEN)
+22 ;
+23 ;Encounter never transmitted to or accepted by NPCD
+24 IF (('$$XMITED^SCDXFU03(IEN))&('$$ACCEPTED^SCDXFU03(IEN)))
SET NTNEED=""
+25 ;Another parent encounter has same Visit ID (i.e. duplicate encounter)
+26 IF ($$VIDCNT^SCDXFU03($PIECE(NODE,"^",20),IEN))
SET NTNEED=""
+27 ;
+28 SET DELENT=$$CRTDEL^SCDXFU02($PIECE(NODE,U,1),$PIECE(NODE,U,2),EVTDT,NODE)
+29 IF DELENT<0
SET DELENT=$$DELXMIT^SCDXFU03(IEN,1)
QUIT
+30 ;
+31 SET XMIT=$$CRTXMIT^SCDXFU01(IEN,DELENT,EVTDT)
+32 IF XMIT<0
SET DELENT=$$DELXMIT^SCDXFU03(IEN,1)
QUIT
+33 ;
+34 ;Delete entry in transmission file (409.73) - not needed
+35 IF $DATA(NTNEED)
SET DELENT=$$DELXMIT^SCDXFU03(DELENT,2)
QUIT
+36 ;
+37 DO XMITFLAG^SCDXFU01(XMIT,0)
+38 QUIT
End DoDot:1
+39 QUIT
+40 ;
VALIDATE(XMIT,CLINIC) ;this entry point performs the validation at check out.
+1 ;
+2 ;INPUT - XMIT this is the IEN of an entry in the transmit file 409.73
+3 SET XMIT=+$GET(XMIT)
+4 SET CLINIC=+$GET(CLINIC)
+5 IF XMIT<1!(CLINIC<1)
GOTO VALQ
+6 NEW VAL
+7 SET VAL=$$VALWL^SCMSVUT2(+$GET(CLINIC))
+8 IF VAL<1
GOTO VALQ
+9 IF 'SDMODE
IF '$DATA(ZTQUEUED)
IF '$DATA(VALQUIET)
WRITE !!,"Performing Ambulatory Care Validation Checks.",!
+10 SET ERR=$$VALIDATE^SCMSVUT2(XMIT)
+11 IF SDMODE!($DATA(ZTQUEUED))!($DATA(VALQUIET))
GOTO VALQ
+12 IF ERR<1
Begin DoDot:1
+13 WRITE !,"No validation errors found!"
+14 QUIT
End DoDot:1
GOTO VALQ
+15 SET DIR(0)="Y"
+16 SET DIR("B")="YES"
+17 SET DIR("A")="Do you wish to correct the validation errors"
+18 DO ^DIR
+19 KILL DIR
+20 IF Y<1
GOTO VALQ
+21 ;
+22 DO ENP^SCENI0(XMIT)
+23 ;
VALQ QUIT
+1 ;
FINAL(VISIT,PXKVST) ;
+1 ;INPUT VISIT - the IEN of the visit at hand.
+2 ;
+3 IF $DATA(SDIEMM)
QUIT
+4 IF '$DATA(VISIT)
QUIT
+5 IF VISIT=""
QUIT
+6 IF $DATA(VALSTP)
QUIT
+7 IF $DATA(^TMP("PXKSAVE",$JOB))
QUIT
+8 NEW ENC,CLN,XMT,SDMODE
+9 SET ENC=0
+10 FOR
SET ENC=$ORDER(^SCE("AVSIT",VISIT,ENC))
IF ENC=""
QUIT
IF $PIECE(^SCE(ENC,0),U,6)=""
QUIT
+11 IF ENC=""
QUIT
+12 IF '$DATA(^SCE(ENC,0))
QUIT
+13 IF '$$COMPL(^SCE(ENC,0))
QUIT
+14 SET CLN=$PIECE(^SCE(ENC,0),U,4)
+15 SET XMT=+$ORDER(^SD(409.73,"AENC",ENC,0))
+16 IF 'XMT
QUIT
+17 SET SDMODE=0
+18 DO TERM
+19 DO VALIDATE(XMT,CLN)
+20 QUIT
+21 ;
TERM ;this is to reset the io variables for lsitman to function properly
+1 ;when coming from PCE.
+2 NEW X
+3 SET X="IORVON;IORVOFF;IOIL;IOSTBM;IOSC;IORC;IOEDEOP;IOINHI;IOINORM;IOUON;IOUOFF;IOBON;IOBOFF;IOSGR0"
+4 ;;;S X="IORVON;IORVOFF;IOSC;IORC;IOEDEOP;IOINHI;IOINORM;IOUON;IOUOFF;IOBON;IOBOFF;IOSGR0"
+5 DO ENDR^%ZISS
+6 QUIT
+7 ;
OK() ;
+1 IF SDAMEVT=6
IF SDBEFORE=""
IF SDAFTER]""
QUIT 0
+2 QUIT 1
+3 ;