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

PSOPROD2.m

Go to the documentation of this file.
  1. PSOPROD2 ;ALB/MRD - Pharmacy Productivity and Revenue Report ;9/8/15
  1. ;;7.0;OUTPATIENT PHARMACY;**448**;DEC 1997;Build 25
  1. ;Reference to $$BPSINSCO^BPSUTIL supported by IA 4410
  1. ;Reference to $$PAIDAMNT^BPSUTIL supported by IA 4146
  1. ;Reference to $$STATUS^BPSOSRX supported by IA 4412
  1. ;Reference to File 9002313.93 - BPS NCPDP REJECT CODES supported by IA 4720
  1. ;
  1. Q
  1. ;
  1. EN ; Main entry point for compile and print.
  1. ;
  1. K ^TMP("PSOPRODA",$J),^TMP("PSOPRODB",$J)
  1. ;
  1. D COMPILE
  1. D PRINT
  1. ;
  1. K ^TMP("PSOPRODA",$J),^TMP("PSOPRODB",$J)
  1. ;
  1. I $D(ZTQUEUED) S ZTREQ="@" ; If queued, purge the task after exiting.
  1. ;
  1. Q
  1. ;
  1. COMPILE ; Compile data for report.
  1. ;
  1. ; Variables assumed to exist from EN^PSOPROD1:
  1. ; PSODIV - Either equal to "ALL", or an array of each Division
  1. ; selected by the user to be included.
  1. ; PSODTBEGIN - Earliest Date Resolved to include.
  1. ; PSODTEND - Latest Date Resolved to include.
  1. ; PSOINCLUDE - Populated when user selects which to include.
  1. ; The user can selected by PATIENT, DRUG, RX, INSURANCE
  1. ; or REJECT CODE. (For more info, see comments in ^PSOPROD1.)
  1. ; PSOREPORT - "P" for Productivity report, "R" for Revenue report.
  1. ; PSOSORT - D/R/B/N/C to indicate the primary sort (Division, date
  1. ; Resolved, resolved By, drug Name, reject Code).
  1. ; PSOSTATUS - "P" to include E Payable rejects, "R" to include E
  1. ; Rejected rejects, "B" in include both.
  1. ;
  1. ; The data to be displayed on the report is compiled into the ^TMP
  1. ; array in the following format:
  1. ; ^TMP("PSOPRODA",$J,SortValue,Rx,Fill,Reject) = Data
  1. ; SortValue - Value of the field corresponding to the SortCode,
  1. ; such as Division, Drug Name or Reject Code.
  1. ; Rx - Prescription Number - file #52, IEN.
  1. ; Fill - Refill Number - file #52.25, field #5.
  1. ; Reject - Reject Number - file #52.25, IEN.
  1. ; Data =
  1. ; [1] Release Date - file #52, field #31, or sub-file #52.1, field #17.
  1. ; [2] Date Rejected - sub-file #52.25, field #1.
  1. ; [3] Date Resolved - sub-file #52.25, field #10.
  1. ; [4] Resolved By - sub-file #52.25, field #11.
  1. ; [5] Action Taken - file #52.25, field #12.
  1. ; [6] Amount Paid - sub-file #9002313.0301, field #509.
  1. ; [7] Insurance Name - file #9002313.59, field #902.33.
  1. ; [8] Drug - file #52, field #6.
  1. ; [9] Rejection - sub-file #52.25, field #.01.
  1. ; [10] Division - file #52, field #20.
  1. ; [11] Patient - file #52, field #2.
  1. ; [12] E-Payable? - 1 if ECME Status is E PAYABLE.
  1. ;
  1. N PSOACTION,PSOCOB,PSODATA,PSODIVISION,PSODATE,PSODRUG
  1. N PSODTREJECTED,PSODTRESLVDA,PSODTRESLVDB,PSOECMESTATUS
  1. N PSOEPAYABLE,PSOFILL,PSOINSURANCE,PSOPAIDAMT,PSOPATIENT
  1. N PSOREJ,PSOREJCODEA,PSOREJCODEB,PSORESLVDBYA,PSORESLVDBYB
  1. N PSORX,PSOSORTB
  1. ;
  1. I IOST["C-",'PSOEXCEL W !,"Compiling..."
  1. ;
  1. ; All closed/resolved rejects will appear in the "CLSDAT" cross-
  1. ; reference: ^PSRX("CLSDAT",Closed Date/Time,Rx,Reject). Loop
  1. ; through them and include those that meet the filter criteria.
  1. ;
  1. S PSODATE=PSODTEND+.999999
  1. F S PSODATE=$O(^PSRX("CLSDAT",PSODATE),-1) Q:PSODATE="" Q:(PSODATE\1)<PSODTBEGIN D
  1. . S PSORX=""
  1. . F S PSORX=$O(^PSRX("CLSDAT",PSODATE,PSORX)) Q:PSORX="" D
  1. . . ;
  1. . . ; Check to see if this Rx/Reject should be included.
  1. . . ;
  1. . . I PSOINCLUDE("RX")'="ALL",'$D(PSOINCLUDE("RX",PSORX)) Q
  1. . . ;
  1. . . ; Check to see if this Patient should be included.
  1. . . ;
  1. . . S PSOPATIENT=$$GET1^DIQ(52,PSORX,2,"I")
  1. . . I PSOINCLUDE("PATIENT")'="ALL",'$D(PSOINCLUDE("PATIENT",PSOPATIENT)) Q
  1. . . ;
  1. . . ; Check to see if this Drug should be included.
  1. . . ;
  1. . . S PSODRUG=$$GET1^DIQ(52,PSORX,6,"I")
  1. . . I PSOINCLUDE("DRUG")'="ALL",'$D(PSOINCLUDE("DRUG",PSODRUG)) Q
  1. . . S PSODRUG=$$GET1^DIQ(50,PSODRUG_",",.01)
  1. . . ;
  1. . . ; Check to see if this Division should be included.
  1. . . ;
  1. . . S PSODIVISION=$$GET1^DIQ(52,PSORX,20,"I")
  1. . . I PSODIV'="ALL",'$D(PSODIV(PSODIVISION)) Q
  1. . . ;
  1. . . S PSOREJ=""
  1. . . F S PSOREJ=$O(^PSRX("CLSDAT",PSODATE,PSORX,PSOREJ)) Q:PSOREJ="" D
  1. . . . ;
  1. . . . ; For the RRR Revenue report, skip if RRR flag is not set.
  1. . . . ;
  1. . . . I PSOREPORT="R",'$$GET1^DIQ(52.25,PSOREJ_","_PSORX,30,"I") Q
  1. . . . ;
  1. . . . ; Check to see if this Reject Code should be included.
  1. . . . ;
  1. . . . S PSOREJCODEA=$$GET1^DIQ(52.25,PSOREJ_","_PSORX_",",.01)
  1. . . . I PSOINCLUDE("REJECT CODE")'="ALL",'$D(PSOINCLUDE("REJECT CODE",PSOREJCODEA)) Q
  1. . . . S PSOREJCODEB=PSOREJCODEA
  1. . . . ;
  1. . . . ; Determine Fill# and COB.
  1. . . . ;
  1. . . . S PSOFILL=$$GET1^DIQ(52.25,PSOREJ_","_PSORX_",",5)
  1. . . . I PSOFILL="" S PSOFILL=0
  1. . . . S PSOCOB=$$GET1^DIQ(52.25,PSOREJ_","_PSORX_",",27,"I")
  1. . . . I PSOCOB="" S PSOCOB=1
  1. . . . ;
  1. . . . ; If any unresolved rejects, Quit.
  1. . . . ;
  1. . . . I $$FIND^PSOREJUT(PSORX,PSOFILL,,,1) Q
  1. . . . ;
  1. . . . ; Pull Date Rejected, Date Resolved, Resolved By, Action Taken
  1. . . . ; and Paid Amount.
  1. . . . ;
  1. . . . S PSODTREJECTED=$$GET1^DIQ(52.25,PSOREJ_","_PSORX_",",1,"I")\1 ; Date Rejected.
  1. . . . S PSODTRESLVDA=PSODATE\1 ; Date Resolved.
  1. . . . S PSORESLVDBYA=$$GET1^DIQ(52.25,PSOREJ_","_PSORX_",",11,"I") ; Resolved By.
  1. . . . S PSOACTION=$$GET1^DIQ(52.25,PSOREJ_","_PSORX_",",12) ; Action Taken.
  1. . . . S PSODTRESLVDB=PSODTRESLVDA,PSORESLVDBYB=PSORESLVDBYA
  1. . . . S PSOPAIDAMT=$P($$PAIDAMNT^BPSUTIL(PSORX,PSOFILL),U,2) ; Amount Paid; IA 4146.
  1. . . . I PSOPAIDAMT'="" S PSOPAIDAMT=$J(PSOPAIDAMT,1,2)
  1. . . . ;
  1. . . . I $$ECMEINS(.PSOEPAYABLE) D ADDLINE
  1. . . . ;
  1. . . . ; If the report type is RRR Revenue report, then conditionally
  1. . . . ; display all subsequent refills on the Prescription.
  1. . . . ;
  1. . . . I PSOREPORT="R" D
  1. . . . . ;
  1. . . . . ; Clear out those data elements that are based on the Reject
  1. . . . . ; and not the Prescription.
  1. . . . . ;
  1. . . . . S PSODTREJECTED=""
  1. . . . . S PSODTRESLVDB=""
  1. . . . . S PSORESLVDBYB=""
  1. . . . . S PSOACTION=""
  1. . . . . S PSOREJCODEB=""
  1. . . . . ;
  1. . . . . F S PSOFILL=$O(^PSRX(PSORX,1,PSOFILL)) Q:'PSOFILL D
  1. . . . . . S PSOPAIDAMT=$P($$PAIDAMNT^BPSUTIL(PSORX,PSOFILL),U,2) ; Amount Paid; IA 4146.
  1. . . . . . I PSOPAIDAMT'="" S PSOPAIDAMT=$J(PSOPAIDAMT,1,2)
  1. . . . . . I $$ECMEINS(.PSOEPAYABLE) D ADDLINE
  1. . . . . . Q
  1. . . . . Q
  1. . . . Q
  1. . . Q
  1. . Q
  1. ;
  1. Q
  1. ;
  1. ECMEINS(PSOEPAYABLE) ; Check ECME Status and Insurance Company.
  1. ;
  1. ; Determine ECME Status and Insurance. Check to see if this ECME
  1. ; Status and this Insurance should be included. If not, Quit 0.
  1. ; If it passes the checks, Quit 1. The variable EPAYABLE, passed
  1. ; by reference, gets set to 1 if the ECME status is E PAYABLE.
  1. ;
  1. S PSOEPAYABLE=0
  1. S PSOECMESTATUS=$P($$STATUS^BPSOSRX(PSORX,PSOFILL,,,PSOCOB),U,1) ; IA 4412.
  1. I PSOECMESTATUS'="E PAYABLE",PSOECMESTATUS'="E REJECTED" Q 0
  1. I PSOECMESTATUS="E PAYABLE",PSOSTATUS="R" Q 0
  1. I PSOECMESTATUS="E REJECTED",PSOSTATUS="P" Q 0
  1. I PSOECMESTATUS="E PAYABLE" S PSOEPAYABLE=1
  1. ;
  1. S PSOINSURANCE=$$BPSINSCO^BPSUTIL(PSORX,PSOFILL) ; IA 4410.
  1. I PSOINCLUDE("INSURANCE")'="ALL",'$D(PSOINCLUDE("INSURANCE",PSOINSURANCE)) Q 0
  1. ;
  1. Q 1
  1. ;
  1. ADDLINE ; Add one Rx/Fill to the ^TMP global.
  1. ;
  1. I PSOFILL=0 S PSODATA=$$GET1^DIQ(52,PSORX_",",31,"I")\1 ; Release Date.
  1. I PSOFILL>0 S PSODATA=$$GET1^DIQ(52.1,PSOFILL_","_PSORX_",",17,"I")\1 ; Release Date.
  1. I +PSODATA=0 S PSODATA=""
  1. S PSODATA=PSODATA_"^"_PSODTREJECTED ; Date Rejected.
  1. S PSODATA=PSODATA_"^"_PSODTRESLVDB ; Date Resolved.
  1. S PSODATA=PSODATA_"^"_PSORESLVDBYB ; Resolved By.
  1. S PSODATA=PSODATA_"^"_PSOACTION ; Action Taken.
  1. S PSODATA=PSODATA_"^"_PSOPAIDAMT ; Amount Paid
  1. S PSODATA=PSODATA_"^"_PSOINSURANCE ; Insurance Name.
  1. S PSODATA=PSODATA_"^"_PSODRUG ; Drug.
  1. S PSODATA=PSODATA_"^"_PSOREJCODEB ; Rejection.
  1. S PSODATA=PSODATA_"^"_PSODIVISION ; Division.
  1. S PSODATA=PSODATA_"^"_PSOPATIENT ; Patient.
  1. S PSODATA=PSODATA_"^"_PSOEPAYABLE ; E-Payable?
  1. ;
  1. ; Determine the first sort level, indicated by the user. Possible
  1. ; sorts are Division, Date Resolved, User Resolved By, Drug Name
  1. ; and Reject Code.
  1. ;
  1. S PSOSORTB=$S(PSOSORT="D":PSODIVISION,PSOSORT="R":PSODTRESLVDA,PSOSORT="B":PSORESLVDBYA,PSOSORT="N":PSODRUG,PSOSORT="C":PSOREJCODEA,1:" ")
  1. ;
  1. ; If there is already a resolved reject for this Rx/Fill, then reset
  1. ; the Amount Paid field to "*****" for the current reject. Since we
  1. ; are looping through the rejects in reverse chronological order, the
  1. ; result will be that only the most recently resolved reject will
  1. ; display the dollar amount instead of both of them.
  1. ;
  1. I $D(^TMP("PSOPRODB",$J,PSORX,PSOFILL)) S $P(PSODATA,U,6)="*****"
  1. S ^TMP("PSOPRODB",$J,PSORX,PSOFILL)=""
  1. ;
  1. ; Add to ^TMP global.
  1. ;
  1. S ^TMP("PSOPRODA",$J,PSOSORTB,PSORX,PSOFILL,PSOREJ)=PSODATA
  1. ;
  1. Q
  1. ;
  1. PRINT ; Print report data.
  1. ;
  1. ; Variables assumed to exist from EN^PSOPROD1:
  1. ; PSODIV - Either equal to "ALL", or an array of each Division
  1. ; selected by the user to be included.
  1. ; PSODTBEGIN - Earliest Date Resolved to include.
  1. ; PSODTEND - Latest Date Resolved to include.
  1. ; PSOEXCEL - 1 if user requested Excel format, otherwise 0.
  1. ; PSOINCLUDE - Populated when user selects which to include.
  1. ; The user can selected by PATIENT, DRUG, RX, INSURANCE
  1. ; or REJECT CODE. (For more info, see comments in ^PSOPROD1.)
  1. ; PSOREPORT - "P" for Productivity report, "R" for Revenue report.
  1. ; PSOSHOWPAT - 1 if user wants patient names displayed, else 0.
  1. ; PSOSORT - D/R/B/N/C to indicate the primary sort (Division, date
  1. ; Resolved, resolved By, drug Name, reject Code).
  1. ; PSOSTATUS - "P" to include E Payable rejects, "R" to include E
  1. ; Rejected rejects, "B" in include both.
  1. ;
  1. N DIR,PSOCRT,PSODASHES,PSODATA,PSOFILL,PSOPAGE,PSORX
  1. N PSOSORTB,PSOSTOP,PSOX,Y
  1. ;
  1. S PSOCRT=$S(IOST["C-":1,1:0)
  1. I PSOEXCEL S IOSL=999999 ; Ensure long screen length for Excel output.
  1. S PSOPAGE=0,PSOSTOP=0,$P(PSODASHES,"=",113)=""
  1. I PSOINCLUDE="PATIENT",'PSOEXCEL,'PSOSHOWPAT S PSOINCLUDE("PATIENT")=""
  1. ;
  1. D HDR
  1. I '$D(^TMP("PSOPRODA",$J)) W:'PSOEXCEL !!?5,"No data meets the criteria." G PX
  1. ;
  1. S PSOSORTB=""
  1. F S PSOSORTB=$O(^TMP("PSOPRODA",$J,PSOSORTB)) Q:PSOSORTB=""!PSOSTOP D
  1. . S PSORX=""
  1. . F S PSORX=$O(^TMP("PSOPRODA",$J,PSOSORTB,PSORX)) Q:PSORX=""!PSOSTOP D
  1. . . S PSOFILL=""
  1. . . F S PSOFILL=$O(^TMP("PSOPRODA",$J,PSOSORTB,PSORX,PSOFILL)) Q:PSOFILL=""!PSOSTOP D
  1. . . . S PSOREJ=""
  1. . . . F S PSOREJ=$O(^TMP("PSOPRODA",$J,PSOSORTB,PSORX,PSOFILL,PSOREJ)) Q:PSOREJ=""!PSOSTOP D
  1. . . . . S PSODATA=$G(^TMP("PSOPRODA",$J,PSOSORTB,PSORX,PSOFILL,PSOREJ))
  1. . . . . ;
  1. . . . . ; If Excel, write the formatted line then Quit.
  1. . . . . ;
  1. . . . . I PSOEXCEL D EXCELN Q
  1. . . . . ;
  1. . . . . I $Y+3>IOSL D HDR I PSOSTOP Q
  1. . . . . ;
  1. . . . . W !,$$GET1^DIQ(52,PSORX_",",.01),"/",PSOFILL
  1. . . . . W ?12,$$FMTE^XLFDT($P(PSODATA,U,1),"2Z") ; Release Date.
  1. . . . . W ?22,$$FMTE^XLFDT($P(PSODATA,U,2),"2Z") ; Date Rejected.
  1. . . . . W ?35,$$FMTE^XLFDT($P(PSODATA,U,3),"2Z") ; Date Resolved.
  1. . . . . I $P(PSODATA,U,4)'="" W ?48,$E($$GET1^DIQ(200,$P(PSODATA,U,4)_",",.01),1,16) ; Resolved By.
  1. . . . . E I '$P(PSODATA,U,12) W ?48,"*Not ePayable*" ; E-Payable?
  1. . . . . W ?65,$E($P(PSODATA,U,5),1,21) ; Action Taken.
  1. . . . . W ?87,$J($P(PSODATA,U,6),10) ; Amount Paid.
  1. . . . . W ?99,$E($$GET1^DIQ(36,$P(PSODATA,U,7)_",",.01),1,13) ; Insurance Name.
  1. . . . . W !?4,$E($P(PSODATA,U,8),1,31) ; Drug.
  1. . . . . I $P(PSODATA,U,9)'="" D ; Rejection.
  1. . . . . . S PSOX=$O(^BPSF(9002313.93,"B",$P(PSODATA,U,9),"")) ; IA 4720.
  1. . . . . . S PSOX=$$GET1^DIQ(9002313.93,PSOX_",",.02) ; IA 4720.
  1. . . . . . W ?36,$E($P(PSODATA,U,9)_" - "_PSOX,1,29)
  1. . . . . . Q
  1. . . . . W ?66,$E($$GET1^DIQ(59,$P(PSODATA,U,10)_",",.01),1,17) ; Division.
  1. . . . . I PSOSHOWPAT W ?84,$E($$GET1^DIQ(2,$P(PSODATA,U,11)_",",.01),1,18) ; Patient.
  1. . . . . ;
  1. . . . . Q
  1. . . . Q
  1. . . Q
  1. . Q
  1. ;
  1. I PSOSTOP G PRINTX
  1. I $Y+4>IOSL D HDR I PSOSTOP G PRINTX
  1. I 'PSOEXCEL W !!?5,"*** End of Report ***"
  1. ;
  1. PX ;
  1. I PSOCRT S DIR(0)="E" W ! D ^DIR K DIR
  1. PRINTX ;
  1. Q
  1. ;
  1. EXCELN ; Write one line in Excel format.
  1. ;
  1. N PSOX
  1. ;
  1. W !,$$GET1^DIQ(52,PSORX_",",.01)_"/"_PSOFILL,"^" ; Rx / Fill.
  1. W $$FMTE^XLFDT($P(PSODATA,U,1),"2Z"),"^" ; Release Date.
  1. W $$FMTE^XLFDT($P(PSODATA,U,2),"2Z"),"^" ; Date Rejected.
  1. W $$FMTE^XLFDT($P(PSODATA,U,3),"2Z"),"^" ; Date Resolved.
  1. W $$GET1^DIQ(200,$P(PSODATA,U,4)_",",.01),"^" ; Resolved By.
  1. W $P(PSODATA,U,5),"^" ; Action Taken.
  1. W $P(PSODATA,U,6),"^" ; Amount Paid.
  1. W $$GET1^DIQ(36,$P(PSODATA,U,7)_",",.01),"^" ; Insurance Name.
  1. W $P(PSODATA,U,8),"^" ; Drug
  1. S PSOX=""
  1. I $P(PSODATA,U,9)'="" D ; Rejection.
  1. . S PSOX=$O(^BPSF(9002313.93,"B",$P(PSODATA,U,9),"")) ; IA 4720.
  1. . S PSOX=$P(PSODATA,U,9)_" - "_$$GET1^DIQ(9002313.93,PSOX_",",.02) ; IA 4720.
  1. . Q
  1. W PSOX,"^" ; Rejection.
  1. W $$GET1^DIQ(59,$P(PSODATA,U,10)_",",.01),"^" ; Division.
  1. W $$GET1^DIQ(2,$P(PSODATA,U,11)_",",.01),"^" ; Patient.
  1. W $S($P(PSODATA,U,12):"Y",1:"N") ; E-Payable?
  1. ;
  1. Q
  1. ;
  1. HDR ; Write the report header.
  1. ;
  1. ; If PAGE (i.e. not the first page) and device is the screen, do an
  1. ; end-of-page reader call. If PAGE or screen output, do a form feed.
  1. ; If this is the first page ('PSOPAGE), and device is file or printer
  1. ; ('PSOCRT), reset the left margin ($C(13)).
  1. ;
  1. I PSOPAGE,PSOCRT S DIR(0)="E" D ^DIR K DIR I 'Y S PSOSTOP=1 G HDRX
  1. I PSOPAGE!PSOCRT W @IOF
  1. I 'PSOPAGE,'PSOCRT W $C(13)
  1. S PSOPAGE=PSOPAGE+1
  1. ;
  1. ; For Excel format, display only the column headers then exit.
  1. ;
  1. I PSOEXCEL D EXCELHDR G HDRX
  1. ;
  1. ; Write the report header.
  1. ;
  1. I PSOREPORT="P" W "Pharmacy Productivity Report"
  1. E W "RRR Revenue Report"
  1. W ?58,"Print Date: ",$$FMTE^XLFDT($$NOW^XLFDT,"1M")
  1. W ?97,"Page: ",PSOPAGE
  1. W !,"Selected Divisions: ",PSODIV
  1. W !,"Date Reject Resolved: ",$$FMTE^XLFDT(PSODTBEGIN,"2Z")," - ",$$FMTE^XLFDT(PSODTEND,"2Z")
  1. I PSOSTATUS(0)'="" W ?50,"Status: ",PSOSTATUS(0)
  1. I PSOINCLUDE(PSOINCLUDE)="" W !,"Select by ",PSOINCLUDE
  1. E W !,$E("Select by "_PSOINCLUDE_": "_PSOINCLUDE(PSOINCLUDE),1,132)
  1. W !,"Sort by ",PSOSORT(0)
  1. ;
  1. ; Write the column headers.
  1. ;
  1. W !,PSODASHES
  1. W !,"RX#/FILL",?12,"REL DATE",?22,"DT REJECTED",?35,"DT RESOLVED"
  1. W ?48,"RESOLVED BY",?65,"ACTION TAKEN",?89,"AMT PAID",?98,"INSURANCE NAME"
  1. W !?4,"DRUG",?36,"REJECTION",?66,"DIVISION"
  1. I PSOSHOWPAT W ?84,"PATIENT NAME"
  1. W !,PSODASHES
  1. ;
  1. HDRX ;
  1. Q
  1. ;
  1. EXCELHDR ; Write the Excel header record.
  1. ;
  1. W "Rx#/FILL^REL DATE^DT REJECTED^DT RESOLVED^RESOLVED BY^"
  1. W "ACTION TAKEN^AMOUNT PAID^INSURANCE NAME^DRUG^REJECTON^"
  1. W "DIVISION^PATIENT NAME^E-PAYABLE?"
  1. Q
  1. ;