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

BKMQQCRB.m

Go to the documentation of this file.
BKMQQCRB ;VNGT/HS/ALA - Updates to HIVQual Report ; 10 Mar 2010  6:06 PM
 ;;2.2;HIV MANAGEMENT SYSTEM;;Apr 01, 2015;Build 40
 ;
EN ;
 D VIS,LAB
 Q
 ;
VIS ; Visit breakdown by every 4 and 6 months
 NEW TREF,TAX,TOTPTS,TOTPTS1,BKMDFN,IEN,TOTVIS,TOTVIS1,RVRSE,RVRSB,PR,LBDT
 NEW TOTCD4,TOTCD41,TOTVIR,TOTVIR1,TOTBTH,TOTBTH1,GLOBNO,TOTLCD,TOTLVR
 NEW REVPER,P1B,P1E,HP1B,HP1E,P2B,P2E,HP2B,HP2E,P3B,P3E,HP3B,HP3E,VIS
 NEW P61B,P61E,HP61B,HP61E,P62B,P62E,HP62B,HP62E,HVSDTM,VLBC4,VLBVR,VCPC4,VCPVR
 NEW P1,P2,P3,P61,P62,LC1,LV1,LC2,LV2,LC3,LV3,LB1,LB2,LB3,LBC1,LBV1,LBC2,LBV2,LBB1,LBB2
 ;
 S TREF="BQITAX" K @TREF
 S TAX="BGP HIV/AIDS DXS"
 D BLD^BQITUTL(TAX,TREF)
 D DTR^BKMQQCRU(EDATE)
 S RVRSE=9999999-EDATE,RVRSB=9999999-REVPER
 ;
 ;   Total patients who had visit every 4 months
 S TOTPTS=$P(GLOB,")")_",""HIVCHK"",""V4MPTCNT"")"
 ;   Total patients who had visit every 6 months
 S TOTPTS1=$P(GLOB,")")_",""HIVCHK"",""V6MPTCNT"")"
 ;   Total number of visits for the patients who had a visit every 4 months
 S TOTVIS=$P(GLOB,")")_",""HIVCHK"",""V4MVSCNT"")"
 ;   Total number of visits for the patients who had a visit every 6 months
 S TOTVIS1=$P(GLOB,")")_",""HIVCHK"",""V6MVSCNT"")"
 S @TOTPTS=0,@TOTPTS1=0,@TOTVIS=0,@TOTVIS1=0
 ;
 S TOTCD4=$P(GLOB,")")_",""HIVCHK"",""CD4MPTCNT"")"
 S TOTCD41=$P(GLOB,")")_",""HIVCHK"",""CD6MPTCNT"")"
 S TOTVIR=$P(GLOB,")")_",""HIVCHK"",""VR4MPTCNT"")"
 S TOTVIR1=$P(GLOB,")")_",""HIVCHK"",""VR6MPTCNT"")"
 S TOTBTH=$P(GLOB,")")_",""HIVCHK"",""BTH4MPTCNT"")"
 S TOTBTH1=$P(GLOB,")")_",""HIVCHK"",""BTH6MPTCNT"")"
 S TOTLVR=$P(GLOB,")")_",""HIVCHK"",""LVR4MPTCNT"")"
 S TOTLCD=$P(GLOB,")")_",""HIVCHK"",""LCD4MPTCNT"")"
 S (@TOTCD4,@TOTCD41,@TOTVIR,@TOTVIR1,@TOTBTH,@TOTBTH1,@TOTLVR,@TOTLCD)=0
 ;
 ; Build taxonomy list of items
 D TAX
 ;
 S BKMDFN=0
 F  S BKMDFN=$O(@GLOB@("HIVCHK",BKMDFN)) Q:'BKMDFN  D
 . S GLOBNO=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""NOVIRAL"")",@GLOBNO=0
 . NEW TIEN,VDATA,PDATA,VISIT,VSDTM,XX,XVIR,XCD4
 . S IEN=""
 . S (P1,P2,P3,P61,P62,LC1,LV1,LC2,LV2,LC3,LV3,LB1,LB2,LB3,LBC1,LBV1,LBC2,LBV2,LBB1,LBB2)=0
 . S LBDT=RVRSE-.001
 . F  S LBDT=$O(^AUPNVSIT("AA",BKMDFN,LBDT)) Q:LBDT=""!(LBDT\1>RVRSB)  D
 .. S IEN=""
 .. F  S IEN=$O(^AUPNVSIT("AA",BKMDFN,LBDT,IEN),-1) Q:IEN=""  D
 ... S VISIT=IEN
 ... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 ... I $P(VDATA,U,11)=1 Q
 ... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 ... ;I VSDTM<REVPER!(VSDTM>EDATE) Q
 ... S HVSDTM=$$FMTH^XLFDT(VSDTM,1)
 ... ;   Check for most recent quarterly period or Period 1
 ... I HVSDTM'>HP1B,HVSDTM'<HP1E D
 .... D LBVS(VISIT)
 .... I VLBC4'=0!(VCPC4'=0) S XX("P1","C")=$G(XX("P1","C"))+1,@TOTLCD=@TOTLCD+1
 .... I VLBVR'=0!(VCPVR'=0) S XX("P1","V")=$G(XX("P1","V"))+1,@TOTLVR=@TOTLVR+1
 .... ;I VLBC4'=0!(VCPC4'=0),VLBVR'=0!(VCPVR'=0) S LB1=LB1+1
 .... I VIS'=0 S P1=$G(P1)+1
 ... ;   Check for middle quarterly period or Period 2
 ... I HVSDTM'>HP2B,HVSDTM'<HP2E D
 .... D LBVS(VISIT)
 .... I VLBC4'=0!(VCPC4'=0) S XX("P2","C")=$G(XX("P2","C"))+1
 .... I VLBVR'=0!(VCPVR'=0) S XX("P2","V")=$G(XX("P2","V"))+1
 .... ;I VLBC4'=0!(VCPC4'=0),VLBVR'=0!(VCPVR'=0) S LB2=LB2+1
 .... I VIS'=0 S P2=$G(P2)+1
 ... ;   Check for last quarterly period or Period 3
 ... I HVSDTM'>HP3B,HVSDTM'<HP3E D
 .... D LBVS(VISIT)
 .... I VLBC4'=0!(VCPC4'=0) S XX("P3","C")=$G(XX("P3","C"))+1
 .... I VLBVR'=0!(VCPVR'=0) S XX("P3","V")=$G(XX("P3","V"))+1
 .... ;I VLBC4'=0!(VCPC4'=0),VLBVR'=0!(VCPVR'=0) S LB3=LB3+1
 .... I VIS'=0 S P3=$G(P3)+1
 ... ;   Check for most recent six month period
 ... I HVSDTM'>HP61B,HVSDTM'<HP61E D
 .... D LBVS(VISIT)
 .... I VLBC4'=0!(VCPC4'=0) S XX("P61","C")=$G(XX("P61","C"))+1
 .... I VLBVR'=0!(VCPVR'=0) S XX("P61","V")=$G(XX("P61","V"))+1,@GLOBNO=@GLOBNO+1
 .... ;I VLBC4'=0!(VCPC4'=0),VLBVR'=0!(VCPVR'=0) S LBB1=LBB1+1
 .... ;I VLBVR=0,VCPVR=0 S @GLOBNO=@GLOBNO+1
 .... I VIS'=0 S P61=$G(P61)+1
 ... ;   Check for previous six month period
 ... I HVSDTM'>HP62B,HVSDTM'<HP62E D
 .... D LBVS(VISIT)
 .... I VLBC4'=0!(VCPC4'=0) S XX("P62","C")=$G(XX("P62","C"))+1
 .... I VLBVR'=0!(VCPVR'=0) S XX("P62","V")=$G(XX("P62","V"))+1
 .... ;I VLBC4'=0!(VCPC4'=0),VLBVR'=0!(VCPVR'=0) S LBB2=LBB2+1
 .... I VIS'=0 S P62=$G(P62)+1
 . I P1'=0,P2'=0,P3'=0 D
 .. NEW XCD4,XVIR
 .. S @TOTPTS=@TOTPTS+1
 .. S XCD4=0 F PR="P1","P2","P3" I +$G(XX(PR,"C"))'=0 S XCD4=XCD4+1
 .. S XVIR=0 F PR="P1","P2","P3" I +$G(XX(PR,"V"))'=0 S XVIR=XVIR+1
 .. I XCD4>2,XVIR=0 S @TOTCD4=@TOTCD4+1
 .. I XCD4=0,XVIR>2 S @TOTVIR=@TOTVIR+1
 .. I XCD4'=0,XVIR'=0,XCD4'<3,XVIR'<3 S @TOTBTH=@TOTBTH+1
 . I P61'=0,P62'=0 D
 .. S @TOTPTS1=@TOTPTS1+1
 .. S XCD4=0 F PR="P61","P62" I +$G(XX(PR,"C"))'=0 S XCD4=XCD4+1
 .. S XVIR=0 F PR="P61","P62" I +$G(XX(PR,"V"))'=0 S XVIR=XVIR+1
 .. I XCD4>1,XVIR=0 S @TOTCD41=@TOTCD41+1
 .. I XCD4=0,XVIR>1 S @TOTVIR1=@TOTVIR1+1
 .. I XCD4'=0,XVIR'=0,XCD4'<2,XVIR'<2 S @TOTBTH1=@TOTBTH1+1
 . K XX
 K BQITAX
 Q
 ;
LAB ; CD4 and Viral Load break down by every 4 and 6 months
 NEW REVPER,P1B,P1E,HP1B,HP1E,P2B,P2E,HP2B,HP2E,P3B,P3E,HP3B,HP3E
 NEW TAX,IEN,CD4,VIRAL,RVRSE,RVRSB,LBDT,QFL,RESULT,CCPT,CD4,VCPT,VIRAL
 NEW P61B,P61E,HP61B,HP61E,P62B,P62E,HP62B,HP62E,HVSDTM,GLOBVN,GLOBVS
 NEW CCPT,VCPT,GLOBAL,GLOBAL1,PTGLOB,PTGLOB1,PTGLOB2,GLOBC1,GLOBC2,GLOBC3,GLOBC4
 NEW PC1,PC2,PC3,PC61,PC62,PTGLOB3,PTGLOB4,PTLAB1,PTLAB2,PV1,PV2,PV3,PV61,PV62
 NEW PTLABC,PTLABV
 ;
 ; Build taxonomy list of items
 D TAX
 ;
 ; Get Dates of performance
 D DTR^BKMQQCRU(EDATE\1)
 S RVRSE=9999999-(EDATE\1),RVRSB=9999999-(REVPER\1)
 ;
 ; CD4RES1 = CD4 Result 0-199
 ; CD4RES2 = CD4 Result 200-349
 ; CD4RES3 = CD4 Result 350-499
 ; CD4RES4 = CD4 Result >500
 S GLOBC1=$P(GLOB,")")_",""HIVCHK"",""CD4RES1"")"
 S PTGLOB1=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""CD4RES1"")"
 S GLOBC2=$P(GLOB,")")_",""HIVCHK"",""CD4RES2"")"
 S PTGLOB2=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""CD4RES2"")"
 S GLOBC3=$P(GLOB,")")_",""HIVCHK"",""CD4RES3"")"
 S PTGLOB3=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""CD4RES3"")"
 S GLOBC4=$P(GLOB,")")_",""HIVCHK"",""CD4RES4"")"
 S PTGLOB4=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""CD4RES4"")"
 ;S GLOBAL2=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""VIRALCNT"")"
 ;S PTGLOB2=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""VIRAL"")"
 S PTLAB1=$P(GLOB,")")_",""ZLAB"",BKMDFN,""VIRAL"",VSDTM)"
 S PTLABV=$P(GLOB,")")_",""ZLAB"",BKMDFN,""VIRAL"")"
 S PTLAB2=$P(GLOB,")")_",""ZLAB"",BKMDFN,""CD4"",VSDTM)"
 S PTLABC=$P(GLOB,")")_",""ZLAB"",BKMDFN,""CD4"")"
 S GLOBVS=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""VIRALSUP"")"
 S GLOBVN=$P(GLOB,")")_",""HIVCHK"",BKMDFN,""VIRALNSU"")"
 S (@GLOBC1,@GLOBC2,@GLOBC3,@GLOBC4)=0
 ;
 S BKMDFN=0
 F  S BKMDFN=$O(@GLOB@("HIVCHK",BKMDFN)) Q:'BKMDFN  D
 . NEW TIEN,VDATA,PDATA,VISIT,VSDTM,COLDTM
 . S LBDT=RVRSE-.001
 . F  S LBDT=$O(^AUPNVLAB("AE",BKMDFN,LBDT)) Q:LBDT=""!(LBDT\1>RVRSB)  D
 .. S TIEN=""
 .. F  S TIEN=$O(^AUPNVLAB("AE",BKMDFN,LBDT,TIEN)) Q:TIEN=""  D
 ... I '$D(@CD4@(TIEN)),'$D(@VIRAL@(TIEN)) Q
 ... S IEN="",QFL=0
 ... F  S IEN=$O(^AUPNVLAB("AE",BKMDFN,LBDT,TIEN,IEN),-1) Q:IEN=""  D
 .... S PDATA=$G(^AUPNVLAB(IEN,0)) I PDATA="" Q
 .... S VISIT=$P(PDATA,U,3) I VISIT="" Q
 .... S VDATA=$G(^AUPNVSIT(VISIT,0)) I VDATA="" Q
 .... I $P(VDATA,U,11)=1 Q
 .... S VSDTM=$P(VDATA,U,1)\1 I VSDTM=0 Q
 .... ; Get collection date/time
 .... S COLDTM=$P($G(^AUPNVLAB(IEN,12)),U,1)\1
 .... I COLDTM'=0 S VSDTM=COLDTM
 .... S HVSDTM=$$FMTH^XLFDT(VSDTM,1)
 .... I VSDTM<REVPER!(VSDTM>EDATE) Q
 .... S RESULT=$P(PDATA,U,4)
 .... I RESULT'="" D
 ..... I $D(@CD4@(TIEN)) D
 ...... S @PTLAB2=RESULT
 ..... I $D(@VIRAL@(TIEN)) D
 ...... NEW OPER,VRLRES,RES
 ...... I RESULT=""!(RESULT?.A) Q
 ...... S @PTLAB1=RESULT
 . ;
 . S VSDTM=$O(@PTLABC@(""),-1)
 . I VSDTM'="" D
 .. S RESULT=@PTLABC@(VSDTM)
 .. I RESULT<200 S @PTGLOB1=$G(@PTGLOB1)+1,@GLOBC1=@GLOBC1+1 Q
 .. I RESULT>199,RESULT<350 S @PTGLOB2=$G(@PTGLOB2)+1,@GLOBC2=@GLOBC2+1 Q
 .. I RESULT>349,RESULT<500 S @PTGLOB3=$G(@PTGLOB3)+1,@GLOBC3=@GLOBC3+1 Q
 .. I RESULT>499 S @PTGLOB4=$G(@PTGLOB4)+1,@GLOBC4=@GLOBC4+1 Q
 . ;
 . S VSDTM=$O(@PTLABV@(""),-1)
 . I VSDTM'="" D
 .. S RESULT=@PTLABV@(VSDTM)
 .. I RESULT="<400" S @GLOBVS=RESULT,QFL=1 Q
 .. S OPER=$S($E(RESULT,1)="<":"<",$E(RESULT,1)=">":">",1:"")
 .. S VRLRES=$S($E(RESULT,1)?.P:$E(RESULT,2,99),1:RESULT)
 .. S RES=400
 .. I OPER="" S OPER="<"
 .. I @(VRLRES_OPER_RES) S @GLOBVS=RESULT Q
 .. S OPER="'<"
 .. I @(VRLRES_OPER_RES) S @GLOBVN=RESULT Q
 ;
 K @VCPT,@CD4,@VIRAL,@CCPT
 Q
 ;
TAX ;EP - Build taxonomy item lists
 S CD4="BKMCD4" K @CD4
 F TAX="BKMV CD4 ABS TESTS TAX","BKMV CD4 ABS LOINC CODES"  D BLD^BQITUTL(TAX,CD4)
 S CCPT="BKMCCPT" K @CCPT
 F TAX="BKMV CD4 ABS CPTS" D BLD^BQITUTL(TAX,CCPT)
 S VIRAL="BKMVIR" K @VIRAL
 F TAX="BGP HIV VIRAL LOAD TAX","BGP VIRAL LOAD LOINC CODES" D BLD^BQITUTL(TAX,VIRAL)
 S VCPT="BKMVCPT" K @VCPT
 F TAX="BGP HIV VIRAL LOAD CPTS" D BLD^BQITUTL(TAX,VCPT)
 Q
 ;
LBVS(VIEN) ;EP - Find labs for a specific visit
 NEW IEN,PDATA,TIEN
 S VLBC4=0,VLBVR=0,VCPC4=0,VCPVR=0,VIS=0
 S IEN=""
 F  S IEN=$O(^AUPNVLAB("AD",VIEN,IEN)) Q:IEN=""  D
 . S PDATA=$G(^AUPNVLAB(IEN,0)) I PDATA="" Q
 . S TIEN=$P(PDATA,U,1) I TIEN="" Q
 . I '$D(@CD4@(TIEN)),'$D(@VIRAL@(TIEN)) Q
 . I $D(@CD4@(TIEN)) S VLBC4=VLBC4+1
 . I $D(@VIRAL@(TIEN)) S VLBVR=VLBVR+1
 ;
 S IEN=""
 F  S IEN=$O(^AUPNVCPT("AD",VIEN,IEN)) Q:IEN=""  D
 . S PDATA=$G(^AUPNVCPT(IEN,0)) I PDATA="" Q
 . S TIEN=$P(PDATA,U,1) I TIEN="" Q
 . I '$D(@CCPT@(TIEN)),'$D(@VCPT@(TIEN)) Q
 . I $D(@CCPT@(TIEN)) S VCPC4=VCPC4+1
 . I $D(@VCPT@(TIEN)) S VCPVR=VCPVR+1
 ;
 S IEN=""
 F  S IEN=$O(^AUPNVPOV("AD",VIEN,IEN)) Q:IEN=""  D
 . S PDATA=$G(^AUPNVPOV(IEN,0)) I PDATA="" Q
 . S TIEN=$P(PDATA,U,1) I TIEN="" Q
 . I '$D(@TREF@(TIEN)) Q
 . S VIS=VIS+1
 Q