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

AMHRLP.m

Go to the documentation of this file.
AMHRLP ; IHS/CMI/LAB - TUCSON-OHPRD/LAB - PRINT BH RECORD REPORT ;
 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
START ;EP - Set up header line, dash line
 K ^XTMP("AMHFLAT",$J) ;just in case
 S X=0,AMHHEAD="" F  S X=$O(^AMHTRPT(AMHRPT,12,X)) Q:X'=+X  S AMHHDR=$P(^AMHSORT($P(^AMHTRPT(AMHRPT,12,X,0),U),0),U,6),AMHLENG=$P(^AMHTRPT(AMHRPT,12,X,0),U,2),AMHHDR=$E(AMHHDR,1,AMHLENG) D
 .S J=$L(AMHHDR),AMHHEAD=AMHHEAD_AMHHDR,K=$P(^AMHTRPT(AMHRPT,12,X,0),U,2)+1 F I=J:1:K S AMHHEAD=AMHHEAD_" "
 .Q
 S AMHDASH="",$P(AMHDASH,"-",AMHTCW)="-"
 D COVPAGE^AMHRLP1 ;print cover page - note: if user ^'s out of cover page, processing continues
PROC ;process printing of report
 I AMHCTYP="T" G DONE ;--- if displaying only total, that was done in the cover page - go to done
 S AMHPG=0 I '$D(^XTMP("AMHRL",AMHJOB,AMHBTH)) G DONE
 S (AMHSRTV,AMHFRST)="" K AMHQUIT
 F  S AMHSRTV=$O(^XTMP("AMHRL",AMHJOB,AMHBTH,"DATA HITS",AMHSRTV)) Q:AMHSRTV=""!($D(AMHQUIT))  D V
 G:$D(AMHQUIT) DONE
 I AMHCTYP="F" D WRITEF G DONE
 I $Y>(IOSL-4) D HEAD G:$D(AMHQUIT) DONE
 I $D(AMHRCNT),AMHPTVS="V" W !!!,"Total ",$S(AMHPTVS="P":"Patients",1:"Visits"),":  ",AMHRCNT
 I $D(AMHRCNT),AMHPTVS="S" W !!!,"Total Number of Suicide Forms:  ",AMHRCNT
 W !!,"Total Patients:  ",AMHPTCT
DONE ;
 D DONE^AMHRLP2
 Q
V ;GETS DATA HITS
 S AMHSCNT=0
 ;get readable sort value
 S AMHSRTR="",AMHR=$O(^XTMP("AMHRL",AMHJOB,AMHBTH,"DATA HITS",AMHSRTV,"")) I AMHR]"" S AMHCRIT=AMHSORT D
 .I AMHPTVS="S" S AMHR0=^AMHPSUIC(AMHR,0),DFN=$P(AMHR0,U,4) X:$D(^AMHSORT(AMHSORT,3)) ^(3) S AMHSRTR=AMHPRNT
 .I AMHPTVS="V" S AMHR0=^AMHREC(AMHR,0),DFN=$P(AMHR0,U,8) X:$D(^AMHSORT(AMHSORT,3)) ^(3) S AMHSRTR=AMHPRNT
 .I AMHPTVS="P" S DFN=AMHR X:$D(^AMHSORT(AMHSORT,3)) ^(3) S AMHSRTR=AMHPRNT
 I $G(AMHSPAG)!($D(AMHFRST)) D HEAD Q:$D(AMHQUIT)
 K AMHFRST
 S AMHR=0 F  S AMHR=$O(^XTMP("AMHRL",AMHJOB,AMHBTH,"DATA HITS",AMHSRTV,AMHR)) Q:AMHR'=+AMHR!($D(AMHQUIT))  D
 .I AMHPTVS="V" S AMHR0=^AMHREC(AMHR,0),DFN=$P(AMHR0,U,8) D PRINT Q
 .I AMHPTVS="S" S AMHR0=^AMHPSUIC(AMHR,0),DFN=$P(AMHR0,U,4) D PRINT Q
 .S DFN=AMHR D PRINT
 .Q
 Q:$D(AMHQUIT)
 I $Y>(IOSL-3) D HEAD Q:$D(AMHQUIT)
 ;W:$G(AMHSPAG) !!,"SUB-TOTAL for ",AMHSORV," ",AMHSRTR,":  ",AMHSCNT
 ;W:AMHCTYP="S" !?10,$E(AMHSRTR,1,30),?45,$J(AMHSCNT,8)
 I $G(AMHSPAG) W !!,"SUB-TOTAL for ",AMHSORV," ",AMHSRTR,":  ",AMHSCNT I AMHPTVS="V" W "    # of PATIENTS:  ",$S($D(^XTMP("AMHRL",AMHJOB,AMHBTH,"SUB PAT COUNT",AMHSRTV)):^XTMP("AMHRL",AMHJOB,AMHBTH,"SUB PAT COUNT",AMHSRTV),1:0)
 I AMHCTYP="S",(AMHPTVS="V"!((AMHPTVS="S"))) W !,?10,$E(AMHSRTR,1,30),?45,$J(AMHSCNT,8)," (V)",?60,$S($D(^XTMP("AMHRL",AMHJOB,AMHBTH,"SUB PAT COUNT",AMHSRTV)):$J(^XTMP("AMHRL",AMHJOB,AMHBTH,"SUB PAT COUNT",AMHSRTV),8),1:"       0")," (P)"
 I AMHCTYP="S",AMHPTVS="P" W !?10,$E(AMHSRTR,1,30),?45,$J(AMHSCNT,8)
 Q
PRINT ;
 I AMHCTYP="F" D FLAT Q
 S AMHSCNT=AMHSCNT+1 Q:AMHCTYP="S"
 K ^XTMP("AMHLINE",$J) S ^XTMP("AMHLINE",$J,1)=""
 I $Y>(IOSL-5) D HEAD Q:$D(AMHQUIT)
 S AMHI=0 F  S AMHI=$O(^AMHTRPT(AMHRPT,12,AMHI)) Q:AMHI'=+AMHI!($D(AMHQUIT))  S AMHCRIT=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U) D
 .I '$P(^AMHSORT(AMHCRIT,0),U,8) D SINGLE Q
 .D MULT
 .Q
 S AMHX=0 F  S AMHX=$O(^XTMP("AMHLINE",$J,AMHX)) Q:AMHX'=+AMHX!($D(AMHQUIT))  D
 .I $Y>(IOSL-4) D HEAD Q:$D(AMHQUIT)
 .W !,^XTMP("AMHLINE",$J,AMHX)
 Q
SINGLE ;process single valued item
 K AMHPRNT
 S AMHX=0
 X:$D(^AMHSORT(AMHCRIT,3)) ^(3)
 S AMHLENG=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2),AMHPRNT=$E($G(AMHPRNT),1,AMHLENG) D
 .S J=$L(AMHPRNT),^XTMP("AMHLINE",$J,1)=^XTMP("AMHLINE",$J,1)_AMHPRNT,K=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2)+1 F I=J:1:K S ^XTMP("AMHLINE",$J,1)=^XTMP("AMHLINE",$J,1)_" "
 .S X=1 F  S X=$O(^XTMP("AMHLINE",$J,X)) Q:X'=+X  I $L(^XTMP("AMHLINE",$J,X))<$L(^XTMP("AMHLINE",$J,1)) S K=$L(^XTMP("AMHLINE",$J,X))+1,J=$L(^XTMP("AMHLINE",$J,1)) F I=K:1:J S ^XTMP("AMHLINE",$J,X)=^XTMP("AMHLINE",$J,X)_" "
 Q
MULT ;
 K AMHPRNT,AMHPRNM S (AMHX,AMHPCNT)=0
 X:$D(^AMHSORT(AMHCRIT,3)) ^(3)
 I '$D(AMHPRNM) S AMHPRNT="--" D
 .S AMHLENG=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2),AMHPRNT=$E(AMHPRNT,1,AMHLENG) D
 ..S J=$L(AMHPRNT),^XTMP("AMHLINE",$J,1)=^XTMP("AMHLINE",$J,1)_AMHPRNT,K=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2)+1 F I=J:1:K S ^XTMP("AMHLINE",$J,1)=^XTMP("AMHLINE",$J,1)_" "
 S X=0 F  S X=$O(AMHPRNM(X)) Q:X'=+X  D
 .I X=1 D  Q
 ..S AMHLENG=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2),AMHPRNT=$E(AMHPRNM(1),1,AMHLENG) D
 ...S J=$L(AMHPRNT),^XTMP("AMHLINE",$J,1)=^XTMP("AMHLINE",$J,1)_AMHPRNT,K=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2)+1 F I=J:1:K S ^XTMP("AMHLINE",$J,1)=^XTMP("AMHLINE",$J,1)_" "
 .S AMHLENG=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2),AMHPRNT=$E(AMHPRNM(X),1,AMHLENG) D
 ..I '$D(^XTMP("AMHLINE",$J,X)) S ^XTMP("AMHLINE",$J,X)="",K=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2)+1,$P(^XTMP("AMHLINE",$J,X)," ",($L(^XTMP("AMHLINE",$J,1))-K))=""
 ..S J=$L(AMHPRNT),^XTMP("AMHLINE",$J,X)=^XTMP("AMHLINE",$J,X)_AMHPRNT,K=$P(^AMHTRPT(AMHRPT,12,AMHI,0),U,2)+1 F I=J:1:K S ^XTMP("AMHLINE",$J,X)=^XTMP("AMHLINE",$J,X)_" "
 S X=1 F  S X=$O(^XTMP("AMHLINE",$J,X)) Q:X'=+X  I $L(^XTMP("AMHLINE",$J,X))<$L(^XTMP("AMHLINE",$J,1)) S K=$L(^XTMP("AMHLINE",$J,X))+1,J=$L(^XTMP("AMHLINE",$J,1)) F I=K:1:J S ^XTMP("AMHLINE",$J,X)=^XTMP("AMHLINE",$J,X)_" "
 Q
DIQ ;
 I DA="" S AMHPRNT="--" Q
 K AMHPRNT,AMHFILE,AMHFIEL
 S AMHFILE=$P($P(^AMHSORT(AMHCRIT,0),U,4),","),AMHFIEL=$P($P(^(0),U,4),",",2)
 S DIQ(0)="EN",DIQ="AMHPRNT(",DIC=AMHFILE,DR=AMHFIEL D EN^DIQ1 K DIC,DR,DIQ
 I '$D(AMHPRNT(AMHFILE,DA,AMHFIEL,"E")) S AMHPRNT(AMHFILE,DA,AMHFIEL,"E")="--"
 S AMHPRNT=AMHPRNT(AMHFILE,DA,AMHFIEL,"E")
 Q
FLAT ;
 S AMHREC=AMHR0
 D FLAT^AMHRLP3
 S ^XTMP($J,"AMHFLAT",AMHR)=AMHTX
 K AMHTX,AMHREC,X
 Q
 Q:AMHCTYP="F"
 D HEAD^AMHRLP2
 Q
WRITEF ;write flat file from global
 D WRITEF^AMHRLP2
 Q