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

AMHEHR1.m

Go to the documentation of this file.
AMHEHR1 ; IHS/CMI/LAB - ADD NEW MHSS ACTIVITY RECORDS 13 Aug 2007 4:21 PM ; 14 Nov 2013  2:57 PM
 ;;4.0;IHS BEHAVIORAL HEALTH;**4,6,8**;JUN 02, 2010;Build 7
 ;
EEPC ;EP - called from option
 W !!,"This option is used to loop through all MHSS PROBLEM/DX table "
 W !,"entries created by EHR users to change the grouping from the "
 W !,"generic 99.9 OTHER EHR CLINICAL grouping to a more specific"
 W !,"MHSS PROBLEM CODE grouping.",!!
 S AMHEPC=$O(^AMHPROBC("B","99.9",0))
 S AMHQ=0
 I 'AMHEPC W !!,"Problem code 99.9 is not in the file.",! D EXIT Q
 I '$O(^AMHPROB("AC",AMHEPC,0)) W !!,"There are no newly created entries in the MHSS Problem/DX table.",!,"No action is needed at this time.",!! D PAUSE^AMHLEA,EXIT Q
 S AMHX=0 F  S AMHX=$O(^AMHPROB("AC",AMHEPC,AMHX)) Q:AMHX'=+AMHX!(AMHQ)  D
 .W !!,"CODE: ",$$VAL^XBDIQ1(9002012.2,AMHX,.01)
 .W !,"ICD Narrative: ",$$VAL^XBDIQ1(9002012.2,AMHX,.02)
 .S AMHPCG="" K DIC S DIC="^AMHPROBC(",DIC(0)="AEMQ",DIC("S")="I '$P(^(0),U,4)",DIC("A")="Enter the Problem Code Grouping: "
 .D ^DIC
 .I X="^" S AMHQ=1 Q
 .I Y=-1 W !,"nothing changed for CODE: ",$$VAL^XBDIQ1(9002012.2,AMHX,.01) K DIC,Y Q
 .S AMHPCG=+Y
 .K DIR,DIC
 .W !,"Are you sure you want to change the MHSS Problem Code Grouping to"
 .S DIR("A")="     "_$$VAL^XBDIQ1(9002012.4,AMHPCG,.01)_"  -  "_$$VAL^XBDIQ1(9002012.4,AMHPCG,.02)
 .S DIR(0)="Y",DIR("B")="N" KILL DA D ^DIR KILL DIR
 .I 'Y W !,"nothing changed for CODE: ",$$VAL^XBDIQ1(9002012.2,AMHX,.01) K DIC,Y Q
 .S DA=AMHX,DIE="^AMHPROB(",DR=".03////"_AMHPCG D ^DIE K DA,DIE,DR,DIU,DIV,DIW
 .Q
 Q
 ;
EXIT ;
 D EN^XBVK("AMH")
 Q
 ;
EHRALERT ;EP - called from option/scheduled
 ;find all visits entered that day or day before and send alert if there is no activity time
 ;go through all BH/EHR visits added/edited in the past 2 days and send bulletin if one
 ;has never been sent before
 NEW AMHD,AMHR,AMHP,%
 S AMHD=$$FMADD^XLFDT(DT,-3)_".9999"
 F  S AMHD=$O(^AMHREC("ALM",AMHD)) Q:AMHD'=+AMHD  D
 .S AMHR=0 F  S AMHR=$O(^AMHREC("ALM",AMHD,AMHR)) Q:AMHR'=+AMHR  D
 ..Q:$P($G(^AMHREC(AMHR,11)),U,10)'=1  ;NOT CREATED BY EHR
 ..Q:$P(^AMHREC(AMHR,0),U,12)  ;HAS ANY ACTIVITY TIME
 ..S AMHP=$$PPINT^AMHUTIL(AMHR)
 ..I AMHP=""  S %=$O(^AMHREC("AD",AMHR,0)) I % S AMHP=$P($G(^AMHRPROV(%,0)),U,1)
 ..Q:AMHP=""
 ..;send alert to user only if one never sent
 ..S (G,X)=0 F  S X=$O(^AMHREC(AMHR,97,X)) Q:X'=+X!(G)  D
 ...Q:$P(^AMHREC(AMHR,97,X,0),U,2)'=AMHP
 ...S G=1
 ..Q:G  ;already got an alert for this visit
 ..;S XQA(DUZ)=""
 ..S XQA(AMHP)=""
 ..S XQAOPT=""
 ..S XQAROU=""
 ..S XQAFLG="D"
 ..S AMHTEXT(1)=" "
 ..S AMHTEXT(2)=" "
 ..S AMHTEXT(3)="This Behavioral Health visit is missing an activity time.  The activity"
 ..S AMHTEXT(4)="time can be entered through EHR or with PCC data entry using the AT"
 ..S AMHTEXT(5)="mnemonic."
 ..S XQATEXT="AMHTEXT"
 ..S XQAMSG="HRN: "_$$HRN^AUPNPAT($P(^AMHREC(AMHR,0),U,8),DUZ(2))_"  Date: "_$$VAL^XBDIQ1(9002011,AMHR,.01)_" is missing an activity time."
 ..S XQAID="OR,"_$P(^AMHREC(AMHR,0),U,8)_",46"
 ..D SETUP^XQALERT
 ..S (G,X)=0 F  S X=$O(^AMHREC(AMHR,97,X)) Q:X'=+X  S G=X
 ..S G=G+1
 ..S ^AMHREC(AMHR,97,G,0)=DT_"^"_AMHP,^AMHREC(AMHR,97,"B",DT,G)=""
 ..S ^AMHREC(AMHR,97,0)="^9002011.97DA^"_G_"^"_G
 Q
TIUDSP ;EP
 S AMHSTR="" D S(AMHSTR)
 I '+$$CANDO^TIULP(AMHDOC,"PRINT RECORD",DUZ) Q  ;S AMHSTR="You do not have security clearance to display the TIU NOTE." D S(AMHSTR) Q
 ; Extract specified note
 S AMHGBL=$NA(^TMP("AMHOENPS",$J)),AMHHLF=IOM\2
 K @AMHGBL
 D EXTRACT^TIULQ(AMHDOC,AMHGBL,.AMHERR,".01;.02;.03;.05;.07;.08;1202;1203;1205;1208;1209;1301;1307;1402;1501:1505;1507:1513;1701","",1,"E")
 M AMHTIU=^TMP("AMHOENPS",$J,AMHDOC)
 K ^TMP("AMHOENPS",$J)
 S AMHSTR="TIU DOCUMENT:  "_AMHTIU(.01,"E") D S(AMHSTR)
 S AMHSTR="AUTHOR: "_AMHTIU(1202,"E") D S(AMHSTR)
 S AMHSTR="SIGNED BY: "_AMHTIU(1502,"E")_"               STATUS: "_AMHTIU(.05,"E") D S(AMHSTR)
 S AMHSTR="LOCATION: "_AMHTIU(1205,"E") D S(AMHSTR)
 F AMHX=0:0 S AMHX=$O(AMHTIU("TEXT",AMHX)) Q:'AMHX  S AMHSTR=AMHTIU("TEXT",AMHX,0) D S(AMHSTR)
 I $L($G(AMHTIU(1501,"E"))) D
 .S AMHSTR="/es/ "_$G(AMHTIU(1503,"E")) D S(AMHSTR)
 .S AMHSTR="Signed: "_$G(AMHTIU(1501,"E")) D S(AMHSTR)
 ;NOW GET ADDENDA USING "DAD" XREF
 I $O(^TIU(8925,"DAD",AMHDOC,0)) S AMHSTR="" D S(AMHSTR)   ;S AMHSTR="This document has addenda." D S(AMHSTR)
 S AMHX1=0 F  S AMHX1=$O(^TIU(8925,"DAD",AMHDOC,AMHX1)) Q:AMHX1'=+AMHX1  D
 .I '+$$CANDO^TIULP(AMHX1,"PRINT RECORD",DUZ) Q  ;S AMHSTR="You do not have security clearance to display the addendum." D S(AMHSTR) Q
 .S AMHGBL=$NA(^TMP("AMHOENPS",$J))
 .K @AMHGBL
 .K AMHTIU
 .D EXTRACT^TIULQ(AMHX1,AMHGBL,.AMHERR,".01;.02;.03;.05;.07;.08;1202;1203;1205;1208;1209;1301;1307;1402;1501:1505;1507:1513;1701","",1,"E")
 .M AMHTIU=^TMP("AMHOENPS",$J,AMHX1)
 .K ^TMP("AMHOENPS",$J)
 .S AMHSTR="" D S(AMHSTR)
 .S AMHSTR=AMHTIU(.01,"E") D S(AMHSTR)
 .S AMHSTR="AUTHOR: "_AMHTIU(1202,"E") D S(AMHSTR)
 .S AMHSTR="SIGNED BY: "_AMHTIU(1502,"E")_"               STATUS: "_AMHTIU(.05,"E") D S(AMHSTR)
 .S AMHSTR="LOCATION: "_AMHTIU(1205,"E") D S(AMHSTR)
 .F AMHX=0:0 S AMHX=$O(AMHTIU("TEXT",AMHX)) Q:'AMHX  S AMHSTR=AMHTIU("TEXT",AMHX,0) D S(AMHSTR)
 .I $L($G(AMHTIU(1501,"E"))) D
 ..S AMHSTR="/es/ "_$G(AMHTIU(1503,"E")) D S(AMHSTR)
 ..S AMHSTR="Signed: "_$G(AMHTIU(1501,"E")) D S(AMHSTR)
 ;
 Q
 ;
S(Y,F,C,T) ;EP - set up array
 I '$G(F) S F=0
 I '$G(T) S T=0
 ;blank lines
 F F=1:1:F S X="" D S1
 S X=Y
 I $G(C) S L=$L(Y),T=(80-L)/2 D  D S1 Q
 .F %=1:1:(T-1) S X=" "_X
 F %=1:1:T S X=" "_Y
 D S1
 Q
S1 ;
 S AMHC=AMHC+1
 S AMHTIUD(AMHC,0)=X
 Q
GETDSM ;EP
 NEW X,Y,C,G,D
 S D=$P($P(^AMHREC(AMHR,0),U),".")
 ;SET UP ARRAY OF ALL ACTIVE WITH CODING SYSTEM
 S X=0,C=0 F  S X=$O(^AMHPROB("B",AMHCODE,X)) Q:X'=+X  D
 .I $P(^AMHPROB(X,0),U,14)]"",$P(^AMHPROB(X,0),U,14)'>D Q  ;DON'T PICK INACTIVE ONES
 .I $P(^AMHPROB(X,0),U,10)=4!($P(^AMHPROB(X,0),U,10)=5) Q:$P(^AMHPROB(X,0),U,10)'=AMH45  ;ONLY 4 OR 5
 .S C=C+1
 .S Y(X)=""
 .Q
 I C=1 S AMHDSM=$O(Y(0)) Q  ;FOUND ONLY 1 SO USE IT
 I C=0 Q  ;NONE FOUND SO GO ADD ONE
 ;FIND ONE THAT IS EHR DEFAULT, IF NONE, TAKE 1ST ONE
 S X=0,G="" F  S X=$O(Y(X)) Q:X'=+X!(G)  D
 .I $P(^AMHPROB(X,0),U,15) S G=X Q
 I G S AMHDSM=G Q  ;FOUND AN EHR DEFAULT
 S AMHDSM=$O(Y(0))
 Q
SETARRAY ;EP
 NEW AMHERR
 S AMHIENS=AMHR_","
 S AMHFDA(9002011,AMHIENS,.02)=AMH02
 S AMHFDA(9002011,AMHIENS,.04)=AMH04
 S AMHFDA(9002011,AMHIENS,.05)=AMH05
 S AMHFDA(9002011,AMHIENS,.06)=AMH06
 S AMHFDA(9002011,AMHIENS,.07)=AMH07
 S AMHFDA(9002011,AMHIENS,.09)=AMH09
 S AMHFDA(9002011,AMHIENS,.11)=AMH11
 S AMHFDA(9002011,AMHIENS,.12)=AMH12
 S AMHFDA(9002011,AMHIENS,.25)=AMH25
 S AMHFDA(9002011,AMHIENS,.26)=AMH26
 S AMHFDA(9002011,AMHIENS,1108)=AMH1108
 S AMHFDA(9002011,AMHIENS,1117)=AMH1117
 S AMHFDA(9002011,AMHIENS,1401)=AMH1401
 S AMHFDA(9002011,AMHIENS,1402)=AMH1402
 S AMHFDA(9002011,AMHIENS,1403)=AMH1403
 S AMHFDA(9002011,AMHIENS,1404)=AMH1404
 S AMHFDA(9002011,AMHIENS,1405)=AMH1405
 S AMHFDA(9002011,AMHIENS,1406)=AMH1406
 S AMHFDA(9002011,AMHIENS,1501)=AMH1501
 S AMHFDA(9002011,AMHIENS,1601)=AMH1601
 S AMHFDA(9002011,AMHIENS,1701)=AMH1701
 S AMHFDA(9002011,AMHIENS,1407)=AMH1407
 S AMHFDA(9002011,AMHIENS,1408)=AMH1408
 S AMHFDA(9002011,AMHIENS,1901)=AMH1901
 S AMHFDA(9002011,AMHIENS,.34)=$P($G(^AUPNVSIT(AMHVSIT,11)),U,15)
 Q
SCRREF ;EP - ANY REFUSALS FOR SCREENINGS FOR THIS PATIENT/DATE?
 ;if any screenings have REF/UAS then wipe it out
 ;IPV/DV
 I $P($G(^AMHREC(AMHR,14)),U,1)="REF"!($P($G(^AMHREC(AMHR,14)),U,1)="UAS") D
 .S DA=AMHR,DR="1401///@;1402///@;1501///@",DIE="^AMHREC(" D ^DIE K DA,DIE,DR
 I $P($G(^AMHREC(AMHR,14)),U,3)="REF"!($P($G(^AMHREC(AMHR,14)),U,3)="UAS") D
 .S DA=AMHR,DR="1403///@;1404///@;1601///@",DIE="^AMHREC(" D ^DIE K DA,DIE,DR
 I $P($G(^AMHREC(AMHR,14)),U,5)="REF"!($P($G(^AMHREC(AMHR,14)),U,5)="UAS") D
 .S DA=AMHR,DR="1405///@;1406///@;1701///@",DIE="^AMHREC(" D ^DIE K DA,DIE,DR
 I $P($G(^AMHREC(AMHR,14)),U,7)="REF"!($P($G(^AMHREC(AMHR,14)),U,7)="UAS") D
 .S DA=AMHR,DR="1407///@;1408///@;1901///@",DIE="^AMHREC(" D ^DIE K DA,DIE,DR
 ;
 NEW AMHX,AMHY,AMHZ,AMHD
 S AMHD=$P($P(^AMHREC(AMHR,0),U,1),".")
 ;IPV
 ;IF HAS A GOOD VALUE THEN SKIP THIS
 S R=$$VALI^XBDIQ1(9002011,AMHR,1401) I R]"",R'="REF",R'="UAS" G RALC
 S AMHZ=$O(^AUTTEXAM("C",34,0))
 S AMHX=0 F  S AMHX=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX)) Q:AMHX'=+AMHX  D
 .Q:(9999999-AMHX)'=AMHD  ;not correct date
 .S AMHY=0 F  S AMHY=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX,AMHY)) Q:AMHY'=+AMHY  D
 ..;file UAS or REF
 ..S R=$$VALI^XBDIQ1(9000022,AMHY,.07)
 ..I R'="R",R'="U" Q  ;only u and r
 ..S DIE="^AMHREC(",DA=AMHR,DR="1401///"_$S(R="R":"REF",R="U":"UAS",1:"")_";1402////"_$$VALI^XBDIQ1(9000022,AMHY,1204)_";1501///"_$TR($$VAL^XBDIQ1(9000022,AMHY,1101),";",":") D ^DIE K DA,DR,DIE
RALC ;ALCOHOL
 S R=$$VALI^XBDIQ1(9002011,AMHR,1403) I R]"",R'="REF",R'="UAS" G RDEP
 S AMHZ=$O(^AUTTEXAM("C",35,0))
 S AMHX=0 F  S AMHX=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX)) Q:AMHX'=+AMHX  D
 .Q:(9999999-AMHX)'=AMHD  ;not correct date
 .S AMHY=0 F  S AMHY=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX,AMHY)) Q:AMHY'=+AMHY  D
 ..;file UAS or REF
 ..S R=$$VALI^XBDIQ1(9000022,AMHY,.07)
 ..I R'="R",R'="U" Q  ;only u and r
 ..S DIE="^AMHREC(",DA=AMHR,DR="1403///"_$S(R="R":"REF",R="U":"UAS",1:"")_";1404////"_$$VALI^XBDIQ1(9000022,AMHY,1204)_";1601///"_$TR($$VAL^XBDIQ1(9000022,AMHY,1101),";",":") D ^DIE K DA,DR,DIE
RDEP ;DEPRESSION
 S R=$$VALI^XBDIQ1(9002011,AMHR,1403) I R]"",R'="REF",R'="UAS" G RSUI
 S AMHZ=$O(^AUTTEXAM("C",36,0))
 S AMHX=0 F  S AMHX=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX)) Q:AMHX'=+AMHX  D
 .Q:(9999999-AMHX)'=AMHD  ;not correct date
 .S AMHY=0 F  S AMHY=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX,AMHY)) Q:AMHY'=+AMHY  D
 ..;file UAS or REF
 ..S R=$$VALI^XBDIQ1(9000022,AMHY,.07)
 ..I R'="R",R'="U" Q  ;only u and r
 ..S DIE="^AMHREC(",DA=AMHR,DR="1405///"_$S(R="R":"REF",R="U":"UAS",1:"")_";1406////"_$$VALI^XBDIQ1(9000022,AMHY,1204)_";1701///"_$TR($$VAL^XBDIQ1(9000022,AMHY,1101),";",":") D ^DIE K DA,DR,DIE
RSUI ;SUICIDE RISK
 S AMHZ=$O(^AUTTEXAM("C",43,0))
 S AMHX=0 F  S AMHX=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX)) Q:AMHX'=+AMHX  D
 .Q:(9999999-AMHX)'=AMHD  ;not correct date
 .S AMHY=0 F  S AMHY=$O(^AUPNPREF("AA",AMHPAT,9999999.15,AMHZ,AMHX,AMHY)) Q:AMHY'=+AMHY  D
 ..;file UAS or REF
 ..S R=$$VALI^XBDIQ1(9000022,AMHY,.07)
 ..I R'="R",R'="U" Q  ;only u and r
 ..S DIE="^AMHREC(",DA=AMHR,DR="1407///"_$S(R="R":"REF",R="U":"UAS",1:"")_";1408////"_$$VALI^XBDIQ1(9000022,AMHY,1204)_";1901///"_$TR($$VAL^XBDIQ1(9000022,AMHY,1101),";",":") D ^DIE K DA,DR,DIE
 Q