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

BQITASK6.m

Go to the documentation of this file.
BQITASK6 ;GDIT/HS/ALA-MU CQ Job ; 30 Sep 2011  1:06 PM
 ;;2.3;ICARE MANAGEMENT SYSTEM;**1,3,4**;Apr 18, 2012;Build 66
 ;
NIN ;EP -- BQI UPDATE MU CQM monthly
 ;
 I $G(DUZ(2))="" D
 . D DZ^BQITASK1 M DUZ=^XTMP("BQIRMDR","DUZ")
 ;
 NEW DESC,BJOB,BCJOB,BQPROH
 S BQPROH=+$P(^BQI(90508,1,12),U,7)
 S BQIMUDTM=$$NOW^XLFDT(),BQIMUDT=$P(BQIMUDTM,".",1),BQIMUTIM=$P(BQIMUDTM,".",2)
 S CDOW=$$DOW^XLFDT(BQIMUDT,1)
 I CDOW'=6,CDOW'=0,BQPROH,$E(BQIMUTIM,1,2)+3>6,$E(BQIMUTIM,1,2)+3<18 D  Q
 . S ZTDTH=BQIMUDT_".183"
 . S ZTDESC="MU CQ Monthly Compile",ZTRTN="NIN^BQITASK6",ZTIO=""
 . D ^%ZTLOAD
 . S BQIUPD(90508,"1,",12.05)=ZTSK
 . D FILE^DIE("","BQIUPD","ERROR")
 . K ZTDESC,ZTRTN,ZTIO,ZTDTH,ZTSK
 ;
 ;   Set the DATE/TIME MU STARTED field
 NEW DA,BQIMUTIM,BQIMUDT,CDOW,BQIMUDTM,STOP
 S DA=$O(^BQI(90508,0)) I 'DA Q
 S BQIUPD(90508,DA_",",4.19)=$$NOW^XLFDT()
 S BQIUPD(90508,DA_",",4.21)=1
 D FILE^DIE("","BQIUPD","ERROR")
 K BQIUPD
 K ^XTMP("BQIMUMON")
 S ^XTMP("BQIMUMON",0)=$$FMADD^XLFDT(DT,14)_U_DT_U_"Monthly MU Provider List"
 ;
 I $O(^XTMP("BQIMCQMPT",0))="" S ^XTMP("BQICQMPT",0)=$$FMADD^XLFDT(DT,14)_U_DT_U_"MU CQ Patients"
 S BGPPROV=$P(^BQI(90508,1,12),U,3),BCJOB=$P(^BQI(90508,1,12),U,5)
 S STOP=0
 F  S BGPPROV=$O(^BQI(90508,1,14,"B",BGPPROV)) Q:BGPPROV=""  D  Q:STOP
 . D MON^BQIMUPRS(BGPPROV)
 . S $P(^BQI(90508,1,12),U,3)=BGPPROV
 . S ^XTMP("BQIMUMON",BGPPROV)=$P(^BQI(90508,1,12),U,8)_U_$P(^BQI(90508,1,12),U,9)
 . ; If not prohibited, keep running
 . S BQPROH=+$P(^BQI(90508,1,12),U,7)
 . I 'BQPROH Q
 . ; If prohibited, check the date and time to see if the job needs to stop
 . S BQIMUDTM=$$NOW^XLFDT(),BQIMUDT=$P(BQIMUDTM,".",1),BQIMUTIM=$P(BQIMUDTM,".",2)
 . ; if it is a holiday, keep running
 . I $D(^HOLIDAY("B",DT)) Q
 . S CDOW=$$DOW^XLFDT(BQIMUDT,1)
 . ; If day of week is Saturday, keeping running even if prohibited
 . I CDOW=6 Q
 . ; If day of week is Sunday, keeping running even if prohibited
 . I CDOW=0 Q
 . ;If the time plus 3 hours is less than 6 am or greater than 6 pm keep going
 . I $E(BQIMUTIM,1,2)+3<6 Q
 . I $E(BQIMUTIM,1,2)+3>18 Q
 . S STOP=1
 . S ZTDTH=BQIMUDT_".183"
 . S ZTDESC="MU CQ Continue Monthly Compile",ZTRTN="NIN^BQITASK6",ZTIO=""
 . D ^%ZTLOAD
 . S BQIUPD(90508,"1,",12.05)=ZTSK
 . D FILE^DIE("","BQIUPD","ERROR")
 . K ZTDESC,ZTRTN,ZTIO,ZTDTH,ZTSK
 ;
HOS ; Hospital CQ
 I $P(^BQI(90508,1,0),U,6)=1 D
 . NEW BGPINDT,BGPMUYF,BGPRTYPE,BGP0RPTH,BGPBEN,X,BQIGREF,FAC,BQTDT,BQTMN,BGPBD,BGPED
 . K BGPIND
 . S BGPINDT=""
 . S BGPMUYF="90595.11"
 . S BGPRTYPE=4,BGP0RPTH="A"
 . S BGPMUT="H" ; BGPMU Hospital Measures
 . S BGPRTYPE=4,BGP0RPTH="A"
 . S BGPBEN=3
 . S X=0 F  S X=$O(^BGPMUIND(BGPMUYF,X)) Q:'X  I $P(^BGPMUIND(BGPMUYF,X,0),U,4)="H" S BGPIND(X)=""
 . S BQIGREF=$NA(^TMP("BQICQMH9",$J)) K @BQIGREF
 . ;
 . S FAC=$$HME^BQIGPUTL()
 . S BGPBD=$P(^BQI(90508,1,12),U,8),BGPED=$P(^BQI(90508,1,12),U,9)
 . S BQTDT=$E(BGPBD,1,5)_"00"
 . S BQTMN=$O(^BQIFAC(FAC,50,"B",BQTDT,""))
 . I BQTMN="" D UPH
 . ; Already data there, don't recalculate and quit
 . ;I $G(^BQIFAC(FAC,50,BQTMN,1,1,0))'="" Q
 . S BGPBD=$P(^BQI(90508,1,12),U,8),BGPED=$P(^BQI(90508,1,12),U,9)
 . ; Previous
 . S BGPPBD="",BGPPED=""
 . ; Baseline
 . S BGPBBD=BGPPBD,BGPBED=BGPPED
 . D BQI^BGPMUEHD(.BQIGREF)
 . K CDEN,CNUM,CEXC,PDEN,PNUM,PEXC,CSORT,PSORT,MTOT
 . S BN=""
 . F  S BN=$O(@BQIGREF@(BN)) Q:BN=""  D
 .. S I=""
 .. F  S I=$O(@BQIGREF@(BN,"C",I)) Q:I=""  D
 ... I $P($G(^BGPMUIND(90596.11,I,0)),U,4)[".ED." D  Q
 .... S MTOT=$P(@BQIGREF@(BN,"C",I),U,2)/60
 .... S CSORT(I,MTOT,BN)="",CSORT(I)=$G(CSORT(I))+1
 ... S CDEN(I)=$G(CDEN(I))+$P($G(@BQIGREF@(BN,"C",I)),U,1)
 ... S CNUM(I)=$G(CNUM(I))+$P($G(@BQIGREF@(BN,"C",I)),U,2)
 ... S CEXC(I)=$G(CEXC(I))+$P($G(@BQIGREF@(BN,"C",I)),U,3)
 . D STORH(50)
 . K @BQIGREF,CSORT,PSORT
 ;
 ;  Set the DATE/TIME MU STOPPED field
 NEW DA
 S DA=$O(^BQI(90508,0)) I 'DA Q
 S BQIUPD(90508,DA_",",4.2)=$$NOW^XLFDT()
 S BQIUPD(90508,DA_",",4.21)="@"
 S BQIUPD(90508,DA_",",12.03)=+BGPPROV
 I +BGPPROV=0 D
 . S BMDT=$P(^BQI(90508,1,12),U,9),BMDT=$$FMADD^XLFDT(BMDT,1)
 . S BMDT=$E(BMDT,1,5)_"00"
 . I $D(^XTMP("BQIMMON",BMDT)) K ^XTMP("BQIMMON",BMDT)
 . S BQIUPD(90508,DA_",",12.05)="@"
 D FILE^DIE("","BQIUPD","ERROR")
 K BQIUPD
 ; Create and send export files
 D EN^BQIMUEXP
 D HOS^BQIMUEXP
 Q
 ;
STORH(NODE) ;
 NEW CVALUE,PVALUE,CT,I,MSN,FAC
 I '$D(@BQIGREF) Q
 S FAC=$$HME^BQIGPUTL()
 I NODE=60 D  Q
 . S $P(^BQIFAC(FAC,2),U,1)=$$NOW^XLFDT()
 . S CT=0
 . S I=0 F  S I=$O(^BGPMUIND(90596.11,I)) Q:'I  D
 .. S MSN=$P(^BGPMUIND(90596.11,I,0),U,1)
 .. I $G(^BGPMUIND(90595.11,MSN,0))="" Q
 .. I $P(^BGPMUIND(90595.11,MSN,0),U,4)'="H" Q
 .. S CT=CT+1,^BQIFAC(FAC,NODE,BQTMN,10,CT,0)=$P(^BGPMUIND(90596.11,I,0),"^",4)_U_$G(CDEN(I))_U_$G(CNUM(I))_U_$G(CEXC(I))
 .. S ^BQIFAC(FAC,NODE,BQTMN,10,"B",$P(^BGPMUIND(90596.11,I,0),"^",4),CT)=""
 ;
 I NODE=50 D  Q
 . S $P(^BQIFAC(FAC,2),U,1)=$$NOW^XLFDT()
 . S CT=0
 . S I=0 F  S I=$O(^BGPMUIND(90596.11,I)) Q:'I  D
 .. S MSN=$P(^BGPMUIND(90596.11,I,0),U,1)
 .. I $G(^BGPMUIND(90595.11,MSN,0))="" Q
 .. I $P(^BGPMUIND(90595.11,MSN,0),U,4)'="H" Q
 .. S CT=CT+1,^BQIFAC(FAC,NODE,BQTMN,1,CT,0)=$P(^BGPMUIND(90596.11,I,0),"^",4)_U_$G(CDEN(I))_U_$G(CNUM(I))_U_$G(CEXC(I))
 .. S ^BQIFAC(FAC,NODE,BQTMN,1,"B",$P(^BGPMUIND(90596.11,I,0),"^",4),CT)=""
 ;
 K ^BQIFAC(FAC,NODE),^BQIFAC(FAC,NODE,"B")
 I NODE=11 S $P(^BQIFAC(FAC,1),U,1,4)=BGPBD_U_BGPED_U_BGPPBD_U_BGPPED
 I NODE=21 S $P(^BQIFAC(FAC,1),U,5,8)=BGPBD_U_BGPED_U_BGPPBD_U_BGPPED
 S CT=0
 S I=0 F  S I=$O(^BGPMUIND(90596.11,I)) Q:'I  D
 . S MSN=$P(^BGPMUIND(90596.11,I,0),U,1)
 . I $G(^BGPMUIND(90595.11,MSN,0))="" Q
 . I $P(^BGPMUIND(90595.11,MSN,0),U,4)'="H" Q
 . I $P($G(^BGPMUIND(90596.11,I,0)),U,4)[".ED." D
 .. S CVALUE=$$MED(I,.CSORT),PVALUE=$$MED(I,.PSORT)
 .. S CT=CT+1,^BQIFAC(FAC,NODE,CT,0)=$P(^BGPMUIND(90596.11,I,0),"^",4)_U_$P(CVALUE,U,1)_U_$P(CVALUE,U,2)_U_$G(CEXC(I))_U_$P(PVALUE,U,1)_U_$P(PVALUE,U,2)_U_$G(PEXC(I))
 . I $P($G(^BGPMUIND(90596.11,I,0)),U,4)'[".ED." D
 .. S CT=CT+1,^BQIFAC(FAC,NODE,CT,0)=$P(^BGPMUIND(90596.11,I,0),"^",4)_U_$G(CDEN(I))_U_$G(CNUM(I))_U_$G(CEXC(I))_U_$G(PDEN(I))_U_$G(PNUM(I))_U_$G(PEXC(I))
 . S ^BQIFAC(FAC,NODE,"B",$P(^BGPMUIND(90596.11,I,0),"^",4),CT)=""
 Q
 ;
MED(ITM,LIST) ;EP - Find Median for LIST
 ; Input
 ;    ITM  - Which measure to check list for
 ;    LIST - By ITM, the list of sorted values
 NEW CNT,MID,CT,PVAL,VAL,TOT,DFN,MED
 S CNT=$G(LIST(ITM))
 I CNT=1 Q $O(LIST(ITM,""))_U_1
 I CNT=2 D  Q (TOT/CNT)_U_CNT
 . S TOT=0,VAL=""
 . F  S VAL=$O(LIST(ITM,VAL)) Q:VAL=""  D
 .. S DFN="" F  S DFN=$O(LIST(ITM,VAL,DFN)) Q:DFN=""  S TOT=TOT+VAL
 ;
 ;S MID=(CNT+1)\2
 S MID=CNT\2
 S CT=0,VAL="",QFL=0,MED="",TOT=0
 F  S VAL=$O(LIST(ITM,VAL)) Q:VAL=""  D  Q:QFL
 . S DFN=""
 . F  S DFN=$O(LIST(ITM,VAL,DFN)) Q:DFN=""  D
 .. S CT=CT+1,NVAL=$O(LIST(ITM,VAL))
 .. I CT=MID S TOT=TOT+VAL+NVAL,MED=(TOT/2),QFL=1 Q
 .. S PVAL=VAL
 Q MED_U_CNT
 ;
UPH ;EP Update Hospital
 NEW BEGDT,ENDT,TMFRAME,XX,V,I,ERROR,BQIUPD
 S BEGDT=$P($G(^BQI(90508,1,12)),U,8),ENDT=$P($G(^BQI(90508,1,12)),U,9)
 ;S TMFRAME=$$FMTE^BQIUL1(BEGDT)_" - "_$$FMTE^BQIUL1(ENDT)
 ;
 I $G(^BQIFAC(FAC,50,0))="" S ^BQIFAC(FAC,50,0)="^90505.66D^^"
 S BQDATE=$E(BEGDT,1,5)_"00"
 NEW DA,X,IENS
 S DA(1)=FAC,DIC="^BQIFAC("_DA(1)_",50,",X=BQDATE,DIC(0)="LNZ",DLAYGO=90505.66,DIC("P")=DLAYGO
 D ^DIC
 S DA=+Y I DA=-1 Q
 S BQTMN=DA
 Q