ECXSASUR ;BIR/DMA-SAS Report from Surgery Extract; 19 Jul 95 / 11:13 AM ;5/17/19 14:40
;;3.0;DSS EXTRACTS;**8,149,178**;Dec 22, 1997;Build 67
EN ;entry point from menu option
N ECXPORT,CNT ;149
W @IOF,!!,"Surgery Extract SAS Report",!!
;ecxaud=1 for 'sas' audit
S ECXHEAD="SUR",ECXAUD=1
;select extract
D AUDIT^ECXUTLA(ECXHEAD,.ECXERR,.ECXARRAY,ECXAUD)
I ECXERR D AUDIT^ECXKILL Q
;select all surgery sites/divisions
S ECXALL=1 D SUR^ECXDVSN2(.ECXDIV,ECXALL,.ECXERR)
I ECXERR D AUDIT^ECXKILL Q
W !!
S ECXPGM="PROCESS^ECXSASUR",ECXDESC="Surgery Extract SAS Report"
S ECXSAVE("ECXHEAD")="",ECXSAVE("ECXDIV(")="",ECXSAVE("ECXARRAY(")=""
S ECXPORT=$$EXPORT^ECXUTL1 Q:ECXPORT=-1 I $G(ECXPORT) D Q ;149 Section added
.K ^TMP($J,"ECXPORT")
.S ^TMP($J,"ECXPORT",0)="EXTRACT LOG #^DIVISION/SITE^FEEDER LOCATION^FDR LOCATION NAME^FEEDER KEY^QUANTITY",CNT=1
.D PROCESS
.D EXPDISP^ECXUTL1
.D AUDIT^ECXKILL
W !
D DEVICE^ECXUTLA(ECXPGM,ECXDESC,.ECXSAVE)
I ECXSAVE("POP")=1 D Q
.W !!,?5,"Try again later... exiting.",! ;149 Fixed spelling of "again"
.D AUDIT^ECXKILL
I ECXSAVE("ZTSK")=0 D
.K ECXSAVE,ECXPGM,ECXDESC
.D PROCESS
I IO'=IO(0) D ^%ZISC
D HOME^%ZIS
D AUDIT^ECXKILL
Q
;
PROCESS ;queued entry
N J,JJ,X,Y,SS,LN,PG,DIV,EC,EC16,EC31,ECF1,ECFK,ECFL,ECFLNM,ECFLX,ECFX,QFLG,TOT,F1,F1SUB,F1NM,F2,F2SUB,F2NM,FL,DIQ,DR,DA,DIR,DIRUT,DTOUT,DUOUT,DIVL
K ^TMP($J,"ECXAUD")
S ECXEXT=ECXARRAY("EXTRACT"),ECXDEF=ECXARRAY("DEF")
S (QFLG,PG)=0,$P(LN,"-",80)=""
;get run date in external format
D NOW^%DTC S Y=$E(%,1,12) D DD^%DT S ECXRUN=Y
;setup array of feeder location names
F F1=1:1:14 S X=$P($T(FEED1+F1),";",3),F1SUB=$P(X,U,1),F1NM=$P(X,U,2) S ^TMP($J,"ECXFL","OR"_F1SUB)=F1NM D
.F F2=1:1:7 S X=$P($T(FEED2+F2),";",3),F2SUB=$P(X,U,1),F2NM=$P(X,U,2) S ^TMP($J,"ECXFL","OR"_F1SUB_F2SUB)=F1NM_" - "_F2NM,FL(F2SUB)=F2NM
;process extract records
;type='p'rimary or 's'econdary or 'i'mplant
;ignore type=secondary
S J="" F S J=$O(^ECX(727.811,"AC",ECXEXT,J)) Q:'J I $D(^ECX(727.811,J,0)) S EC=^(0),DIV=$P(EC,U,4) I $P(EC,U,17)'="S",$P(EC,U,28)'="C" D
.S EC16="" ;178 - NCD 21-12
.;determine feeder location
.S ECF1=$E($P(EC,U,32),1,4)
.I ECF1="" D
..S ECF1=$P(EC,U,30),ECF1="OR"_$E("GEORCANECNAMINENCYWACLDEOT",ECF1*2-1,ECF1*2)
..S:ECF1="OR" ECF1="ORNO"
..I $P(EC,U,30)="",$P(EC,U,12)="",$P(EC,U,11)="059" S ECF1="ORCY"
.S ECFL=DIV_ECF1
.;determine surgical specialty
.S ECSS=$P(EC,U,11) S:ECSS="" ECSS=999 I $P(EC,U,32)'="" S ECSS="NON"
.;type=implant generates one product record; volume is always at least 1
.I $P(EC,U,17)="I" D Q
..S ECFLX=ECFL_"I",ECFK=ECSS_"-"_$$RJ^XLFSTR($P(EC,U,23),5,0)
..S ECQ=$P(EC,U,24) S:'ECQ ECQ=1
..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFLX,ECFK))+ECQ
.;type=primary generates four or five product records, but only two are of interest here
.;anesthesia time product
.S ECQ=+$P(EC,U,22) I ECQ>0 D
..S ECFLX=ECFL_"A",EC16=$P(EC,U,16)
..S ECD=$S(EC16="G":1,EC16="L":3,EC16="S":4,EC16="E":4,EC16="M":7,EC16="":6,1:5)
..S ECFK=ECSS_"-"_"2"_ECD
..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFLX,ECFK))+ECQ
.;surgeon time product
.S ECQ=+$P(EC,U,21) I ECQ>0 D
..S EC31=+$P(EC,U,31),ECFX=$S(EC31=10:"D",EC31=24:"M",EC31=32:"P",EC31=43:"C",1:"S")
..S ECFLX=ECFL_ECFX
..S ECFK=ECSS_"-40"
..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFLX,ECFK))+ECQ
.;patient time product
.S ECQ=+$P(EC,U,20) I ECQ>0 D
..S ECFK=ECSS_"-10"
..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+ECQ
.;recovery room time product only if not cystoscopy and not non-or
.;178 21-12
.;I ECFL'="ORCY",$P(EC,U,32)="" D
.;.S ECQ=+$P(EC,U,33) I ECQ>0 D
.;..S ECFK=ECSS_"-60"
.;..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+ECQ
.S ECFK=ECSS_"-60"
.S ECQ=+$P(EC,U,33)
.I ECQ>0 S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+ECQ
.I ECQ=0 D
.. I $F("GLMSE",$G(EC16))>1 S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+2
.;technician time product, only for cystoscopy
.I ECFL="ORCY" D
..S ECQ=+$P(EC,U,20) S:($P(EC,U,22)>$P(EC,U,20)) ECQ=+$P(EC,U,22) I ECQ>0 D
...S ECFK=ECSS_"-70"
...S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+ECQ
.;cleanup time product
.S ECQ=2 D
..S ECFK=ECSS_"-30"
..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+ECQ
;print the report
U IO
S DIV="" F S DIV=$O(^TMP($J,"ECXAUD",DIV)) Q:DIV="" D Q:QFLG
.I '$G(ECXPORT) D HEADER ;149
.S ECFL="" F S ECFL=$O(^TMP($J,"ECXAUD",DIV,ECFL)) Q:ECFL="" D Q:QFLG
..S DIVL=$L(DIV),ECFLX=$E(ECFL,DIVL+1,99),ECFLNM=$G(^TMP($J,"ECXFL",ECFLX)) S:ECFLNM="" ECFLNM="NON-OR"
..I ECFLNM="NON-OR" D
...S F2SUB=$E(ECFLX,5),F2NM=""
...S:F2SUB]"" F2NM=$G(FL(F2SUB)) S:F2NM]"" ECFLNM=ECFLNM_" - "_F2NM
..I '$G(ECXPORT) D:($Y+3>IOSL) HEADER Q:QFLG W !,ECFL,?12,ECFLNM ;149
..S ECFK="" F S ECFK=$O(^TMP($J,"ECXAUD",DIV,ECFL,ECFK)) Q:ECFK="" S TOT=^(ECFK) D Q:QFLG
...I $G(ECXPORT) S ^TMP($J,"ECXPORT",CNT)=ECXEXT_U_$P($G(ECXDIV(DIV)),U,2)_"("_$P($G(ECXDIV(DIV)),U)_")"_U_ECFL_U_ECFLNM_U_ECFK_U_TOT,CNT=CNT+1 Q ;149
...D:($Y+3>IOSL) HEADER Q:QFLG W ?48,ECFK,?68,$$RJ^XLFSTR(TOT,6," "),!
;close
I $G(ECXPORT) Q ;149
I $E(IOST)'="C" W @IOF
I $E(IOST)="C",'QFLG D
.S SS=22-$Y F JJ=1:1:SS W !
.S DIR(0)="E" W ! D ^DIR K DIR
D AUDIT^ECXKILL
Q
N ECXTAB
S ECXTAB=48
D SASHEAD^ECXUTLA(DIV,ECXHEAD,.ECXDIV,.ECXARRAY,.PG,ECXTAB)
Q
;
FEED1 ;or location names
;;AM^AMBULATORY OR
;;CA^CARDIAC OR
;;CL^CLINIC
;;CN^CARDIAC/NEURO OR
;;CY^CYSTOSCOPY RM.
;;DE^DEDICATED RM.
;;EN^ENDOSCOPY RM.
;;GE^GENERAL OR
;;IN^ICU
;;NE^NEUROSURGERY OR
;;NO^UNKNOWN
;;OR^ORTHOPEDIC OR
;;OT^OTHER LOCATION
;;WA^WARD
;
FEED2 ;service location names
;;A^ANESTHESIA
;;I^IMPLANTS
;;C^SPINAL CORD
;;D^DENTAL
;;M^MEDICINE
;;P^PSYCH
;;S^SURGERY
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HECXSASUR 5833 printed Dec 13, 2024@01:53:47 Page 2
ECXSASUR ;BIR/DMA-SAS Report from Surgery Extract; 19 Jul 95 / 11:13 AM ;5/17/19 14:40
+1 ;;3.0;DSS EXTRACTS;**8,149,178**;Dec 22, 1997;Build 67
EN ;entry point from menu option
+1 ;149
NEW ECXPORT,CNT
+2 WRITE @IOF,!!,"Surgery Extract SAS Report",!!
+3 ;ecxaud=1 for 'sas' audit
+4 SET ECXHEAD="SUR"
SET ECXAUD=1
+5 ;select extract
+6 DO AUDIT^ECXUTLA(ECXHEAD,.ECXERR,.ECXARRAY,ECXAUD)
+7 IF ECXERR
DO AUDIT^ECXKILL
QUIT
+8 ;select all surgery sites/divisions
+9 SET ECXALL=1
DO SUR^ECXDVSN2(.ECXDIV,ECXALL,.ECXERR)
+10 IF ECXERR
DO AUDIT^ECXKILL
QUIT
+11 WRITE !!
+12 SET ECXPGM="PROCESS^ECXSASUR"
SET ECXDESC="Surgery Extract SAS Report"
+13 SET ECXSAVE("ECXHEAD")=""
SET ECXSAVE("ECXDIV(")=""
SET ECXSAVE("ECXARRAY(")=""
+14 ;149 Section added
SET ECXPORT=$$EXPORT^ECXUTL1
if ECXPORT=-1
QUIT
IF $GET(ECXPORT)
Begin DoDot:1
+15 KILL ^TMP($JOB,"ECXPORT")
+16 SET ^TMP($JOB,"ECXPORT",0)="EXTRACT LOG #^DIVISION/SITE^FEEDER LOCATION^FDR LOCATION NAME^FEEDER KEY^QUANTITY"
SET CNT=1
+17 DO PROCESS
+18 DO EXPDISP^ECXUTL1
+19 DO AUDIT^ECXKILL
End DoDot:1
QUIT
+20 WRITE !
+21 DO DEVICE^ECXUTLA(ECXPGM,ECXDESC,.ECXSAVE)
+22 IF ECXSAVE("POP")=1
Begin DoDot:1
+23 ;149 Fixed spelling of "again"
WRITE !!,?5,"Try again later... exiting.",!
+24 DO AUDIT^ECXKILL
End DoDot:1
QUIT
+25 IF ECXSAVE("ZTSK")=0
Begin DoDot:1
+26 KILL ECXSAVE,ECXPGM,ECXDESC
+27 DO PROCESS
End DoDot:1
+28 IF IO'=IO(0)
DO ^%ZISC
+29 DO HOME^%ZIS
+30 DO AUDIT^ECXKILL
+31 QUIT
+32 ;
PROCESS ;queued entry
+1 NEW J,JJ,X,Y,SS,LN,PG,DIV,EC,EC16,EC31,ECF1,ECFK,ECFL,ECFLNM,ECFLX,ECFX,QFLG,TOT,F1,F1SUB,F1NM,F2,F2SUB,F2NM,FL,DIQ,DR,DA,DIR,DIRUT,DTOUT,DUOUT,DIVL
+2 KILL ^TMP($JOB,"ECXAUD")
+3 SET ECXEXT=ECXARRAY("EXTRACT")
SET ECXDEF=ECXARRAY("DEF")
+4 SET (QFLG,PG)=0
SET $PIECE(LN,"-",80)=""
+5 ;get run date in external format
+6 DO NOW^%DTC
SET Y=$EXTRACT(%,1,12)
DO DD^%DT
SET ECXRUN=Y
+7 ;setup array of feeder location names
+8 FOR F1=1:1:14
SET X=$PIECE($TEXT(FEED1+F1),";",3)
SET F1SUB=$PIECE(X,U,1)
SET F1NM=$PIECE(X,U,2)
SET ^TMP($JOB,"ECXFL","OR"_F1SUB)=F1NM
Begin DoDot:1
+9 FOR F2=1:1:7
SET X=$PIECE($TEXT(FEED2+F2),";",3)
SET F2SUB=$PIECE(X,U,1)
SET F2NM=$PIECE(X,U,2)
SET ^TMP($JOB,"ECXFL","OR"_F1SUB_F2SUB)=F1NM_" - "_F2NM
SET FL(F2SUB)=F2NM
End DoDot:1
+10 ;process extract records
+11 ;type='p'rimary or 's'econdary or 'i'mplant
+12 ;ignore type=secondary
+13 SET J=""
FOR
SET J=$ORDER(^ECX(727.811,"AC",ECXEXT,J))
if 'J
QUIT
IF $DATA(^ECX(727.811,J,0))
SET EC=^(0)
SET DIV=$PIECE(EC,U,4)
IF $PIECE(EC,U,17)'="S"
IF $PIECE(EC,U,28)'="C"
Begin DoDot:1
+14 ;178 - NCD 21-12
SET EC16=""
+15 ;determine feeder location
+16 SET ECF1=$EXTRACT($PIECE(EC,U,32),1,4)
+17 IF ECF1=""
Begin DoDot:2
+18 SET ECF1=$PIECE(EC,U,30)
SET ECF1="OR"_$EXTRACT("GEORCANECNAMINENCYWACLDEOT",ECF1*2-1,ECF1*2)
+19 if ECF1="OR"
SET ECF1="ORNO"
+20 IF $PIECE(EC,U,30)=""
IF $PIECE(EC,U,12)=""
IF $PIECE(EC,U,11)="059"
SET ECF1="ORCY"
End DoDot:2
+21 SET ECFL=DIV_ECF1
+22 ;determine surgical specialty
+23 SET ECSS=$PIECE(EC,U,11)
if ECSS=""
SET ECSS=999
IF $PIECE(EC,U,32)'=""
SET ECSS="NON"
+24 ;type=implant generates one product record; volume is always at least 1
+25 IF $PIECE(EC,U,17)="I"
Begin DoDot:2
+26 SET ECFLX=ECFL_"I"
SET ECFK=ECSS_"-"_$$RJ^XLFSTR($PIECE(EC,U,23),5,0)
+27 SET ECQ=$PIECE(EC,U,24)
if 'ECQ
SET ECQ=1
+28 SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFLX,ECFK))+ECQ
End DoDot:2
QUIT
+29 ;type=primary generates four or five product records, but only two are of interest here
+30 ;anesthesia time product
+31 SET ECQ=+$PIECE(EC,U,22)
IF ECQ>0
Begin DoDot:2
+32 SET ECFLX=ECFL_"A"
SET EC16=$PIECE(EC,U,16)
+33 SET ECD=$SELECT(EC16="G":1,EC16="L":3,EC16="S":4,EC16="E":4,EC16="M":7,EC16="":6,1:5)
+34 SET ECFK=ECSS_"-"_"2"_ECD
+35 SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFLX,ECFK))+ECQ
End DoDot:2
+36 ;surgeon time product
+37 SET ECQ=+$PIECE(EC,U,21)
IF ECQ>0
Begin DoDot:2
+38 SET EC31=+$PIECE(EC,U,31)
SET ECFX=$SELECT(EC31=10:"D",EC31=24:"M",EC31=32:"P",EC31=43:"C",1:"S")
+39 SET ECFLX=ECFL_ECFX
+40 SET ECFK=ECSS_"-40"
+41 SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFLX,ECFK))+ECQ
End DoDot:2
+42 ;patient time product
+43 SET ECQ=+$PIECE(EC,U,20)
IF ECQ>0
Begin DoDot:2
+44 SET ECFK=ECSS_"-10"
+45 SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFL,ECFK))+ECQ
End DoDot:2
+46 ;recovery room time product only if not cystoscopy and not non-or
+47 ;178 21-12
+48 ;I ECFL'="ORCY",$P(EC,U,32)="" D
+49 ;.S ECQ=+$P(EC,U,33) I ECQ>0 D
+50 ;..S ECFK=ECSS_"-60"
+51 ;..S ^(ECFK)=$G(^TMP($J,"ECXAUD",DIV,ECFL,ECFK))+ECQ
+52 SET ECFK=ECSS_"-60"
+53 SET ECQ=+$PIECE(EC,U,33)
+54 IF ECQ>0
SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFL,ECFK))+ECQ
+55 IF ECQ=0
Begin DoDot:2
+56 IF $FIND("GLMSE",$GET(EC16))>1
SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFL,ECFK))+2
End DoDot:2
+57 ;technician time product, only for cystoscopy
+58 IF ECFL="ORCY"
Begin DoDot:2
+59 SET ECQ=+$PIECE(EC,U,20)
if ($PIECE(EC,U,22)>$PIECE(EC,U,20))
SET ECQ=+$PIECE(EC,U,22)
IF ECQ>0
Begin DoDot:3
+60 SET ECFK=ECSS_"-70"
+61 SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFL,ECFK))+ECQ
End DoDot:3
End DoDot:2
+62 ;cleanup time product
+63 SET ECQ=2
Begin DoDot:2
+64 SET ECFK=ECSS_"-30"
+65 SET ^(ECFK)=$GET(^TMP($JOB,"ECXAUD",DIV,ECFL,ECFK))+ECQ
End DoDot:2
End DoDot:1
+66 ;print the report
+67 USE IO
+68 SET DIV=""
FOR
SET DIV=$ORDER(^TMP($JOB,"ECXAUD",DIV))
if DIV=""
QUIT
Begin DoDot:1
+69 ;149
IF '$GET(ECXPORT)
DO HEADER
+70 SET ECFL=""
FOR
SET ECFL=$ORDER(^TMP($JOB,"ECXAUD",DIV,ECFL))
if ECFL=""
QUIT
Begin DoDot:2
+71 SET DIVL=$LENGTH(DIV)
SET ECFLX=$EXTRACT(ECFL,DIVL+1,99)
SET ECFLNM=$GET(^TMP($JOB,"ECXFL",ECFLX))
if ECFLNM=""
SET ECFLNM="NON-OR"
+72 IF ECFLNM="NON-OR"
Begin DoDot:3
+73 SET F2SUB=$EXTRACT(ECFLX,5)
SET F2NM=""
+74 if F2SUB]""
SET F2NM=$GET(FL(F2SUB))
if F2NM]""
SET ECFLNM=ECFLNM_" - "_F2NM
End DoDot:3
+75 ;149
IF '$GET(ECXPORT)
if ($Y+3>IOSL)
DO HEADER
if QFLG
QUIT
WRITE !,ECFL,?12,ECFLNM
+76 SET ECFK=""
FOR
SET ECFK=$ORDER(^TMP($JOB,"ECXAUD",DIV,ECFL,ECFK))
if ECFK=""
QUIT
SET TOT=^(ECFK)
Begin DoDot:3
+77 ;149
IF $GET(ECXPORT)
SET ^TMP($JOB,"ECXPORT",CNT)=ECXEXT_U_$PIECE($GET(ECXDIV(DIV)),U,2)_"("_$PIECE($GET(ECXDIV(DIV)),U)_")"_U_ECFL_U_ECFLNM_U_ECFK_U_TOT
SET CNT=CNT+1
QUIT
+78 if ($Y+3>IOSL)
DO HEADER
if QFLG
QUIT
WRITE ?48,ECFK,?68,$$RJ^XLFSTR(TOT,6," "),!
End DoDot:3
if QFLG
QUIT
End DoDot:2
if QFLG
QUIT
End DoDot:1
if QFLG
QUIT
+79 ;close
+80 ;149
IF $GET(ECXPORT)
QUIT
+81 IF $EXTRACT(IOST)'="C"
WRITE @IOF
+82 IF $EXTRACT(IOST)="C"
IF 'QFLG
Begin DoDot:1
+83 SET SS=22-$Y
FOR JJ=1:1:SS
WRITE !
+84 SET DIR(0)="E"
WRITE !
DO ^DIR
KILL DIR
End DoDot:1
+85 DO AUDIT^ECXKILL
+86 QUIT
+1 NEW ECXTAB
+2 SET ECXTAB=48
+3 DO SASHEAD^ECXUTLA(DIV,ECXHEAD,.ECXDIV,.ECXARRAY,.PG,ECXTAB)
+4 QUIT
+5 ;
FEED1 ;or location names
+1 ;;AM^AMBULATORY OR
+2 ;;CA^CARDIAC OR
+3 ;;CL^CLINIC
+4 ;;CN^CARDIAC/NEURO OR
+5 ;;CY^CYSTOSCOPY RM.
+6 ;;DE^DEDICATED RM.
+7 ;;EN^ENDOSCOPY RM.
+8 ;;GE^GENERAL OR
+9 ;;IN^ICU
+10 ;;NE^NEUROSURGERY OR
+11 ;;NO^UNKNOWN
+12 ;;OR^ORTHOPEDIC OR
+13 ;;OT^OTHER LOCATION
+14 ;;WA^WARD
+15 ;
FEED2 ;service location names
+1 ;;A^ANESTHESIA
+2 ;;I^IMPLANTS
+3 ;;C^SPINAL CORD
+4 ;;D^DENTAL
+5 ;;M^MEDICINE
+6 ;;P^PSYCH
+7 ;;S^SURGERY