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

BQIIPMON.m

Go to the documentation of this file.
BQIIPMON ;VNGT/HS/ALA-IPC Monthly Calculation ; 26 May 2011  8:11 AM
 ;;2.3;ICARE MANAGEMENT SYSTEM;**1,3,4**;Apr 18, 2012;Build 66
 ;
 ;
EN ;EP - IPC calculations
 ; 
 NEW BQMON,CYR,PYR,YR,TMFRAME,CRIPC,CRN,MSN,IDATA,CODE,TYP,BARDUZ2
 NEW BCODE,BCT,BEGDT,BN,BQDTE,CD,CNT,DEN,DFN,EDAY,ENDT,EXEC,FAC,IEN
 NEW NUM,PCT,PDEN,PNUM,PRV,QFL,TDEN,TNUM,TP,XX,Y,CRST,BQDA,PROW
 S QFL=0
 S CRST=$P($G(^BQI(90508,1,11)),U,2) S:CRST="" CRST=1
 S CRST="0"_CRST
 ;
 ; If passing a date in
 I $G(BQDATE)'="" D
 . S BEGDT=$E(BQDATE,1,5)_"01",CYR=$E(BQDATE,1,3),BQMON=$E(BQDATE,4,5)
 . I $L(BQMON)=1 S BQMON="0"_BQMON
 . S EDAY="31^"_($$LEAP^XLFDT2(CYR)+28)_"^31^30^31^30^31^31^30^31^30^31"
 . S ENDT=$E(BQDATE,1,5)_$P(EDAY,U,+BQMON)
 ;
 ; If no date, then if not the designated day of the month, quit
 I $G(BQDATE)="" D  Q:QFL
 . I $E(DT,6,7)'=CRST D CHK Q:QFL
 . S BQMON=$E(DT,4,5),CYR=$E(DT,1,3),PYR=CYR-1
 . S BQDTE=$P($T(BQM+BQMON),";;",2)
 . S BQMON=$P(BQDTE,U,1)
 . I $L(BQMON)=1 S BQMON="0"_BQMON
 . S BEGDT=@($P(BQDTE,U,2))_$P(BQDTE,U,1)_"01"
 . S EDAY="31^"_($$LEAP^XLFDT2($P(BQDTE,U,2))+28)_"^31^30^31^30^31^31^30^31^30^31"
 . S ENDT=@($P(BQDTE,U,2))_$P(BQDTE,U,1)_$P(EDAY,U,+$P(BQDTE,U,1))
 . ;S BQDATE=$S(BQMON="01":PYR,1:CYR)_BQMON_"00"
 . S BQDATE=@($P(BQDTE,U,2))_$P(BQDTE,U,1)_"00"
 ;
 S BQIUPD(90508,"1,",11.05)=BQDATE
 D FILE^DIE("","BQIUPD","ERROR")
 ;
 ; Get current IPC
 S CRIPC=$P($G(^BQI(90508,1,11)),U,1)
 S CRN=$O(^BQI(90508,1,22,"B",CRIPC,"")) I CRN="" Q
 ;
 ; Set the date
 NEW DA,DIC,X,PRDTE,PRN,ROW,FROW,QFL,RMON,RYEAR,RROW
 I $G(^BQI(90508,1,22,CRN,3,0))="" S ^BQI(90508,1,22,CRN,3,0)="^90508.223D^^"
 S DA(2)=1,DA(1)=CRN,DIC(0)="LMNZ",DLAYGO=90508.223,X=$S($L(BQDATE)=5:BQDATE_"00",1:BQDATE)
 S DIC="^BQI(90508,"_DA(2)_",22,"_DA(1)_",3,"
 D ^DIC
 I Y=-1 K DO,DD D FILE^DICN
 S BQDA=+Y
 S PRDTE=$O(^BQI(90508,1,22,CRN,3,"B",X),-1)
 ;
 S QFL=0 F BI=1:1:13 S FROW=$P($T(ROW+BI),";;",2) D  Q:QFL
 . S RMON=$P(FROW,U,1),RYEAR=$P(FROW,U,2),RROW=$P(FROW,U,3)
 . I $E(BQDATE,1,3)=RYEAR,$E(BQDATE,4,5)=RMON D  Q
 .. S ROW=RROW,QFL=1
 .. S $P(^BQI(90508,1,22,CRN,3,BQDA,0),U,2)=ROW
 I 'QFL D
 . S PRN=$O(^BQI(90508,1,22,CRN,3,"B",PRDTE,""))
 . S PROW=$P(^BQI(90508,1,22,CRN,3,PRN,0),U,2)
 . S ROW=PROW+1
 . S $P(^BQI(90508,1,22,CRN,3,BQDA,0),U,2)=ROW
 ;
 ;  Set the DATE/TIME FLAG STARTED field
 NEW DA
 S DA=$O(^BQI(90508,0)) I 'DA Q
 S BQIUPD(90508,DA_",",8.1)=$$NOW^XLFDT()
 S BQIUPD(90508,DA_",",8.12)=1
 S BQIUPD(90508,DA_",",24.08)=$G(ZTSK)
 D FILE^DIE("","BQIUPD","ERROR")
 K BQIUPD
 ;
 ; Calculate the IPC measures
 S MSN=0
 F  S MSN=$O(^BQI(90508,1,22,CRN,1,MSN)) Q:'MSN  D
 . S IDATA=^BQI(90508,1,22,CRN,1,MSN,0)
 . S CODE=$P(IDATA,U,1),TYP=$P(IDATA,U,2)
 . ; If inactive, quit
 . I $P(IDATA,U,7)=1 Q
 . ; If type is non calculable
 . I TYP="N" D NCLC Q
 . ; If type is RPMS
 . I TYP="R" D  Q
 .. S EXEC=$G(^BQI(90508,1,22,CRN,1,MSN,1)) I EXEC="" Q
 .. X EXEC
 . ; If type is CRS
 . I TYP="G" D CRS Q
 . I TYP="M" D MU
 ;
 ; Update the Goal Set
 NEW TPRN,PRV,TPRD,GPRN,GPRD,DEN,FAC,YEAR
 S PRV="",YEAR=$$GET1^DIQ(90508,1_",",2,"E")
 F  S PRV=$O(^AUPNPAT("AK",PRV)) Q:PRV=""  D
 . I $P(^VA(200,PRV,0),U,13)'="" Q
 . S TPRN=$O(^BQIPROV(PRV,30,"B","IPC_TOTP","")) I TPRN="" Q
 . S TPRD=$O(^BQIPROV(PRV,30,TPRN,1,"B",BQDATE,"")) I TPRD="" Q
 . S GPRN=$O(^BQIPROV(PRV,30,"B",YEAR_"_2452","")) I GPRN="" Q
 . S GPRD=$O(^BQIPROV(PRV,30,GPRN,1,"B",BQDATE,"")) I GPRD="" Q
 . S DEN=$P(^BQIPROV(PRV,30,TPRN,1,TPRD,0),U,2)
 . S $P(^BQIPROV(PRV,30,GPRN,1,GPRD,0),U,2)=DEN
 . S $P(^BQIPROV(PRV,2),U,3)=$$NOW^XLFDT()
 . ; Update the MU bundles
 . NEW MPRN,IPRN,IPRD,DEN,NUM,MCOD,MPRD,MBUN
 . S MPRN=$O(^BQIPROV(PRV,30,"B","IPC_WGT","")) I MPRN="" Q
 . S MPRD=$O(^BQIPROV(PRV,30,MPRN,1,"B",BQDATE,"")) I MPRD="" Q
 . K MBUN
 . F MCOD="MU_6","MU_6","MU_7" D
 .. S IPRN=$O(^BQIPROV(PRV,30,"B",MCOD,"")) I IPRN="" Q
 .. S IPRD=$O(^BQIPROV(PRV,30,IPRN,1,"B",BQDATE,"")) I IPRD="" Q
 .. S DEN=$P(^BQIPROV(PRV,30,IPRN,1,IPRD,0),U,2),NUM=$P(^(0),U,3)
 .. S MBUN(+DEN)=+NUM
 . S DEN=$O(MBUN("")),NUM=MBUN(DEN)
 . S $P(^BQIPROV(PRV,30,MPRN,1,MPRD,0),U,2)=DEN,$P(^BQIPROV(PRV,30,MPRN,1,MPRD,0),U,3)=NUM
 ;
 S FAC=$$HME^BQIGPUTL()
 S TPRN=$O(^BQIFAC(FAC,30,"B","IPC_TOTP","")) I TPRN="" Q
 S TPRD=$O(^BQIFAC(FAC,30,TPRN,1,"B",BQDATE,"")) I TPRD="" Q
 S GPRN=$O(^BQIFAC(FAC,30,"B",YEAR_"_2452","")) I GPRN="" Q
 S GPRD=$O(^BQIFAC(FAC,30,GPRN,1,"B",BQDATE,"")) I GPRD="" Q
 S DEN=$P(^BQIFAC(FAC,30,TPRN,1,TPRD,0),U,2)
 S $P(^BQIFAC(FAC,30,GPRN,1,GPRD,0),U,2)=DEN
 ;
 ;  Set the DATE/TIME FLAG ENDED field
 NEW DA
 S DA=$O(^BQI(90508,0)) I 'DA Q
 S BQIUPD(90508,DA_",",8.11)=$$NOW^XLFDT()
 S BQIUPD(90508,DA_",",8.12)="@"
 S BQIUPD(90508,DA_",",24.08)="@"
 D FILE^DIE("","BQIUPD","ERROR")
 K BQIUPD
 Q
 ;
NCLC ; No calculation possible
 Q
 ;
CRS ; Get values from BQIPAT
 S PRV="",TDEN=0,TNUM=0
 F  S PRV=$O(^AUPNPAT("AK",PRV)) Q:PRV=""  D
 . I $P(^VA(200,PRV,0),U,13)'="" Q
 . S DFN="",PDEN=0,PNUM=0
 . F  S DFN=$O(^AUPNPAT("AK",PRV,DFN)) Q:DFN=""  D
 .. I '$$HRN^BQIUL1(DFN) Q
 .. S IEN=$O(^BQIPAT(DFN,30,"B",CODE,"")) I IEN="" Q
 .. S PNUM=PNUM+$P(^BQIPAT(DFN,30,IEN,0),U,3)
 .. S PDEN=PDEN+$P(^BQIPAT(DFN,30,IEN,0),U,4)
 . D STORP^BQIIPUTL(PRV,CODE,BQDATE,PDEN,PNUM)
 . S TNUM=TNUM+PNUM,TDEN=TDEN+PDEN
 S FAC=$$HME^BQIGPUTL()
 D STORF^BQIIPUTL(FAC,CODE,BQDATE,TDEN,TNUM)
 Q
 ;
MU ; Get values for MU measures
 S PRV="",TDEN=0,TNUM=0
 F  S PRV=$O(^AUPNPAT("AK",PRV)) Q:PRV=""  D
 . I $P(^VA(200,PRV,0),U,13)'="" Q
 . NEW BGPBEN,BGPRTYPE,BGP0RPTH,BGPMUT,BGPMUYF,BGPBD,BGPED,BGPTP,BGPINDT
 . NEW BQTDT,BQTMN,BQIGREF,DFN,CDEN,CNUM,CEXC,NUM,BQTN,MUIND
 . S PDEN=0,PNUM=0
 . ; Current
 . S BGPBEN=3
 . S BGPRTYPE=4,BGP0RPTH="A",BGPMUT="P",BGPMUYF=90595.11
 . S (BGPBD,BGPED,BGPTP,BGPINDT)=""
 . S BGPBD=BEGDT,BGPED=ENDT
 . S BGPPBD="",BGPPED=""
 . ; Baseline
 . S BGPBBD=BGPPBD,BGPBED=BGPPED
 . S BQIGREF=$NA(^TMP("BQICQM",$J)) K @BQIGREF
 . S MUIND=$P($G(^BGPMUIND(90596.11,$P(CODE,"_",2),0)),U,1) I MUIND="" Q
 . S BGPIND(MUIND)="",BGPPROV=PRV
 . D BQI^BGPMUEPD(.BQIGREF,BGPPROV)
 . K CDEN,CNUM,CEXC,NUM
 . S DFN=""
 . F  S DFN=$O(@BQIGREF@(BGPPROV,DFN)) Q:DFN=""  D
 .. S I=""
 .. F  S I=$O(@BQIGREF@(BGPPROV,DFN,"C",I)) Q:I=""  D
 ... S CDEN=$G(CDEN)+$P($G(@BQIGREF@(BGPPROV,DFN,"C",I)),U,1)
 ... S NUM=$P($G(@BQIGREF@(BGPPROV,DFN,"C",I)),U,2)
 ... I NUM>1,$$FMTE^BQIUL1(NUM)'?.N S NUM=1
 ... S CNUM=$G(CNUM)+NUM
 ... S CEXC=$G(CEXC)+$P($G(@BQIGREF@(BGPPROV,DFN,"C",I)),U,3)
 . S PDEN=PDEN+$G(CDEN),PNUM=PNUM+$G(CNUM),TDEN=TDEN+PDEN,TNUM=TNUM+PNUM
 . D STORP^BQIIPUTL(PRV,CODE,BQDATE,PDEN,PNUM)
 S FAC=$$HME^BQIGPUTL()
 D STORF^BQIIPUTL(FAC,CODE,BQDATE,TDEN,TNUM)
 K BQIND
 Q
 ;
CHK ; EP - Check whether the IPC data ran or not
 NEW LPRV
 S QFL=1
 I $E(DT,6,7)<CRST Q
 S BQMON=$E(DT,4,5),CYR=$E(DT,1,3),PYR=CYR-1
 S BQDTE=$P($T(BQM+BQMON),";;",2)
 S BQMON=$P(BQDTE,U,1)
 I $L(BQMON)=1 S BQMON="0"_BQMON
 S CRIPC=$P($G(^BQI(90508,1,11)),U,1)
 S CRN=$O(^BQI(90508,1,22,"B",CRIPC,"")) I CRN="" Q
 S BQDATE=@($P(BQDTE,U,2))_$P(BQDTE,U,1)_"00"
 I $D(^BQI(90508,1,22,CRN,3,"B",BQDATE)) Q
 S LPRV=$O(^AUPNPAT("AK",""),-1)
 I $D(^BQIPROV(LPRV,30,"AB",BQDATE)) Q
 S QFL=0
 Q
 ;
NMS(CDE) ; New measure
 Q
 ;
NTM(PROV) ; New timeframe
 Q
 ;
ROW ;
 ;;08^312^49
 ;;09^312^50
 ;;10^312^51
 ;;11^312^52
 ;;12^312^53
 ;;01^313^54
 ;;02^313^55
 ;;03^313^56
 ;;04^313^57
 ;;05^313^58
 ;;06^313^59
 ;;07^313^60
 ;;08^313^61
 ;;09^313^62
 ;;10^313^63
 ;;11^313^64
 ;;12^313^65
 Q
 ;
BQM ;
 ;;12^PYR
 ;;01^CYR
 ;;02^CYR
 ;;03^CYR
 ;;04^CYR
 ;;05^CYR
 ;;06^CYR
 ;;07^CYR
 ;;08^CYR
 ;;09^CYR
 ;;10^CYR
 ;;11^CYR