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

AMHRAGS.m

Go to the documentation of this file.
AMHRAGS ; IHS/CMI/LAB - AGE/SEX REPORT ;
 ;;4.0;IHS BEHAVIORAL HEALTH;**1**;JUN 18, 2010;Build 8
 ;
PREPROC ;
 D XTMP^AMHUTIL("AMHRAGS","BH CNTS BY AGE/SEX")
 S AMHRNN=AMHRBIN,AMHRA="" F I=1:1 S AMHRX=$P(AMHRNN,";",I) Q:AMHRX=""  D SETA
 S AMHRDOBS=AMHRA
 Q
SETA ;
 S AMHRY=$P(AMHRX,"-"),AMHRZ=$P(AMHRX,"-",2)
 I AMHRA]"" S AMHRA=AMHRA_";"
 S AMHRA=AMHRA_(DT+1-(10000*(AMHRZ+1)))_"-"_(DT-(AMHRY*10000))
 S ^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL","AGE",I)=0
 Q
SETTMP ;
 Q:$P(AMHR0,U,8)=""
 ;Q:$D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"PATIENT",$P(AMHR0,U,8)))  ;quit if already counted this patient
 S AMHPPOV=$O(^AMHRPRO("AD",AMHR,""))
 S AMHRAGE="" D GETAGE
 Q:'AMHRAGE
 Q:AMHRSEX=""
 D @(AMHRPROC_"^AMHRPTST")
 Q:$D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"PATIENT",$P(AMHR0,U,8),@AMHSORT))
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE",AMHRSEX,@AMHSORT,AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL",AMHRSEX,AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(@AMHSORT)=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL SORT",AMHRSEX,@AMHSORT)):^(@AMHSORT)+1,1:1)
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE","B",@AMHSORT,AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL","B",AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(@AMHSORT)=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL SORT","B",@AMHSORT)):^(@AMHSORT)+1,1:1)
 S ^XTMP("AMHRAGS",AMHJOB,AMHBTH,"PATIENT",$P(AMHR0,U,8),@AMHSORT)=""
 Q
GETAGE ;
 S AMHRDOB=$P(^DPT($P(AMHR0,U,8),0),U,3) Q:AMHRDOB=""
 S AMHRSEX=$P(^DPT($P(AMHR0,U,8),0),U,2)
ATT ;
 F I=1:1 S AMHRNN=$P(AMHRA,";",I) Q:AMHRNN=""  S AMHRX=$P(AMHRNN,"-"),AMHRY=$P(AMHRNN,"-",2) I AMHRDOB'<AMHRX,AMHRDOB'>AMHRY  S AMHRAGE=I Q
 Q
 ;
XIT ;
 K AMHRY,AMHRX,AMHRA
 Q
PRINT ;EP ;PRINT RECORD BY AGE/SEX
 S AMHR132S="",$P(AMHR132S,"-",132)=""
 D NOW^%DTC S Y=X D DD^%DT S AMHRDT=Y
 D COVPAGE^AMHRPTCP
 S AMHRPG=0,AMHSORT="",AMHRSEX=""
 K AMHQUIT
 I '$D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE")) D HEAD W !!,"No data to report.",! G DONE
 F  S AMHRSEX=$O(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE",AMHRSEX)) Q:AMHRSEX=""!($D(AMHQUIT))  D SORT
DONE ;
 D DONE^AMHLEIN,^AMHEKL
 K ^XTMP("AMHRPT",AMHJOB,AMHBTH)
 K ^XTMP("AMHRAGS",AMHJOB,AMHBTH),AMHJOB,AMHBTH
 Q
SORT ;
 D HEAD Q:$D(AMHQUIT)
 S AMHSORT=""
 F  S AMHSORT=$O(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE",AMHRSEX,AMHSORT)) Q:AMHSORT=""!($D(AMHQUIT))  D
 .I $Y>(IOSL-5) D HEAD Q:$D(AMHQUIT)
 .W !,$E(AMHSORT,1,30) S AMHRSRT2=$O(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE",AMHRSEX,AMHSORT,"")) ;W ?32,$E(AMHRSRT2,1,9)
 .N I,J,K S J=39 F I=1:1:$L(AMHRBIN,";") S K=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"AGE",AMHRSEX,AMHSORT,I)):^(I),1:".") W ?J,$J(K,6) S J=J+9
 .W ?J,$J(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL SORT",AMHRSEX,AMHSORT),6)
 .Q
 Q:$D(AMHQUIT)
 I $Y>(IOSL-5) D HEAD Q:$D(AMHQUIT)
 S T=0 W !,"TOTAL:" S J=39 F I=1:1:$L(AMHRBIN,";") S K=$S($D(^XTMP("AMHRAGS",AMHJOB,AMHBTH,"TOTAL",AMHRSEX,I)):^(I),1:".") W ?J,$J(K,6) S J=J+9,T=T+K
 W ?J,$J(T,6)
 Q
 I $E(IOST)="C",IO=IO(0) W ! S DIR(0)="EO" D ^DIR K DIR I Y=0!(Y="^")!($D(DTOUT)) S AMHQUIT="" Q
HEAD1 ;
 W:$D(IOF) @IOF S AMHRPG=AMHRPG+1
 W !?13,"********** CONFIDENTIAL PATIENT INFORMATION **********"
 W !?37,"BEHAVIORAL HEALTH RECORD/ENCOUNTER COUNTS",?100,AMHRDT,?123,"Page ",AMHRPG,!
 S AMHRLENG=15+$L(AMHTITL) W ?((132-AMHRLENG)/2),AMHTITL," BY AGE AND SEX",!
 W ?43,"ENCOUNTER DATES:  ",AMHBDD,"  TO  ",AMHEDD,!
 W !?61,"SEX: ",$S(AMHRSEX="M":"MALE",AMHRSEX="F":"FEMALE",1:"BOTH")
 W !,AMHHD1 S J=41 F I=1:1:$L(AMHRBIN,";") S K=$P(AMHRBIN,";",I) Q:K=""  W ?J,K S J=J+9
 W ?J,"TOTAL"
 W !,AMHR132S
 Q
PI ;EP ;age/sex record counts interactive print ?
 W !!
BIN D SETBIN
 W !,"The Age Groups to be used are currently defined as:",! D LIST
 S DIR(0)="Y",DIR("A")="Do you wish to modify these age groups" D ^DIR K DIR
 I $D(DIRUT) S AMHQUIT="" G XIT
 I Y=0 G XIT
RUN ;
 K AMHQUIT S AMHRY="",AMHRA=-1 W ! F  D AGE Q:AMHRX=""  I $D(AMHQUIT) G BIN
 D CLOSE I $D(AMHQUIT) G BIN
 D LIST
 G XIT
 ;
AGE ;
 S AMHRX=""
 S DIR(0)="NO^0:150:0",DIR("A")="Enter the starting age of the "_$S(AMHRY="":"first",1:"next")_" age group" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
 I $D(DUOUT)!($D(DTOUT)) S AMHQUIT="" Q
 S AMHRX=Y
 I Y="" Q
 I AMHRX?1.3N,AMHRX>AMHRA D SET Q
 W $C(7) W !,"Make sure the age is higher the beginning age of the previous group.",! G RUN
 ;
SET S AMHRA=AMHRX
 I AMHRY="" S AMHRY=AMHRX Q
 S AMHRY=AMHRY_"-"_(AMHRX-1)_";"_AMHRX
 Q
 ;
CLOSE I AMHRY="" Q
GC ;
 S DIR(0)="NO^0:150:0",DIR("A")="Enter the highest age for the last group" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
 I $D(DUOUT)!($D(DTOUT)) S AMHQUIT="" Q
 S AMHRX=Y I Y="" S AMHRX=199
 I AMHRX?1.3N,AMHRX'<AMHRA S AMHRY=AMHRY_"-"_AMHRX,AMHRBIN=AMHRY Q
 W "  ??",$C(7) G CLOSE
 Q
 ;
 ;
LIST ;
 S %=AMHRBIN
 F I=1:1 S X=$P(%,";",I) Q:X=""  W !,$P(X,"-")," - ",$P(X,"-",2)
 W !
 Q
 ;
SETBIN ;
 S AMHRBIN="0-0;1-4;5-14;15-19;20-24;25-44;45-64;65-125"
 Q