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

AMHRSR31.m

Go to the documentation of this file.
AMHRSR31 ; IHS/CMI/LAB - list SUICIDE RISK ASSESSMENT screenings ;
 ;;4.0;IHS BEHAVIORAL HEALTH;**8**;JUN 02, 2010;Build 7
 ;
 ;
PROC ;
 S AMHRCNT=0
 S AMHRH=$H,AMHRJ=$J
 K ^XTMP("AMHRSR3",AMHRJ,AMHRH)
 D XTMP^AMHUTIL("AMHRSR3","SUICIDE RISK ASSESSMENT REPORT")
 ;go through exam SRA, then through AUPNPREF for refusals
 S DFN=0 F  S DFN=$O(^AUPNPAT(DFN)) Q:DFN'=+DFN  D
 .Q:'$D(^DPT(DFN,0))
 .Q:$P(^DPT(DFN,0),U,19)  ;merged away
 .Q:'$$ALLOWP^AMHUTIL(DUZ,DFN)
 .Q:$$DEMO^AMHUTIL1(DFN,$G(AMHDEMO))
 .I AMHRSEX'[$P(^DPT(DFN,0),U,2) Q  ;not right gender
 .I AMHRDESP]"",$P($G(^AMHPATR(DFN,0)),U,2)'=AMHRDESP Q  ;not correct designated mh provider
 .I AMHRSSP]"",$P($G(^AMHPATR(DFN,0)),U,3)'=AMHRSSP Q
 .I AMHRCDP]"",$P($G(^AMHPATR(DFN,0)),U,4)'=AMHRCDP Q
 .D GATHER
 .Q
 D GETSCR
 Q
GATHER ;gather up all exams, refusals and bh in time period for patient in DFN
 ;if at least one match criteria then set ^xtmp($j,$h,"pts",dfn)=""
BH ;now go through BH
 S AMHRSD=$$FMADD^XLFDT(AMHRBD,-1),AMHRSD=AMHRSD_".9999"
 F  S AMHRSD=$O(^AMHREC("AF",DFN,AMHRSD)) Q:AMHRSD'=+AMHRSD!($P(AMHRSD,".")>AMHRED)  D
 .S AMHRBIEN=0 F  S AMHRBIEN=$O(^AMHREC("AF",DFN,AMHRSD,AMHRBIEN)) Q:AMHRBIEN'=+AMHRBIEN  D
 ..S AMHRDATE=$P(AMHRSD,".")
 ..Q:'$D(^AMHREC(AMHRBIEN,0))
 ..Q:$P($G(^AMHREC(AMHRBIEN,14)),U,7)=""
 ..Q:'$$ALLOWVI^AMHUTIL(DUZ,AMHRBIEN)
 ..Q:AMHRDATE>AMHRED
 ..Q:AMHRDATE<AMHRBD
 ..S X=$$AGE^AUPNPAT(DFN,AMHRDATE)
 ..I $D(AMHRAGET),X>$P(AMHRAGET,"-",2) Q
 ..I $D(AMHRAGET),X<$P(AMHRAGET,"-",1) Q
 ..;clinic check
 ..I $D(AMHRCLNT) S X=$P(^AMHREC(AMHRBIEN,0),U,25) Q:X=""  Q:'$D(AMHRCLNT(X))
 ..;result check
 ..S AMHRRES=$$VAL^XBDIQ1(9002011,AMHRBIEN,1407) S:AMHRRES["REFUSED" AMHRRES="REFUSED SCREENING"
 ..I AMHRRES="LOW",'$D(AMHRREST(1)) Q
 ..I AMHRRES="MODERATE",'$D(AMHRREST(2)) Q
 ..I AMHRRES="HIGH",'$D(AMHRREST(3)) Q
 ..I AMHRRES["REFUSED",'$D(AMHRREST(4)) Q  ;do not want refusals
 ..I AMHRRES["UNABLE",'$D(AMHRREST(5)) Q  ;do not want unables
 ..I AMHRRES["REFERRAL",'$D(AMHRREST(6)) Q  ;do not want unables
 ..I AMHRRES="",'$D(AMHRREST(7)) Q
 ..;PRIMARY PROVIDER CHECK
 ..S X=$$BHPPIN(AMHRBIEN)
 ..I $D(AMHRPROV),X="" Q  ;want only certain primary providers on visit
 ..I $D(AMHRPROV),'$D(AMHRPROV(X)) Q  ;want one provider and it's not this one
 ..I AMHRPPUN,X'="" Q  ;want only unknown and this one has a primary provider
 ..S X=$P($G(^AMHREC(AMHRBIEN,14)),U,8)
 ..I $D(AMHRSPRV),X="" Q  ;want only certain SCR providers on visit
 ..I $D(AMHRSPRV),'$D(AMHRSPRV(X)) Q  ;want one provider and it's not this one
 ..I AMHRSPUN,X'="" Q  ;want only unknown and this one has a SCR provider
 ..S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN)=""
 Q:$D(^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN))   ;already got this patient so no need to go on
PCC ;
 Q:'AMHREXPC
 S AMHREIEN=0 F  S AMHREIEN=$O(^AUPNVXAM("AC",DFN,AMHREIEN)) Q:AMHREIEN'=+AMHREIEN  D
 .Q:'$D(^AUPNVXAM(AMHREIEN,0))
 .Q:$P(^AUPNVXAM(AMHREIEN,0),U)'=AMHREXC  ;not ipv/dv
 .S AMHRVIEN=$P(^AUPNVXAM(AMHREIEN,0),U,3)
 .Q:'AMHRVIEN
 .Q:'$$ALLOWPCC^AMHUTIL(DUZ,AMHRVIEN)
 .S AMHRDATE=$P($P($G(^AUPNVSIT(AMHRVIEN,0)),U),".")
 .Q:AMHRDATE=""
 .Q:AMHRDATE>AMHRED
 .Q:AMHRDATE<AMHRBD
 .S X=$$AGE^AUPNPAT(DFN,AMHRDATE)
 .I $D(AMHRAGET),X>$P(AMHRAGET,"-",2) Q
 .I $D(AMHRAGET),X<$P(AMHRAGET,"-",1) Q
 .;clinic check
 .I $D(AMHRCLNT) S X=$P(^AUPNVSIT(AMHRVIEN,0),U,8) Q:X=""  Q:'$D(AMHRCLNT(X))
 .;result check
 .S AMHRRES=$$VAL^XBDIQ1(9000010.13,AMHREIEN,.04) S:AMHRRES["REFUSED" AMHRRES="REFUSED SCREENING"
 .I AMHRRES="LOW",'$D(AMHRREST(1)) Q
 .I AMHRRES="MODERATE",'$D(AMHRREST(2)) Q
 .I AMHRRES="HIGH",'$D(AMHRREST(3)) Q
 .I AMHRRES["REFERRAL",'$D(AMHRREST(6)) Q  ;do not want unables
 .I AMHRRES="",'$D(AMHRREST(7)) Q
 .;PRIMARY PROVIDER CHECK
 .S X=$$PRIMPROV^APCLV(AMHRVIEN,"I")
 .I $D(AMHRPROV),X="" Q  ;want only certain primary providers on visit
 .I $D(AMHRPROV),'$D(AMHRPROV(X)) Q  ;want one provider and it's not this one
 .I AMHRPPUN,X'="" Q  ;want only unknown and this one has a primary provider
 .S X=$P($G(^AUPNVXAM(AMHREIEN,12)),U,4)
 .I $D(AMHRSPRV),X="" Q  ;want only certain SCR providers on visit
 .I $D(AMHRSPRV),'$D(AMHRSPRV(X)) Q  ;want one provider and it's not this one
 .I AMHRSPUN,X'="" Q  ;want only unknown and this one has a SCR provider
 .S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN)=""
REF ;now go through refusals in pcc
 Q:$D(^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN))  ;already got one so no need to go on
 S AMHRRIEN=0 F  S AMHRRIEN=$O(^AUPNPREF("AC",DFN,AMHRRIEN)) Q:AMHRRIEN'=+AMHRRIEN  D
 .Q:'$D(^AUPNPREF(AMHRRIEN,0))
 .Q:$P(^AUPNPREF(AMHRRIEN,0),U,5)'=9999999.15
 .Q:$P(^AUPNPREF(AMHRRIEN,0),U,6)'=AMHREXC
 .S AMHRDATE=$P(^AUPNPREF(AMHRRIEN,0),U,3)
 .Q:AMHRDATE=""
 .Q:AMHRDATE>AMHRED
 .Q:AMHRDATE<AMHRBD
 .S X=$$AGE^AUPNPAT(DFN,AMHRDATE)
 .I $D(AMHRAGET),X>$P(AMHRAGET,"-",2) Q
 .I $D(AMHRAGET),X<$P(AMHRAGET,"-",1) Q
 .S AMHRRES=$$VAL^XBDIQ1(9000022,AMHRRIEN,.07) S:AMHRRES["REFUSED" AMHRRES="REFUSED SCREENING"
 .I AMHRRES["REFUSED",'$D(AMHRREST(4)) Q  ;do not want refusals
 .I AMHRRES["UNABLE",'$D(AMHRREST(5)) Q  ;do not want unables
 .S X=$P($G(^AUPNPREF(AMHRRIEN,12)),U,4)
 .I $D(AMHRSPRV),X="" Q  ;want only certain SCR providers on visit
 .I $D(AMHRSPRV),'$D(AMHRSPRV(X)) Q  ;want one provider and it's not this one
 .I AMHRSPUN,X'="" Q  ;want only unknown and this one has a SCR provider
 .S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN)=""
 Q
 ;
GETSCR ;
 K ^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS")
 S DFN=0 F  S DFN=$O(^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN)) Q:DFN'=+DFN  D GETSCR1
 Q
GETSCR1 ;
 S AMHRSD=$$FMADD^XLFDT(AMHRBD,-1),AMHRSD=AMHRSD_".9999"
 F  S AMHRSD=$O(^AMHREC("AF",DFN,AMHRSD)) Q:AMHRSD'=+AMHRSD!($P(AMHRSD,".")>AMHRED)  D
 .S AMHRBIEN=0 F  S AMHRBIEN=$O(^AMHREC("AF",DFN,AMHRSD,AMHRBIEN)) Q:AMHRBIEN'=+AMHRBIEN  D
 ..S AMHRDATE=$P(AMHRSD,".")
 ..Q:'$D(^AMHREC(AMHRBIEN,0))
 ..Q:$P($G(^AMHREC(AMHRBIEN,14)),U,7)=""
 ..Q:AMHRDATE>AMHRED
 ..Q:AMHRDATE<AMHRBD
 ..S AMHRCNT=AMHRCNT+1
 ..S AMHRRES=$$VAL^XBDIQ1(9002011,AMHRBIEN,1407) S:AMHRRES["REFUSED" AMHRRES="REFUSED SCREENING"
 ..I AMHRRES="LOW",'$D(AMHRREST(1)) Q
 ..I AMHRRES="MODERATE",'$D(AMHRREST(2)) Q
 ..I AMHRRES="HIGH",'$D(AMHRREST(3)) Q
 ..I AMHRRES["REFUSED",'$D(AMHRREST(4)) Q  ;do not want refusals
 ..I AMHRRES["UNABLE",'$D(AMHRREST(5)) Q  ;do not want unables
 ..I AMHRRES["REFERRAL",'$D(AMHRREST(6)) Q  ;do not want unables
 ..I AMHRRES="",'$D(AMHRREST(7)) Q
 ..S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT)="BH"_U_$$BHPPNAME(AMHRBIEN)_U_AMHRRES_U_$$VAL^XBDIQ1(9002011,AMHRBIEN,1901)_U_$$AGE^AUPNPAT(DFN,AMHRDATE)_U_$$VAL^XBDIQ1(2,DFN,.02)_U_AMHRDATE_U_AMHRBIEN_U_DFN
 ..S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,10)=$$VAL^XBDIQ1(9002011,AMHRBIEN,.25)
 ..S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,15)=AMHRBIEN
 ..S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,16)=$$VAL^XBDIQ1(9002011,AMHRBIEN,1408)
 ..S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,17)=$$VAL^XBDIQ1(9000001,DFN,.14)
 Q:'AMHREXPC
 ;go through exam SRA, then through AUPNPREF for refusals
 S AMHREIEN=0 F  S AMHREIEN=$O(^AUPNVXAM("AC",DFN,AMHREIEN)) Q:AMHREIEN'=+AMHREIEN  D
 .Q:'$D(^AUPNVXAM(AMHREIEN,0))
 .Q:$P(^AUPNVXAM(AMHREIEN,0),U)'=AMHREXC
 .S AMHRVIEN=$P(^AUPNVXAM(AMHREIEN,0),U,3)
 .Q:'AMHRVIEN
 .S AMHRDATE=$P($P($G(^AUPNVSIT(AMHRVIEN,0)),U),".")
 .Q:AMHRDATE=""
 .Q:AMHRDATE>AMHRED
 .Q:AMHRDATE<AMHRBD
 .I $D(^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN,AMHRDATE)) Q
 .S AMHRCNT=AMHRCNT+1
 .S AMHRRES=$$VAL^XBDIQ1(9000010.13,AMHREIEN,.04) S:AMHRRES["REFUSED" AMHRRES="REFUSED SCREENING"
 .I AMHRRES="",'$D(AMHRREST(7)) Q  ;NO BLANKS
 .I AMHRRES="LOW",'$D(AMHRREST(1)) Q
 .I AMHRRES="MODERATE",'$D(AMHRREST(2)) Q
 .I AMHRRES="HIGH",'$D(AMHRREST(3)) Q
 .I AMHRRES["REFERRAL",'$D(AMHRREST(6)) Q  ;do not want unables
 .I AMHRRES="",'$D(AMHRREST(7)) Q
 .S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT)="EX"_U_$$PPV(AMHRVIEN)_U_AMHRRES_U_$$VAL^XBDIQ1(9000010.13,AMHREIEN,81101)_U_$$AGE^AUPNPAT(DFN,AMHRDATE)_U_$$VAL^XBDIQ1(2,DFN,.02)_U_AMHRDATE_U_AMHREIEN_U_DFN
 .S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,10)=$$VAL^XBDIQ1(9000010,AMHRVIEN,.08)
 .S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,15)=AMHRVIEN
 .S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,16)=$$SPRV(AMHREIEN)
 .S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,17)=$$VAL^XBDIQ1(9000001,DFN,.14)
 .S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN,AMHRDATE)=AMHRCNT
 ;now go through refusals in pcc
 S AMHRRIEN=0 F  S AMHRRIEN=$O(^AUPNPREF("AC",DFN,AMHRRIEN)) Q:AMHRRIEN'=+AMHRRIEN  D
 .Q:'$D(^AUPNPREF(AMHRRIEN,0))
 .Q:$P(^AUPNPREF(AMHRRIEN,0),U,5)'=9999999.15
 .Q:$P(^AUPNPREF(AMHRRIEN,0),U,6)'=AMHREXC
 .S AMHRDATE=$P(^AUPNPREF(AMHRRIEN,0),U,3)
 .Q:AMHRDATE=""
 .Q:AMHRDATE>AMHRED
 .Q:AMHRDATE<AMHRBD
 .I $P(^AUPNPREF(AMHRRIEN,0),U,7)="R",'$D(AMHRREST(4)) Q
 .I $P(^AUPNPREF(AMHRRIEN,0),U,7)="U",'$D(AMHRREST(5)) Q
 .I $D(^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN,AMHRDATE)) Q
 .S AMHRRES=$$VAL^XBDIQ1(9000022,AMHRRIEN,.07) S:AMHRRES["REFUSED" AMHRRES="REFUSED SCREENING"
 .S AMHRCNT=AMHRCNT+1
 .S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT)="REF"_U_"UNKNOWN"_U_AMHRRES_U_$$VAL^XBDIQ1(9000022,AMHRRIEN,1101)_U_$$AGE^AUPNPAT(DFN,AMHRDATE)_U_$$VAL^XBDIQ1(2,DFN,.02)_U_AMHRDATE_U_AMHRRIEN_U_DFN_U
 .S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,16)=$$PRVREF(AMHRRIEN)
 .S $P(^XTMP("AMHRSR3",AMHRJ,AMHRH,"VSTS",AMHRCNT),U,17)=$$VAL^XBDIQ1(9000001,DFN,.14)
 .S ^XTMP("AMHRSR3",AMHRJ,AMHRH,"PTS",DFN,AMHRDATE)=AMHRCNT
 Q
BHPPIN(R) ;
 NEW %,%1
 S %=0,%1="" F  S %=$O(^AMHRPROV("AD",R,%)) Q:%'=+%  I $P(^AMHRPROV(%,0),U,4)="P" S %1=$P(^AMHRPROV(%,0),U)
 Q %1
BHPPNAME(R) ;EP primary provider internal # from 200
 NEW %,%1
 S %=0,%1="" F  S %=$O(^AMHRPROV("AD",R,%)) Q:%'=+%  I $P(^AMHRPROV(%,0),U,4)="P" S %1=$P(^AMHRPROV(%,0),U),%1=$P($G(^VA(200,%1,0)),U)
 I %1]"" Q %1
 Q "UNKNOWN"
SPRV(E) ;
 I $P($G(^AUPNVXAM(E,12)),U,4) Q $$VAL^XBDIQ1(9000010.13,E,1204)
 Q "UNKNOWN"
PRVREF(R) ;
 I $P($G(^AUPNPREF(R,12)),U,4)]"" Q $$VAL^XBDIQ1(9000022,R,1204)
 Q "UNKNOWN"
PPV(V) ;
 NEW %
 S %=$$PRIMPROV^APCLV(V,"N")
 I %]"" Q %
 Q "UNKNOWN"
CTR(X,Y) ;EP - Center X in a field Y wide.
 Q $J("",$S($D(Y):Y,1:IOM)-$L(X)\2)_X
 ;----------
EOP ;EP - End of page.
 Q:$E(IOST)'="C"
 Q:IO'=IO(0)
 Q:$D(ZTQUEUED)!'(IOT="TRM")!$D(IO("S"))
 NEW DIR
 K DIRUT,DFOUT,DLOUT,DTOUT,DUOUT
 W !
 S DIR("A")="End of Report.  Press Enter",DIR(0)="E" D ^DIR
 Q
 ;----------
USR() ;EP - Return name of current user from ^VA(200.
 Q $S($G(DUZ):$S($D(^VA(200,DUZ,0)):$P(^(0),U),1:"UNKNOWN"),1:"DUZ UNDEFINED OR 0")
 ;----------
LOC() ;EP - Return location name from file 4 based on DUZ(2).
 Q $S($G(DUZ(2)):$S($D(^DIC(4,DUZ(2),0)):$P(^(0),U),1:"UNKNOWN"),1:"DUZ(2) UNDEFINED OR 0")
 ;----------