VistA-WorldVistAEHR/r/REGISTRATION-DGQE-DG-DPT-GR.../DGMSTR3.m

147 lines
7.8 KiB
Mathematica
Raw Permalink Normal View History

2009-11-29 13:37:14 -05:00
DGMSTR3 ;ALB/GRR - GENERATE AND PRINT MST STATISTICAL REPORT ; 1/30/01 10:45am
;;5.3;Registration;**195,319**; Aug 13, 1993
;^TMP("DGMSTR3,JOB... - Array to hold ICD codes
;DGPCDT - Current date in print format
;DGSDAT - Start Date of selection range
;DGEDAT - End Date of selection range
;DGDX - ICD Code
;DGDLOS - Length of Stay
;DGPDAYS - Pass days
;DGMST("N") - Number of new cases of MST
;DGMST("O","R") - Number of outpatient visits related to MST
;DGMST("O","NR") - Number of outpatient visits not related to MST
;DGMST("O","U") - Number of unique outpatients treated for MST
;DGMST("O","AR") - Average number of outpatient visits related to MST
;DGMST("O","ANR") - Average number of outpatient visits not related to MST
;DGMST("I", - Same totals as above except for inpatient
;DGMST("LOS") - Total Length of Stay related to MST
EN ;ENTRY POINT FOR ROUTINE
N TJOB
S TJOB=$J
K ^TMP("DGMSTR3",$J)
N DGMST,DGPCDT,DGSUB,DGSTAT,DGPSDT,DGPEDT,DTOUT,DUOUT,ZTSAVE,X,Y
N DTOUT,DUOUT,ZTSAVE
K DGMST
D DT^DICRW
S Y=DT D DD^%DT S DGPCDT=Y
F DGSTAT="O","I" F DGSUB="R","NR","U","AR","ANR","T" S DGMST(DGSTAT,DGSUB)=0
S DGMST("N")=0,DGMST("LOS")=0,DGMST("ALOS")=0
;GET DATE RANGE
SDAT S DIR(0)="D^:"_DT_":EX",DIR("A")="Start Date"
D ^DIR K DIR
Q:$D(DTOUT)!($D(DUOUT))
S DGSDAT=+Y,Y=+Y D DD^%DT S DGPSDT=Y
TDAT S DIR(0)="D^"_DGSDAT_":"_DT_":EX",DIR("A")="End Date"
D ^DIR K DIR
Q:$D(DTOUT)!($D(DUOUT))
S DGEDAT=+Y_.9999,Y=+Y D DD^%DT S DGPEDT=Y
DEVICE F X="DGMST(","DGSDAT","DGPSDT","DGEDAT","DGPEDT","DGPCDT" S ZTSAVE(X)=""
W !!,"This may take long to print, queue the report to free-up your terminal!",!
D EN^XUTMDEVQ("RPT^DGMSTR3","MST Statistical Summary",.ZTSAVE)
D HOME^%ZIS
Q
RPT ;LOOP THROUGH AND CALCULATE NEW MST CASES
N DFN,SEX,DGSEDT,DGDATE,DGEIEN,DGAPST,DGCALC,DGTYP,DGGEN,DGIEN,DA,X,Y,DTOUT,DUOUT,VADM
N DGCSTAT,DGDA,DGCC,DGCLIEN,DGDX,DGMIEN,DGPTFIEN,DGLOS,DGPDAYS
N DGDXERR,DGLOS,DGOCIEN
S DGDATE=DGSDAT F S DGDATE=$O(^DGMS(29.11,"B",DGDATE)) Q:DGDATE'>0!(DGDATE>DGEDAT) S DGIEN=0 F S DGIEN=$O(^DGMS(29.11,"B",DGDATE,DGIEN)) Q:DGIEN'>0 S:$P($G(^DGMS(29.11,DGIEN,0)),"^",3)="Y" DGMST("N")=DGMST("N")+1
;GET IEN FOR MST CLASSIFICATION TYPE
S DIC=409.41,DIC(0)="X",X="MILITARY SEXUAL TRAUMA"
D ^DIC K DIC
I Y'>0 W !!,"Military Sexual Trauma entry missing from Outpatient Classification Type (409.41) file" Q
S DGOCIEN=+Y K DFN S DFN=""
;CALCULATE OUTPATIENT TOTALS
S DGDATE=DGSDAT F S DGDATE=$O(^SCE("B",DGDATE)) Q:DGDATE'>0!(DGDATE>DGEDAT) D
.S DGEIEN=0 F S DGEIEN=$O(^SCE("B",DGDATE,DGEIEN)) Q:DGEIEN'>0 D
..S Y(0)=$G(^SCE(DGEIEN,0)) Q:Y(0)=""
..S DFN=$P(Y(0),"^",2),DGAPST=$P(Y(0),"^",12) Q:DGAPST=8 ;DGAPST=8 MEANS INPATIENT, DONT COUNT
..I DFN="" Q
..S DGCSTAT=$$GETSTAT^DGMSTAPI(DFN,DGEDAT)
..S DGCC=$P(DGCSTAT,"^",2)
..I DGCC'="Y"&(DGCC'="N")&(DGCC'="D")&(DGCC'="U") Q
..S DGCLIEN=$O(^SDD(409.42,"AO",DGEIEN,DGOCIEN,0)),DGMST("O","T")=DGMST("O","T")+1 I DGCLIEN]"" D
...I $P($G(^SDD(409.42,DGCLIEN,0)),"^",3)'=1 S DGMST("O","NR")=DGMST("O","NR")+1
...E S DGMST("O","R")=DGMST("O","R")+1 I '$D(DFN(DFN,"O")) S DFN(DFN,"O")="",DGMST("O","U")=DGMST("O","U")+1
..D DEM^VADPT S SEX=$P(VADM(5),"^")
..I SEX="M"!(SEX="F") D
...S DGDX=$$GETPDX^SDOE(DGEIEN,.DGDXERR) ;; CHANGED 4.16.99 SCK CORRECT FOR API
...I DGDX'="" S DGDX=$P($G(^ICD9(DGDX,0)),"^") I DGDX'="" D
....I '$D(^TMP("DGMSTR3",$J,DGDX)) F DGGEN="M","F" F DGTYP="I","O" S ^TMP("DGMSTR3",$J,DGDX,DGGEN,DGTYP)=0
....S ^TMP("DGMSTR3",$J,DGDX,SEX,"O")=^TMP("DGMSTR3",$J,DGDX,SEX,"O")+1
;LOOP FOR INPATIENT CALCULATIONS
S DGDATE=DGSDAT F S DGDATE=$O(^DGPM("B",DGDATE)) Q:DGDATE'>0!(DGDATE>DGEDAT) S DGDA=0 F S DGDA=$O(^DGPM("B",DGDATE,DGDA)) Q:DGDA'>0 S DGPTFIEN=$P($G(^DGPM(DGDA,0)),"^",16) I DGPTFIEN'="" D
.S DGMIEN=0,DGPDAYS=0,DGCALC=0 F S DGMIEN=$O(^DGPT(DGPTFIEN,"M",DGMIEN)) Q:DGMIEN'>0 D
..S Y(0)=$G(^(DGMIEN,0)),DGPDAYS=DGPDAYS+(+$P(Y(0),"^",4)),DGMST("I","T")=DGMST("I","T")+1
..I $P(Y(0),"^",29)="Y" D
...S DGMST("I","R")=DGMST("I","R")+1,DGCALC=1
...S DFN=$P(^DGPT(DGPTFIEN,0),"^")
...Q:DFN=""
...I '$D(DFN(DFN,"I")) S DFN(DFN,"I")="",DGMST("I","U")=DGMST("I","U")+1
...S DGDX=$P(Y(0),"^",5) D DEM^VADPT S SEX=$P(VADM(5),"^")
...I DGDX'="",SEX="M"!(SEX="F") S DGDX=$P($G(^ICD9(DGDX,0)),"^") I DGDX'="" D
....I '$D(^TMP("DGMSTR3",$J,DGDX)) F DGGEN="M","F" F DGTYP="I","O" S ^TMP("DGMSTR3",$J,DGDX,DGGEN,DGTYP)=0
....S ^TMP("DGMSTR3",$J,DGDX,SEX,"I")=^TMP("DGMSTR3",$J,DGDX,SEX,"I")+1
..E S DGMST("I","NR")=DGMST("I","NR")+1
.I +$G(DGCALC)>0,$P($G(^DGPT(DGPTFIEN,70)),"^")]"" D
..S DGLOS=$$CALCLOS(DGPTFIEN,DGPDAYS),DGMST("LOS")=DGMST("LOS")+DGLOS
PRT ;LAST CALCULATIONS AND PRINT
I DGMST("LOS")>0 S DGMST("ALOS")=DGMST("LOS")/DGMST("I","R")
I DGMST("O","T")>0 S DGMST("O","AR")=$J(DGMST("O","R")/DGMST("O","T"),7,2),DGMST("O","ANR")=$J(DGMST("O","NR")/DGMST("O","T"),7,2)
I DGMST("I","T")>0 S DGMST("I","AR")=$J(DGMST("I","R")/DGMST("I","T"),7,2),DGMST("I","ANR")=$J(DGMST("I","NR")/DGMST("I","T"),7,2)
D NOFF
W !!,"# OF NEW CASES IDENTIFIED FOR MST",?78-$L(DGMST("N")),DGMST("N")
W !!,"-------------OUTPATIENT STATISTICS-------------"
W !!,"# OF OUTPATIENT ENCOUNTERS RELATED TO MST",?78-$L(DGMST("O","R")),DGMST("O","R")
W !,"# OF OUTPATIENT ENCOUNTERS NOT RELATED TO MST",?78-$L(DGMST("O","NR")),DGMST("O","NR")
W !,"# OF UNIQUE OUTPATIENTS TREATED FOR MST",?78-$L(DGMST("O","U")),DGMST("O","U")
W !,"AVERAGE # OF ENCOUNTERS RELATED TO MST",?78-$L(DGMST("O","AR")),DGMST("O","AR")
W !,"AVERAGE # OF ENCOUNTERS NOT RELATED TO MST",?78-$L(DGMST("O","ANR")),DGMST("O","ANR")
W !!,"-------------INPATIENT STATISTICS---------------"
W !!,"# OF INPATIENT EPISODES RELATED TO MST",?78-$L(DGMST("I","R")),DGMST("I","R")
W !,"# OF INPATIENT EPISODES NOT RELATED TO MST",?78-$L(DGMST("I","NR")),DGMST("I","NR")
W !,"# OF UNIQUE INPATIENTS TREATED FOR MST",?78-$L(DGMST("I","U")),DGMST("I","U")
W !,"AVERAGE # OF INPATIENT EPISODES TREATED FOR MST",?78-$L(DGMST("I","AR")),DGMST("I","AR")
W !,"AVERAGE # OF INPATIENT EPISODES NOT TREATED FOR MST",?78-$L(DGMST("I","ANR")),DGMST("I","ANR")
W !,"TOTAL LENGTH OF STAY OF INPATIENTS TREATED FOR MST",?78-$L(DGMST("LOS")),DGMST("LOS")
W !,"AVERAGE LENGTH OF STAY OF INPATIENTS TREATED FOR MST",?78-$L(DGMST("ALOS")),DGMST("ALOS")
I $Y+3>$G(IOSL) D Q:$D(DTOUT)!($D(DUOUT))
.I $E(IOST,1,2)="C-" S DIR(0)="E" D ^DIR K DIR Q:$D(DTOUT)!($D(DUOUT))
.;I IO=IO(0) S DIR(0)="E" D ^DIR K DIR Q:$D(DTOUT)!($D(DUOUT))
.D HED
G:$O(^TMP("DGMSTR3",$J,0))="" END1 ;;CHANGED BY SCK 4.16.99 CHECK ON ERROR
W !!,"ICD-9 CODE",?24,"NUMBER OF MALE",?54,"NUMBER OF FEMALE"
W !,?22,"OUTPATIENT",?35,"INPATIENT",?52,"OUTPATIENT",?65,"INPATIENT"
S DGDX="" F S DGDX=$O(^TMP("DGMSTR3",$J,DGDX)) Q:DGDX="" D Q:$D(DTOUT)!($D(DUOUT))
.I $Y+3>IOSL D Q:$D(DTOUT)!($D(DUOUT))
..I $E(IOST,1,2)="C-" S DIR(0)="E" D ^DIR K DIR Q:$D(DTOUT)!($D(DUOUT))
..;I IO=IO(0) S DIR(0)="E" D ^DIR K DIR Q:$D(DTOUT)!($D(DUOUT))
..D HED W !!,"ICD-9 CODE",?24,"NUMBER OF MALE",?54,"NUMBER OF FEMALE",!,?22,"OUTPATIENT",?35,"INPATIENT",?52,"OUTPATIENT",?65,"INPATIENT"
.W !,?2,DGDX,?28-$L(^TMP("DGMSTR3",$J,DGDX,"M","O"))
.W ^TMP("DGMSTR3",$J,DGDX,"M","O")
.W ?40-$L(^TMP("DGMSTR3",$J,DGDX,"M","I"))
.W ^TMP("DGMSTR3",$J,DGDX,"M","I")
.W ?58-$L(^TMP("DGMSTR3",$J,DGDX,"F","O")),^TMP("DGMSTR3",$J,DGDX,"F","O")
.W ?70-$L(^TMP("DGMSTR3",$J,DGDX,"F","I"))
.W ^TMP("DGMSTR3",$J,DGDX,"F","I")
I $E(IOST,1,2)="C-" S DIR="E" D ^DIR K DIR
END1 K DA,DGSDAT,DGEDAT,DGMST,DGPCDT,DGPEDT,DGPSDT,X,Y
K ^TMP("DGMSTAPI",$J)
K TJOB
Q
;
CALCLOS(DGPTFIEN,DGPDAYS) ;CALCULATE LOS FOR EPISODE
N DGADT,DGDDT,DGLDAYS,DGDAYS,Y,X1,X2
S Y(70)=$G(^DGPT(DGPTFIEN,70)) Q:Y(70)="" 0
S DGDDT=$P(Y(70),"^")\1,DGADT=$P(^DGPT(DGPTFIEN,0),"^",2)\1,DGLDAYS=$P(Y(70),"^",8)
S X1=DGDDT,X2=DGADT D ^%DTC
S DGDAYS=X-(DGLDAYS+DGPDAYS)
Q DGDAYS
;
HED ;PRINT HEADER INFO
W @IOF
NOFF W !,?20,"MST Statistical Report"
W !,?20,"Date Range: ",DGPSDT," - ",DGPEDT
W !,?20,"Date Report Printed: ",DGPCDT
Q
;