Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: ACDRR1CB

ACDRR1CB.m

Go to the documentation of this file.
ACDRR1CB ;IHS/ADC/EDE/KML - BROKE UP ACDRR1C;
 ;;4.1;CHEMICAL DEPENDENCY MIS;;MAY 11, 1998
 ;
PATIENTS ; EP-PROCESS PATIENTS WITH VISITS WITHIN TIME FRAME
 D ZEROCNTS
 S ACDPIEN=0
 F  S ACDPIEN=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN)) Q:'ACDPIEN  D:'^(ACDPIEN) FINDPRB D:^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN) PATCNT
 D PROBCNT ;                       count patients by problem
 D DRUGCNT ;                       count patients by drug used
 D COMPLOS ;                       length of stay by cc/ct
 D TBLCNTS ;                       save counts for print routine
 Q
 ;
ZEROCNTS ; ZERO COUNTERS
 S ACDCT("SEEN")=0
 S ACDCT("SEEN","M")=0
 S ACDCT("SEEN","F")=0
 S ACDCT("ALCOHOL")=0
 S ACDCT("ALCOHOL","CS")=0
 S ACDCT("ALCOHOL","DAYS")=0
 S ACDCT("ALCOHOL","HRS")=0
 S ACDCT("ALCOHOL","M")=0
 S ACDCT("ALCOHOL","F")=0
 S ACDCT("ALCOHOL ONLY")=0
 S ACDCT("ALCOHOL ONLY","CS")=0
 S ACDCT("ALCOHOL ONLY","DAYS")=0
 S ACDCT("ALCOHOL ONLY","HRS")=0
 S ACDCT("ALCOHOL ONLY","M")=0
 S ACDCT("ALCOHOL ONLY","F")=0
 S ACDCT("DRUGS")=0
 S ACDCT("DRUGS","CS")=0
 S ACDCT("DRUGS","DAYS")=0
 S ACDCT("DRUGS","HRS")=0
 S ACDCT("DRUGS","M")=0
 S ACDCT("DRUGS","F")=0
 S ACDCT("DRUGS ONLY")=0
 S ACDCT("DRUGS ONLY","CS")=0
 S ACDCT("DRUGS ONLY","DAYS")=0
 S ACDCT("DRUGS ONLY","HRS")=0
 S ACDCT("DRUGS ONLY","M")=0
 S ACDCT("DRUGS ONLY","F")=0
 S ACDCT("ALCOHOL&DRUGS")=0
 S ACDCT("ALCOHOL&DRUGS","CS")=0
 S ACDCT("ALCOHOL&DRUGS","DAYS")=0
 S ACDCT("ALCOHOL&DRUGS","HRS")=0
 S ACDCT("ALCOHOL&DRUGS","M")=0
 S ACDCT("ALCOHOL&DRUGS","F")=0
 S ACDCT("NEITHER")=0
 S ACDCT("NEITHER","CS")=0
 S ACDCT("NEITHER","DAYS")=0
 S ACDCT("NEITHER","HRS")=0
 S ACDCT("NEITHER","M")=0
 S ACDCT("NEITHER","F")=0
 F Y=1:1:3 D
 .  S ACDCT("TOBACCO",Y)=0
 .  S ACDCT("TOBACCO",Y,"M")=0
 .  S ACDCT("TOBACCO",Y,"F")=0
 .  Q
 Q
 ;
PATCNT ; COUNT PATIENT DATA
 D PATCNT^ACDRR1CC
 Q
 ;
PROBCNT ; PATIENT COUNT BY PROBLEM
 D PROBCNT^ACDRR1CC
 Q
 ;
DRUGCNT ; PATIENT COUNT BY DRUG
 D DRUGCNT^ACDRR1CC
 Q
 ;
TBLCNTS ; TABLE COUNTS FOR PRINT ROUTINE
 K ^TMP("ACDRR1",ACDJOB,ACDBT)
 ; seen
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"SEEN")=ACDCT("SEEN")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"SEEN",X)=+$G(ACDCT("SEEN",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"SEEN","AGE",X)=+$G(ACDCT("SEEN","AGE",X))
 ; length of stay by component code/type
 S ACDCCT=""
 F  S ACDCCT=$O(^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT)) Q:ACDCCT=""  D
 .  S Z=$P(ACDCCT,"/"),Z=$P($G(^ACDCOMP(Z,0)),U,2) S:Z="" Z=$P(ACDCCT,"/") S Z=Z_"/"_$P(ACDCCT,"/",2)
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"LOS",Z,"AVG")=^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"TOTAL")/^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"COUNT")
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"LOS",Z,"COUNT")=^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"COUNT")
 .  Q
 ; tribe
 S ACDTRIBE=""
 F  S ACDTRIBE=$O(ACDCT("TRIBE",ACDTRIBE)) Q:ACDTRIBE=""  D
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"TRIBE",ACDTRIBE)=ACDCT("TRIBE",ACDTRIBE)
 .  F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"TRIBE",ACDTRIBE,X)=+$G(ACDCT("TRIBE",ACDTRIBE,X))
 .  F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"TRIBE",ACDTRIBE,"AGE",X)=+$G(ACDCT("TRIBE",ACDTRIBE,"AGE",X))
 .  Q
 ; alcohol
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL")=ACDCT("ALCOHOL")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL","CS")=ACDCT("ALCOHOL","CS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL","DAYS")=ACDCT("ALCOHOL","DAYS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL","HRS")=ACDCT("ALCOHOL","HRS")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL",X)=+$G(ACDCT("ALCOHOL",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL","AGE",X)=+$G(ACDCT("ALCOHOL","AGE",X))
 ; alcohol only
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL ONLY")=ACDCT("ALCOHOL ONLY")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL ONLY","CS")=ACDCT("ALCOHOL ONLY","CS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL ONLY","DAYS")=ACDCT("ALCOHOL ONLY","DAYS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL ONLY","HRS")=ACDCT("ALCOHOL ONLY","HRS")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL ONLY",X)=+$G(ACDCT("ALCOHOL ONLY",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL ONLY","AGE",X)=+$G(ACDCT("ALCOHOL ONLY","AGE",X))
 ; drugs
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS")=ACDCT("DRUGS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS","CS")=ACDCT("DRUGS","CS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS","DAYS")=ACDCT("DRUGS","DAYS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS","HRS")=ACDCT("DRUGS","HRS")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS",X)=+$G(ACDCT("DRUGS",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS","AGE",X)=+$G(ACDCT("DRUGS","AGE",X))
 ; drugs only
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS ONLY")=ACDCT("DRUGS ONLY")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS ONLY","CS")=ACDCT("DRUGS ONLY","CS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS ONLY","DAYS")=ACDCT("DRUGS ONLY","DAYS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS ONLY","HRS")=ACDCT("DRUGS ONLY","HRS")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS ONLY",X)=+$G(ACDCT("DRUGS ONLY",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUGS ONLY","AGE",X)=+$G(ACDCT("DRUGS ONLY","AGE",X))
 ; alcohol&drugs
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL&DRUGS")=ACDCT("ALCOHOL&DRUGS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL&DRUGS","CS")=ACDCT("ALCOHOL&DRUGS","CS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL&DRUGS","DAYS")=ACDCT("ALCOHOL&DRUGS","DAYS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL&DRUGS","HRS")=ACDCT("ALCOHOL&DRUGS","HRS")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL&DRUGS",X)=+$G(ACDCT("ALCOHOL&DRUGS",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"ALCOHOL&DRUGS","AGE",X)=+$G(ACDCT("ALCOHOL&DRUGS","AGE",X))
 ; neither
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"NEITHER")=ACDCT("NEITHER")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"NEITHER","CS")=ACDCT("NEITHER","CS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"NEITHER","DAYS")=ACDCT("NEITHER","DAYS")
 S ^TMP("ACDRR1",ACDJOB,ACDBT,"NEITHER","HRS")=ACDCT("NEITHER","HRS")
 F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"NEITHER",X)=+$G(ACDCT("NEITHER",X))
 F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"NEITHER","AGE",X)=+$G(ACDCT("NEITHER","AGE",X))
 ; tobacco
 F Y=1:1:3 D
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"TOBACCO",Y)=ACDCT("TOBACCO",Y)
 .  F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"TOBACCO",Y,X)=+$G(ACDCT("TOBACCO",Y,X))
 .  F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"TOBACCO",Y,"AGE",X)=+$G(ACDCT("TOBACCO",Y,"AGE",X))
 .  Q
 ; problem
 S ACDPRIEN=0
 F  S ACDPRIEN=$O(^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN)) Q:'ACDPRIEN  S Y=^(ACDPRIEN) D
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"PROBLEM",Y,ACDPRIEN)=""
 .  F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"PROBLEM",Y,ACDPRIEN,X)=$G(^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN,X))
 .  F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"PROBLEM",Y,ACDPRIEN,"AGE",X)=$G(^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN,"AGE",X))
 .  Q
 ; primary problem
 S ACDPRIEN=0
 F  S ACDPRIEN=$O(^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN)) Q:'ACDPRIEN  S Y=^(ACDPRIEN) D
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"PRI PROB",Y,ACDPRIEN)=""
 .  F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"PRI PROB",Y,ACDPRIEN,X)=$G(^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN,X))
 .  F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"PRI PROB",Y,ACDPRIEN,"AGE",X)=$G(^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN,"AGE",X))
 .  Q
 ; drugs
 S ACDDRUG=""
 F  S ACDDRUG=$O(^TMP("ACDRR1",$J,1,"DRUG",ACDDRUG)) Q:ACDDRUG=""  S Y=^(ACDDRUG) D
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUG",Y,ACDDRUG)=""
 .  F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUG",Y,ACDDRUG,X)=$G(^TMP("ACDRR1",$J,1,"DRUG",ACDDRUG,X))
 .  F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUG",Y,ACDDRUG,"AGE",X)=$G(^TMP("ACDRR1",$J,1,"DRUG",ACDDRUG,"AGE",X))
 .  Q
 ; drug combinations
 S ACDCMBO=""
 F  S ACDCMBO=$O(^TMP("ACDRR1",$J,1,"DRUG COMBO",ACDCMBO)) Q:ACDCMBO=""  D
 .  S C=^TMP("ACDRR1",$J,1,"DRUG COMBO",ACDCMBO)
 .  S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUG COMBO",ACDCMBO)=C
 .  F X="M","F" S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUG COMBO",C,ACDCMBO,X)=$G(^TMP("ACDRR1",$J,1,"DRUG COMBO",ACDCMBO,X))
 .  F X=1:1:3 S ^TMP("ACDRR1",ACDJOB,ACDBT,"DRUG COMBO",C,ACDCMBO,"AGE",X)=$G(^TMP("ACDRR1",$J,1,"DRUG COMBO",ACDCMBO,"AGE",X))
 .  Q
 Q
 ;
FINDPRB ; FIND PROBLEMS IN EARLIER IN/RE/FU OR LATER TD
 ; find in/re/fu before time frame or td after time frame
 S ACDVIEN=0,ACDVHIT=0
 F  S ACDVIEN=$O(^ACDVIS("D",ACDPIEN,ACDVIEN)) Q:'ACDVIEN  I $D(^ACDVIS(ACDVIEN,0)) S X=^(0) I $G(^ACDVIS(ACDVIEN,"BWP"))=ACDPGM D  Q:^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN)
 .  S ACDVDATE=$P(X,U)
 .  I ACDVDATE>ACDDTLO,ACDVHIT NEW ACDVIEN S ACDVIEN=ACDVHIT D PRCIIF^ACDRR1C Q:^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN)  S ACDVHIT=0
 .  S ACDTC=$P(X,U,4)
 .  I ACDTC'="IN",ACDTC'="RE",ACDTC'="FU",ACDTC'="TD" Q
 .  I ACDVDATE>ACDDTLO,ACDTC'="TD" Q
 .  S ACDVHIT=ACDVIEN
 .  I ACDTC="TD" NEW ACDVIEN S ACDVIEN=ACDVHIT,ACDVHIT=0 D PRCTD^ACDRR1C
 .  Q
 Q
 ;
COMPLOS ; COMPUTE LENGTH OF STAY BY COMP CODE/TYPE
 S ACDPIEN=0
 F  S ACDPIEN=$O(^TMP("ACDRR1",$J,1,"LOS",ACDPIEN)) Q:'ACDPIEN  D
 .  S ACDCCT=""
 .  F  S ACDCCT=$O(^TMP("ACDRR1",$J,1,"LOS",ACDPIEN,ACDCCT)) Q:ACDCCT=""  D
 ..  S ACDDATE=""
 ..  F  S ACDDATE=$O(^TMP("ACDRR1",$J,1,"LOS",ACDPIEN,ACDCCT,ACDDATE)) Q:ACDDATE=""  D COMPLOS2
 ..  Q
 .  Q
 Q
 ;
COMPLOS2 ; COMPUTE LENGTH OF STAY FOR ONE TD
 ; find in/re for same patient & component code/type before td
 S ACDCC=$P(ACDCCT,"/"),ACDCT=$P(ACDCCT,"/",2)
 S ACDVIEN=0,ACDINRE=0
 F  S ACDVIEN=$O(^ACDVIS("D",ACDPIEN,ACDVIEN)) Q:'ACDVIEN  I $D(^ACDVIS(ACDVIEN,0)) S X=^(0) D
 .  Q:$G(^ACDVIS(ACDVIEN,"BWP"))'=ACDPGM
 .  Q:$P(X,U,2)'=ACDCC
 .  Q:$P(X,U,7)'=ACDCT
 .  I $P(X,U,4)'="IN",$P(X,U,4)'="RE" Q
 .  S X=$P(X,U)
 .  Q:X>ACDDATE
 .  S:X>ACDINRE ACDINRE=X
 .  Q
 Q:'ACDINRE
 S X2=ACDINRE,X1=ACDDATE
 D ^%DTC
 Q:'%Y
 S ^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"TOTAL")=$G(^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"TOTAL"))+X
 S ^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"COUNT")=$G(^TMP("ACDRR1",$J,1,"LOS","T",ACDCCT,"COUNT"))+1
 Q