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

BQIRGASP.m

Go to the documentation of this file.
BQIRGASP ;VNGT/HS/ALA-Asthma Patient ; 06 Mar 2009  3:58 PM
 ;;2.5;ICARE MANAGEMENT SYSTEM;**1,2**;May 24, 2016;Build 14
 ;
 ;
EN(DATA,DFN,SOURCE) ;EP - BQI REFRESH PATIENT CARE MGT
 ; Input
 ;   DFN    - Patient internal entry number
 ;   SOURCE - The Care Managment Source Type (full name e.g. Asthma)
 ;
 NEW UID,II,BQDFN,SRCN,SRC,RESULT
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S DATA=$NA(^TMP(UID,"BQIRGASP"))
 K @DATA
 ;
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIRMPAT D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 S @DATA@(II)="I00010RESULT^T00050MSG"_$C(30)
 S BQDFN=$G(DFN,""),SOURCE=$G(SOURCE,"")
 I BQDFN="" S RESULT=-1_U_"No patient selected" G DONE
 ;
 I SOURCE'="" D  G DONE
 . S SRCN=$O(^BQI(90506.5,"B",SOURCE,"")) I SRCN="" S RESULT=-1_U_SOURCE_" not found" Q
 . S SRC=$P(^BQI(90506.5,SRCN,0),U,2)
 . D PAT(BQDFN,SRC)
 . S RESULT=1_U
 ;
 I SOURCE="" D  G DONE
 . K ^BQIPAT(DFN,60)
 . ; If flag is set for nightly/weekly
 . S SRIEN=""
 . F  S SRIEN=$O(^BQI(90506.5,"AD",1,SRIEN)) Q:SRIEN=""  D
 .. I $P($G(^BQI(90506.5,SRIEN,0)),"^",10)=1 Q
 .. ;I $P($G(^BQI(90506.5,SRIEN,0)),"^",16)'=1 Q
 .. S SOURCE=$P($G(^BQI(90506.5,SRIEN,0)),"^",1)
 .. S SRC=$P($G(^BQI(90506.5,SRIEN,0)),U,2)
 .. D PAT(BQDFN,SRC)
 .. S RESULT=1_U
 ;
DONE ;
 S II=II+1,@DATA@(II)=RESULT_$C(30)
 S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
PAT(BQDFN,SRC) ;EP - Get all Care Mgmt data for a patient
 ;
 NEW DA,IENS,DIC,PSRIEN,SRIEN,CDRIEN,X,Y,CODE,DLAYGO,DIC,HDR,IEN,ORD,V
 NEW BQIUPD,VALUE,VISIT,OTHER,STVW,VAL,VSDTM,CT,ASN,%ANS,APCHSBWR,R,T,W
 NEW APCHSDAT,APCHSTEX,APCHSTXN,LPAP,%1,%ANS,%DT,%X,%Y,AIEN,AMQQTAXN,LT,M
 NEW APCHC,APCHCPT,APCHLAST,APCHRF,BD,C,D,D0,DAT1,DAT2,DATE,E,ED,G,H,J
 S SRIEN=$O(^BQI(90506.5,"C",SRC,"")) I SRIEN="" Q
 ; Check for bad records
 I $O(^BQIPAT(BQDFN,60,"B",SRIEN,""))="" D
 . S ASN=0
 . F  S ASN=$O(^BQIPAT(BQDFN,60,ASN)) Q:'ASN  D
 .. I $G(^BQIPAT(BQDFN,60,ASN,0))'="",$P($G(^BQIPAT(BQDFN,60,ASN,0)),U,1)'=SRIEN Q
 .. I $G(^BQIPAT(BQDFN,60,ASN,0))'="",$P($G(^BQIPAT(BQDFN,60,ASN,0)),U,1)=SRIEN Q
 .. K ^BQIPAT(BQDFN,60,ASN)
 ;
 S DA(1)=BQDFN,X=$P(^BQI(90506.5,SRIEN,0),U,1),DIC(0)="L",DLAYGO=90507.56
 S DIC="^BQIPAT("_DA(1)_",60,"
 I $G(^BQIPAT(BQDFN,60,0))="" S ^BQIPAT(BQDFN,60,0)="^90507.56P^^"
 D ^DIC
 S (PSRIEN,DA)=+Y
 S IENS=$$IENS^DILF(.DA)
 S BQIUPD(90507.56,IENS,.02)=$$NOW^XLFDT()
 ;
 I $G(SRC)="DM" D
 . S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J),BDMJOB=UID,BDMBTH=$H
 . S CYR=$P($G(^BQI(90508,1,"DM")),U,1),BDMDMRG=$P($G(^BQI(90508,1,"DM")),"^",2)
 . S CIEN=$O(^BQI(90508,1,21,"B",CYR,"")) I CIEN="" Q
 . S PGTHR=$P(^BQI(90508,1,21,CIEN,0),U,2),PGRF=$P(^(0),U,4)
 . K ^XTMP(PGRF,BDMJOB) S ^XTMP(PGRF,0)=$$FMADD^XLFDT(DT,1)_"^"_DT_"^iCare DM AUDIT"
 . S BDMRBD=DT,BDMADAT=DT,BDMTYPE="P",BDMRED=$$FMADD^XLFDT(BDMADAT,-365)
 . S BDMBDAT=$$FMADD^XLFDT(BDMADAT,-365),BDMPD=DFN
 . D @("GATHER^"_PGTHR)
 ;
 ; Check for Alternate display order first
 S ORD=""
 F  S ORD=$O(^BQI(90506.1,"AF",SRC,ORD)) Q:ORD=""  D
 . S AIEN=""
 . F  S AIEN=$O(^BQI(90506.1,"AF",SRC,ORD,AIEN)) Q:AIEN=""  D UPD(AIEN)
 ;
 ; Check for normal display order
 S ORD=""
 F  S ORD=$O(^BQI(90506.1,"AD",SRC,ORD)) Q:ORD=""  D
 . S AIEN=""
 . F  S AIEN=$O(^BQI(90506.1,"AD",SRC,ORD,AIEN)) Q:AIEN=""  D UPD(AIEN)
 ;
 ; Check for site-populated fields
 S AIEN=0 F  S AIEN=$O(^BQI(90506.5,SRIEN,10,AIEN)) Q:'AIEN  D
 . S EXEC=$G(^BQI(90506.5,SRIEN,10,AIEN,3)) I EXEC="" Q
 . X EXEC
 . S CODE=$P(^BQI(90506.5,SRIEN,10,AIEN,0),"^",1)
 . D FILD
 Q
 ;
UPD(AIEN) ; EP - Update values
 ;I $$GET1^DIQ(90506.1,AIEN_",",.1,"I")=1 Q
 I $P($G(^BQI(90506.1,AIEN,0)),"^",10)=1 Q
 S STVW=AIEN,VAL="",VISIT="",OTHER=""
 D CVAL(BQDFN)
 S CODE=$P($G(^BQI(90506.1,AIEN,0)),U,1) I CODE="" Q
 I VAL'="" D
 . I CODE="DM_TOBUSE" S VAL=$P(VAL,U,2)
 . I CODE="DM_A1C" S VAL=$P(VAL,U,2)_" ("_$$FMTMDY^BQIUL1($P(VAL,U,1))_")"
 . I CODE="DM_CREAT"!(CODE="DM_TCHOL")!(CODE="DM_HDL")!(CODE="DM_LDL")!(CODE="DM_TRIG") S VAL=$P(VAL,U,1)_"("_$P(VAL,U,2)_")"
 . I CODE="DM_EGFR"!(CODE="DM_UACR") S VAL=$P(VAL,U,2)_" ("_$P(VAL,U,3)_")"
 . I CODE="DM_TBTEST" S VAL=$P(VAL,"|",1)
 . I CODE="DM_TBRES" S VAL=$P(VAL,"|",3)
 ;
 I VAL="",CODE="DM_DMTYP" D
 . D CURR
 . D @("TYPEDM^"_PGTHR) I BDMTYDM'="" S VAL=BDMTYDM
 D FILD
 Q
 ;
FILD ;EP - File the data
 S DA(2)=BQDFN,DA(1)=PSRIEN,X=CODE,DIC(0)="L",DLAYGO=90507.561
 S DIC="^BQIPAT("_DA(2)_",60,"_DA(1)_",1,"
 I $G(^BQIPAT(BQDFN,60,PSRIEN,1,0))="" S ^BQIPAT(BQDFN,60,PSRIEN,1,0)="^90507.561^^"
 D ^DIC I +Y=-1 K DD,DO D FILE^DICN
 S (CDRIEN,DA)=+Y
 S IENS=$$IENS^DILF(.DA)
 S BQIUPD(90507.561,IENS,.02)=$G(VAL)
 S BQIUPD(90507.561,IENS,.03)=$G(DATE)
 S BQIUPD(90507.561,IENS,.04)=$G(VISIT)
 S BQIUPD(90507.561,IENS,.05)=$G(OTHER)
 K VAL,OTHER,DATE,VISIT
 I $D(BQIUPD)>0 D FILE^DIE("","BQIUPD","ERROR")
 Q
 ;
CVAL(DFN) ; Get demographic values
 ;Parameters
 ;  FIL  = FileMan file number
 ;  FLD  = FileMan field number
 ;  EXEC = If an executable is needed to determine value
 ;  HDR  = Header value
 ;the executable expects the value to be returned in variable VAL
 NEW FIL,FLD,EXEC,RCODE,RGIEN,RIEN,RHDR,MVALUE,CODE
 S FIL=$P($G(^BQI(90506.1,STVW,0)),"^",5)
 S FLD=$P($G(^BQI(90506.1,STVW,0)),"^",6)
 S EXEC=$G(^BQI(90506.1,STVW,5))
 S HDR=$P($G(^BQI(90506.1,STVW,0)),"^",8)
 I $G(DFN)="" S VAL="" Q
 ;
 I $G(EXEC)'="" X EXEC Q
 ;
 I FIL'="",FLD'="" S VAL=$$GET1^DIQ(FIL,DFN_",",FLD,"E")
 Q
 ;
 S RCODE=$$GET1^DIQ(90506.1,STVW_",",.01,"E")
 S RGIEN=$O(^BQI(90506.3,"AC",CRIEN,"")),VAL=""
 I RGIEN'="" D  Q:VAL'=""
 . S RIEN=$O(^BQI(90506.3,RGIEN,10,"AC",RCODE,""))
 . I RIEN'="",$P($G(^BQI(90506.3,RGIEN,10,RIEN,1)),U,1)="M" D  Q
 .. S RHDR=$P(^BQI(90506.3,RGIEN,10,RIEN,0),U,2),MVALUE=""
 .. NEW SNAME,SRIEN,SORD,SXREF,SIEN
 .. S SNAME=$P(^BQI(90506.3,RGIEN,10,RIEN,0),U,1)
 .. S SRIEN=$O(^BQI(90506.3,"B",SNAME,"")) I SRIEN="" Q
 .. S SORD="",SXREF=$S($D(^BQI(90506.3,SRIEN,10,"AF")):"AF",1:"C")
 .. F  S SORD=$O(^BQI(90506.3,SRIEN,10,SXREF,SORD)) Q:SORD=""  D
 ... S SIEN=""
 ... F  S SIEN=$O(^BQI(90506.3,SRIEN,10,SXREF,SORD,SIEN)) Q:SIEN=""  D
 .... I $P(^BQI(90506.3,SRIEN,10,SIEN,0),U,4)'="S" Q
 .... S CODE=$P(^BQI(90506.3,SRIEN,10,SIEN,0),U,7) I CODE="" Q
 .... S STVW=$O(^BQI(90506.1,"B",CODE,"")) I STVW="" Q
 .... I $P($G(^BQI(90506.1,STVW,0)),"^",10)=1 Q
 .... NEW FIL,FLD,EXEC
 .... S FIL=$P($G(^BQI(90506.1,STVW,0)),"^",5)
 .... S FLD=$P($G(^BQI(90506.1,STVW,0)),"^",6)
 .... S EXEC=$G(^BQI(90506.1,STVW,1))
 .... S HDR=RHDR
 .... I $G(DFN)="" S VAL="" Q
 .... ;
 .... I $G(EXEC)'="" X EXEC S VAL=VAL_$S(VAL'="":$C(10),1:"") Q
 .... I FIL'="",FLD'="" S VAL=$$GET1^DIQ(FIL,DFN_",",FLD,"E")
 .... S VALUE=VALUE_VAL_$S(VAL'="":$C(10),1:"")
 .... S VAL=VALUE
 ... S MVALUE=MVALUE_$$TKO^BQIUL1(VAL,$C(10))
 .. S VAL=MVALUE
 Q
 ;
CURR ;EP - Get current DM Audit information
 S CYR=$P($G(^BQI(90508,1,"DM")),U,1)
 S CIEN=$O(^BQI(90508,1,21,"B",CYR,"")) I CIEN="" Q
 S PGTHR=$P(^BQI(90508,1,21,CIEN,0),U,2),PGRF=$P(^(0),U,4)
 Q