SCRPW57 ;RENO/KEITH - Most Frequent 50 ICD Diagnosis Codes (OP7) or (IP7) ;5/6/03 1:18pm
;;5.3;Scheduling;**144,295,466,593**;AUG 13, 1993;Build 13
S SDSTA=$G(SDSTA,2)
D RQUE^SCRPW50("START^SCRPW57","Most Frequent 50 ICD Diagnosis Codes "_$S(SDSTA=2:"(OP7)",1:"(IP7)"),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="" D STOP,DLIST Q:SDOUT D
.S DFN=0 F S DFN=$O(^TMP("SCRPW",$J,SDIV,0,"LIST",DFN)) Q:'DFN D
..S SDDX=0 F S SDDX=$O(^TMP("SCRPW",$J,SDIV,0,"LIST",DFN,SDDX)) Q:'SDDX S SDPT="" F S SDPT=$O(^TMP("SCRPW",$J,SDIV,0,"LIST",DFN,SDDX,SDPT)) Q:SDPT="" D
...S $P(^TMP("SCRPW",$J,SDIV,0,SDDX,SDPT),U,2)=$P($G(^TMP("SCRPW",$J,SDIV,0,SDDX,SDPT)),U,2)+1
...S:$D(^TMP("SCRPW",$J,SDIV,0,"LIST",DFN,SDDX,SDPT,"P")) $P(^TMP("SCRPW",$J,SDIV,0,SDDX,SDPT),U)=$P($G(^TMP("SCRPW",$J,SDIV,0,SDDX,SDPT)),U)+1
...Q
..Q
.S SDDX=0 F S SDDX=$O(^TMP("SCRPW",$J,SDIV,0,SDDX)) Q:'SDDX S SDI=^TMP("SCRPW",$J,SDIV,0,SDDX),^TMP("SCRPW",$J,SDIV,1,SDI,SDDX)=""
.Q
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 ICD DIAGNOSIS CODES "_$S(SDSTA=2:"(OP7)",1:"(IP7)")_" <*>",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,DFN,SD,SDDX,SDDXP,SDDIV,SDFL,SDI,SDII,SDIII,SDIV,SDIVN,SDLINE,SDMD,SDOE,SDOE0,SDOUT,SDPAGE,SDPG,SDPNOW,SDDIAG,SDPRTY,SDPT,SDPTN,SDPTV,SDSTOP,SDT,SDTIT,SDV,SDVCT,SDX,X,Y,SDSTA 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 SDDX="" F S SDDX=$O(^TMP("SCRPW",$J,SDV,1,SDI,SDDX)) Q:SDDX=""!SDOUT!(SDII>49) D PLINE
Q
;
PLINE ;Print output line
N DIWL,DIWF,SDL2 S DIWL=1 S DIWF="C38|"
D:$Y>(IOSL-8) HDR Q:SDOUT D HD1
S SDDIAG=$$ICDDX^SCRPWICD(SDDX),SDDIAG=$P(SDDIAG,U,2)_" "_$P(SDDIAG,U,4),SDII=SDII+1
K ^UTILITY($J,"W") S X=SDDIAG D ^DIWP
F SDL2=1:1:^UTILITY($J,"W",DIWL) D
.I SDL2=1 W !,$J(SDII,3),?6,$E(^UTILITY($J,"W",DIWL,SDL2,0),1,38) I 1
.E W !,?6,$E(^UTILITY($J,"W",DIWL,SDL2,0),1,38)
D W !
.S (SDFL,SDPT)="" F S SDPT=$O(^TMP("SCRPW",$J,SDV,0,SDDX,SDPT)) Q:SDPT=""!SDOUT D
..I $Y>(IOSL-3) D HDR,HD1 Q:SDOUT S SDFL=1
..S SDPTV=^TMP("SCRPW",$J,SDV,0,SDDX,SDPT)
..S SDPTN=$$CODE2TXT^XUA4A72(SDPT),SDPTN=$P(SDPT,"V",2)_" "_$P(SDPTN,U,2)
..W:SDFL ! W ?46,$E(SDPTN,1,38) D S SDFL=SDFL+1
...F SDIII=1:1:4 W ?(86+(12*(SDIII-1))),$J($P(SDPTV,U,SDIII),10,0)
..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 !?87,"Prim. Dx.",?103,"Total",?111,"Prim. Dx.",?127,"Total",!,"Rank ICD Diagnosis code",?48,"Provider Type",?89,"Uniques",?101,"Uniques",?110,"Encounters",?122,"Encounters"
N SDI W !,"----",?6,$E(SDLINE,1,38),?46,$E(SDLINE,1,38) F SDI=0:1:3 W ?(86+(12*SDI)),$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
Q 1
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 SDDIAG,SDPRTY,SDI,SDII,SDIII,SDX S DFN=$P(SDOE0,U,2)
D GETDX^SDOE(SDOE,"SDDIAG"),PROV^SCRPW50(SDOE,.SDPRTY)
S SDI=0 F S SDI=$O(SDDIAG(SDI)) Q:'SDI S SDDX=$P(SDDIAG(SDI),U),SDDXP=$S($P(SDDIAG(SDI),U,12)="P":"P",1:"S") I SDDX D
.S ^TMP("SCRPW",$J,SDIV,0,SDDX)=$G(^TMP("SCRPW",$J,SDIV,0,SDDX))+1
.S SDII=0 F S SDII=$O(SDPRTY(SDII)) Q:'SDII S SDX=SDPRTY(SDII) I $L(SDX) D
..S $P(^TMP("SCRPW",$J,SDIV,0,SDDX,SDX),U,4)=$P($G(^TMP("SCRPW",$J,SDIV,0,SDDX,SDX)),U,4)+1 D
...S:SDDXP="P" $P(^TMP("SCRPW",$J,SDIV,0,SDDX,SDX),U,3)=$P($G(^TMP("SCRPW",$J,SDIV,0,SDDX,SDX)),U,3)+1
...S ^TMP("SCRPW",$J,SDIV,0,"LIST",DFN,SDDX,SDX,SDDXP)=""
...Q
..Q
.Q
Q
;
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSCRPW57 5493 printed Dec 13, 2024@02:43:53 Page 2
SCRPW57 ;RENO/KEITH - Most Frequent 50 ICD Diagnosis Codes (OP7) or (IP7) ;5/6/03 1:18pm
+1 ;;5.3;Scheduling;**144,295,466,593**;AUG 13, 1993;Build 13
+2 SET SDSTA=$GET(SDSTA,2)
+3 DO RQUE^SCRPW50("START^SCRPW57","Most Frequent 50 ICD Diagnosis Codes "_$SELECT(SDSTA=2:"(OP7)",1:"(IP7)"),1)
QUIT
+4 ;
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=""
QUIT
DO STOP
DO DLIST
if SDOUT
QUIT
Begin DoDot:1
+5 SET DFN=0
FOR
SET DFN=$ORDER(^TMP("SCRPW",$JOB,SDIV,0,"LIST",DFN))
if 'DFN
QUIT
Begin DoDot:2
+6 SET SDDX=0
FOR
SET SDDX=$ORDER(^TMP("SCRPW",$JOB,SDIV,0,"LIST",DFN,SDDX))
if 'SDDX
QUIT
SET SDPT=""
FOR
SET SDPT=$ORDER(^TMP("SCRPW",$JOB,SDIV,0,"LIST",DFN,SDDX,SDPT))
if SDPT=""
QUIT
Begin DoDot:3
+7 SET $PIECE(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDPT),U,2)=$PIECE($GET(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDPT)),U,2)+1
+8 if $DATA(^TMP("SCRPW",$JOB,SDIV,0,"LIST",DFN,SDDX,SDPT,"P"))
SET $PIECE(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDPT),U)=$PIECE($GET(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDPT)),U)+1
+9 QUIT
End DoDot:3
+10 QUIT
End DoDot:2
+11 SET SDDX=0
FOR
SET SDDX=$ORDER(^TMP("SCRPW",$JOB,SDIV,0,SDDX))
if 'SDDX
QUIT
SET SDI=^TMP("SCRPW",$JOB,SDIV,0,SDDX)
SET ^TMP("SCRPW",$JOB,SDIV,1,SDI,SDDX)=""
+12 QUIT
End DoDot:1
+13 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 ICD DIAGNOSIS CODES "_$SELECT(SDSTA=2:"(OP7)",1:"(IP7)")_" <*>"
SET SDPG=0
if $EXTRACT(IOST)="C"
DO DISP0^SCRPW23
+14 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
+15 if SDOUT
GOTO EXIT
SET SDIVN=""
FOR
SET SDIVN=$ORDER(SDIV(SDIVN))
if SDIVN=""!SDOUT
QUIT
DO DPRT(SDIV(SDIVN))
+16 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,DFN,SD,SDDX,SDDXP,SDDIV,SDFL,SDI,SDII,SDIII,SDIV,SDIVN,SDLINE,SDMD,SDOE,SDOE0,SDOUT,SDPAGE,SDPG,SDPNOW,SDDIAG,SDPRTY,SDPT,SDPTN,SDPTV,SDSTOP,SDT,SDTIT,SDV,SDVCT,SDX,X,Y,SDSTA
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 SDDX=""
FOR
SET SDDX=$ORDER(^TMP("SCRPW",$JOB,SDV,1,SDI,SDDX))
if SDDX=""!SDOUT!(SDII>49)
QUIT
DO PLINE
+7 QUIT
+8 ;
PLINE ;Print output line
+1 NEW DIWL,DIWF,SDL2
SET DIWL=1
SET DIWF="C38|"
+2 if $Y>(IOSL-8)
DO HDR
if SDOUT
QUIT
DO HD1
+3 SET SDDIAG=$$ICDDX^SCRPWICD(SDDX)
SET SDDIAG=$PIECE(SDDIAG,U,2)_" "_$PIECE(SDDIAG,U,4)
SET SDII=SDII+1
+4 KILL ^UTILITY($JOB,"W")
SET X=SDDIAG
DO ^DIWP
+5 FOR SDL2=1:1:^UTILITY($JOB,"W",DIWL)
Begin DoDot:1
+6 IF SDL2=1
WRITE !,$JUSTIFY(SDII,3),?6,$EXTRACT(^UTILITY($JOB,"W",DIWL,SDL2,0),1,38)
IF 1
+7 IF '$TEST
WRITE !,?6,$EXTRACT(^UTILITY($JOB,"W",DIWL,SDL2,0),1,38)
End DoDot:1
+8 Begin DoDot:1
+9 SET (SDFL,SDPT)=""
FOR
SET SDPT=$ORDER(^TMP("SCRPW",$JOB,SDV,0,SDDX,SDPT))
if SDPT=""!SDOUT
QUIT
Begin DoDot:2
+10 IF $Y>(IOSL-3)
DO HDR
DO HD1
if SDOUT
QUIT
SET SDFL=1
+11 SET SDPTV=^TMP("SCRPW",$JOB,SDV,0,SDDX,SDPT)
+12 SET SDPTN=$$CODE2TXT^XUA4A72(SDPT)
SET SDPTN=$PIECE(SDPT,"V",2)_" "_$PIECE(SDPTN,U,2)
+13 if SDFL
WRITE !
WRITE ?46,$EXTRACT(SDPTN,1,38)
Begin DoDot:3
+14 FOR SDIII=1:1:4
WRITE ?(86+(12*(SDIII-1))),$JUSTIFY($PIECE(SDPTV,U,SDIII),10,0)
End DoDot:3
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 !?87,"Prim. Dx.",?103,"Total",?111,"Prim. Dx.",?127,"Total",!,"Rank ICD Diagnosis code",?48,"Provider Type",?89,"Uniques",?101,"Uniques",?110,"Encounters",?122,"Encounters"
+2 NEW SDI
WRITE !,"----",?6,$EXTRACT(SDLINE,1,38),?46,$EXTRACT(SDLINE,1,38)
FOR SDI=0:1:3
WRITE ?(86+(12*SDI)),$EXTRACT(SDLINE,1,10)
+3 QUIT
+4 ;
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 QUIT 1
+2 IF $PIECE(SDOE0,U,4)
IF $PIECE($GET(^SC($PIECE(SDOE0,U,4),0)),U,17)="Y"
QUIT 0
+3 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
+4 QUIT 0
+5 ;
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 SDDIAG,SDPRTY,SDI,SDII,SDIII,SDX
SET DFN=$PIECE(SDOE0,U,2)
+4 DO GETDX^SDOE(SDOE,"SDDIAG")
DO PROV^SCRPW50(SDOE,.SDPRTY)
+5 SET SDI=0
FOR
SET SDI=$ORDER(SDDIAG(SDI))
if 'SDI
QUIT
SET SDDX=$PIECE(SDDIAG(SDI),U)
SET SDDXP=$SELECT($PIECE(SDDIAG(SDI),U,12)="P":"P",1:"S")
IF SDDX
Begin DoDot:1
+6 SET ^TMP("SCRPW",$JOB,SDIV,0,SDDX)=$GET(^TMP("SCRPW",$JOB,SDIV,0,SDDX))+1
+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 $PIECE(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDX),U,4)=$PIECE($GET(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDX)),U,4)+1
Begin DoDot:3
+9 if SDDXP="P"
SET $PIECE(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDX),U,3)=$PIECE($GET(^TMP("SCRPW",$JOB,SDIV,0,SDDX,SDX)),U,3)+1
+10 SET ^TMP("SCRPW",$JOB,SDIV,0,"LIST",DFN,SDDX,SDX,SDDXP)=""
+11 QUIT
End DoDot:3
+12 QUIT
End DoDot:2
+13 QUIT
End DoDot:1
+14 QUIT
+15 ;