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

AMHBHSC.m

Go to the documentation of this file.
AMHBHSC ; IHS/CMI/LAB - BEHAVIORAL HEALTH SPECIAL CROSSREFERENCE FOR GUI ;
 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
 ;
 ; AMHSETLV - Setting Primary List view - Assumes MH Encounter is central
 ; AMHCTYPE - Screen to Admin Type
 ; AMHGREF  - Primary Global Reference
 ; AMHSBJGR - Subject Global Reference - Used if all of the entries are to be used under this node -- don't need to check a date
 ; AMHDIVAL - Look at all divisions - Not used here, used to screen patients selected prior to calling this routine
 ; AMHBHALL - Look at all users' entries - Only relates to MH REC
 ;
SETUP ;
 S BGUCRFS="",AMHVTYPE=$G(AMHVTYPE)
 S:'$D(AMHGREF) AMHVTYPE=1,AMHGREF="^AMHREC(""AF"",AMHPIEN)"
 S:BGUMAX=25 BGUMAX=0 S AMHLIM=BGUMAX,BGUMAX=999999999 S:'AMHLIM AMHLIM=BGUMAX
 S AMHDIR=1 S:BGUDIR="B" AMHDIR=-1 S BGUDIR=""
 S (BGUBEGIN,BGUEND)="",AMHC=0,AMHGROUP=$G(AMHGROUP),AMHSETLV=$G(AMHSETLV,1),AMHDIVAL=1
 Q
 ;
MHRC ; Get records for a patient by date range
 ;S AMHGREF=$G(AMHGREF,"^AMHREC(""AF"",AMHPIEN)")
 S AMHPIEN=$P(BGUBEGIN,"`"),BGUBEGIN=$P(BGUBEGIN,"`",2)
 D MHREC
 Q
 ;
MHENC ; Get records for an encounter
 I '$D(BGUDRIVR) S BGUDRIVR="MHENC^AMHBHSC",AMHVIEN=BGUBEGIN  D SETUP Q
 D:AMHVIEN'="" MHENCTR
 D KILL
 Q
 ;
MHREC ;
 I '$D(BGUDRIVR) S BGUDRIVR="MHREC^AMHBHSC",AMHSDATE=$P(BGUBEGIN,"`"),AMHVIEN=$P(BGUBEGIN,"`",2),AMHEDATE=$P(BGUEND,"`",1) D SETUP Q
 S AMHVWOPT="2",AMHSBJGR=$G(AMHSBJGR),AMHCTYPE=$G(AMHCTYPE),AMHDTCK=$G(AMHDTCK)
 D MHREC1,KILL
 Q
MHREC1 ;
 D
 .I AMHSDATE'=+AMHSDATE D  Q
 ..S:AMHSDATE="" AMHSDATE="1/1/1980"
 ..S:AMHEDATE="" AMHEDATE="T"
 ..D DT^DILF("",AMHSDATE,.AMHSDAT)
 ..I AMHSDAT=-1 S AMHSDATE="1/1/1980" D DT^DILF("",AMHSDATE,.AMHSDAT)
 ..D DT^DILF("",AMHEDATE,.AMHEDAT)
 ..I AMHEDAT=-1 S AMHEDATE="T" D DT^DILF("",AMHEDATE,.AMHEDAT)
 ..S:AMHDIR<0 AMHEDAT=AMHEDAT+.9999
 .S AMHSDAT=AMHSDATE,AMHEDAT=AMHEDATE
 S AMHCTYPE=$G(AMHCTYPE)
 S AMHC=0,AMHX=0 ;,AMHLIM=$S(AMHVWOPT="0":AMHVWNO,1:999999)
 I AMHDTCK'="" D @AMHDTCK Q
 S AMHX=$S(AMHDIR>0:$O(@AMHGREF@(AMHSDAT),-1),1:$O(@AMHGREF@(AMHEDAT))) F  S AMHX=$O(@AMHGREF@(AMHX),AMHDIR) Q:'AMHX  Q:$S(AMHDIR>0:AMHX\1>AMHEDAT,1:AMHX\1<AMHSDAT)  D  Q:AMHC=AMHLIM
 .F  S AMHVIEN=$O(@AMHGREF@(AMHX,AMHVIEN)) Q:'AMHVIEN  Q:AMHC=AMHLIM  D MHENCTR
 Q
 ;
MHENCTR ;
 I AMHCTYPE'="",$P(^AMHREC(AMHVIEN,0),U,7)'=AMHCTYPE Q
 S AMHBHALL=1 I AMHVTYPE S AMHBHALL=0,AMHXX=$S(AMHGROUP:$P(^AMHGROUP(AMHVIEN,0),U,5),1:$P(^AMHREC(AMHVIEN,0),U,4)) I AMHXX,$D(^AMHSITE(AMHXX,16,DUZ)) S AMHBHALL=1
 I 'AMHBHALL,$S(AMHGROUP:$P(^AMHGROUP(AMHVIEN,0),U,15)'=DUZ,1:$P(^AMHREC(AMHVIEN,0),U,19)'=DUZ) S BGUV(BGUFILE,88888)=0 D  Q:'BGUV(BGUFILE,88888)
 .I AMHGROUP D  Q
 ..F  S BGUV(BGUFILE,88888)=$O(^AMHGROUP(AMHVIEN,11,BGUV(BGUFILE,88888))) Q:'BGUV(BGUFILE,88888)  Q:$P(^AMHGROUP(AMHVIEN,11,BGUV(BGUFILE,88888),0),U)=DUZ
 .F  S BGUV(BGUFILE,88888)=$O(^AMHRPROV("AD",AMHVIEN,BGUV(BGUFILE,88888))) Q:'BGUV(BGUFILE,88888)  Q:$P(^AMHRPROV(BGUV(BGUFILE,88888),0),U)=DUZ
 D
 .I 'AMHGROUP D:AMHSETLV  Q  ;PICKUP ALL THESE FIELDS IF AMHSETLV IS SET, INSTEAD OF REQUIRING THEIR OWN FLAGS
 ..S BGUV(BGUFILE,666666)=$O(^AMHREDU("AD",AMHVIEN,0))
 ..S BGUV(BGUFILE,777777)=$O(^AMHRHF("AD",AMHVIEN,0))
 ..S BGUV(BGUFILE,99999)=$O(^AMHRPRO("AD",AMHVIEN,0))
 ..S BGUV(BGUFILE,88888)=0 D
 ...F  S BGUV(BGUFILE,88888)=$O(^AMHRPROV("AD",AMHVIEN,BGUV(BGUFILE,88888))) Q:BGUV(BGUFILE,88888)=""  Q:$P(^AMHRPROV(BGUV(BGUFILE,88888),0),U,4)="P"
 .I AMHSETLV D
 ..S BGUV(BGUFILE,99999)=$O(^AMHGROUP(AMHVIEN,21,0)) S:BGUV(BGUFILE,99999) BGUV(BGUFILE,99999)=$P(^(BGUV(BGUFILE,99999),0),U)
 ..S BGUV(BGUFILE,88888)=0 D
 ..F  S BGUV(BGUFILE,88888)=$O(^AMHGROUP(AMHVIEN,11,BGUV(BGUFILE,88888))) Q:'BGUV(BGUFILE,88888)  I $P(^AMHGROUP(AMHVIEN,11,BGUV(BGUFILE,88888),0),U,2)="P" S BGUV(BGUFILE,88888)=$P(^(0),U) Q
 I AMHSBJGR="" S BGUSUB(1)=AMHVIEN,BGUV(BGUFILE,.0001)=AMHX D FIELDS^BGULIST S AMHC=BGUICNT Q
 S AMHSIEN=0 F  S AMHSIEN=$O(@AMHSBJGR@(AMHSIEN)) Q:'AMHSIEN  S AMHC=AMHC+1,BGUSUB(1)=AMHSIEN,BGUV(BGUFILE,.0001)=AMHX D FIELDS^BGULIST S AMHC=BGUICNT
 Q
 ;
ADM ; Get Administration Entries
 S AMHCTYPE=$O(^AMHTSET("B","ADMINISTRATIVE",""))
 S AMHBHALL=1,AMHGREF="^AMHREC(""B"")",AMHVTYPE=1
 D MHREC
 Q
 ;
MHCASE ;
 S AMHGREF="^AMHPCASE(""C"",AMHPIEN)",AMHDTCK="MHCASE1"
 D MHRC
 Q
 ;
MHCASE1 ;
 S AMHVIEN=0 F  S AMHVIEN=$O(@AMHGREF@(AMHVIEN)) Q:'AMHVIEN  Q:AMHC=AMHLIM  S AMHX=$P(^AMHPCASE(AMHVIEN,0),U,1) I AMHX'<AMHSDAT,AMHX'>AMHEDAT D MHENCTR
 Q
 ;
MHTREAT ;
 S AMHGREF="^AMHPTXP(""AC"",AMHPIEN)",AMHDTCK="MHTREAT1",AMHSETLV=""
 D MHRC
 Q
 ;
MHTREAT1 ;
 S AMHVIEN=0 F  S AMHVIEN=$O(@AMHGREF@(AMHVIEN)) Q:'AMHVIEN  Q:AMHC=AMHLIM  S AMHX=$P(^AMHPTXP(AMHVIEN,0),U,1) I AMHX'<AMHSDAT,AMHX'>AMHEDAT D MHENCTR
 Q
 ;
MHSUIV ;
 S AMHGREF="^AMHPSUIC(""AD"")",AMHSETLV=""
 D MHREC
 Q
 ;
MHSUI ;
 S AMHGREF="^AMHPSUIC(""AC"",AMHPIEN)",AMHDTCK="MHSUI1",AMHSETLV=""
 D MHRC
 Q
 ;
MHSUI1 ;
 S AMHVIEN=0 F  S AMHVIEN=$O(@AMHGREF@(AMHVIEN)) Q:'AMHVIEN  Q:AMHC=AMHLIM  S AMHX=$P(^AMHPSUIC(AMHVIEN,0),U,6) I AMHX'<AMHSDAT,AMHX'>AMHEDAT D MHENCTR
 Q
 ;
HF ; Health Factors
 S AMHSBJGR="^AMHRHF(""AD"",AMHVIEN)",AMHSETLV=0,AMHCTYPE=""
 D MHENC
 Q
 ;
EDU ; Patient Education
 S AMHSBJGR="^AMHREDU(""AD"",AMHVIEN)",AMHSETLV=0,AMHCTYPE=""
 D MHENC
 Q
 ;
MHGRP ;
 S AMHGREF="^AMHGROUP(""B"")",AMHGROUP=1,AMHVTYPE=1
 D MHREC
 Q
 ;
KILL ;
 K BGUDRIVR,AMHC,AMHCTYPE,AMHDIVAL,AMHDTCK,AMHEDATE,AMHGREF,AMHGROUP,AMHBHALL,AMHLBONL,AMHLIM,AMHPIEN,AMHSBJGR,AMHSDATE,AMHSETLV,AMHSIEN,AMHVIEN,AMHVTYPE,AMHVWNO,AMHVWOPT,AMHX,AMHXX
 Q