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

BQIIPMNU.m

Go to the documentation of this file.
BQIIPMNU ;GDIT/HS/ALA-Update Monthly ; 24 Jun 2013  8:43 AM
 ;;2.7;ICARE MANAGEMENT SYSTEM;**1**;Dec 19, 2017;Build 12
 ;
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=@($P(BQDTE,U,2))_$P(BQDTE,U,1)_"00"
 ;
 S BQIUPD(90508,"1,",11.05)=BQDATE
 D FILE^DIE("","BQIUPD","ERROR")
 ;
 ;  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
 ; 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
 ;
 D PROC
 ;
 I CRIPC="IPC4/IPC5" D
 . S CRIPC="IPCMH",CRN=3 D PROC
 ;
 ; Send the files to the Data Warehouse
 ; Provider List
 D PROV^BQIIPCMF
 ; Measure List
 D MEAS^BQIIPCMF
 ; Data
 D RET^BQIIPCME(.DATA,BQDATE,"")
 ;
 ;  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)="@"
 S BQIUPD(90508,"1,",11.04)="@"
 D FILE^DIE("","BQIUPD","ERROR")
 K BQIUPD
 Q
 ;
PROC ;EP - Process the data
 I $G(DEBUG)=1 W !,CRIPC
 ; 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)
 ;
 I CRIPC'="IPCMH" D
 . S QFL=0 F BI=1:1:16 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
 ;
 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) I $G(DEBUG)=1 W !,IDATA
 . ; If inactive, quit
 . I $P(IDATA,U,7)=1 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
 . ;
 . S BQIPROV=$P($G(^BQI(90508,1,11)),U,3)
 . S TDEN=0,TNUM=0
 . F  S BQIPROV=$O(^AUPNPAT("AK",BQIPROV)) Q:BQIPROV=""  D
 .. I $P(^VA(200,BQIPROV,0),U,13)'="" Q
 .. S MSNN=MSN
 .. D EN^BQIIPSNG(BQIPROV,BQDATE,CRIPC)
 .. S $P(^BQI(90508,1,11),U,3)=BQIPROV,MSN=MSNN
 ;
 S $P(^BQI(90508,1,11),U,3)=""
 ;
 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 CRS, update the facility
 . ;I TYP'="G" Q
 . 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 IPRN=$O(^BQIPROV(PRV,30,"B",CODE,"")) 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 TNUM=TNUM+NUM,TDEN=TDEN+DEN
 . S FAC=$$HME^BQIGPUTL()
 . I $G(DEBUG)=1 W !,FAC,"|",CODE,"|",BQDATE,"|",TDEN,"|",TNUM
 . D STORF^BQIIPUTL(FAC,CODE,BQDATE,TDEN,TNUM)
 ;
 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
 . I CODE="IPC_CCPR"!(CODE="IPC_PEMP") Q
 . NEW TMN,TEAM,TMM,OK,TDEN,TNUM,IPRN,IPRD,DEN,NUM
 . S TMN=0
 . F  S TMN=$O(^BSDPCT(TMN)) Q:'TMN  D
 .. ; Check inactivation date
 .. I $P(^BSDPCT(TMN,0),"^",3)'="" Q
 .. S TEAM=$P(^BSDPCT(TMN,0),"^",1)
 .. ; Check if the team members has at least one member with patients assigned to them
 .. S OK=0
 .. S TMM="" F  S TMM=$O(^BSDPCT(TMN,1,"B",TMM)) Q:TMM=""  I $O(^AUPNPAT("AK",TMM,""))'="" S OK=1
 .. I 'OK Q
 .. I CODE="IPC_CCTM" D  Q
 ... S EXEC=$G(^BQI(90508,1,22,CRN,1,MSN,1)) I EXEC="" Q
 ... X EXEC
 .. S TDEN=0,TNUM=0
 .. S TMM="" F  S TMM=$O(^BSDPCT(TMN,1,"B",TMM)) Q:TMM=""  I $O(^AUPNPAT("AK",TMM,""))'="" D
 ... I $P(^VA(200,TMM,0),U,13)'="" Q
 ... S IPRN=$O(^BQIPROV(TMM,30,"B",CODE,"")) I IPRN="" Q
 ... S IPRD=$O(^BQIPROV(TMM,30,IPRN,1,"B",BQDATE,"")) I IPRD="" Q
 ... S DEN=$P(^BQIPROV(TMM,30,IPRN,1,IPRD,0),U,2),NUM=$P(^(0),U,3)
 ... S TNUM=TNUM+NUM,TDEN=TDEN+DEN
 .. I $G(DEBUG)=1 W !,TEAM,"|",CODE,"|",TDEN,"|",TNUM
 .. D STORT^BQIIPUTL(TEAM,CODE,BQDATE,TDEN,TNUM)
 ;
TOT ;EP total up values for MU
 I CRIPC'="IPCMH" D
 . NEW MCOD
 . F MCOD="MU_2","MU_6","MU_7","MU_3","MU_5","MU_8","MU_55","MU_56","MU_57" D
 .. NEW PRV,TDEN,TNUM,IPRN,IPRD,DEN,NUM
 .. 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 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 TDEN=TDEN+DEN,TNUM=TNUM+NUM
 .. S FAC=$$HME^BQIGPUTL()
 .. D STORF^BQIIPUTL(FAC,MCOD,BQDATE,TDEN,TNUM)
 . ;
 . S YEAR=$$GET1^DIQ(90508,1_",",2,"E")
 . S FAC=$$HME^BQIGPUTL()
 . S TPRN=$O(^BQIFAC(FAC,30,"B","IPC_TOTP",""))
 . I TPRN'="" S TPRD=$O(^BQIFAC(FAC,30,TPRN,1,"B",BQDATE,""))
 . S GPRN=$O(^BQIFAC(FAC,30,"B",YEAR_"_2452","")),GPRD=""
 . I GPRN'="" S GPRD=$O(^BQIFAC(FAC,30,GPRN,1,"B",BQDATE,""))
 . I TPRN'="",TPRD'="" D
 .. S DEN=$P(^BQIFAC(FAC,30,TPRN,1,TPRD,0),U,2)
 .. I GPRN=""!(GPRD="") Q
 .. S $P(^BQIFAC(FAC,30,GPRN,1,GPRD,0),U,2)=DEN
 ;
 Q
 ;
CHK ; EP - Check whether the IPC data ran or not
 NEW LPRV,PRDTE
 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"
 S PRDTE=$O(^BQI(90508,1,22,CRN,3,"B",BQDATE),-1)
 ; if date has already been set and last provider done
 S LPRV=$O(^AUPNPAT("AK",""),-1)
 I $D(^BQIPROV(LPRV,30,"AB",BQDATE)),$D(^BQI(90508,1,22,CRN,3,"B",BQDATE)) Q
 ; If date not set up
 I '$D(BQI(90508,1,22,CRN,3,"B",BQDATE)) D
 . ; If a provider is still in the queue and the date is the previous date
 . I $P(^BQI(90508,1,11),U,3)="",$P(^BQI(90508,1,11),U,5)=PRDTE S QFL=0 Q
 Q
 ;
ROW ;
 ;;06^314^71
 ;;07^314^72
 ;;08^314^73
 ;;09^314^74
 ;;10^314^75
 ;;11^314^76
 ;;12^314^77
 ;;01^315^78
 ;;02^315^79
 ;;03^315^80
 ;;04^315^81
 ;;05^315^82
 ;;06^315^83
 ;;07^315^84
 ;;08^315^85
 ;;09^315^86
 ;;10^315^87
 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