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

BKMQQCR.m

Go to the documentation of this file.
BKMQQCR ;VNGT/HS/ALA - BKMV Quality of Care Report
 ;;2.1;HIV MANAGEMENT SYSTEM;**1**;FEB 7, 2011;Build 30
 Q
 ; Check taxonomies - added per bugzilla #1497
 ;D FLTRMSG^BKMIMRP1 ; will be replaced by RPC call to BQITAXX
 ;
RUN(DATA,BKMRPOP,EDATE,OWNR,PLIEN,BKMTAG,DFN,GUI) ; EP - Run Quality of Care Report
 ;
 ; Input:
 ;    DFN - Either set to a single Patient Internal ID or
 ;          in an array in the following format:
 ;                 DFN(IX)=DFN_$C(28)
 ;    GUI   - Running from GUI is 0, running from RPMS is 1       
 ;    EDATE - Ending date for report
 ;    OWNR  - Owner Internal Entry Number if running report by panel
 ;    PLIEN - Panel Internal Entry Number if running report by panel
 ;    BKMRPOP - Report Population:
 ;            - R = Active on HMS Register
 ;            - D = Active HIV/AIDS Diagnostic Tag
 ;            - P = By selected patients
 ;    BKMTAG  - If BKMRPOP is by Diagnostic Tag, identifies the status:
 ;            - Proposed
 ;            - Accepted
 ;            - Proposed or Accepted
 ;
 N BQII,GLOB,HMSIEN,LIST,II,PT,CNT,DENPOP,NDA
 ;
 S BQII=0
 ;
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BKMQQCR D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 NEW BN,PLNM,LIST,UID,PER1,PERSIX,AMH,BDT,BEGDATE,BKMCCPT,BKMCD4,BKMDFN,BKMIEN,BKMPATN
 NEW BKMREG,BKMVCPT,BKMVIR,CCPT,CD4,COLDTM,CPT,CPTTAXX,CPTTAXX1,CPTTAXX2,DATE,EDT,ENDATE
 NEW GLOBAL3,HEND,HP1B,HP1E,HP2B,HP2E,HP3B,HP3E,HP61B,HP61E,HP62B,HP62E,HREV,HSDTM,ICDTAX1,IEN
 NEW NUMB,P1B,P1E,P2B,P2E,P3B,P3E,P61B,P61E,P62B,P62E,PDATA,PRCTAX,PTOTAL,QFL,REG,REGIEN,RESULT
 NEW REVPER,SITETAX,STAT,TAX,TIEN,TOTPTS,TREF,TXN,TYP,VCPT,VDATA,VSDTM,VIRAL,VISTOT,VSTDT,Y
 NEW VISIT,RGST,TAGST
 S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S GLOB=$NA(^TMP("BKMQQCRA",UID))
 K @GLOB
 S HMSIEN=$O(^BQI(90506.2,"B","HIV/AIDS",""))
 I HMSIEN="" S BMXSEC="HMS Register missing from file definition." Q
 S EDATE=$$DATE^BQIUL1($G(EDATE))
 S REVPER=$$FMADD^XLFDT(EDATE,-365),PER1=$$FMADD^XLFDT(EDATE,-121)
 S PERSIX=$$FMADD^XLFDT(EDATE,-183)
 I EDATE'[".24" S EDATE=EDATE_".24" ; Report should include info through midnight on the end date.
 S DFN=$G(DFN,""),OWNR=$G(OWNR),PLIEN=$G(PLIEN),PLNM="",GUI=$G(GUI,0)
 ;
 I OWNR="",PLIEN="",GUI D
 . I BKMRPOP="P" Q
 . I BKMRPOP="D" S RIEN="" D
 .. F  S RIEN=$O(^BQIREG("B",3,RIEN)) Q:RIEN=""  D
 ... S TAGST=$P(^BQIREG(RIEN,0),U,3),PT=$P(^BQIREG(RIEN,0),U,2)
 ... I BKMTAG="B",TAGST="A"!(TAGST="P") S @GLOB@("HIVCHK",PT)="" Q
 ... I TAGST=BKMTAG S @GLOB@("HIVCHK",PT)=""
 . I BKMRPOP="R" D
 .. S RIEN=0
 .. F  S RIEN=$O(^BKM(90451,RIEN)) Q:'RIEN  D
 ... S RGST=$P($G(^BKM(90451,RIEN,1,1,0)),U,7),PT=$P(^BKM(90451,RIEN,0),U,1)
 ... I RGST="A" S @GLOB@("HIVCHK",PT)=""
 ;
 I OWNR'="",PLIEN'="" D
 . N IENS,DA
 . S DA(1)=OWNR,DA=PLIEN,IENS=$$IENS^DILF(.DA)
 . S PLNM=$$GET1^DIQ(90505.01,IENS,.01,"I")
 . I BKMRPOP="P" Q
 . S PT=0
 . F  S PT=$O(^BQICARE(OWNR,1,PLIEN,40,PT)) Q:'PT  S @GLOB@("HIVCHK",PT)=""
 ;
 I BKMRPOP="P" D
 . I GUI D  Q
 .. S PT="" F  S PT=$O(DFN(PT)) Q:PT=""  S @GLOB@("HIVCHK",PT)=""
 . S LIST=DFN
 . I DFN="" D
 .. S LIST="",BN=""
 .. F  S BN=$O(DFN(BN)) Q:BN=""  S LIST=LIST_DFN(BN)
 .. K DFN
 . F II=1:1 S PT=$P(LIST,$C(28),II) Q:PT=""  S @GLOB@("HIVCHK",PT)=""
 ;
 S DENPOP=$S(BKMRPOP="R":"Active HMS Register Patients",BKMRPOP="P":"User Selected",1:"HIV/AIDS Diagnostic Tag: "_$S(BKMTAG="A":"Accepted",BKMTAG="P":"Proposed",1:"Proposed and Accepted"))
 D ACTWRK^BKMQQCRU
 I '$D(@GLOB@("HIVCHK")) S BMXSEC="RPC Call Failed: This report cannot be run. None of the patients selected for this report meet the criteria."
 G XIT:$G(BMXSEC)'=""
 ;
 S BKMDFN=0
 F CNT=0:1 S BKMDFN=$O(@GLOB@("HIVCHK",BKMDFN)) I 'BKMDFN Q
 S @GLOB@("HIVTOT1")=CNT
 ; compile totals by Gender and Age
 D GENDER,AGE
 NEW DA,DLAYGO,DIC,X,LOGN,BKMUPD
 I $G(^BKM(90450,1,60,0))="" S ^BKM(90450,1,60,0)="^90450.11D^^"
 S DA(1)=1,DLAYGO=90450.11,DIC="^BKM(90450,"_DA(1)_",60,",DIC(0)="L"
 S X=$$NOW^XLFDT() K DO,DD D FILE^DICN S LOGN=+Y
 ; run CD4, Viral load, rapid plasma reagin algorithms
 S BKMUPD(90450.11,LOGN_",1,",.02)=$$NOW^XLFDT()
 D CD4CHK^BKMQQCR1
 S BKMUPD(90450.11,LOGN_",1,",.03)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.04)=$$NOW^XLFDT()
 D VRLLD^BKMQQCR1
 S BKMUPD(90450.11,LOGN_",1,",.05)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.06)=$$NOW^XLFDT()
 D RPR^BKMQQCR1
 S BKMUPD(90450.11,LOGN_",1,",.07)=$$NOW^XLFDT()
 ; run chlamydia, gonorrhea, tuberculosis, and pneumo algorithms
 S BKMUPD(90450.11,LOGN_",1,",.08)=$$NOW^XLFDT()
 D CHLAM^BKMQQCR2
 S BKMUPD(90450.11,LOGN_",1,",.09)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1)=$$NOW^XLFDT()
 D GON^BKMQQCR2
 S BKMUPD(90450.11,LOGN_",1,",.11)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.12)=$$NOW^XLFDT()
 D TBT21^BKMQQCR2
 S BKMUPD(90450.11,LOGN_",1,",.13)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.14)=$$NOW^XLFDT()
 D PNEUMO^BKMQQCR2
 S BKMUPD(90450.11,LOGN_",1,",.15)=$$NOW^XLFDT()
 ; run tetanus, eye, dental, and pap algorithms
 S BKMUPD(90450.11,LOGN_",1,",.16)=$$NOW^XLFDT()
 D TETSTAT^BKMQQCR3
 S BKMUPD(90450.11,LOGN_",1,",.17)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.18)=$$NOW^XLFDT()
 D EYEEXAM^BKMQQCR3
 S BKMUPD(90450.11,LOGN_",1,",.19)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.2)=$$NOW^XLFDT()
 D DENTEXAM^BKMQQCR3
 S BKMUPD(90450.11,LOGN_",1,",.21)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.22)=$$NOW^XLFDT()
 D PAP^BKMQQCR3
 S BKMUPD(90450.11,LOGN_",1,",.23)=$$NOW^XLFDT()
 ; run ARV and MAC algorithms
 S BKMUPD(90450.11,LOGN_",1,",.24)=$$NOW^XLFDT()
 D ARVM03^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.25)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.26)=$$NOW^XLFDT()
 D ARVM02^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.27)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.28)=$$NOW^XLFDT()
 D ARVM05^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.29)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.101)=$$NOW^XLFDT()
 D ARVM09^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.102)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.103)=$$NOW^XLFDT()
 D ARVM10^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.104)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.105)=$$NOW^XLFDT()
 D ARVM11^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.106)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.107)=$$NOW^XLFDT()
 D ARVM12^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.108)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.109)=$$NOW^XLFDT()
 D ARVM13^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.1011)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1012)=$$NOW^XLFDT()
 D PCP^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.1013)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1014)=$$NOW^XLFDT()
 D MAC^BKMQQCR4
 S BKMUPD(90450.11,LOGN_",1,",.1015)=$$NOW^XLFDT()
 ; run tobacco, substance abuse algorithms
 S BKMUPD(90450.11,LOGN_",1,",.1016)=$$NOW^XLFDT()
 D TOBACCO^BKMQQCR5
 S BKMUPD(90450.11,LOGN_",1,",.1017)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1018)=$$NOW^XLFDT()
 D SUBS01^BKMQQCR5
 S BKMUPD(90450.11,LOGN_",1,",.1019)=$$NOW^XLFDT()
 ; run Lipids,HEP C Screen and CRC
 S BKMUPD(90450.11,LOGN_",1,",.1021)=$$NOW^XLFDT()
 D LIPIDS^BKMQQCR2
 S BKMUPD(90450.11,LOGN_",1,",.1022)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1023)=$$NOW^XLFDT()
 D HEPC^BKMQQCR1
 S BKMUPD(90450.11,LOGN_",1,",.1024)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1025)=$$NOW^XLFDT()
 D CRC^BKMQQCR1
 S BKMUPD(90450.11,LOGN_",1,",.1026)=$$NOW^XLFDT()
 ;
 ; New updates for HIVQual
 S BKMUPD(90450.11,LOGN_",1,",.1027)=$$NOW^XLFDT()
 D ^BKMQQCRB
 S BKMUPD(90450.11,LOGN_",1,",.1028)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1029)=$$NOW^XLFDT()
 D ^BKMQQCRC
 S BKMUPD(90450.11,LOGN_",1,",.1031)=$$NOW^XLFDT()
 S BKMUPD(90450.11,LOGN_",1,",.1032)=$$NOW^XLFDT()
 D ^BKMQQCRD
 S BKMUPD(90450.11,LOGN_",1,",.1033)=$$NOW^XLFDT()
 ;K ^ARLIS1 M ^ARLIS1=^TMP("BKMQQCRA",UID)
EN2 ; do mathematical calculations
 D CD4CALC^BKMQQCR6,VRLLDC^BKMQQCR6,RPRCALC^BKMQQCR6
 D CHLAMC^BKMQQCR7,GONCALC^BKMQQCR7,TBCALC^BKMQQCR7
 D PNEUMOC^BKMQQCR8,TETCALC^BKMQQCR8,EYECALC^BKMQQCR8,DENTCALC^BKMQQCR8,PAPCALC^BKMQQCR8
 D ARVCALC^BKMQQCR9,PCP^BKMQQCR9,MAC^BKMQQCR9,TOBCALC^BKMQQCR9,SUBCALC^BKMQQCR9
 D LIPCALC^BKMQQCR8,HEPCCALC^BKMQQCR8,CRCCALC^BKMQQCR8
 D VISCALC^BKMQQCR9,LABCALC^BKMQQCR9,MHCHK^BKMQQCR9,EDCHK^BKMQQCR9
 D APHCALC^BKMQQCR9
 ;
EN3 ; print the report
 D PRINT^BKMQQCRA
 I 'GUI D CLEAN,XIT
 D FILE^DIE("","BKMUPD","ERROR")
 Q
 ;
GENDER ; gender totals compilation
 N DFN,TOTM,TOTF,TOTU,SEX
 S (DFN,TOTM,TOTF,TOTU)=0
 F  S DFN=$O(@GLOB@("HIVCHK",DFN)) Q:'DFN  D
 .S SEX=$$GET1^DIQ(2,DFN_",",".02","I")
 .I SEX="F" S TOTF=TOTF+1 Q
 .I SEX="M" S TOTM=TOTM+1 Q
 .S TOTU=TOTU+1
 S @GLOB@("FEMALE")=TOTF
 S @GLOB@("MALE")=TOTM
 S @GLOB@("UNSPEC")=TOTU
 Q
 ;
AGE ; age totals compilation
 N DFN,AGE,CNT1,CNT2,CNT3,CNT4
 S DFN=0,(CNT1,CNT2,CNT3,CNT4)=0
 F  S DFN=$O(@GLOB@("HIVCHK",DFN)) Q:'DFN  D
 . S AGE=$$AGE^BKMIMRP1(DFN)
 . ; AGE could return days, weeks or months for patients under 3 years
 . I AGE'?1.N S CNT1=CNT1+1 Q
 . ; AGE<15 is a single category
 . I AGE<15 S CNT1=CNT1+1 Q
 . I AGE'>44 S CNT2=CNT2+1 Q
 . I AGE'>64 S CNT3=CNT3+1 Q
 . ; AGE>64
 . S CNT4=CNT4+1
 S @GLOB@("AGE1")=CNT1
 S @GLOB@("AGE2")=CNT2
 S @GLOB@("AGE3")=CNT3
 S @GLOB@("AGE4")=CNT4
 Q
 ;
CLEAN ;clean up variables
 K @GLOB
 Q
 ;
XIT ;
 Q
 ;
ERR ;
 D ^%ZTER
 N Y,ERRDTM
 S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
 S BMXSEC="Recording that an error occurred at "_ERRDTM
 Q