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

AMHRPS1.m

Go to the documentation of this file.
AMHRPS1 ; IHS/CMI/LAB - PROCESS REPORT ;
 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
 ;
 ;
 ;
 ;
START ;
 D XTMP^AMHUTIL("AMHRPS","BH - ABUSE/SUICIDE REPORT")
 S (AMHBT,AMHBTH)=$H,AMHJOB=$J
 S AMHRNN=AMHRBIN,AMHRA="" F I=1:1 S AMHRX=$P(AMHRNN,";",I) Q:AMHRX=""  D SETA
 S AMHRDOBS=AMHRA
 D DATE,XIT
 Q
 ;
DATE ; Run by encounter date
 S X1=AMHBD,X2=-1 D C^%DTC S AMHSD=X
 S AMHODAT=AMHSD_".9999" F  S AMHODAT=$O(^AMHREC("B",AMHODAT)) Q:AMHODAT=""!((AMHODAT\1)>AMHED)  D D1
 Q
 ;
XIT ;
 S AMHET=$H
 D EOJ
 Q
EOJ ;
 Q
D1 ;
 S (AMHR,AMHRCNT)=0 F  S AMHR=$O(^AMHREC("B",AMHODAT,AMHR)) Q:AMHR'=+AMHR  I $D(^AMHREC(AMHR,0)),$P(^(0),U,2)]"",$P(^(0),U,3)]"" S AMHR0=^(0) D PROC
 Q
PROC ;
 S DFN=$P(AMHR0,U,8) Q:DFN=""  ;do not use if no patient
 Q:'$$ALLOWP^AMHUTIL(DUZ,DFN)
 Q:$$DEMO^AMHUTIL1(DFN,$G(AMHDEMO))
 Q:'$$ALLOWVI^AMHUTIL(DUZ,AMHR)
 Q:'$D(^AMHRPRO("AD",AMHR))  ;quit if no problems entered
 Q:$D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"PATIENTS",DFN))  ;quit if already counted this patient
 ;find pov
 S (AMHFOUND,X)=0,AMHSORT="" F  S X=$O(^AMHRPRO("AD",AMHR,X)) Q:X'=+X!(AMHFOUND)  S P=$P(^AMHRPRO(X,0),U),P=$P(^AMHPROB(P,0),U) I $D(AMHPROB(P)) S AMHFOUND=1,AMHSORT=P
 Q:'AMHFOUND  ; quit if not visit for problem
SETTMP ;
 S AMHRAGE="" D GETAGE
 Q:'AMHRAGE
 Q:AMHRSEX=""
 S ^XTMP("AMHRPS",AMHJOB,AMHBTH,"PATIENTS",DFN)=""
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"AGE",AMHRSEX,AMHSORT,AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"TOTAL",AMHRSEX,AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(AMHSORT)=$S($D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"TOTAL SORT",AMHRSEX,AMHSORT)):^(AMHSORT)+1,1:1)
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"AGE","B",AMHSORT,AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(AMHRAGE)=$S($D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"TOTAL","B",AMHRAGE)):^(AMHRAGE)+1,1:1)
 S ^(AMHSORT)=$S($D(^XTMP("AMHRPS",AMHJOB,AMHBTH,"TOTAL SORT","B",AMHSORT)):^(AMHSORT)+1,1:1)
 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
 ;
 ;
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("AMHRPS",AMHJOB,AMHBTH,"TOTAL","AGE",I)=0
 Q