QANBRIF ;HISC/GJC-Auto E-Mail for locally quick cases ; 5/30/12 1:58pm
;;2.0;Incident Reporting;**1,18,20,33**;08/07/1992;Build 12
;
S QANZERO=$S($D(^QA(740,1,0))#2:^(0),1:0) I +QANZERO'>0 S QANERROR=1 D ERROR G EXIT
S QANSITE=$S($D(^DIC(4,+QANZERO,0))#2:$P(^(0),"^"),1:"") I QANSITE="" S QANERROR=2 D ERROR G EXIT
S QANSTNO=$S($D(^DIC(4,+QANZERO,99))#2:$P(^(99),"^"),1:"") I QANSTNO="" S QANERROR=3 D ERROR G EXIT
S QANSERV=$P(QANZERO,"^",4) I QANSERV="" S QANERROR=4 D ERROR G EXIT
S QANDOM=$P(QANZERO,"^",5) I QANDOM="" S QANERROR=5 D ERROR G EXIT
S QA=+$O(^DIC(4.2,"B",QANDOM,0)) I $S('$D(^DIC(4.2,QA,0))#2:1,$P(^(0),"^")'=QANDOM:1,1:0) S QANERROR=6 D ERROR G EXIT
S QANQAN=$S($D(^QA(740,1,"QAN")):^("QAN"),1:"") I +QANQAN'>0 S QANERROR=7 D ERROR G EXIT
S QANMLGP=+$P(QANQAN,U),QANMLGP(0)=$S($D(^XMB(3.8,QANMLGP,0))#2:$P(^(0),U),1:"") I QANMLGP(0)']"" S QANERROR=7 D ERROR G EXIT
D INC D:$D(^UTILITY($J,"QAN MAIL")) BULL
EXIT ;Kill and quit
K ^UTILITY($J),C,DA,DIE,DIWF,DIWL,DIWR,DR,QA,QAN0,QAN1,QAN742
K QAN7424,QANCASE,QANDATE,QANDESC,QANDOM,QANERROR,QANINCD,QANINCR
K QANMLGP,QANNCDNT,QANLOOP,QANOK,QANPAT,QANPROV,QANQAN,QANQUIT,QANSERV
K QANSITE,QANSLEV,QANSRVCE,QANSTNO,QANTYDTH,QANZERO,X,XMDUZ,XMSUB
K QANDOB,XMTEXT,XMY,Y
Q
BULL ;Mail message
D KILL^XM
S XMY(QANSERV_"@"_QANDOM)="",XMDUZ=.5
S XMSUB="QAN Incident Event: "_^DD("SITE")_" ("_^DD("SITE",1)_")"
S XMTEXT="^UTILITY($J,""QAN MAIL""," D ^XMD,KILL^XM
Q
ERROR ;Error messages
W *7,!!,"*** ",$P($T(ERR+QANERROR),";;",2)," ***",!!,*7
Q
INC ;Choose the incident. Check 'ACS' x-ref for brief.
S QANINCR=0
F QAN0=0:0 S QAN0=$O(^QA(742.4,"ACS",3,QAN0)) Q:QAN0'>0 S (QANDESC,QANQUIT)=0 D INC1
Q
INC1 ;If brief 'ACS' x-ref, and not transmitted to region, 18th piece.
S QAN7424=$G(^QA(742.4,QAN0,0)) Q:QAN7424']""
Q:+$P(QAN7424,U,18)'=0 ;Has been xmitted.
S QANDATE=$P(QAN7424,U,3),QANCASE=$P(QAN7424,U),QANNCDNT=+$P(QAN7424,U,2)
Q:QANNCDNT'>0 ;check for null incident
S QANINCD=$S($D(^QA(742.1,QANNCDNT,0)):$P(^(0),U),1:"") Q:QANINCD']""
S QANINCD=$TR(QANINCD,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
S QANTYDTH=$S(QANINCD="DEATH":$P(QAN7424,U,14),1:""),QANPROV=$P(QAN7424,U,16)
I $D(^QA(742.4,QAN0,1,0)) D DESC^QANFULL
;/*** Grab patient data ***/
F QAN1=0:0 S QAN1=$O(^QA(742,"BCS",QAN0,QAN1)) Q:QAN1'>0 S QAN742=$G(^QA(742,QAN1,0)) S:QAN742]"" QANOK=0 D:QAN742]"" PAT
I QANQUIT K DA,DIE,DR S DIE="^QA(742.4,",DA=QAN0,DR=".17///^S X=3" D ^DIE K DA,DIE,DR
I QANQUIT K DA,DIE,DR S DIE="^QA(742.4,",DA=QAN0,DR=".21///^S X=1" D ^DIE K DA,DIE,DR
Q
INCK ;Check status of incident
I QANINCD="HOMICIDE" S QANOK=1
I QANINCD="DEATH" D
. S QANTYDTH=+$G(QANTYDTH)
. I '$D(^QA(742.14,"BUPPER","OTHER",QANTYDTH)),('$D(^QA(742.14,"BUPPER","WITHIN 24 HOURS OF ADMISSION (EX. DOA'S AND TERMINALS)",QANTYDTH))) S QANOK=1
I QANINCD="SUICIDE" S QANOK=1
I QANINCD="SEXUAL ASSAULT" S QANOK=1
I QANINCD="SUICIDE ATTEMPT" S QANOK=1
I QANINCD="INFORMED CONSENT-FAIL. TO OBTAIN" S QANOK=1
I QANINCD="PATIENT ABUSE" S QANOK=1
I QANINCD="INJURY NOT OTHERWISE LISTED",(QANSLEV'<2) S QANOK=1
I QANINCD="ASSAULT-PATIENT TO PATIENT",(QANSLEV'<2) S QANOK=1
I QANINCD="FIRE-PATIENT INVOLVED IN",(QANSLEV'<2) S QANOK=1
I QANINCD="ASSAULT-PATIENT/STAFF",(QANSLEV'<2) S QANOK=1
I QANINCD="FALL",(QANSLEV'<2) S QANOK=1
I QANINCD="MEDICATION ERROR",(QANSLEV'<2) S QANOK=1
I QANINCD="TRANSFUSION ERROR",(QANSLEV'<2) S QANOK=1
I QANINCD="MISSING PATIENT",(QANSLEV'<2) S QANOK=1
Q
PAT ;Patient data
S (QANSRVCE,Y)=$P(QAN742,U,8),C=$P(^DD(742,.08,0),U,2) D:Y]"" Y^DIQ S QANSRVCE=Y
S QANSLEV=+$P(QAN742,U,10) D INCK Q:'QANOK
S QANQUIT=1,QANINCR=QANINCR+1
S QANPAT=$P(QAN742,U),^UTILITY($J,"QAN PAT",QAN1)=$P(^DPT(QANPAT,0),U)
S ^UTILITY($J,"QAN SSN",QAN1)=$P(^DPT(QANPAT,0),U,9)
S QANDOB=$P(^DPT(QANPAT,0),U,3)
S ^UTILITY($J,"QAN MAIL",QANINCR)="BRIEF^"_QANCASE_"^INCD^"_QANINCD_"^"_QANDATE_"^^^^"_QANMLGP(0)_"^^^"_$G(QANPROV)_"^"
S QANINCR=QANINCR+1
S ^UTILITY($J,"QAN MAIL",QANINCR)="BRIEF^"_QANCASE_"^PAT^"_$G(^UTILITY($J,"QAN PAT",QAN1))_"^"_$G(^UTILITY($J,"QAN SSN",QAN1))_"^"_QANSLEV_"^"_QANTYDTH_"^"_QANSRVCE_"^^"_QANDOB_"^"
I QANDESC,($D(^UTILITY($J,"W",DIWL))) D
. F QA=0:0 S QA=$O(^UTILITY($J,"W",DIWL,QA)) Q:QA'>0 D
.. S QANINCR=QANINCR+1
.. S ^UTILITY($J,"QAN MAIL",QANINCR)="BRIEF^"_QANCASE_"^DESC^"_$G(^UTILITY($J,"W",DIWL,QA,0))_"^"
.. Q
. Q
Q
ERR ;;ERROR MESSAGES: REASONS EWS BULLETIN COULD NOT BE SENT
;;SITE NOT FOUND IN QA SITE PARAMETERS FILE
;;SITE NOT FOUND IN INSTITUTION FILE
;;SITE NUMBER NOT FOUND IN INSTITUTION FILE
;;NQADB MAIL GROUP/SERVER NOT FOUND IN QA SITE PARAMETERS FILE
;;NQADB DOMAIN NOT FOUND IN QA SITE PARAMETERS FILE
;;NQADB DOMAIN NOT FOUND IN DOMAIN FILE
;;QA INCIDENT MAILGROUP NOT FOUND IN QA SITE PARAMETERS FILE
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HQANBRIF 4874 printed Oct 16, 2024@18:00:20 Page 2
QANBRIF ;HISC/GJC-Auto E-Mail for locally quick cases ; 5/30/12 1:58pm
+1 ;;2.0;Incident Reporting;**1,18,20,33**;08/07/1992;Build 12
+2 ;
+3 SET QANZERO=$SELECT($DATA(^QA(740,1,0))#2:^(0),1:0)
IF +QANZERO'>0
SET QANERROR=1
DO ERROR
GOTO EXIT
+4 SET QANSITE=$SELECT($DATA(^DIC(4,+QANZERO,0))#2:$PIECE(^(0),"^"),1:"")
IF QANSITE=""
SET QANERROR=2
DO ERROR
GOTO EXIT
+5 SET QANSTNO=$SELECT($DATA(^DIC(4,+QANZERO,99))#2:$PIECE(^(99),"^"),1:"")
IF QANSTNO=""
SET QANERROR=3
DO ERROR
GOTO EXIT
+6 SET QANSERV=$PIECE(QANZERO,"^",4)
IF QANSERV=""
SET QANERROR=4
DO ERROR
GOTO EXIT
+7 SET QANDOM=$PIECE(QANZERO,"^",5)
IF QANDOM=""
SET QANERROR=5
DO ERROR
GOTO EXIT
+8 SET QA=+$ORDER(^DIC(4.2,"B",QANDOM,0))
IF $SELECT('$DATA(^DIC(4.2,QA,0))#2:1,$PIECE(^(0),"^")'=QANDOM:1,1:0)
SET QANERROR=6
DO ERROR
GOTO EXIT
+9 SET QANQAN=$SELECT($DATA(^QA(740,1,"QAN")):^("QAN"),1:"")
IF +QANQAN'>0
SET QANERROR=7
DO ERROR
GOTO EXIT
+10 SET QANMLGP=+$PIECE(QANQAN,U)
SET QANMLGP(0)=$SELECT($DATA(^XMB(3.8,QANMLGP,0))#2:$PIECE(^(0),U),1:"")
IF QANMLGP(0)']""
SET QANERROR=7
DO ERROR
GOTO EXIT
+11 DO INC
if $DATA(^UTILITY($JOB,"QAN MAIL"))
DO BULL
EXIT ;Kill and quit
+1 KILL ^UTILITY($JOB),C,DA,DIE,DIWF,DIWL,DIWR,DR,QA,QAN0,QAN1,QAN742
+2 KILL QAN7424,QANCASE,QANDATE,QANDESC,QANDOM,QANERROR,QANINCD,QANINCR
+3 KILL QANMLGP,QANNCDNT,QANLOOP,QANOK,QANPAT,QANPROV,QANQAN,QANQUIT,QANSERV
+4 KILL QANSITE,QANSLEV,QANSRVCE,QANSTNO,QANTYDTH,QANZERO,X,XMDUZ,XMSUB
+5 KILL QANDOB,XMTEXT,XMY,Y
+6 QUIT
BULL ;Mail message
+1 DO KILL^XM
+2 SET XMY(QANSERV_"@"_QANDOM)=""
SET XMDUZ=.5
+3 SET XMSUB="QAN Incident Event: "_^DD("SITE")_" ("_^DD("SITE",1)_")"
+4 SET XMTEXT="^UTILITY($J,""QAN MAIL"","
DO ^XMD
DO KILL^XM
+5 QUIT
ERROR ;Error messages
+1 WRITE *7,!!,"*** ",$PIECE($TEXT(ERR+QANERROR),";;",2)," ***",!!,*7
+2 QUIT
INC ;Choose the incident. Check 'ACS' x-ref for brief.
+1 SET QANINCR=0
+2 FOR QAN0=0:0
SET QAN0=$ORDER(^QA(742.4,"ACS",3,QAN0))
if QAN0'>0
QUIT
SET (QANDESC,QANQUIT)=0
DO INC1
+3 QUIT
INC1 ;If brief 'ACS' x-ref, and not transmitted to region, 18th piece.
+1 SET QAN7424=$GET(^QA(742.4,QAN0,0))
if QAN7424']""
QUIT
+2 ;Has been xmitted.
if +$PIECE(QAN7424,U,18)'=0
QUIT
+3 SET QANDATE=$PIECE(QAN7424,U,3)
SET QANCASE=$PIECE(QAN7424,U)
SET QANNCDNT=+$PIECE(QAN7424,U,2)
+4 ;check for null incident
if QANNCDNT'>0
QUIT
+5 SET QANINCD=$SELECT($DATA(^QA(742.1,QANNCDNT,0)):$PIECE(^(0),U),1:"")
if QANINCD']""
QUIT
+6 SET QANINCD=$TRANSLATE(QANINCD,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+7 SET QANTYDTH=$SELECT(QANINCD="DEATH":$PIECE(QAN7424,U,14),1:"")
SET QANPROV=$PIECE(QAN7424,U,16)
+8 IF $DATA(^QA(742.4,QAN0,1,0))
DO DESC^QANFULL
+9 ;/*** Grab patient data ***/
+10 FOR QAN1=0:0
SET QAN1=$ORDER(^QA(742,"BCS",QAN0,QAN1))
if QAN1'>0
QUIT
SET QAN742=$GET(^QA(742,QAN1,0))
if QAN742]""
SET QANOK=0
if QAN742]""
DO PAT
+11 IF QANQUIT
KILL DA,DIE,DR
SET DIE="^QA(742.4,"
SET DA=QAN0
SET DR=".17///^S X=3"
DO ^DIE
KILL DA,DIE,DR
+12 IF QANQUIT
KILL DA,DIE,DR
SET DIE="^QA(742.4,"
SET DA=QAN0
SET DR=".21///^S X=1"
DO ^DIE
KILL DA,DIE,DR
+13 QUIT
INCK ;Check status of incident
+1 IF QANINCD="HOMICIDE"
SET QANOK=1
+2 IF QANINCD="DEATH"
Begin DoDot:1
+3 SET QANTYDTH=+$GET(QANTYDTH)
+4 IF '$DATA(^QA(742.14,"BUPPER","OTHER",QANTYDTH))
IF ('$DATA(^QA(742.14,"BUPPER","WITHIN 24 HOURS OF ADMISSION (EX. DOA'S AND TERMINALS)",QANTYDTH)))
SET QANOK=1
End DoDot:1
+5 IF QANINCD="SUICIDE"
SET QANOK=1
+6 IF QANINCD="SEXUAL ASSAULT"
SET QANOK=1
+7 IF QANINCD="SUICIDE ATTEMPT"
SET QANOK=1
+8 IF QANINCD="INFORMED CONSENT-FAIL. TO OBTAIN"
SET QANOK=1
+9 IF QANINCD="PATIENT ABUSE"
SET QANOK=1
+10 IF QANINCD="INJURY NOT OTHERWISE LISTED"
IF (QANSLEV'<2)
SET QANOK=1
+11 IF QANINCD="ASSAULT-PATIENT TO PATIENT"
IF (QANSLEV'<2)
SET QANOK=1
+12 IF QANINCD="FIRE-PATIENT INVOLVED IN"
IF (QANSLEV'<2)
SET QANOK=1
+13 IF QANINCD="ASSAULT-PATIENT/STAFF"
IF (QANSLEV'<2)
SET QANOK=1
+14 IF QANINCD="FALL"
IF (QANSLEV'<2)
SET QANOK=1
+15 IF QANINCD="MEDICATION ERROR"
IF (QANSLEV'<2)
SET QANOK=1
+16 IF QANINCD="TRANSFUSION ERROR"
IF (QANSLEV'<2)
SET QANOK=1
+17 IF QANINCD="MISSING PATIENT"
IF (QANSLEV'<2)
SET QANOK=1
+18 QUIT
PAT ;Patient data
+1 SET (QANSRVCE,Y)=$PIECE(QAN742,U,8)
SET C=$PIECE(^DD(742,.08,0),U,2)
if Y]""
DO Y^DIQ
SET QANSRVCE=Y
+2 SET QANSLEV=+$PIECE(QAN742,U,10)
DO INCK
if 'QANOK
QUIT
+3 SET QANQUIT=1
SET QANINCR=QANINCR+1
+4 SET QANPAT=$PIECE(QAN742,U)
SET ^UTILITY($JOB,"QAN PAT",QAN1)=$PIECE(^DPT(QANPAT,0),U)
+5 SET ^UTILITY($JOB,"QAN SSN",QAN1)=$PIECE(^DPT(QANPAT,0),U,9)
+6 SET QANDOB=$PIECE(^DPT(QANPAT,0),U,3)
+7 SET ^UTILITY($JOB,"QAN MAIL",QANINCR)="BRIEF^"_QANCASE_"^INCD^"_QANINCD_"^"_QANDATE_"^^^^"_QANMLGP(0)_"^^^"_$GET(QANPROV)_"^"
+8 SET QANINCR=QANINCR+1
+9 SET ^UTILITY($JOB,"QAN MAIL",QANINCR)="BRIEF^"_QANCASE_"^PAT^"_$GET(^UTILITY($JOB,"QAN PAT",QAN1))_"^"_$GET(^UTILITY($JOB,"QAN SSN",QAN1))_"^"_QANSLEV_"^"_QANTYDTH_"^"_QANSRVCE_"^^"_QANDOB_"^"
+10 IF QANDESC
IF ($DATA(^UTILITY($JOB,"W",DIWL)))
Begin DoDot:1
+11 FOR QA=0:0
SET QA=$ORDER(^UTILITY($JOB,"W",DIWL,QA))
if QA'>0
QUIT
Begin DoDot:2
+12 SET QANINCR=QANINCR+1
+13 SET ^UTILITY($JOB,"QAN MAIL",QANINCR)="BRIEF^"_QANCASE_"^DESC^"_$GET(^UTILITY($JOB,"W",DIWL,QA,0))_"^"
+14 QUIT
End DoDot:2
+15 QUIT
End DoDot:1
+16 QUIT
ERR ;;ERROR MESSAGES: REASONS EWS BULLETIN COULD NOT BE SENT
+1 ;;SITE NOT FOUND IN QA SITE PARAMETERS FILE
+2 ;;SITE NOT FOUND IN INSTITUTION FILE
+3 ;;SITE NUMBER NOT FOUND IN INSTITUTION FILE
+4 ;;NQADB MAIL GROUP/SERVER NOT FOUND IN QA SITE PARAMETERS FILE
+5 ;;NQADB DOMAIN NOT FOUND IN QA SITE PARAMETERS FILE
+6 ;;NQADB DOMAIN NOT FOUND IN DOMAIN FILE
+7 ;;QA INCIDENT MAILGROUP NOT FOUND IN QA SITE PARAMETERS FILE