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

ACDRR1CC.m

Go to the documentation of this file.
ACDRR1CC ;IHS/ADC/EDE/KML - BROKE UP ACDRR1CB;
 ;;4.1;CHEMICAL DEPENDENCY MIS;;MAY 11, 1998
 ;
PATCNT ; EP-COUNT PATIENT DATA
 S ACDSEX=$$SEX^AUPNPAT(ACDPIEN) S:ACDSEX="" ACDSEX="M"
 S Y=$$AGE^AUPNPAT(ACDPIEN,ACDDTLO),ACDAGE=$S(Y<13:1,Y<21:2,1:3)
 S Y=$$TRIBE^AUPNPAT(ACDPIEN,"E"),ACDTRIBE=$S(Y="":"UNKNOWN",1:Y)
 D COUNTCS
 D COMPDAYS
 S ACDCT("SEEN")=ACDCT("SEEN")+1
 S ACDCT("SEEN",ACDSEX)=$G(ACDCT("SEEN",ACDSEX))+1
 S ACDCT("SEEN","AGE",ACDAGE)=$G(ACDCT("SEEN","AGE",ACDAGE))+1
 S ACDCT("TRIBE",ACDTRIBE)=$G(ACDCT("TRIBE",ACDTRIBE))+1
 S ACDCT("TRIBE",ACDTRIBE,ACDSEX)=$G(ACDCT("TRIBE",ACDTRIBE,ACDSEX))+1
 S ACDCT("TRIBE",ACDTRIBE,"AGE",ACDAGE)=$G(ACDCT("TRIBE",ACDTRIBE,"AGE",ACDAGE))+1
 S (X,Y)=0
 F  S Y=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN,"T",Y)) Q:Y=""  S X=X+Y
 S:X>3 X=3
 I X D
 .  S ACDCT("TOBACCO",X)=ACDCT("TOBACCO",X)+1
 .  S ACDCT("TOBACCO",X,ACDSEX)=$G(ACDCT("TOBACCO",X,ACDSEX))+1
 .  S ACDCT("TOBACCO",X,"AGE",ACDAGE)=$G(ACDCT("TOBACCO",X,"AGE",ACDAGE))+1
 .  Q
 S ACDA=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN,"A",0))
 S ACDD=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN,"D",0))
 I ACDA D
 .  S ACDCT("ALCOHOL")=ACDCT("ALCOHOL")+1
 .  S ACDCT("ALCOHOL","CS")=ACDCT("ALCOHOL","CS")+ACDCSC
 .  S ACDCT("ALCOHOL","DAYS")=ACDCT("ALCOHOL","DAYS")+ACDADAYS
 .  S ACDCT("ALCOHOL","HRS")=ACDCT("ALCOHOL","HRS")+ACDCSH
 .  S ACDCT("ALCOHOL",ACDSEX)=ACDCT("ALCOHOL",ACDSEX)+1
 .  S ACDCT("ALCOHOL","AGE",ACDAGE)=$G(ACDCT("ALCOHOL","AGE",ACDAGE))+1
 .  Q
 I ACDD D
 .  S ACDCT("DRUGS")=ACDCT("DRUGS")+1
 .  S ACDCT("DRUGS","CS")=ACDCT("DRUGS","CS")+ACDCSC
 .  S ACDCT("DRUGS","DAYS")=ACDCT("DRUGS","DAYS")+ACDDDAYS
 .  S ACDCT("DRUGS","HRS")=ACDCT("DRUGS","HRS")+ACDCSH
 .  S ACDCT("DRUGS",ACDSEX)=ACDCT("DRUGS",ACDSEX)+1
 .  S ACDCT("DRUGS","AGE",ACDAGE)=$G(ACDCT("DRUGS","AGE",ACDAGE))+1
 .  Q
 I ACDA,ACDD D
 .  S ACDCT("ALCOHOL&DRUGS")=ACDCT("ALCOHOL&DRUGS")+1
 .  S ACDCT("ALCOHOL&DRUGS","CS")=ACDCT("ALCOHOL&DRUGS","CS")+ACDCSC
 .  S ACDCT("ALCOHOL&DRUGS","DAYS")=ACDCT("ALCOHOL&DRUGS","DAYS")+ACDADAYS
 .  S ACDCT("ALCOHOL&DRUGS","HRS")=ACDCT("ALCOHOL&DRUGS","HRS")+ACDCSH
 .  S ACDCT("ALCOHOL&DRUGS",ACDSEX)=ACDCT("ALCOHOL&DRUGS",ACDSEX)+1
 .  Q
 I ACDA,'ACDD D
 .  S ACDCT("ALCOHOL ONLY")=ACDCT("ALCOHOL ONLY")+1
 .  S ACDCT("ALCOHOL ONLY","CS")=ACDCT("ALCOHOL ONLY","CS")+ACDCSC
 .  S ACDCT("ALCOHOL ONLY","DAYS")=ACDCT("ALCOHOL ONLY","DAYS")+ACDADAYS
 .  S ACDCT("ALCOHOL ONLY","HRS")=ACDCT("ALCOHOL ONLY","HRS")+ACDCSH
 .  S ACDCT("ALCOHOL ONLY",ACDSEX)=ACDCT("ALCOHOL ONLY",ACDSEX)+1
 .  Q
 I ACDD,'ACDA D
 .  S ACDCT("DRUGS ONLY")=ACDCT("DRUGS ONLY")+1
 .  S ACDCT("DRUGS ONLY","CS")=ACDCT("DRUGS ONLY","CS")+ACDCSC
 .  S ACDCT("DRUGS ONLY","DAYS")=ACDCT("DRUGS ONLY","DAYS")+ACDDDAYS
 .  S ACDCT("DRUGS ONLY","HRS")=ACDCT("DRUGS ONLY","HRS")+ACDCSH
 .  S ACDCT("DRUGS ONLY",ACDSEX)=ACDCT("DRUGS ONLY",ACDSEX)+1
 .  Q
 I 'ACDA,'ACDD D
 .  S ACDCT("NEITHER")=ACDCT("NEITHER")+1
 .  S ACDCT("NEITHER","CS")=ACDCT("NEITHER","CS")+ACDCSC
 .  S ACDCT("NEITHER","DAYS")=ACDCT("NEITHER","DAYS")+ACDADAYS
 .  S ACDCT("NEITHER","HRS")=ACDCT("NEITHER","HRS")+ACDCSH
 .  S ACDCT("NEITHER",ACDSEX)=ACDCT("NEITHER",ACDSEX)+1
 .  Q
 Q
 ;
COUNTCS ; COUNT ALL CS ENTRIES FOR THIS PATIENT & GET AVG HOURS
 NEW ACDVIEN
 S (ACDVIEN,ACDCSC,ACDCSH,ACDCSHC)=0
 F  S ACDVIEN=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN,"CS",ACDVIEN)) Q:'ACDVIEN  D
 .  S ACDCSIEN=0
 .  F  S ACDCSIEN=$O(^ACDCS("C",ACDVIEN,ACDCSIEN)) Q:'ACDCSIEN  S ACDCSC=ACDCSC+1 I $D(^ACDCS(ACDCSIEN,0)) S X=$P(^(0),U,4) S:X ACDCSHC=ACDCSHC+1,ACDCSH=ACDCSH+X
 .  Q
 I ACDCSHC S ACDCSH=ACDCSH/ACDCSHC,ACDCSH=ACDCSH+.5,ACDCSH=$P(ACDCSH,".")
 Q
 ;
COMPDAYS ; COMPUTE AVERAGE NUMBER OF DAYS USED FOR ALCOHOL/DRUGS
 NEW ACDVIEN
 S (ACDADAYS,ACDVIEN,C,V)=0
 F  S ACDVIEN=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN,"A",ACDVIEN)) Q:'ACDVIEN  S Y=$G(^(ACDVIEN,"DAYS")) I Y S C=C+1,V=V+Y
 I V,C S ACDADAYS=V/C,ACDADAYS=ACDADAYS+.5,ACDADAYS=$P(ACDADAYS,".")
 S (ACDDDAYS,ACDVIEN,C,V)=0
 F  S ACDVIEN=$O(^TMP("ACDRR1",$J,1,"PATIENT",ACDPIEN,"D",ACDVIEN)) Q:'ACDVIEN  S Y=$G(^(ACDVIEN,"DAYS")) I Y S C=C+1,V=V+Y
 I V,C S ACDDDAYS=V/C,ACDDDAYS=ACDDDAYS+.5,ACDDDAYS=$P(ACDDDAYS,".")
 Q
 ;
 ;
PROBCNT ; EP-COUNT PATIENTS BY PROBLEM
 ; compute patient totals for each problem
 NEW A,C,F,M,Y
 S ACDPRIEN=0
 F  S ACDPRIEN=$O(^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN)) Q:'ACDPRIEN  D
 .  F Y=1:1:3 S ACDATBL(Y)=0
 .  S (C,F,M,Y)=0
 .  F  S Y=$O(^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN,Y)) Q:'Y  D
 ..  S C=C+1
 ..  S ACDSEX=$$SEX^AUPNPAT(Y) S:ACDSEX="-1" ACDSEX="M"
 ..  S @ACDSEX=@ACDSEX+1
 ..  S A=$$AGE^AUPNPAT(Y,ACDDTLO),ACDAGE=$S(A<13:1,A<21:2,1:3)
 ..  S ACDATBL(ACDAGE)=ACDATBL(ACDAGE)+1
 ..  Q
 .  K ^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN) S ^(ACDPRIEN)=C
 .  F ACDSEX="M","F" S ^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN,ACDSEX)=@ACDSEX
 .  F ACDAGE=1:1:3 S ^TMP("ACDRR1",$J,1,"PROBLEM",ACDPRIEN,"AGE",ACDAGE)=$G(ACDATBL(ACDAGE))
 .  Q
 K ACDATBL
 S ACDPRIEN=0
 F  S ACDPRIEN=$O(^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN)) Q:'ACDPRIEN  D
 .  F Y=1:1:3 S ACDATBL(Y)=0
 .  S (C,F,M,Y)=0
 .  F  S Y=$O(^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN,Y)) Q:'Y  D
 ..  S C=C+1
 ..  S ACDSEX=$$SEX^AUPNPAT(Y) S:ACDSEX="-1" ACDSEX="M"
 ..  S @ACDSEX=@ACDSEX+1
 ..  S A=$$AGE^AUPNPAT(Y,ACDDTLO),ACDAGE=$S(A<13:1,A<21:2,1:3)
 ..  S ACDATBL(ACDAGE)=ACDATBL(ACDAGE)+1
 ..  Q
 .  K ^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN) S ^(ACDPRIEN)=C
 .  F ACDSEX="M","F" S ^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN,ACDSEX)=@ACDSEX
 .  F ACDAGE=1:1:3 S ^TMP("ACDRR1",$J,1,"PRI PROB",ACDPRIEN,"AGE",ACDAGE)=$G(ACDATBL(ACDAGE))
 .  Q
 K ACDATBL
 Q
 ;
DRUGCNT ; EP-COUNT PATIENTS BY DRUG USED
 ; compute patient totals for each drug
 NEW A,C,F,M,Y
 S ACDDIEN=""
 F  S ACDDIEN=$O(^TMP("ACDRR1",$J,1,"DRUG",ACDDIEN)) Q:ACDDIEN=""  D
 .  F Y=1:1:3 S ACDATBL(Y)=0
 .  S (C,F,M,Y)=0
 .  F  S Y=$O(^TMP("ACDRR1",$J,1,"DRUG",ACDDIEN,Y)) Q:'Y  D
 ..  S C=C+1
 ..  S ACDSEX=$$SEX^AUPNPAT(Y) S:ACDSEX="" ACDSEX="M"
 ..  S @ACDSEX=@ACDSEX+1
 ..  S A=$$AGE^AUPNPAT(Y,ACDDTLO),ACDAGE=$S(A<13:1,A<21:2,1:3)
 ..  S ACDATBL(ACDAGE)=ACDATBL(ACDAGE)+1
 ..  Q
 .  K ^TMP("ACDRR1",$J,1,"DRUG",ACDDIEN) S ^(ACDDIEN)=C
 .  F ACDSEX="M","F" S ^TMP("ACDRR1",$J,1,"DRUG",ACDDIEN,ACDSEX)=@ACDSEX
 .  F ACDAGE=1:1:3 S ^TMP("ACDRR1",$J,1,"DRUG",ACDDIEN,"AGE",ACDAGE)=$G(ACDATBL(ACDAGE))
 .  Q
 ; compute patient totals for each drug combonation (alcohol included)
 K ACDATBL
 S X=""
 F  S X=$O(^TMP("ACDRR1",$J,1,"DRUG COMBO",X)) Q:X=""  D
 .  F Y=1:1:3 S ACDATBL(Y)=0
 .  S (C,F,M,Y)=0
 .  F  S ACDPIEN=$O(^TMP("ACDRR1",$J,1,"DRUG COMBO",X,ACDPIEN)) Q:'ACDPIEN  D
 ..  S C=C+1
 ..  S ACDSEX=$$SEX^AUPNPAT(ACDPIEN) S:ACDSEX="-1" ACDSEX="M"
 ..  S @ACDSEX=@ACDSEX+1
 ..  S A=$$AGE^AUPNPAT(ACDPIEN,ACDDTLO),ACDAGE=$S(A<13:1,A<21:2,1:3)
 ..  S ACDATBL(ACDAGE)=ACDATBL(ACDAGE)+1
 ..  Q
 .  K ^TMP("ACDRR1",$J,1,"DRUG COMBO",X) S ^(X)=C
 .  F ACDSEX="M","F" S ^TMP("ACDRR1",$J,1,"DRUG COMBO",X,ACDSEX)=@ACDSEX
 .  F ACDAGE=1:1:3 S ^TMP("ACDRR1",$J,1,"DRUG COMBO",X,"AGE",ACDAGE)=$G(ACDATBL(ACDAGE))
 .  Q
 K ACDATBL
 Q