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

BQIIPCME.m

Go to the documentation of this file.
BQIIPCME ;GDIT/HS/ALA-Get IPC Monthly Data Export by Provider ; 11 Oct 2011  4:10 PM
 ;;2.7;ICARE MANAGEMENT SYSTEM;**1**;Dec 19, 2017;Build 12
 ;
 ;
RET(DATA,DATE,PLIST) ;EP -- BQI IPC PROV MON EXPORT NDW
 NEW UID,II,HDR,C1,C2,C3,C4,NAME,HEAD,HX,PEC,SORT,QFL,PCT,CT,DDATA,CPER,PPER,TIT,BQMON
 NEW BN,LIST,FAC,ASUFAC,DBID
 ;S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
 S UID=$J
 ;S DATA=$NA(^TMP("BQIIPCME",UID))
 S DATA=$NA(^BQIDATA1(UID))
 K @DATA
 S II=0
 NEW $ESTACK,$ETRAP S $ETRAP="D ERR^BQIIPCME D UNWIND^%ZTER" ; SAC 2006 2.2.3.3.2
 ; If a list of IENs, process them instead of entire panel
 I $D(PLIST)>0 D
 . I $D(PLIST)>1 D
 .. S LIST="",BN=""
 .. F  S BN=$O(PLIST(BN)) Q:BN=""  S LIST=LIST_PLIST(BN)
 .. K PLIST S PLIST=LIST
 ;
 ; Get current IPC
 S CRIPC=$P($G(^BQI(90508,1,11)),U,1)
 I CRIPC'="IPCMH" S CRIPC="IPCMH"
 S CRN=$O(^BQI(90508,1,22,"B",CRIPC,"")) I CRN="" Q
 S ASUFAC=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),0)),U,10)
 S DBID=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),1)),U,3)
 ;
 K Z
 S HDR="T00010ASUFAC^T00050PROVIDER^T00015DB_ID^T00060IPC_MEAS^T00015TDATE^T00030NUMERATOR^T00030DENOMINATOR"
 ;S @DATA@(II)=HDR
 ;S @DATA@(II)=HDR_$C(30)
 ;
 S (C1,C2,C3,C4,CT,PCT)=0
 I $G(PLIST)="" S PROV="" F  S PROV=$O(^BQIPROV("AD",DATE,PROV)) Q:PROV=""  D RTE(PROV)
 I $G(PLIST)'="" F BQI=1:1 S PROV=$P(PLIST,$C(28),BQI) Q:PROV=""  D RTE(PROV)
 ;
 S PRV=""
 F  S PRV=$O(DDATA(PRV)) Q:PRV=""  D
 . S ID=""
 . F  S ID=$O(DDATA(PRV,ID)) Q:ID=""  D
 .. I '$D(Z(PRV,ID,DATE)) Q
 .. S FDATA=ASUFAC_U_DBID_U_DDATA(PRV,ID)_Z(PRV,ID,DATE)_U
 .. S FDATA=$$TKO^BQIUL1(FDATA,"^")
 .. I $P(FDATA,U,4)=0 S $P(FDATA,U,4)=""
 .. I $P(FDATA,U,5)=0 S $P(FDATA,U,5)=""
 .. ;S II=II+1,@DATA@(II)=FDATA_$C(30)
 .. S II=II+1,@DATA@(II)=FDATA
 ;
DONE ;
 K Z,IPRD,IPRN,MEAS,MSDN,MSNN,NA,NDA,NO,NUM1,NUM2,PIEN,PROV,PRVR,PTMN,T,TAG,TEAM,TMM,TMN,TOTP,TPRD,TPRN
 K FDATA,FLNM,FTOTF,FTOTP,GP,GPRD,GPRN,I,ID,IDD,IDN,IID,DLAYGO,DOD,DPCP,BQITOTP
WRITE ;
 S FLNM=$S('$$PROD^XUPROD():"IPCZ",1:"IPC")
 S ZTQUEUED=1
 NEW XBGL,XBQ,XBQTO,XBNAR,XBMED,XBFLT,XBUF,XBFN
 S XBMED="F",XBQ="N",XBFLT=1,XBF=UID,XBE=UID
 S XBGL="BQIDATA1"
 S XBNAR="IPC DATA WAREHOUSE EXPORT"
 S ASUFAC=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),0)),U,10)  ;asufac for file name
 S XBFN=FLNM_"_"_ASUFAC_"_"_$$FDATE(DT)_".txt"
 S XBS1="DATA WAREHOUSE SEND"
 S XBUF=$P($G(^AUTTSITE(1,1)),"^",2)
 I XBUF="" S XBUF=$P($G(^XTV(8989.3,1,"DEV")),"^",1)
 ;
 D ^XBGSAVE
 K @DATA,ZTQUEUED,FLN,ASUFAC,XBS1
 K V,VAL,VISIT,WDA,XBFLG,XBFLG(1),XBPAFN,XBS1,YEAR,YES,ZISHC,ZISHDA1,ZTQUEUED
 Q
 ;
ERR ;
 D ^%ZTER
 NEW Y,ERRDTM
 S Y=$$NOW^XLFDT() X ^DD("DD") S ERRDTM=Y
 S BMXSEC="Recording that an error occurred at "_ERRDTM
 I $D(II),$D(DATA) S II=II+1,@DATA@(II)=$C(31)
 Q
 ;
RTE(PRV) ;EP
 ;S DDATA=""
 S PRVR=$P($G(^VA(200,PRV,"NPI")),U,1)
 ; If provider does not have a National Provider ID
 I PRVR="" D
 . S ASUFAC=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),0)),U,10)
 . S DBID=$P($G(^AUTTLOC($P(^AUTTSITE(1,0),U),1)),U,3)
 . S PRVR=DBID_"_"_PRV
 ;S DDATA=PRVR_U
 S CYR=$E(DT,1,3)
 S FAC=$$HME^BQIGPUTL()
 NEW %,%H,BGPHOME,BQIH,BQIINDF,BQIINDG,BQIMEASF,BQIMEASG,BQIROU,BQIY,BQIYR
 D INP^BQINIGHT
 ;
 S IDD=0
 F  S IDD=$O(^BQI(90508,1,22,CRN,1,IDD)) Q:'IDD  D
 . S ID=$P(^BQI(90508,1,22,CRN,1,IDD,0),U,1),MEAS=$P(^(0),U,4),IID=$P(^(0),U,1)
 . I ID="" Q
 . I $P(^BQI(90508,1,22,CRN,1,IDD,0),U,7)=1 Q
 . ;S NID=$$NID(ID) I NID="" S NID=ID
 . NEW DA,IENS
 . S DA(2)=1,DA(1)=CRN,DA=IDD,IENS=$$IENS^DILF(.DA)
 . S CAT=$$GET1^DIQ(90508.221,IENS,.03,"E")
 . I CAT="" D
 .. S CODE=ID
 .. S RIEN=$O(^BQI(90506.1,"B",CODE,"")) I RIEN="" Q
 .. S CAT=$$GET1^DIQ(90506.1,RIEN_",",3.02,"E")
 . ;
 . S DDATA(PRV,ID)=PRVR_U_IID_U_MEAS_U_$$DATE(DATE)_U
 . I IID="IPC_PEMP" D  Q
 .. S IDN=$O(^BQIFAC(FAC,30,"B",IID,"")) I IDN="" D  Q
 ... S $P(Z(PRV,ID,DATE),U,1)=""
 ... S $P(Z(PRV,ID,DATE),U,2)=""
 .. S MSDN=$O(^BQIFAC(FAC,30,IDN,1,"B",DATE,""))
 .. I MSDN="" Q
 .. S DEN=+$P(^BQIFAC(FAC,30,IDN,1,MSDN,0),U,2),NUM=+$P(^BQIFAC(FAC,30,IDN,1,MSDN,0),U,3)
 .. S $P(Z(PRV,ID,DATE),U,1)=NUM,$P(Z(PRV,ID,DATE),U,2)=DEN
 . ;
 . I IID="IPC_CCTM" D  Q
 .. S TMN=$O(^BSDPCT("AB",PRV,"")) I TMN="" Q
 .. S $P(Z(PRV,ID,DATE),U,1)=""
 .. S $P(Z(PRV,ID,DATE),U,2)=""
 .. S TMN="" F  S TMN=$O(^BSDPCT("AB",PRV,TMN)) Q:TMN=""  D
 ... S TMC=$O(^BQITEAM(TMN,10,"B",IID,"")) I TMC="" Q
 ... S TMV=$O(^BQITEAM(TMN,10,TMC,10,"B",DATE,"")) I TMV="" Q
 ... S DEN=+$P(^BQITEAM(TMN,10,TMC,10,TMV,0),U,2),NUM=+$P(^BQITEAM(TMN,10,TMC,10,TMV,0),U,3)
 ... S $P(Z(PRV,ID,DATE),U,1)=NUM,$P(Z(PRV,ID,DATE),U,2)=DEN
 . ;
 . S IDN=$O(^BQIPROV(PRV,30,"B",IID,"")) I IDN="" D  Q
 .. S $P(Z(PRV,ID,DATE),U,1)=""
 .. S $P(Z(PRV,ID,DATE),U,2)=""
 . D
 .. S MSDN=$O(^BQIPROV(PRV,30,IDN,1,"B",DATE,""))
 .. I MSDN="" Q
 .. S DEN=+$P(^BQIPROV(PRV,30,IDN,1,MSDN,0),U,2),NUM=+$P(^BQIPROV(PRV,30,IDN,1,MSDN,0),U,3)
 .. I IID="IPC_TOTP" D  Q
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