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

AMHGP.m

Go to the documentation of this file.
AMHGP ; IHS/CMI/MAW - AMHG Patient Lookup 4/28/2009 12:43:21 PM ;
 ;;4.0;IHS BEHAVIORAL HEALTH;**1,4**;JUN 18, 2010;Build 28
 ;
 ;
 ;
 Q
GETPAT(RETVAL,AMHSTR) ;EP -- return patient in ADO table
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHERRR,AMHUIEN,P
 S P="|"
 K ^AMHTMP($J)
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 S AMHERRR=""
 S ^AMHTMP($J,AMHI)="T00010IEN^T00030PATIENTNAME^T00015DOB^T00001SEX^T00007CHART^T00009SSN^T00010REG^T00030MORE^T00030DOD^T00010AGE^T00001MESSAGEFLAG^T02500MESSAGE"_$C(30)
 S AMHDUZ2=$P(AMHSTR,P)
 S AMHPAT=$P(AMHSTR,P,2)
 S AMHMT=$P(AMHSTR,P,3)
 S AMHNPAT=$P(AMHSTR,P,4)
 I '$G(AMHDUZ2) S AMHDUZ2=DUZ(2)
 ;I AMHNPAT]"" S AMHPAT=AMHNPAT  ;cmi/maw 3/12/09 for testing
 I AMHMT="ALL" S AMHMT=9999999
 S AMHMT=(AMHMT-1)
 I AMHPAT?9N D
 . S AMHPIEN=$$PATSSN(AMHPAT)
 I AMHPAT?1.7N D  ;ihs/cmi/maw 09/12/2012 AMH 4.0p4 allow for 7 digit chart numbers
 . S AMHPIEN=$$PATCHT(.AMHPIEN,AMHPAT)
 I AMHPAT?1.2N1"/"1.2N1"/"4N D
 . S X=AMHPAT D ^%DT S AMHPAT=Y
 . S AMHPIEN=$$PATDOB(.AMHPIEN,AMHPAT)
 I '$G(AMHPIEN) D PATNAM(.AMHPIEN,AMHPAT,AMHNPAT)
 I $G(AMHPIEN),'$G(AMHPATS) D PATADO(.AMHPIEN)
 S ^AMHTMP($J,AMHI+1)=$C(31)
 K AMHPAT,AMHPIEN,AMHCNT,AMHDA,AMHIEN,AMHPATE,AMHNM,AMHDB,AMHSX,AMHCT,AMHSSN,AMHDOD,AMHMORE,AMHAGE,AMHCNTR,AMHDG,AMHDUZ2,AMHMT,AMHNAM
 K AMHPATS,AMHNPAT,AMHPI,AMHUPD
 Q
 ;
PATSSN(PAT) ;EP -- look up by ssn
 S AMHPIEN=$O(^DPT("SSN",PAT,0))
 S AMHPIEN(1)=AMHPIEN
 Q $G(AMHPIEN)
 ;
PATCHT(AMHPIEN,PAT) ;EP -- lookup by chart
 ;ihs/cmi/maw 2/2/2011 added fix for same patient with same chart in multiple divisions
 N AMHCNT,AMHOEN
 S AMHCNT=0,AMHPATE=0,AMHMCNT=0
 S AMHDA=(PAT-1) F  S AMHDA=$O(^AUPNPAT("D",AMHDA)) Q:'AMHDA!(AMHDA>PAT)!(AMHCNT>AMHMT)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^AUPNPAT("D",AMHDA,AMHIEN)) Q:'AMHIEN  D
 .. S AMHOEN=0 F  S AMHOEN=$O(^AUPNPAT("D",AMHDA,AMHIEN,AMHOEN)) Q:'AMHOEN!($G(AMHPIEN))  D
 ... ;I $O(^AUPNPAT("D",AMHDA,AMHIEN,0))=AMHDUZ2 S AMHPIEN=AMHIEN
 ... I AMHOEN=AMHDUZ2 S AMHPIEN=AMHIEN
 ... Q:'$G(AMHPIEN)
 ... S AMHCNT=AMHCNT+1
 ... S:'$D(AMHPIEN(AMHCNT)) AMHPIEN(AMHCNT)=0
 ... S AMHPIEN(AMHCNT)=AMHPIEN
 Q $G(AMHPIEN)
 ;
PATDOB(AMHPATE,PAT) ;EP -- lookup by DOB
 N AMHCNT
 S AMHCNT=0,AMHPATE=0
 S AMHDOB=PAT-1 F  S AMHDOB=$O(^DPT("ADOB",AMHDOB)) Q:'AMHDOB!(AMHDOB'=+PAT)!(AMHCNT>AMHMT)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^DPT("ADOB",AMHDOB,AMHIEN)) Q:'AMHIEN  D
 .. S:'$D(AMHPATE(AMHCNT)) AMHPATE(AMHCNT)=0
 .. S AMHCNT=AMHCNT+1,AMHPATE=1
 .. S AMHPATE(AMHCNT)=AMHIEN
 S AMHPATE=AMHCNT
 Q $G(AMHPATE)
 ;
PATNAM(AMHPATE,PAT,NPAT) ;lookup by name
 S AMHCNT=0,AMHPATE=0
 N AMHLEN
 S AMHLEN=$L(PAT)
 S AMHNAM=PAT
 S AMHNAM=$$BEGIN(PAT)
 I $G(NPAT)]"" S AMHNAM=NPAT
 F  S AMHNAM=$O(^DPT("B",AMHNAM)) Q:AMHNAM=""!($E(AMHNAM,1,AMHLEN)'=PAT)  D
 . S AMHIEN=0 F  S AMHIEN=$O(^DPT("B",AMHNAM,AMHIEN)) Q:'AMHIEN  D
 .. N AMHOEN
 .. I $O(^DPT("B",AMHNAM,AMHIEN,0)) D
 ... S AMHOEN=0 F  S AMHOEN=$O(^DPT("B",AMHNAM,AMHIEN,AMHOEN)) Q:'AMHOEN  D
 .... ;Q:$O(^DPT("B",AMHNAM,AMHIEN,0))  ;cmi/maw 4/25/2005 don't get aliases
 .... S AMHCNT=AMHCNT+1
 .... S:'$D(AMHPATE(AMHCNT)) AMHPATE(AMHCNT)=0
 .... S AMHPATE(AMHCNT)=AMHIEN_U_AMHNAM
 .. I '$O(^DPT("B",AMHNAM,AMHIEN,0)) D
 ... S AMHCNT=AMHCNT+1
 ... S:'$D(AMHPATE(AMHCNT)) AMHPATE(AMHCNT)=0
 ... S AMHPATE(AMHCNT)=AMHIEN
 S AMHPATE=AMHCNT
 Q $G(AMHPATE)
 ;
BEGIN(PT) ;EP -- get begin point
 N AMHPDA,AMHPIEN,AMHPCNT
 S AMHPCNT=0
 S AMHPDA=PT
 I $O(^DPT("B",AMHPDA,0)) D
 . S AMHPDA=$O(^DPT("B",AMHPDA),-1)
 F  S AMHPDA=$O(^DPT("B",AMHPDA)) Q
 I $G(AMHPDA)="" Q ""
 Q $O(^DPT("B",AMHPDA),-1)
 ;
PATADO(PIEN) ;EP -- ado return
 S AMHCNTR=0
 S AMHDA=0 F  S AMHDA=$O(PIEN(AMHDA)) Q:'AMHDA  D
 . S AMHPI=$P($G(PIEN(AMHDA)),U)
 . S AMHAL=$P($G(PIEN(AMHDA)),U,2)
 . Q:'$$GUIPL^AMHUTIL(AMHPI,DUZ,AMHDUZ2)  ;see if user is allowed to see patient
 . ;D PTSEC^DGSEC4(.AMHDG,AMHPI,0)  ;logs patient, cant do here
 . D DGSEC(.AMHDG,AMHPI,DUZ,0)  ;don't log patient but get sensitivity info for patient lookup
 . N AMHDGMSG,AMHFLAG
 . I $G(AMHDG(1)) D
 .. S AMHFLAG=AMHDG(1)
 .. N AMHDGDA
 .. S AMHDGMSG=""
 .. S AMHDGDA=1 F  S AMHDGDA=$O(AMHDG(AMHDGDA)) Q:'AMHDGDA  D
 ... I $E(AMHDG(AMHDGDA),1,3)="* *" Q
 ... S AMHDGMSG=AMHDGMSG_" "_$G(AMHDG(AMHDGDA))
 . S AMHDGMSG=$TR($G(AMHDGMSG),"*")
 . I AMHCNTR>AMHMT Q
 . S AMHCNTR=AMHCNTR+1
 . S AMHNM=$S(AMHAL]"":AMHAL_"  ",1:"")_$P($G(^DPT(AMHPI,0)),U)
 . ;S AMHDB=$$FMTE^XLFDT($P($G(^DPT(AMHPI,0)),U,3))
 . S AMHDB=$$LVDT^AMHGU($P($G(^DPT(AMHPI,0)),U,3))
 . I $G(AMHFLAG),$G(AMHFLAG)'=4,$G(AMHFLAG)'=3 S AMHDB="**SENSITIVE**"
 . S AMHSX=$P($G(^DPT(AMHPI,0)),U,2)
 . S AMHCT=$$HRN^AUPNPAT(AMHPI,AMHDUZ2)
 . S AMHSSN=$P($G(^DPT(AMHPI,0)),U,9)
 . I AMHSSN]"" D
 .. N LN
 .. S LN=$L(AMHSSN)
 .. S AMHSSN="XXX-XX-"_$E(AMHSSN,(LN-3),LN)
 . I $G(AMHFLAG),$G(AMHFLAG)'=4,$G(AMHFLAG)'=3 S AMHSSN="**SENSITIVE**"
 . S AMHUPD=$P($G(^AUPNPAT(AMHPI,0)),U,3)  ;cmi/maw 5/17/2007 added last reg update
 . ;S AMHELG=$$GET1^DIQ(9000001,AMHPI,1111)  ;cmi/maw 5/17/2007 added class/ben for status bar
 . S AMHDOD=$S($P($G(^DPT(AMHPI,.35)),U):$$LVDT^AMHGU($P($G(^DPT(AMHPI,.35)),U)),1:"")
 . S AMHAGE=$$AGE^AUPNPAT(AMHPI,DT)
 . I $G(AMHFLAG) S AMHAGE="**SENSITIVE**"
 . I '$G(AMHFLAG),$$GET1^DIQ(43,1,9999999.01)="YES" S AMHFLAG=9  ;ihs/cmi/maw 12/6/2010 for track all patients spt
 . S AMHI=AMHI+1
 . S ^AMHTMP($J,AMHI)=AMHPI_U_AMHNM_U_AMHDB_U_AMHSX_U_AMHCT_U_AMHSSN_U_$G(AMHHD)_U_$G(AMHMORE)_U_AMHDOD_U_AMHAGE_U_$G(AMHFLAG)_U_$E(AMHDGMSG,1,2500)_$C(30)
 Q
 ;
PATSTR(RETVAL,AMHSTR) ;EP -- return the patient demographic information
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHERRR,AMHUIEN,P
 S P="|"
 K ^AMHTMP($J)
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 S AMHERRR=""
 S ^AMHTMP($J,AMHI)="T00010IEN^T00030PATIENTNAME^T00015DOB^T00001SEX^T00007CHART^T00009SSN^T00010REG^T00030MORE^T00030DOD^T00010AGE^T00001MESSAGEFLAG^T02500MESSAGE"_$C(30)
 S AMHPAT(1)=$P(AMHSTR,P,2)
 S AMHDUZ2=$P(AMHSTR,P)
 S AMHMT=9999999
 D PATADO(.AMHPAT)
 S ^AMHTMP($J,AMHI+1)=$C(31)
 Q
 ;
LOGPAT(RETVAL,AMHSTR) ;-- log sensitive patient information
 S X="MERR^AMHGU",@^%ZOSF("TRAP") ; m error trap
 N AMHI,AMHERRR,AMHPAT,P,AMHFLAG,AMHDGMSG,AMHDGDA,RESULT
 S P="|"
 K ^AMHTMP($J)
 S RETVAL="^AMHTMP("_$J_")"
 S AMHI=0
 S AMHPAT=$P(AMHSTR,P)
 D DGSEC(.RESULT,AMHPAT,DUZ,0)  ;cmi/maw 3/4/2010 logging takes place in NOTICE^DGSEC4
 I $G(RESULT(1))=4 S AMHFLAG=1
 I $G(RESULT(1))=3 S AMHFLAG=1
 I '$G(AMHFLAG),$G(RESULT(1))'=0 D NOTICE^DGSEC4(.RESULT,AMHPAT,"AMHGRPC^Behavioral Health GUI",3)
 I $G(RESULT(1))=0,$$GET1^DIQ(43,1,9999999.01)="YES" D  ;ihs/cmi/maw 12/6/2010 added for track all
 . D NOTICE^DGSEC4(.RESULT,AMHPAT,"AMHGRPC^Behavioral Health GUI",$S($P($G(^DGSL(38.1,AMHPAT,0)),U,2):3,1:1))
 S @RETVAL@(AMHI)="T00001Return"_$C(30)
 S AMHI=AMHI+1
 S @RETVAL@(AMHI)=$G(RESULT)_$C(30)
 S @RETVAL@(AMHI+1)=$C(31)
 Q
 ;
DGSEC(RESULT,DFN,DUZ,DGMSG) ;EP -- mock the dgsec call but dont log, couldnt find a way to call PTSEC^DGSEC4 without logging
 S DGMSG=$G(DGMSG,1)
 I $$STATUS^BDGSPT2(DUZ,DFN,1)["RESTRICTED ACCESS" D  Q
 .S RESULT(1)=5 Q:DGMSG'=1
 .S RESULT(2)="Sorry, you are restricted from accessing this patient's record."
 .S RESULT(3)="If you have questions, please contact your HIM department."
 D OWNREC^DGSEC4(.RESULT,DFN,$G(DUZ),DGMSG)
 I RESULT(1)=1 S RESULT(1)=3 Q
 I RESULT(1)=2 S RESULT(1)=4 Q
 K RESULT
 D SENS^DGSEC4(.RESULT,DFN,$G(DUZ))
 Q
 ;