SCRPW56 ;RENO/KEITH - Most Frequent 50 CPT Codes (OP6) or (IP6) ;06/22/99
;;5.3;Scheduling;**144,180,466,1015**;AUG 13, 1993;Build 21
;06/22/99 ACS - Added CPT modifier API calls
;
S SDSTA=$G(SDSTA,2)
D RQUE^SCRPW50("START^SCRPW56","Most Frequent 50 CPT Codes "_$S(SDSTA=2:"(OP6)",1:"(IP6)"),1) Q
;
START ;Print report
K ^TMP("SCRPW",$J) S (SDSTOP,SDOUT)=0,SDT=SD("FYD")
F S SDT=$O(^SCE("B",SDT)) Q:'SDT!SDOUT!(SDT>SD("EDT")) S SDOE=0 F S SDOE=$O(^SCE("B",SDT,SDOE)) Q:'SDOE!SDOUT S SDOE0=$$GETOE^SDOE(SDOE),SDIV=$P(SDOE0,U,11) I $$VALID() D SET(SDIV) D:SDMD SET(0)
G:SDOUT EXIT S (SDVCT,SDIV)=""
F S SDIV=$O(^TMP("SCRPW",$J,SDIV)) Q:SDIV=""!SDOUT D STOP,DLIST S SDCPT="" F S SDCPT=$O(^TMP("SCRPW",$J,SDIV,0,SDCPT)) Q:SDCPT=""!SDOUT S SDI=^TMP("SCRPW",$J,SDIV,0,SDCPT),^TMP("SCRPW",$J,SDIV,1,SDI,SDCPT)=""
G:SDOUT EXIT S SDLINE="",$P(SDLINE,"-",(IOM+1))="" D NOW^%DTC S Y=% X ^DD("DD") S SDPNOW=$P(Y,":",1,2),SDTIT(1)="<*> MOST FREQUENT 50 CPT CODES "_$S(SDSTA=2:"(OP6)",1:"(IP6)")_" <*>",SDPG=0 D:$E(IOST)="C" DISP0^SCRPW23
I '$D(^TMP("SCRPW",$J)) S SDPAGE=1,SDX="No activity found within report parameters." D HDR G:SDOUT EXIT W !!?(IOM-$L(SDX)\2),SDX G EXIT
G:SDOUT EXIT S SDIVN="" F S SDIVN=$O(SDIV(SDIVN)) Q:SDIVN=""!SDOUT D DPRT(SDIV(SDIVN))
G:SDOUT EXIT D:SDVCT>1 DPRT(0)
EXIT I $E(IOST)="C",'SDOUT N DIR S DIR(0)="E" D ^DIR
K ^TMP("SCRPW",$J),%,%H,%I,DIR,SD,SDCPT,SDDIV,SDFL,SDI,SDII,SDIII,SDIV,SDIVN,SDLINE,SDMD,SDOE,SDOE0,SDOUT,SDPAGE,SDPG,SDPNOW,SDPROC,SDPRTY,SDPT,SDPTN,SDQTY,SDSTOP,SDT,SDTIT,SDV,SDVCT,SDX,X,Y Q
;
DPRT(SDV) ;Print division
;Required input: SDV=division ifn or '0' for combined divisions
I SDV S SDTIT(2)="For "_$S(SDDIV["DIVISIONS":"division",1:"facility")_": "_SDIVN
I 'SDV S SDTIT(2)="Report for: "_$P(SDDIV,U,2) D
.S SDI=2,SDIVN="" F S SDIVN=$O(SDIV(SDIVN)) Q:SDIVN="" S SDI=SDI+1,SDTIT(SDI)=$J("Division: ",$L(SDIVN))_SDIVN
.Q
S SDPAGE=1 D HDR Q:SDOUT S (SDI,SDII)="" F S SDI=$O(^TMP("SCRPW",$J,SDV,1,SDI),-1) Q:SDI=""!SDOUT!(SDII>49) S SDCPT="" F S SDCPT=$O(^TMP("SCRPW",$J,SDV,1,SDI,SDCPT)) Q:SDCPT=""!SDOUT!(SDII>49) D PLINE
Q
;
PLINE ;Print output line
D:$Y>(IOSL-8) HDR Q:SDOUT D HD1
;S SDPROC=$G(^ICPT(SDCPT,0)),SDPROC=$P(SDPROC,U)_" "_$P(SDPROC,U,2),SDII=SDII+1
N CPTINFO,CPTCODE,CPTTEXT
S CPTINFO=$$CPT^ICPTCOD(SDCPT,,1)
Q:CPTINFO'>0
S CPTCODE=$P(CPTINFO,"^",2)
S CPTTEXT=$P(CPTINFO,"^",3)
S SDPROC=CPTCODE_" "_CPTTEXT
S SDII=SDII+1
W !?7,$J(SDII,3),?13,SDPROC,?50,$J(SDI,10,0) D W !
.S (SDFL,SDPT)="" F S SDPT=$O(^TMP("SCRPW",$J,SDV,0,SDCPT,SDPT)) Q:SDPT=""!SDOUT D
..I $Y>(IOSL-3) D HDR,HD1 Q:SDOUT S SDFL=1
..S SDPTN=$$CODE2TXT^XUA4A72(SDPT),SDPTN=$P(SDPT,"V",2)_" "_$P(SDPTN,U,2)
..W:SDFL ! W ?62,$E(SDPTN,1,50),?114,$J(^TMP("SCRPW",$J,SDV,0,SDCPT,SDPT),10,0) S SDFL=SDFL+1
..Q
.Q
Q
;
HDR ;Print header
I $E(IOST)="C",SDPG N DIR S DIR(0)="E" W ! D ^DIR S SDOUT=Y'=1 Q:SDOUT
D STOP Q:SDOUT W:SDPG!($E(IOST)="C") $$XY^SCRPW50(IOF,1,0) W:$X $$XY^SCRPW50("",0,0)
N SDI S SDI=0 W SDLINE F S SDI=$O(SDTIT(SDI)) Q:'SDI W !?(IOM-$L(SDTIT(SDI))\2),SDTIT(SDI)
W !,SDLINE,!,"For Fiscal Year activity through ",SD("PEDT"),!,"Date printed: ",SDPNOW,?(IOM-6-$L(SDPAGE)),"Page: ",SDPAGE,!,SDLINE S SDPAGE=SDPAGE+1,SDPG=1 Q
;
HD1 ;Print subheader
Q:SDOUT W !?52,"CPT Code",?114,"Prov. Type",!?7,"Rank",?13,"CPT Code",?51,"Frequency",?62,"Provider Type",?115,"Frequency"
W !?7,"----",?13,$E(SDLINE,1,35),?50,$E(SDLINE,1,10),?62,$E(SDLINE,1,50),?114,$E(SDLINE,1,10) Q
;
DLIST ;Create alphabetic list of divisions found
Q:'SDIV S SDX=$P($G(^DG(40.8,SDIV,0)),U) S:'$L(SDX) SDX="*** UNKNOWN ***" S SDIV(SDX)=SDIV,SDVCT=SDVCT+1 Q
;
VALID() ;Check encounter record
I $P(SDOE0,U,4),$P($G(^SC($P(SDOE0,U,4),0)),U,17)="Y" Q 0
I SDIV,$$DIV(),$P(SDOE0,U,2),'$P(SDOE0,U,6),$P(SDOE0,U,7),$P(SDOE0,U,12)=SDSTA Q 1
Q 0
;
DIV() ;Check division
Q:'SDDIV 1 Q $D(SDDIV(SDIV))
;
STOP ;Check for stop task request
S:$D(ZTQUEUED) (SDOUT,ZTSTOP)=$S($$S^%ZTLOAD:1,1:0) Q
;
SET(SDIV) ;Set division lists
;Required input: SDIV=division ifn or '0' for summary
S SDSTOP=SDSTOP+1 I SDSTOP#2000=0 D STOP^SCRPW40 Q:SDOUT
N SDPROC,SDPRTY,SDI,SDII,SDIII,SDX
D GETCPT^SDOE(SDOE,"SDPROC"),PROV^SCRPW50(SDOE,.SDPRTY)
S SDI=0 F S SDI=$O(SDPROC(SDI)) Q:'SDI S SDCPT=$P(SDPROC(SDI),U),SDQTY=$P(SDPROC(SDI),U,16) S:'SDQTY SDQTY=1 I SDCPT D
.S ^TMP("SCRPW",$J,SDIV,0,SDCPT)=$G(^TMP("SCRPW",$J,SDIV,0,SDCPT))+SDQTY
.S SDII=0 F S SDII=$O(SDPRTY(SDII)) Q:'SDII S SDX=SDPRTY(SDII) I $L(SDX) D
..S ^TMP("SCRPW",$J,SDIV,0,SDCPT,SDX)=$G(^TMP("SCRPW",$J,SDIV,0,SDCPT,SDX))+1
..Q
.Q
Q
SCRPW56 ;RENO/KEITH - Most Frequent 50 CPT Codes (OP6) or (IP6) ;06/22/99
+1 ;;5.3;Scheduling;**144,180,466,1015**;AUG 13, 1993;Build 21
+2 ;06/22/99 ACS - Added CPT modifier API calls
+3 ;
+4 SET SDSTA=$GET(SDSTA,2)
+5 DO RQUE^SCRPW50("START^SCRPW56","Most Frequent 50 CPT Codes "_$SELECT(SDSTA=2:"(OP6)",1:"(IP6)"),1)
QUIT
+6 ;
START ;Print report
+1 KILL ^TMP("SCRPW",$JOB)
SET (SDSTOP,SDOUT)=0
SET SDT=SD("FYD")
+2 FOR
SET SDT=$ORDER(^SCE("B",SDT))
IF 'SDT!SDOUT!(SDT>SD("EDT"))
QUIT
SET SDOE=0
FOR
SET SDOE=$ORDER(^SCE("B",SDT,SDOE))
IF 'SDOE!SDOUT
QUIT
SET SDOE0=$$GETOE^SDOE(SDOE)
SET SDIV=$PIECE(SDOE0,U,11)
IF $$VALID()
DO SET(SDIV)
IF SDMD
DO SET(0)
+3 IF SDOUT
GOTO EXIT
SET (SDVCT,SDIV)=""
+4 FOR
SET SDIV=$ORDER(^TMP("SCRPW",$JOB,SDIV))
IF SDIV=""!SDOUT
QUIT
DO STOP
DO DLIST
SET SDCPT=""
FOR
SET SDCPT=$ORDER(^TMP("SCRPW",$JOB,SDIV,0,SDCPT))
IF SDCPT=""!SDOUT
QUIT
SET SDI=^TMP("SCRPW",$JOB,SDIV,0,SDCPT)
SET ^TMP("SCRPW",$JOB,SDIV,1,SDI,SDCPT)=""
+5 IF SDOUT
GOTO EXIT
SET SDLINE=""
SET $PIECE(SDLINE,"-",(IOM+1))=""
DO NOW^%DTC
SET Y=%
XECUTE ^DD("DD")
SET SDPNOW=$PIECE(Y,":",1,2)
SET SDTIT(1)="<*> MOST FREQUENT 50 CPT CODES "_$SELECT(SDSTA=2:"(OP6)",1:"(IP6)")_" <*>"
SET SDPG=0
IF $EXTRACT(IOST)="C"
DO DISP0^SCRPW23
+6 IF '$DATA(^TMP("SCRPW",$JOB))
SET SDPAGE=1
SET SDX="No activity found within report parameters."
DO HDR
IF SDOUT
GOTO EXIT
WRITE !!?(IOM-$LENGTH(SDX)\2),SDX
GOTO EXIT
+7 IF SDOUT
GOTO EXIT
SET SDIVN=""
FOR
SET SDIVN=$ORDER(SDIV(SDIVN))
IF SDIVN=""!SDOUT
QUIT
DO DPRT(SDIV(SDIVN))
+8 IF SDOUT
GOTO EXIT
IF SDVCT>1
DO DPRT(0)
EXIT IF $EXTRACT(IOST)="C"
IF 'SDOUT
NEW DIR
SET DIR(0)="E"
DO ^DIR
+1 KILL ^TMP("SCRPW",$JOB),%,%H,%I,DIR,SD,SDCPT,SDDIV,SDFL,SDI,SDII,SDIII,SDIV,SDIVN,SDLINE,SDMD,SDOE,SDOE0,SDOUT,SDPAGE,SDPG,SDPNOW,SDPROC,SDPRTY,SDPT,SDPTN,SDQTY,SDSTOP,SDT,SDTIT,SDV,SDVCT,SDX,X,Y
QUIT
+2 ;
DPRT(SDV) ;Print division
+1 ;Required input: SDV=division ifn or '0' for combined divisions
+2 IF SDV
SET SDTIT(2)="For "_$SELECT(SDDIV["DIVISIONS":"division",1:"facility")_": "_SDIVN
+3 IF 'SDV
SET SDTIT(2)="Report for: "_$PIECE(SDDIV,U,2)
Begin DoDot:1
+4 SET SDI=2
SET SDIVN=""
FOR
SET SDIVN=$ORDER(SDIV(SDIVN))
IF SDIVN=""
QUIT
SET SDI=SDI+1
SET SDTIT(SDI)=$JUSTIFY("Division: ",$LENGTH(SDIVN))_SDIVN
+5 QUIT
End DoDot:1
+6 SET SDPAGE=1
DO HDR
IF SDOUT
QUIT
SET (SDI,SDII)=""
FOR
SET SDI=$ORDER(^TMP("SCRPW",$JOB,SDV,1,SDI),-1)
IF SDI=""!SDOUT!(SDII>49)
QUIT
SET SDCPT=""
FOR
SET SDCPT=$ORDER(^TMP("SCRPW",$JOB,SDV,1,SDI,SDCPT))
IF SDCPT=""!SDOUT!(SDII>49)
QUIT
DO PLINE
+7 QUIT
+8 ;
PLINE ;Print output line
+1 IF $Y>(IOSL-8)
DO HDR
IF SDOUT
QUIT
DO HD1
+2 ;S SDPROC=$G(^ICPT(SDCPT,0)),SDPROC=$P(SDPROC,U)_" "_$P(SDPROC,U,2),SDII=SDII+1
+3 NEW CPTINFO,CPTCODE,CPTTEXT
+4 SET CPTINFO=$$CPT^ICPTCOD(SDCPT,,1)
+5 IF CPTINFO'>0
QUIT
+6 SET CPTCODE=$PIECE(CPTINFO,"^",2)
+7 SET CPTTEXT=$PIECE(CPTINFO,"^",3)
+8 SET SDPROC=CPTCODE_" "_CPTTEXT
+9 SET SDII=SDII+1
+10 WRITE !?7,$JUSTIFY(SDII,3),?13,SDPROC,?50,$JUSTIFY(SDI,10,0)
Begin DoDot:1
+11 SET (SDFL,SDPT)=""
FOR
SET SDPT=$ORDER(^TMP("SCRPW",$JOB,SDV,0,SDCPT,SDPT))
IF SDPT=""!SDOUT
QUIT
Begin DoDot:2
+12 IF $Y>(IOSL-3)
DO HDR
DO HD1
IF SDOUT
QUIT
SET SDFL=1
+13 SET SDPTN=$$CODE2TXT^XUA4A72(SDPT)
SET SDPTN=$PIECE(SDPT,"V",2)_" "_$PIECE(SDPTN,U,2)
+14 IF SDFL
WRITE !
WRITE ?62,$EXTRACT(SDPTN,1,50),?114,$JUSTIFY(^TMP("SCRPW",$JOB,SDV,0,SDCPT,SDPT),10,0)
SET SDFL=SDFL+1
+15 QUIT
End DoDot:2
+16 QUIT
End DoDot:1
WRITE !
+17 QUIT
+18 ;
HDR ;Print header
+1 IF $EXTRACT(IOST)="C"
IF SDPG
NEW DIR
SET DIR(0)="E"
WRITE !
DO ^DIR
SET SDOUT=Y'=1
IF SDOUT
QUIT
+2 DO STOP
IF SDOUT
QUIT
IF SDPG!($EXTRACT(IOST)="C")
WRITE $$XY^SCRPW50(IOF,1,0)
IF $X
WRITE $$XY^SCRPW50("",0,0)
+3 NEW SDI
SET SDI=0
WRITE SDLINE
FOR
SET SDI=$ORDER(SDTIT(SDI))
IF 'SDI
QUIT
WRITE !?(IOM-$LENGTH(SDTIT(SDI))\2),SDTIT(SDI)
+4 WRITE !,SDLINE,!,"For Fiscal Year activity through ",SD("PEDT"),!,"Date printed: ",SDPNOW,?(IOM-6-$LENGTH(SDPAGE)),"Page: ",SDPAGE,!,SDLINE
SET SDPAGE=SDPAGE+1
SET SDPG=1
QUIT
+5 ;
HD1 ;Print subheader
+1 IF SDOUT
QUIT
WRITE !?52,"CPT Code",?114,"Prov. Type",!?7,"Rank",?13,"CPT Code",?51,"Frequency",?62,"Provider Type",?115,"Frequency"
+2 WRITE !?7,"----",?13,$EXTRACT(SDLINE,1,35),?50,$EXTRACT(SDLINE,1,10),?62,$EXTRACT(SDLINE,1,50),?114,$EXTRACT(SDLINE,1,10)
QUIT
+3 ;
DLIST ;Create alphabetic list of divisions found
+1 IF 'SDIV
QUIT
SET SDX=$PIECE($GET(^DG(40.8,SDIV,0)),U)
IF '$LENGTH(SDX)
SET SDX="*** UNKNOWN ***"
SET SDIV(SDX)=SDIV
SET SDVCT=SDVCT+1
QUIT
+2 ;
VALID() ;Check encounter record
+1 IF $PIECE(SDOE0,U,4)
IF $PIECE($GET(^SC($PIECE(SDOE0,U,4),0)),U,17)="Y"
QUIT 0
+2 IF SDIV
IF $$DIV()
IF $PIECE(SDOE0,U,2)
IF '$PIECE(SDOE0,U,6)
IF $PIECE(SDOE0,U,7)
IF $PIECE(SDOE0,U,12)=SDSTA
QUIT 1
+3 QUIT 0
+4 ;
DIV() ;Check division
+1 IF 'SDDIV
QUIT 1
QUIT $DATA(SDDIV(SDIV))
+2 ;
STOP ;Check for stop task request
+1 IF $DATA(ZTQUEUED)
SET (SDOUT,ZTSTOP)=$SELECT($$S^%ZTLOAD:1,1:0)
QUIT
+2 ;
SET(SDIV) ;Set division lists
+1 ;Required input: SDIV=division ifn or '0' for summary
+2 SET SDSTOP=SDSTOP+1
IF SDSTOP#2000=0
DO STOP^SCRPW40
IF SDOUT
QUIT
+3 NEW SDPROC,SDPRTY,SDI,SDII,SDIII,SDX
+4 DO GETCPT^SDOE(SDOE,"SDPROC")
DO PROV^SCRPW50(SDOE,.SDPRTY)
+5 SET SDI=0
FOR
SET SDI=$ORDER(SDPROC(SDI))
IF 'SDI
QUIT
SET SDCPT=$PIECE(SDPROC(SDI),U)
SET SDQTY=$PIECE(SDPROC(SDI),U,16)
IF 'SDQTY
SET SDQTY=1
IF SDCPT
Begin DoDot:1
+6 SET ^TMP("SCRPW",$JOB,SDIV,0,SDCPT)=$GET(^TMP("SCRPW",$JOB,SDIV,0,SDCPT))+SDQTY
+7 SET SDII=0
FOR
SET SDII=$ORDER(SDPRTY(SDII))
IF 'SDII
QUIT
SET SDX=SDPRTY(SDII)
IF $LENGTH(SDX)
Begin DoDot:2
+8 SET ^TMP("SCRPW",$JOB,SDIV,0,SDCPT,SDX)=$GET(^TMP("SCRPW",$JOB,SDIV,0,SDCPT,SDX))+1
+9 QUIT
End DoDot:2
+10 QUIT
End DoDot:1
+11 QUIT