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

BGPGP.m

Go to the documentation of this file.
BGPGP ; IHS/CMI/MAW - BGPG Patient Lookup 4/28/2009 12:43:21 PM ;
 ;;13.0;IHS CLINICAL REPORTING;;NOV 20, 2012;Build 81
 ;;
 ;
 ;
 ;
 Q
GETPAT(RETVAL,BGPSTR) ;EP -- return patient in ADO table
 S X="MERR^BGPGU",@^%ZOSF("TRAP") ; m error trap
 N BGPI,BGPERRR,BGPUIEN,P
 S P="|"
 K ^BGPTMP($J)
 S RETVAL="^BGPTMP("_$J_")"
 S BGPI=0
 S BGPERRR=""
 S ^BGPTMP($J,BGPI)="T00010IEN^T00030PATIENTNAME^T00015DOB^T00001SEX^T00007CHART^T00009SSN^T00010REG^T00030MORE^T00030DOD^T00010AGE^T00001MESSAGEFLAG^T02500MESSAGE"_$C(30)
 S BGPDUZ2=$P(BGPSTR,P)
 S BGPPAT=$P(BGPSTR,P,2)
 S BGPMT=$P(BGPSTR,P,3)
 I BGPMT="" S BGPMT=99999
 S BGPNPAT=$P(BGPSTR,P,4)
 I '$G(BGPDUZ2) S BGPDUZ2=DUZ(2)
 ;I BGPNPAT]"" S BGPPAT=BGPNPAT  ;cmi/maw 3/12/09 for testing
 I BGPMT="ALL" S BGPMT=9999999
 S BGPMT=(BGPMT-1)
 I BGPPAT?9N D
 . S BGPPIEN=$$PATSSN(BGPPAT)
 I BGPPAT?1.6N D
 . S BGPPIEN=$$PATCHT(.BGPPIEN,BGPPAT)
 I BGPPAT?1.2N1"/"1.2N1"/"4N D
 . S X=BGPPAT D ^%DT S BGPPAT=Y
 . S BGPPIEN=$$PATDOB(.BGPPIEN,BGPPAT)
 I '$G(BGPPIEN) D PATNAM(.BGPPIEN,BGPPAT,BGPNPAT)
 I $G(BGPPIEN),'$G(BGPPATS) D PATADO(.BGPPIEN)
 S ^BGPTMP($J,BGPI+1)=$C(31)
 K BGPPAT,BGPPIEN,BGPCNT,BGPDA,BGPIEN,BGPPATE,BGPNM,BGPDB,BGPSX,BGPCT,BGPSSN,BGPDOD,BGPMORE,BGPAGE,BGPCNTR,BGPDG,BGPDUZ2,BGPMT,BGPNAM
 K BGPPATS,BGPNPAT,BGPPI,BGPUPD
 Q
 ;
PATSSN(PAT) ;EP -- look up by ssn
 S BGPPIEN=$O(^DPT("SSN",PAT,0))
 S BGPPIEN(1)=BGPPIEN
 Q $G(BGPPIEN)
 ;
PATCHT(BGPPIEN,PAT) ;EP -- lookup by chart
 ;ihs/cmi/maw 2/2/2011 added fix for same patient with same chart in multiple divisions
 N BGPCNT,BGPOEN
 S BGPCNT=0,BGPPATE=0,BGPMCNT=0
 S BGPDA=(PAT-1) F  S BGPDA=$O(^AUPNPAT("D",BGPDA)) Q:'BGPDA!(BGPDA>PAT)!(BGPCNT>BGPMT)  D
 . S BGPIEN=0 F  S BGPIEN=$O(^AUPNPAT("D",BGPDA,BGPIEN)) Q:'BGPIEN  D
 .. S BGPOEN=0 F  S BGPOEN=$O(^AUPNPAT("D",BGPDA,BGPIEN,BGPOEN)) Q:'BGPOEN!($G(BGPPIEN))  D
 ... ;I $O(^AUPNPAT("D",BGPDA,BGPIEN,0))=BGPDUZ2 S BGPPIEN=BGPIEN
 ... I BGPOEN=BGPDUZ2 S BGPPIEN=BGPIEN
 ... Q:'$G(BGPPIEN)
 ... S BGPCNT=BGPCNT+1
 ... S:'$D(BGPPIEN(BGPCNT)) BGPPIEN(BGPCNT)=0
 ... S BGPPIEN(BGPCNT)=BGPPIEN
 Q $G(BGPPIEN)
 ;
PATDOB(BGPPATE,PAT) ;EP -- lookup by DOB
 N BGPCNT
 S BGPCNT=0,BGPPATE=0
 S BGPDOB=PAT-1 F  S BGPDOB=$O(^DPT("ADOB",BGPDOB)) Q:'BGPDOB!(BGPDOB'=+PAT)!(BGPCNT>BGPMT)  D
 . S BGPIEN=0 F  S BGPIEN=$O(^DPT("ADOB",BGPDOB,BGPIEN)) Q:'BGPIEN  D
 .. S:'$D(BGPPATE(BGPCNT)) BGPPATE(BGPCNT)=0
 .. S BGPCNT=BGPCNT+1,BGPPATE=1
 .. S BGPPATE(BGPCNT)=BGPIEN
 S BGPPATE=BGPCNT
 Q $G(BGPPATE)
 ;
PATNAM(BGPPATE,PAT,NPAT) ;lookup by name
 S BGPCNT=0,BGPPATE=0
 N BGPLEN
 S BGPLEN=$L(PAT)
 S BGPNAM=PAT
 S BGPNAM=$$BEGIN(PAT)
 I $G(NPAT)]"" S BGPNAM=NPAT
 F  S BGPNAM=$O(^DPT("B",BGPNAM)) Q:BGPNAM=""!($E(BGPNAM,1,BGPLEN)'=PAT)  D
 . S BGPIEN=0 F  S BGPIEN=$O(^DPT("B",BGPNAM,BGPIEN)) Q:'BGPIEN  D
 .. N BGPOEN
 .. I $O(^DPT("B",BGPNAM,BGPIEN,0)) D
 ... S BGPOEN=0 F  S BGPOEN=$O(^DPT("B",BGPNAM,BGPIEN,BGPOEN)) Q:'BGPOEN  D
 .... ;Q:$O(^DPT("B",BGPNAM,BGPIEN,0))  ;cmi/maw 4/25/2005 don't get aliases
 .... S BGPCNT=BGPCNT+1
 .... S:'$D(BGPPATE(BGPCNT)) BGPPATE(BGPCNT)=0
 .... S BGPPATE(BGPCNT)=BGPIEN_U_BGPNAM
 .. I '$O(^DPT("B",BGPNAM,BGPIEN,0)) D
 ... S BGPCNT=BGPCNT+1
 ... S:'$D(BGPPATE(BGPCNT)) BGPPATE(BGPCNT)=0
 ... S BGPPATE(BGPCNT)=BGPIEN
 S BGPPATE=BGPCNT
 Q $G(BGPPATE)
 ;
BEGIN(PT) ;EP -- get begin point
 N BGPPDA,BGPPIEN,BGPPCNT
 S BGPPCNT=0
 S BGPPDA=PT
 I $O(^DPT("B",BGPPDA,0)) D
 . S BGPPDA=$O(^DPT("B",BGPPDA),-1)
 F  S BGPPDA=$O(^DPT("B",BGPPDA)) Q
 I $G(BGPPDA)="" Q ""
 Q $O(^DPT("B",BGPPDA),-1)
 ;
PATADO(PIEN) ;EP -- ado return
 S BGPCNTR=0
 S BGPDA=0 F  S BGPDA=$O(PIEN(BGPDA)) Q:'BGPDA  D
 . S BGPPI=$P($G(PIEN(BGPDA)),U)
 . S BGPAL=$P($G(PIEN(BGPDA)),U,2)
 . ;D PTSEC^DGSEC4(.BGPDG,BGPPI,0)  ;logs patient, cant do here
 . D DGSEC(.BGPDG,BGPPI,DUZ,0)  ;don't log patient but get sensitivity info for patient lookup
 . N BGPDGMSG,BGPFLAG
 . I $G(BGPDG(1)) D
 .. S BGPFLAG=BGPDG(1)
 .. N BGPDGDA
 .. S BGPDGMSG=""
 .. S BGPDGDA=1 F  S BGPDGDA=$O(BGPDG(BGPDGDA)) Q:'BGPDGDA  D
 ... I $E(BGPDG(BGPDGDA),1,3)="* *" Q
 ... S BGPDGMSG=BGPDGMSG_" "_$G(BGPDG(BGPDGDA))
 . S BGPDGMSG=$TR($G(BGPDGMSG),"*")
 . I BGPCNTR>BGPMT Q
 . S BGPCNTR=BGPCNTR+1
 . S BGPNM=$S(BGPAL]"":BGPAL_"  ",1:"")_$P($G(^DPT(BGPPI,0)),U)
 . ;S BGPDB=$$FMTE^XLFDT($P($G(^DPT(BGPPI,0)),U,3))
 . S BGPDB=$$LVDT($P($G(^DPT(BGPPI,0)),U,3))
 . I $G(BGPFLAG),$G(BGPFLAG)'=4,$G(BGPFLAG)'=3 S BGPDB="**SENSITIVE**"
 . S BGPSX=$P($G(^DPT(BGPPI,0)),U,2)
 . S BGPCT=$$HRN^AUPNPAT(BGPPI,BGPDUZ2)
 . S BGPSSN=$P($G(^DPT(BGPPI,0)),U,9)
 . I BGPSSN]"" D
 .. N LN
 .. S LN=$L(BGPSSN)
 .. S BGPSSN="XXX-XX-"_$E(BGPSSN,(LN-3),LN)
 . I $G(BGPFLAG),$G(BGPFLAG)'=4,$G(BGPFLAG)'=3 S BGPSSN="**SENSITIVE**"
 . S BGPUPD=$P($G(^AUPNPAT(BGPPI,0)),U,3)  ;cmi/maw 5/17/2007 added last reg update
 . ;S BGPELG=$$GET1^DIQ(9000001,BGPPI,1111)  ;cmi/maw 5/17/2007 added class/ben for status bar
 . S BGPDOD=$S($P($G(^DPT(BGPPI,.35)),U):$$LVDT($P($G(^DPT(BGPPI,.35)),U)),1:"")
 . S BGPAGE=$$AGE^AUPNPAT(BGPPI,DT)
 . I $G(BGPFLAG) S BGPAGE="**SENSITIVE**"
 . I '$G(BGPFLAG),$$GET1^DIQ(43,1,9999999.01)="YES" S BGPFLAG=9  ;ihs/cmi/maw 12/6/2010 for track all patients spt
 . S BGPI=BGPI+1
 . S ^BGPTMP($J,BGPI)=BGPPI_U_BGPNM_U_BGPDB_U_BGPSX_U_BGPCT_U_BGPSSN_U_$G(BGPHD)_U_$G(BGPMORE)_U_BGPDOD_U_BGPAGE_U_$G(BGPFLAG)_U_$E(BGPDGMSG,1,2500)_$C(30)
 Q
 ;
PATSTR(RETVAL,BGPSTR) ;EP -- return the patient demographic information
 S X="MERR^BGPGU",@^%ZOSF("TRAP") ; m error trap
 N BGPI,BGPERRR,BGPUIEN,P
 S P="|"
 K ^BGPTMP($J)
 S RETVAL="^BGPTMP("_$J_")"
 S BGPI=0
 S BGPERRR=""
 S ^BGPTMP($J,BGPI)="T00010IEN^T00030PATIENTNAME^T00015DOB^T00001SEX^T00007CHART^T00009SSN^T00010REG^T00030MORE^T00030DOD^T00010AGE^T00001MESSAGEFLAG^T02500MESSAGE"_$C(30)
 S BGPPAT(1)=$P(BGPSTR,P,2)
 S BGPDUZ2=$P(BGPSTR,P)
 S BGPMT=9999999
 D PATADO(.BGPPAT)
 S ^BGPTMP($J,BGPI+1)=$C(31)
 Q
 ;
LOGPAT(RETVAL,BGPSTR) ;-- log sensitive patient information
 S X="MERR^BGPGU",@^%ZOSF("TRAP") ; m error trap
 N BGPI,BGPERRR,BGPPAT,P,BGPFLAG,BGPDGMSG,BGPDGDA,RESULT
 S P="|"
 K ^BGPTMP($J)
 S RETVAL="^BGPTMP("_$J_")"
 S BGPI=0
 S BGPPAT=$P(BGPSTR,P)
 D DGSEC(.RESULT,BGPPAT,DUZ,0)  ;cmi/maw 3/4/2010 logging takes place in NOTICE^DGSEC4
 I $G(RESULT(1))=4 S BGPFLAG=1
 I $G(RESULT(1))=3 S BGPFLAG=1
 I '$G(BGPFLAG),$G(RESULT(1))'=0 D NOTICE^DGSEC4(.RESULT,BGPPAT,"BGPGRPC^CRS 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,BGPPAT,"BGPGRPC^CRS GUI",$S($P($G(^DGSL(38.1,BGPPAT,0)),U,2):3,1:1))
 S @RETVAL@(BGPI)="T00001Return"_$C(30)
 S BGPI=BGPI+1
 S @RETVAL@(BGPI)=$G(RESULT)_$C(30)
 S @RETVAL@(BGPI+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
 ;
LVDT(PDT) ;EP - return date for list view format
 I PDT="" Q ""
 Q $E(PDT,4,5)_"/"_$E(PDT,6,7)_"/"_($E(PDT,1,3)+1700)
 ;