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

BPSOPR2.m

Go to the documentation of this file.
BPSOPR2 ;ALB/PHH - OPECC Productivity Report Compiler ;9/21/2015
 ;;1.0;E CLAIMS MGMT ENGINE;**20**;JUN 2004;Build 27
 ;;Per VA Directive 6402, this routine should not be modified.
 ;
 Q
 ;
COMPILE ; Entry point for the compile to build the scratch global
 ; This may be a background task if the job is queued.
 ;
 D FIND
 D SORT
 D BUILD
 ;
 D PRINT^BPSOPR3                  ; print report
 D ^%ZISC                         ; close the device
 K @BPGLTMP                       ; kill scratch
 I $D(ZTQUEUED) S ZTREQ="@"       ; purge the task
 Q
 ;
BUILD ; Build report
 N BPSSHDR,BPSIDX,S1,S2,BPSRXFC,DATA,BPSDIV,BPSTRDT,BPSUSER,BPSLINE
 ;
 D SUBINIT(.BPSSHDR)
 ;
 S BPSIDX=1
 ;
 ; Export the report to Excel
 I BPEXCEL D
 .; Data is as follows:
 .; DIVISION^USER^CURRENT STATUS^#TRANS IN DT RANGE^#TRANS TOTAL^ELIG^RX#^REF^ECME#^COB^DOS^TRANS DATE^PAID AMT
 .;
 .S S1=""
 .F  S S1=$O(@BPGLTMP@("SORT",S1)) Q:S1=""  D
 ..S S2=0
 ..F  S S2=$O(@BPGLTMP@("SORT",S1,S2)) Q:'S2  D
 ...S BPSRXFC=""
 ...F  S BPSRXFC=$O(@BPGLTMP@("SORT",S1,S2,BPSRXFC)) Q:BPSRXFC=""  D
 ....S DATA=@BPGLTMP@("SORT",S1,S2,BPSRXFC)
 ....S BPSDIV=$P(DATA,U,9),BPSTRDT=$P(DATA,U,11),BPSUSER=$P(DATA,U,10)
 ....S BPSLINE=BPSDIV_"^"
 ....S BPSLINE=BPSLINE_BPSUSER_"^"
 ....S BPSLINE=BPSLINE_$P(DATA,U)_"^"
 ....S BPSLINE=BPSLINE_+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV,BPSUSER)),"^",13)_"^"
 ....S BPSLINE=BPSLINE_+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV)),"^")_"^"
 ....S BPSLINE=BPSLINE_$S($P(DATA,U,2)="V":"VET",$P(DATA,U,2)="T":"TRI",$P(DATA,U,2)="C":"CVA",1:"")_"^"
 ....S BPSLINE=BPSLINE_$P(DATA,U,3)_"^"
 ....S BPSLINE=BPSLINE_$P(DATA,U,4)_"^"
 ....S BPSLINE=BPSLINE_$P(DATA,U,7)_"^"
 ....S BPSLINE=BPSLINE_$S($P(DATA,U,8)=1:"P",$P(DATA,U,8)=2:"S",$P(DATA,U,8)=3:"T",1:"")_"^"
 ....S BPSLINE=BPSLINE_$P(DATA,U,5)_"^"
 ....S BPSLINE=BPSLINE_$$DATTIM^BPSRPT1((BPSTRDT\1))_"^"
 ....I $P(DATA,U)'="NON-BILLABLE" D
 .....S BPSLINE=BPSLINE_$S($P(DATA,U,6)="":"0.00",1:$P(DATA,U,6))
 ....S @BPGLTMP@("REPORT",BPSIDX)=BPSLINE,BPSIDX=BPSIDX+1
 ;
 I 'BPEXCEL D
 .S S1=""
 .F  S S1=$O(@BPGLTMP@("SORT",S1)) Q:S1=""  D
 ..S BPSLINE=$S(BPSSORD=1:"USER NAME: "_S1,1:"DIVISION: "_S1)
 ..S @BPGLTMP@("REPORT",BPSIDX)=BPSLINE,BPSIDX=BPSIDX+1
 ..S BPSLINE=""
 ..D ADDCHAR^BPSOPR3(.BPSLINE,"-",129)
 ..S @BPGLTMP@("REPORT",BPSIDX)=BPSLINE,BPSIDX=BPSIDX+1
 ..S S2=0
 ..F  S S2=$O(@BPGLTMP@("SORT",S1,S2)) Q:'S2  D
 ...S BPSRXFC=""
 ...F  S BPSRXFC=$O(@BPGLTMP@("SORT",S1,S2,BPSRXFC)) Q:BPSRXFC=""  D
 ....S DATA=@BPGLTMP@("SORT",S1,S2,BPSRXFC)
 ....S BPSDIV=$P(DATA,U,9),BPSTRDT=$P(DATA,U,11),BPSUSER=$P(DATA,U,10)
 ....;
 ....; Print details
 ....I BPSUMDET=0 D
 .....S BPSLINE=$E(BPSUSER,1,15)
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",17-$L(BPSLINE))
 .....S BPSLINE=BPSLINE_$E($P(DATA,U),1,19)
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",37-$L(BPSLINE))
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",4-$L(+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV,BPSUSER)),"^",13)))
 .....S BPSLINE=BPSLINE_+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV,BPSUSER)),"^",13)
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",6-$L(+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV)),"^")))
 .....S BPSLINE=BPSLINE_+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV)),"^")
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",7)
 .....S BPSLINE=BPSLINE_$S($P(DATA,U,2)="V":"VET",$P(DATA,U,2)="T":"TRI",$P(DATA,U,2)="C":"CVA",1:"   ")
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",2)
 .....S BPSLINE=BPSLINE_$P(DATA,U,3)
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",71-$L(BPSLINE))
 .....S BPSLINE=BPSLINE_$P(DATA,U,4)_"/"
 .....S BPSLINE=BPSLINE_$P(DATA,U,7)_"   "
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",12-$L($P(DATA,U,7)))
 .....S BPSLINE=BPSLINE_$S($P(DATA,U,8)=1:"P",$P(DATA,U,8)=2:"S",$P(DATA,U,8)=3:"T",1:" ")
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",3)
 .....S BPSLINE=BPSLINE_$P(DATA,U,5)_"   "
 .....D ADDCHAR^BPSOPR3(.BPSLINE," ",9-$L($P(DATA,U,5)))
 .....S BPSLINE=BPSLINE_$$DATTIM^BPSRPT1((BPSTRDT\1))_" "
 .....I $P(DATA,U)'="NON-BILLABLE" D
 ......D ADDCHAR^BPSOPR3(.BPSLINE," ",15-$L($S($P(DATA,U,6)="":"0.00",1:$P(DATA,U,6))))
 ......S BPSLINE=BPSLINE_$S($P(DATA,U,6)="":"0.00",1:$P(DATA,U,6))
 .....S @BPGLTMP@("REPORT",BPSIDX)=BPSLINE,BPSIDX=BPSIDX+1
 ..;
 ..; Print subtotals
 ..D PRTSGHDR(.BPSSHDR,.BPSIDX,S1)
 ..I BPSSORD=0 D PRTSGTOT(.BPSIDX,S1)
 ..I BPSSORD=1 D PRTSGTOT(.BPSIDX,"",S1)
 ..S DATA=""
 ..D ADDCHAR^BPSOPR3(.DATA," ",129)
 ..S @BPGLTMP@("REPORT",BPSIDX)=DATA,BPSIDX=BPSIDX+1
 ..S DATA=""
 ..D ADDCHAR^BPSOPR3(.DATA," ",129)
 ..S @BPGLTMP@("REPORT",BPSIDX)=DATA,BPSIDX=BPSIDX+1
 ..S DATA=""
 ..D ADDCHAR^BPSOPR3(.DATA,"-",129)
 ..S @BPGLTMP@("REPORT",BPSIDX)=DATA,BPSIDX=BPSIDX+1
 .;
 .I '$D(@BPGLTMP@("REPORT"))!(BPSIDX=1) Q
 .S DATA=""
 .D ADDCHAR^BPSOPR3(.DATA,"-",129)
 .I @BPGLTMP@("REPORT",BPSIDX-1)=DATA D
 ..K @BPGLTMP@("REPORT",BPSIDX-1) S BPSIDX=BPSIDX-1
 ..K @BPGLTMP@("REPORT",BPSIDX-1) S BPSIDX=BPSIDX-1
 ..K @BPGLTMP@("REPORT",BPSIDX-1) S BPSIDX=BPSIDX-1
 .;
 .; Print summary
 .D PRTSGHDR(.BPSSHDR,.BPSIDX)
 .D PRTSGTOT(.BPSIDX)
 ;
 I '$D(@BPGLTMP@("REPORT"))!(BPSIDX=1) D
 .S @BPGLTMP@("REPORT",BPSIDX)="No data available for date range."
 Q
 ;
PRTSGTOT(BPSIDX,BPSDIV,BPSUSER) ; Print grand/subtotals
 N X,BPSUSRNM,BPSDIV1
 ;
 Q:BPSIDX=""
 S BPSDIV=$G(BPSDIV,"")
 S BPSUSER=$G(BPSUSER,"")
 ;
 I BPSUSER="",BPUSER=1 D
 .S X=0
 .F  S X=$O(BPUSER(X)) Q:'X  S BPSUSRNM($P(BPUSER(X),U,2))=""
 .;
 .S BPSUSER=""
 .F  S BPSUSER=$O(BPSUSRNM(BPSUSER)) Q:BPSUSER=""  D
 ..D PRTUTOT(.BPSIDX,BPSDIV,BPSUSER)
 ;
 I BPSUSER="",BPUSER=0 D
 .S BPSDIV1=""
 .F  S BPSDIV1=$O(@BPGLTMP@("USRTOT",BPSDIV1)) Q:BPSDIV1=""  D
 ..S BPSUSER=""
 ..F  S BPSUSER=$O(@BPGLTMP@("USRTOT",BPSDIV1,BPSUSER)) Q:BPSUSER=""  D
 ...S BPSUSRNM(BPSUSER)=""
 .;
 .S BPSUSER=""
 .F  S BPSUSER=$O(BPSUSRNM(BPSUSER)) Q:BPSUSER=""  D
 ..D PRTUTOT(.BPSIDX,BPSDIV,BPSUSER)
 ;
 I BPSUSER'="" D
 .D PRTUTOT(.BPSIDX,BPSDIV,BPSUSER)
 Q
 ;
PRTUTOT(BPSIDX,BPSDIV,BPSUSER) ; Print user totals
 N BPSPYNR,BPSPYREJ,BPSTAMT,BPSTTRN,BPSDIV1,BPSLINE
 ;
 Q:BPSIDX=""
 S BPSDIV=$G(BPSDIV,"")
 Q:BPSUSER=""
 ;
 S (BPSPYNR,BPSPYREJ,BPSTAMT,BPSTTRN)=0
 I BPSDIV'="" D
 .S BPSPYNR=+$P($G(@BPGLTMP@("USRTOT",BPSDIV,BPSUSER)),"^",2)
 .S BPSPYREJ=+$P($G(@BPGLTMP@("USRTOT",BPSDIV,BPSUSER)),"^",3)
 .S BPSTAMT=+$P($G(@BPGLTMP@("USRTOT",BPSDIV,BPSUSER)),"^")
 I BPSDIV="" D
 .S BPSDIV1=""
 .F  S BPSDIV1=$O(@BPGLTMP@("USRTOT",BPSDIV1)) Q:BPSDIV1=""  D
 ..Q:'$D(@BPGLTMP@("USRTOT",BPSDIV1,BPSUSER))
 ..S BPSPYNR=BPSPYNR+$P($G(@BPGLTMP@("USRTOT",BPSDIV1,BPSUSER)),"^",2)
 ..S BPSPYREJ=BPSPYREJ+$P($G(@BPGLTMP@("USRTOT",BPSDIV1,BPSUSER)),"^",3)
 ..S BPSTAMT=BPSTAMT+(+$P($G(@BPGLTMP@("USRTOT",BPSDIV1,BPSUSER)),"^"))
 S BPSTTRN=$$TOTTRN(BPSDIV,BPSUSER)
 ;
 S BPSLINE=$E(BPSUSER,1,15)
 D ADDCHAR^BPSOPR3(.BPSLINE," ",17-$L(BPSLINE))
 S BPSLINE=BPSLINE_BPSPYREJ
 D ADDCHAR^BPSOPR3(.BPSLINE," ",41-$L(BPSLINE))
 S BPSLINE=BPSLINE_BPSPYNR
 D ADDCHAR^BPSOPR3(.BPSLINE," ",69-$L(BPSLINE))
 D ADDCHAR^BPSOPR3(.BPSLINE," ",5-$L(BPSTTRN))
 S BPSLINE=BPSLINE_BPSTTRN
 D ADDCHAR^BPSOPR3(.BPSLINE," ",89-$L(BPSLINE))
 S BPSTAMT=$J(BPSTAMT,7,2)
 D ADDCHAR^BPSOPR3(.BPSLINE," ",15-$L(BPSTAMT))
 S BPSLINE=BPSLINE_BPSTAMT
 ;
 I BPSDIV'="",'$D(@BPGLTMP@("USRTOT",BPSDIV,BPSUSER)) Q
 S @BPGLTMP@("REPORT",BPSIDX)=BPSLINE,BPSIDX=BPSIDX+1
 Q
 ;
TOTTRN(BPSDIV,BPSUSER) ; Get total transactions for a user
 N BPSCNT,BPSTRDT,BPSRXFC,BPSDIV1
 ;
 S BPSDIV=$G(BPSDIV,"")
 Q:BPSUSER=""
 ;
 S BPSCNT=0
 I BPSDIV'="" D
 .S BPSRXFC=""
 .F  S BPSRXFC=$O(@BPGLTMP@("DATA",BPSRXFC)) Q:BPSRXFC=""  D
 ..S BPSCNT=BPSCNT+(+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV,BPSUSER)),"^",13))
 I BPSDIV="" D
 .S BPSRXFC=""
 .F  S BPSRXFC=$O(@BPGLTMP@("DATA",BPSRXFC)) Q:BPSRXFC=""  D
 ..S BPSDIV1=""
 ..F  S BPSDIV1=$O(@BPGLTMP@("DATA",BPSRXFC,BPSDIV1)) Q:BPSDIV1=""  D
 ...Q:'$D(@BPGLTMP@("DATA",BPSRXFC,BPSDIV1,BPSUSER))
 ...S BPSCNT=BPSCNT+(+$P($G(@BPGLTMP@("DATA",BPSRXFC,BPSDIV1,BPSUSER)),"^",13))
 Q BPSCNT
 ;
PRTSGHDR(BPSSHDR,BPSIDX,BPSSGHTX) ; Print subtotals/grand header
 N BPSLINE,BPSCNT
 ;
 S BPSSGHTX=$G(BPSSGHTX,"")
 S BPSSHDR(2)=$S(BPSSGHTX="":"GRAND TOTAL",1:"SUBTOTALS FOR "_BPSSGHTX)
 ;
 F BPSCNT=1:1:4 D
 .S BPSLINE=BPSSHDR(BPSCNT)
 .S @BPGLTMP@("REPORT",BPSIDX)=BPSLINE,BPSIDX=BPSIDX+1
 Q
 ;
SUBINIT(BPSSHDR) ; Set up subtotals header
 S BPSSHDR(1)=""
 S BPSSHDR(3)="                REJECTED AND           NOT REJECTED AND PAYABLE"
 S BPSSHDR(4)="USER            RESOLVED TO PAYABLE    (POSSIBLE BACK-BILL)            TRANS IN DT RANGE     AMOUNT PAID"
 Q
 ;
FIND ; Find records
 N BPLDT57,BP57
 K @BPGLTMP
 ;
 I 'BPEXCEL,'$D(ZTQUEUED) U 0 W !!,"Compiling OPECC Productivity Report.  Please wait ... ",! U IO
 ;
 ; Check Variables
 S:'$G(BPBEGDT) BPBEGDT=0
 S:'$G(BPENDDT) BPENDDT=9999999
 S BPENDDT=BPENDDT+0.9
 ;
 ; Loop through BPS LOG OF TRANSACTIONS file #9002313.57
 S BPLDT57=BPBEGDT-0.00001
 F  S BPLDT57=+$O(^BPSTL("AH",BPLDT57)) Q:BPLDT57=0!(BPLDT57>BPENDDT)  D
 .S BP57=0
 .F  S BP57=$O(^BPSTL("AH",BPLDT57,BP57)) Q:'BP57  D PROCESS^BPSOPR3(BP57)
 Q
 ;
CALCREJ(BPSDIV,BPSUSER,BPRX,BPREF,BPSCOB) ; Calculate reject counts
 ; Returns 1 if reject found, otherwise returns 0
 N BP57,BPSRCNT
 ;
 S (BP57,BPSRCNT)=0
 F  S BP57=$O(^BPSTL("AEC",BPRX,BP57)) Q:'BP57!(BPSRCNT)  D
 .I BPSUSER'=$P($G(^VA(200,+$P($G(^BPSTL(BP57,0)),U,10),0)),U) Q
 .I BPSDIV'=$P($G(^BPS(9002313.56,+$P($G(^BPSTL(BP57,1)),U,7),0)),U) Q
 .I BPREF'=+$P($G(^BPSTL(BP57,1)),U) Q
 .I BPSCOB'=$P($G(^BPSTL(BP57,0)),U,14) Q
 .I $G(^BPSTL(BP57,2))'["Rejected" Q
 .S BPSRCNT=1
 Q BPSRCNT
 ;
ECMENUM(BP57) ; ECME number
 ; Returns ECME number from 9002313.02 as:
 ; 7 or 12 digits of the prescription IEN file 52
 ; or 12 spaces
 N BPST0,PC,PF,BPST4,PR,X
 ;
 S BPST0=$G(^BPSTL(BP57,0)),PC=$P(BPST0,U,4),PF=$P(BPST0,U,9)
 S BPST4=$G(^BPSTL(BP57,4)),PR=$P(BPST4,U,1)
 I PR]"" S PC=PR ;This is a reversal
 I PC=""!(PF="") Q $$FORMAT^BPSSCRU2("",12," ",1)
 S X=$P($G(^BPSC(PC,400,PF,400)),U,2)
 I X="" Q $$FORMAT^BPSSCRU2(X,12," ",1)
 Q $E(X,3,14)
 ;
GETRXFCI(BPSDIV,BPRX,BPREF,BPSCOB) ; Get general RXFC info
 ; Returns: paid amount ^ total transactions ^ IEN of 57 ^ transaction
 ;          type of last matching BP57 found
 ;
 N BPRETVAL,BP57,BPSPAMT,BPSTOTTN,BPSEC,BPSTRTYP
 ;
 S BPRETVAL="0^0^0^",(BP57,BPSPAMT,BPSTOTTN)=0,(BPSEC,BPSTRTYP)=""
 F  S BP57=$O(^BPSTL("AEC",BPRX,BP57)) Q:'BP57  D
 .Q:BPSDIV'=$P($G(^BPS(9002313.56,+$P($G(^BPSTL(BP57,1)),U,7),0)),U)
 .Q:BPREF'=+$P($G(^BPSTL(BP57,1)),U)
 .Q:BPSCOB'=$P($G(^BPSTL(BP57,0)),U,14)
 .Q:$P($G(^BPSTL(BP57,0)),U,15)="E"
 .I '$F(".BB.ERES.ERWV.ERNB.EREV.P2.P2S.","."_$P($G(^BPSTL(BP57,12)),U,1)_".") Q
 .Q:$P($G(^BPSTL(BP57,0)),U,8)=""
 .S BPSEC=$P($G(^BPSTL(BP57,9)),U,4)
 .Q:BPSEC=""
 .I BPELIG=1,'$D(BPELIG(BPSEC)) Q
 .S BPSPAMT=$$TOTAMNT^BPSSCRLG(+$P($G(^BPSTL(BP57,0)),U,5))
 .S BPSTOTTN=BPSTOTTN+1
 .S BPSTRTYP=$P($G(^BPSTL(BP57,0)),U,15)
 .S BPRETVAL=BPSPAMT_"^"_BPSTOTTN_"^"_BP57_"^"_BPSTRTYP
 Q BPRETVAL
 ;
SORT ; Sort report based on divison or user
 N BPSRXFC,BPSDIV,BPSUSER,DATA,S1,S2,S3
 ;
 S BPSRXFC=""
 F  S BPSRXFC=$O(@BPGLTMP@("DATA",BPSRXFC)) Q:BPSRXFC=""  D
 .S BPSDIV=""
 .F  S BPSDIV=$O(@BPGLTMP@("DATA",BPSRXFC,BPSDIV)) Q:BPSDIV=""  D
 ..S BPSUSER=""
 ..F  S BPSUSER=$O(@BPGLTMP@("DATA",BPSRXFC,BPSDIV,BPSUSER)) Q:BPSUSER=""  D
 ...S DATA=@BPGLTMP@("DATA",BPSRXFC,BPSDIV,BPSUSER)
 ...S S1=$S(BPSSORD=1:$P(DATA,"^",10),1:$P(DATA,"^",9))
 ...S S2=$P(DATA,"^",11)
 ...S S3=BPSRXFC
 ...S @BPGLTMP@("SORT",S1,S2,S3)=DATA
 Q
 ;