EDPRPT7C ;SLC/MKB - Exposure Report (CSV format) ;4/25/13 3:15pm
;;2.0;EMERGENCY DEPARTMENT;**6,2**;Feb 24, 2012;Build 23
;
EXP(IEN) ; Get Exposure Report for IEN at EDPSITE
S IEN=+$G(IEN) Q:IEN<1 Q:'$D(^EDP(230,IEN,0))
N BEG,END,LIST,LOG,IN,OUT,X,X0,Y,RLIST,TREAT,OTHER,MD,RN,RES,I,J,RIN,ROUT,TAB
N SHIFT D SETUP^EDPRPT5 ;build SHIFT(#)
I 'SHIFT D ERR^EDPRPT(2300013) Q
S X0=^EDP(230,IEN,0),BEG=$P(X0,U,8),END=$P(X0,U,9),TAB=$C(9)
S:'BEG BEG=$P(X0,U) S:'END END=$$NOW^EDPRPT
D ROOMS(IEN,END)
; put IEN info into CSV
;***pij 4/19/2013 changed ED to IEN
;S X="ED"_TAB_"Room"_TAB_"Shift - Time In"_TAB_"Shift - Time Out"_TAB_"Diagnosis"_TAB_"Dispo"_TAB_"Arr Mode"_TAB_"Notes"
;Begin EDP*2.0*2 changes drp
S X="IEN"_TAB_"Room"_TAB_"Shift - Time In"_TAB_"Shift - Time Out"_TAB_"Diagnosis"_TAB_"ICD"_TAB_"ICD Type"_TAB_"Dispo"_TAB_"Arr Mode"_TAB_"Notes"
;End EDP*2.0*2 Changes
;***
D ADD^EDPCSV(X),BLANK^EDPCSV ;headers
S X=TAB_TAB_"Contagious Patient Information"
D ADD^EDPCSV(X),BLANK^EDPCSV
D ADD(IEN),STAFF(IEN)
D BLANK^EDPCSV
E1 ; look for patients also in ED between BEG and END
D FIND(BEG,END) ;create LIST(#) list of ien's to check
S LOG=0 F S LOG=+$O(LIST(LOG)) Q:'LOG I LOG'=IEN D
. S X0=$G(^EDP(230,LOG,0)),IN=$P(X0,U,8),OUT=$P(X0,U,9)
. D ROOMS(LOG,OUT)
. ; compare treatment rooms
. S I=0 F S I=$O(RLIST(IEN,I)) Q:I<1 D
.. S RIN=$P(RLIST(IEN,I),U,2),ROUT=$P(RLIST(IEN,I),U,3)
.. S J=0 F S J=$O(RLIST(LOG,J)) Q:J<1 I +RLIST(IEN,I)=+RLIST(LOG,J) D
... S X=$P(RLIST(LOG,J),U,2) Q:X>ROUT ;in to room after IEN left
... ;I (RIN<=X)&(X<=ROUT) S TREAT(LOG)="" Q
... S X=$P(RLIST(LOG,J),U,3) Q:X&(X<RIN) ;out of room before IEN came
... ;I (RIN<=X)&(X<=ROUT) S TREAT(LOG)="" Q
... S TREAT(LOG)=""
. I '$D(TREAT(LOG)) S OTHER(LOG)=""
E2 ; return treatment room patients
;***pij 4/19/2013
;D ADD^EDPCSV(TAB_TAB_"Exposed in Treatment Room"),BLANK^EDPCSV
D ADD^EDPCSV(TAB_TAB_"Patients Directly Exposed in Different Treatment Rooms"),BLANK^EDPCSV
;***
I '$O(TREAT(0)) D ADD^EDPCSV(TAB_TAB_" None")
E S LOG=0 F S LOG=$O(TREAT(LOG)) Q:LOG<1 D ADD(LOG),STAFF(LOG)
D BLANK^EDPCSV
; return other ED patients
D ADD^EDPCSV(TAB_TAB_"Other ED Patients"),BLANK^EDPCSV
I '$O(OTHER(0)) D ADD^EDPCSV(TAB_TAB_" None")
E S LOG=0 F S LOG=$O(OTHER(LOG)) Q:LOG<1 D ADD(LOG),STAFF(LOG)
D BLANK^EDPCSV
E3 ; return staff on duty
N MAX,MORE D ADD^EDPCSV(TAB_TAB_"On Duty Staff")
D ADD^EDPCSV(TAB_"Doctors"_TAB_"Nurses"_TAB_"Residents")
S MAX=+$G(RN) S:$G(MD)>MAX MAX=+MD S:$G(RES)>MAX MAX=+RES
S MORE=1,(MD,RN,RES)=0 F D Q:'MORE
. S:MD'="" MD=$O(MD(MD)) S:RN'="" RN=$O(RN(RN))
. S:RES'="" RES=$O(RES(RES)) ;get next
. I MD="",RN="",RES="" S MORE=0 Q ;done
. S X=TAB_$S(MD:MD(MD),1:"")_TAB_$S(RN:RN(RN),1:"")_TAB_$S(RES:RES(RES),1:"")
. D ADD^EDPCSV(X)
Q
;
FIND(IN,OUT) ; create LIST(#) of visits at same time
N TIME,I,X K LIST
S TIME=+$P(IN,".") ;ck today's arrivals
F S TIME=$O(^EDP(230,"ATI",EDPSITE,TIME)) Q:TIME<1!(TIME>OUT) D
. S I=0 F S I=$O(^EDP(230,"ATI",EDPSITE,TIME,I)) Q:I<1 D
.. S X=$P($G(^EDP(230,I,0)),U,9) I X,X<IN Q ;left before IEN arrived
.. S LIST(I)=""
Q
;
ROOMS(LOG,OUT) ; Return RLIST(LOG,n)= room ^ time in ^ time out
N N,D,I,X,LAST S N=0,LAST=""
S D=0 F S D=$O(^EDP(230.1,"ADF",LOG,D)) Q:D<1 S I=+$O(^(D,0)) D
. S X=+$P($G(^EDP(230.1,I,3)),U,4) Q:'X Q:X=LAST ;no location change
. S:N $P(RLIST(LOG,N),U,3)=D ;time in of next room = time out of prev
. S N=N+1,RLIST(LOG,N)=X_U_D,LAST=X ;new room
I N,'$P(RLIST(LOG,N),U,3) S $P(RLIST(LOG,N),U,3)=OUT
Q
;
ADD(LOG) ; Add row to CSV for each room used during visit
N EDPI,EDPX,ROW,LABS,XRAY,X,X0
S EDPI=0 F S EDPI=$O(RLIST(LOG,EDPI)) Q:EDPI<1 S EDPX=RLIST(LOG,EDPI) D
. S ROW=$S(EDPI=1:LOG,1:"")_TAB_$P($G(^EDPB(231.8,+EDPX,0)),U)
. S X=$P(EDPX,U,2) ;shiftTimeIn
. S ROW=ROW_TAB_$$SHIFT^EDPRPT5(X)_" - "_$$EDATE^EDPRPT(X)
. S X=$P(EDPX,U,3) ;shiftTimeOut
. S ROW=ROW_TAB_$$SHIFT^EDPRPT5(X)_" - "_$$EDATE^EDPRPT(X)
. S X0=$G(^EDP(230,LOG,0)),X=$$DXPRI^EDPQPCE(+$P(X0,U,3),LOG)
. S ROW=ROW_TAB_$P(X,U,2) ;Dx
. ;DRP Begin EDP*2.0*2 Changes
. S ROW=ROW_TAB_$P(X,U,1) ; added ICD Code
. S ROW=ROW_TAB_$P(X,U,3) ;added ICDType
. ;End EDP*2.0*2 Changes
. ;TDP - Patch 2 mod to capture all dispositions
. S X=$P($G(^EDP(230,LOG,1)),U,2),ROW=ROW_TAB_$S($$ECODE^EDPRPT(X)'="":$$ECODE^EDPRPT(X),1:$$DISP^EDPRPT(X)) ;dis
. S X=$P(X0,U,10),ROW=ROW_TAB_$$ENAME^EDPRPT(X) ;arrival
. S LABS=$D(^EDP(230,LOG,8,"AC","L")),XRAY=$D(^("R")),X=""
. I LABS!XRAY D S X=X_" ordered"
.. I LABS&XRAY S X="Labs and Imaging" Q
.. S:LABS X="Labs" S:XRAY X="Imaging"
. S ROW=ROW_TAB_X ;notes
. D ADD^EDPCSV(ROW)
Q
;
STAFF(LOG) ; save staff involved in patient care
N D,I,X,ACT S LOG=+$G(LOG)
S D=0 F S D=$O(^EDP(230.1,"ADF",LOG,D)) Q:D<1 S I=+$O(^(D,0)) D
. S ACT=$G(^EDP(230.1,I,3))
. S X=+$P(ACT,U,5) S:X MD(X)=$$EPERS^EDPRPT(X)
. S X=+$P(ACT,U,6) S:X RN(X)=$$EPERS^EDPRPT(X)
. S X=+$P(ACT,U,7) S:X RES(X)=$$EPERS^EDPRPT(X)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HEDPRPT7C 5098 printed Nov 22, 2024@17:02:36 Page 2
EDPRPT7C ;SLC/MKB - Exposure Report (CSV format) ;4/25/13 3:15pm
+1 ;;2.0;EMERGENCY DEPARTMENT;**6,2**;Feb 24, 2012;Build 23
+2 ;
EXP(IEN) ; Get Exposure Report for IEN at EDPSITE
+1 SET IEN=+$GET(IEN)
if IEN<1
QUIT
if '$DATA(^EDP(230,IEN,0))
QUIT
+2 NEW BEG,END,LIST,LOG,IN,OUT,X,X0,Y,RLIST,TREAT,OTHER,MD,RN,RES,I,J,RIN,ROUT,TAB
+3 ;build SHIFT(#)
NEW SHIFT
DO SETUP^EDPRPT5
+4 IF 'SHIFT
DO ERR^EDPRPT(2300013)
QUIT
+5 SET X0=^EDP(230,IEN,0)
SET BEG=$PIECE(X0,U,8)
SET END=$PIECE(X0,U,9)
SET TAB=$CHAR(9)
+6 if 'BEG
SET BEG=$PIECE(X0,U)
if 'END
SET END=$$NOW^EDPRPT
+7 DO ROOMS(IEN,END)
+8 ; put IEN info into CSV
+9 ;***pij 4/19/2013 changed ED to IEN
+10 ;S X="ED"_TAB_"Room"_TAB_"Shift - Time In"_TAB_"Shift - Time Out"_TAB_"Diagnosis"_TAB_"Dispo"_TAB_"Arr Mode"_TAB_"Notes"
+11 ;Begin EDP*2.0*2 changes drp
+12 SET X="IEN"_TAB_"Room"_TAB_"Shift - Time In"_TAB_"Shift - Time Out"_TAB_"Diagnosis"_TAB_"ICD"_TAB_"ICD Type"_TAB_"Dispo"_TAB_"Arr Mode"_TAB_"Notes"
+13 ;End EDP*2.0*2 Changes
+14 ;***
+15 ;headers
DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+16 SET X=TAB_TAB_"Contagious Patient Information"
+17 DO ADD^EDPCSV(X)
DO BLANK^EDPCSV
+18 DO ADD(IEN)
DO STAFF(IEN)
+19 DO BLANK^EDPCSV
E1 ; look for patients also in ED between BEG and END
+1 ;create LIST(#) list of ien's to check
DO FIND(BEG,END)
+2 SET LOG=0
FOR
SET LOG=+$ORDER(LIST(LOG))
if 'LOG
QUIT
IF LOG'=IEN
Begin DoDot:1
+3 SET X0=$GET(^EDP(230,LOG,0))
SET IN=$PIECE(X0,U,8)
SET OUT=$PIECE(X0,U,9)
+4 DO ROOMS(LOG,OUT)
+5 ; compare treatment rooms
+6 SET I=0
FOR
SET I=$ORDER(RLIST(IEN,I))
if I<1
QUIT
Begin DoDot:2
+7 SET RIN=$PIECE(RLIST(IEN,I),U,2)
SET ROUT=$PIECE(RLIST(IEN,I),U,3)
+8 SET J=0
FOR
SET J=$ORDER(RLIST(LOG,J))
if J<1
QUIT
IF +RLIST(IEN,I)=+RLIST(LOG,J)
Begin DoDot:3
+9 ;in to room after IEN left
SET X=$PIECE(RLIST(LOG,J),U,2)
if X>ROUT
QUIT
+10 ;I (RIN<=X)&(X<=ROUT) S TREAT(LOG)="" Q
+11 ;out of room before IEN came
SET X=$PIECE(RLIST(LOG,J),U,3)
if X&(X<RIN)
QUIT
+12 ;I (RIN<=X)&(X<=ROUT) S TREAT(LOG)="" Q
+13 SET TREAT(LOG)=""
End DoDot:3
End DoDot:2
+14 IF '$DATA(TREAT(LOG))
SET OTHER(LOG)=""
End DoDot:1
E2 ; return treatment room patients
+1 ;***pij 4/19/2013
+2 ;D ADD^EDPCSV(TAB_TAB_"Exposed in Treatment Room"),BLANK^EDPCSV
+3 DO ADD^EDPCSV(TAB_TAB_"Patients Directly Exposed in Different Treatment Rooms")
DO BLANK^EDPCSV
+4 ;***
+5 IF '$ORDER(TREAT(0))
DO ADD^EDPCSV(TAB_TAB_" None")
+6 IF '$TEST
SET LOG=0
FOR
SET LOG=$ORDER(TREAT(LOG))
if LOG<1
QUIT
DO ADD(LOG)
DO STAFF(LOG)
+7 DO BLANK^EDPCSV
+8 ; return other ED patients
+9 DO ADD^EDPCSV(TAB_TAB_"Other ED Patients")
DO BLANK^EDPCSV
+10 IF '$ORDER(OTHER(0))
DO ADD^EDPCSV(TAB_TAB_" None")
+11 IF '$TEST
SET LOG=0
FOR
SET LOG=$ORDER(OTHER(LOG))
if LOG<1
QUIT
DO ADD(LOG)
DO STAFF(LOG)
+12 DO BLANK^EDPCSV
E3 ; return staff on duty
+1 NEW MAX,MORE
DO ADD^EDPCSV(TAB_TAB_"On Duty Staff")
+2 DO ADD^EDPCSV(TAB_"Doctors"_TAB_"Nurses"_TAB_"Residents")
+3 SET MAX=+$GET(RN)
if $GET(MD)>MAX
SET MAX=+MD
if $GET(RES)>MAX
SET MAX=+RES
+4 SET MORE=1
SET (MD,RN,RES)=0
FOR
Begin DoDot:1
+5 if MD'=""
SET MD=$ORDER(MD(MD))
if RN'=""
SET RN=$ORDER(RN(RN))
+6 ;get next
if RES'=""
SET RES=$ORDER(RES(RES))
+7 ;done
IF MD=""
IF RN=""
IF RES=""
SET MORE=0
QUIT
+8 SET X=TAB_$SELECT(MD:MD(MD),1:"")_TAB_$SELECT(RN:RN(RN),1:"")_TAB_$SELECT(RES:RES(RES),1:"")
+9 DO ADD^EDPCSV(X)
End DoDot:1
if 'MORE
QUIT
+10 QUIT
+11 ;
FIND(IN,OUT) ; create LIST(#) of visits at same time
+1 NEW TIME,I,X
KILL LIST
+2 ;ck today's arrivals
SET TIME=+$PIECE(IN,".")
+3 FOR
SET TIME=$ORDER(^EDP(230,"ATI",EDPSITE,TIME))
if TIME<1!(TIME>OUT)
QUIT
Begin DoDot:1
+4 SET I=0
FOR
SET I=$ORDER(^EDP(230,"ATI",EDPSITE,TIME,I))
if I<1
QUIT
Begin DoDot:2
+5 ;left before IEN arrived
SET X=$PIECE($GET(^EDP(230,I,0)),U,9)
IF X
IF X<IN
QUIT
+6 SET LIST(I)=""
End DoDot:2
End DoDot:1
+7 QUIT
+8 ;
ROOMS(LOG,OUT) ; Return RLIST(LOG,n)= room ^ time in ^ time out
+1 NEW N,D,I,X,LAST
SET N=0
SET LAST=""
+2 SET D=0
FOR
SET D=$ORDER(^EDP(230.1,"ADF",LOG,D))
if D<1
QUIT
SET I=+$ORDER(^(D,0))
Begin DoDot:1
+3 ;no location change
SET X=+$PIECE($GET(^EDP(230.1,I,3)),U,4)
if 'X
QUIT
if X=LAST
QUIT
+4 ;time in of next room = time out of prev
if N
SET $PIECE(RLIST(LOG,N),U,3)=D
+5 ;new room
SET N=N+1
SET RLIST(LOG,N)=X_U_D
SET LAST=X
End DoDot:1
+6 IF N
IF '$PIECE(RLIST(LOG,N),U,3)
SET $PIECE(RLIST(LOG,N),U,3)=OUT
+7 QUIT
+8 ;
ADD(LOG) ; Add row to CSV for each room used during visit
+1 NEW EDPI,EDPX,ROW,LABS,XRAY,X,X0
+2 SET EDPI=0
FOR
SET EDPI=$ORDER(RLIST(LOG,EDPI))
if EDPI<1
QUIT
SET EDPX=RLIST(LOG,EDPI)
Begin DoDot:1
+3 SET ROW=$SELECT(EDPI=1:LOG,1:"")_TAB_$PIECE($GET(^EDPB(231.8,+EDPX,0)),U)
+4 ;shiftTimeIn
SET X=$PIECE(EDPX,U,2)
+5 SET ROW=ROW_TAB_$$SHIFT^EDPRPT5(X)_" - "_$$EDATE^EDPRPT(X)
+6 ;shiftTimeOut
SET X=$PIECE(EDPX,U,3)
+7 SET ROW=ROW_TAB_$$SHIFT^EDPRPT5(X)_" - "_$$EDATE^EDPRPT(X)
+8 SET X0=$GET(^EDP(230,LOG,0))
SET X=$$DXPRI^EDPQPCE(+$PIECE(X0,U,3),LOG)
+9 ;Dx
SET ROW=ROW_TAB_$PIECE(X,U,2)
+10 ;DRP Begin EDP*2.0*2 Changes
+11 ; added ICD Code
SET ROW=ROW_TAB_$PIECE(X,U,1)
+12 ;added ICDType
SET ROW=ROW_TAB_$PIECE(X,U,3)
+13 ;End EDP*2.0*2 Changes
+14 ;TDP - Patch 2 mod to capture all dispositions
+15 ;dis
SET X=$PIECE($GET(^EDP(230,LOG,1)),U,2)
SET ROW=ROW_TAB_$SELECT($$ECODE^EDPRPT(X)'="":$$ECODE^EDPRPT(X),1:$$DISP^EDPRPT(X))
+16 ;arrival
SET X=$PIECE(X0,U,10)
SET ROW=ROW_TAB_$$ENAME^EDPRPT(X)
+17 SET LABS=$DATA(^EDP(230,LOG,8,"AC","L"))
SET XRAY=$DATA(^("R"))
SET X=""
+18 IF LABS!XRAY
Begin DoDot:2
+19 IF LABS&XRAY
SET X="Labs and Imaging"
QUIT
+20 if LABS
SET X="Labs"
if XRAY
SET X="Imaging"
End DoDot:2
SET X=X_" ordered"
+21 ;notes
SET ROW=ROW_TAB_X
+22 DO ADD^EDPCSV(ROW)
End DoDot:1
+23 QUIT
+24 ;
STAFF(LOG) ; save staff involved in patient care
+1 NEW D,I,X,ACT
SET LOG=+$GET(LOG)
+2 SET D=0
FOR
SET D=$ORDER(^EDP(230.1,"ADF",LOG,D))
if D<1
QUIT
SET I=+$ORDER(^(D,0))
Begin DoDot:1
+3 SET ACT=$GET(^EDP(230.1,I,3))
+4 SET X=+$PIECE(ACT,U,5)
if X
SET MD(X)=$$EPERS^EDPRPT(X)
+5 SET X=+$PIECE(ACT,U,6)
if X
SET RN(X)=$$EPERS^EDPRPT(X)
+6 SET X=+$PIECE(ACT,U,7)
if X
SET RES(X)=$$EPERS^EDPRPT(X)
End DoDot:1
+7 QUIT