PSOPROD1 ;ALB/MRD - Pharmacy Productivity and Revenue Report ;9/8/15
 ;;7.0;OUTPATIENT PHARMACY;**448**;DEC 1997;Build 25
 ;Reference to File 9002313.93 - BPS NCPDP REJECT CODES supported by IA 4720
 ;
 Q
 ;
EN ; Main entry point for user prompts.
 ;
 W @IOF,!,"Pharmacy Productivity/Revenue Report",!!
 ;
 N PSODIV,PSODTBEGIN,PSODTEND,PSOEXCEL,PSOINCLUDE,PSOREPORT,PSOSHOWPAT,PSOSORT,PSOSTATUS
 ;
P1 I '$$DIVISION(.PSODIV) G EXIT
P2 I '$$REPORT(.PSOREPORT) G EXIT:$$STOP,P1
P3 I PSOREPORT="P" S PSOSTATUS="B",PSOSTATUS(0)="" G P4
 I '$$STATUS(.PSOSTATUS) G EXIT:$$STOP,P2
P4 I '$$DATES(.PSODTBEGIN,.PSODTEND) G EXIT:$$STOP,P2:PSOREPORT="P",P3
P5 I '$$INCLUDE(.PSOINCLUDE) G EXIT:$$STOP,P4
P6 I '$$SORT(.PSOSORT) G EXIT:$$STOP,P5
P7 I '$$PATIENT(.PSOSHOWPAT) G EXIT:$$STOP,P6
P8 I '$$EXCEL(.PSOEXCEL) G EXIT:$$STOP,P7
 I '$$DEVICE() G EXIT:$$STOP,P8
 ;
EXIT ; Exit point.
 Q
 ;
STOP() ; Determine if user wishes to exit out of the option entirely.
 ; Function return values:
 ;   1 - Yes, exit entirely.
 ;   0 - No, do not exit but return to the previous question.
 ;
 N DIR,DIRUT,Y
 ;
 S DIR(0)="Y"
 S DIR("A")="Do you want to exit out of this option entirely"
 S DIR("B")="YES"
 S DIR("?",1)="  Enter YES to immediately exit out of this option."
 S DIR("?")="  Enter NO to return to the previous question."
 W !
 D ^DIR
 I $D(DIRUT) S Y=1
 Q Y
 ;
DIVISION(PSODIV) ; Allow user to select Divisions or All Divisions.
 ; Input: None.
 ; Output: PSODIV
 ;   PSODIV = "ALL" if the user opted to include all divisions.
 ;   PSODIV = "D" if the user selected specific division.  If that is
 ;       the case, the selected pharmacies will be listed in PSODIV:
 ;       PSODIV(IEN) = Division name, where IEN is a pointer to file#
 ;       59, Outpatient Site.
 ; Function return values:
 ;   1 - A valid entry or entries were selected.
 ;   0 - User has exited out (^).
 ;
 N DIC,DIR,DIROUT,DIRUT,X,Y,Z
 ;
 ; Allow user to indicate that all divisions should be included or
 ; that they wish to enter specific divisions.
 ;
 S DIR(0)="S^D:DIVISION;A:ALL"
 S DIR("A")="Select Pharmacy (D)ivisions or (A)LL"
 I $G(PSODIV)'="" S DIR("B")=$S(PSODIV="ALL":"ALL",1:"D")
 D ^DIR
 I $D(DIRUT) W $C(7) Q 0
 ;
 ; If user selected all divisions, Quit with 1.
 ;
 I Y="A" K PSODIV S PSODIV="ALL" Q 1
 ;
 ; Allow user to enter multiple specific divisions.
 ;
 F  D  I Y=0 Q
 . ;
 . ; Display the list of divisions selected.
 . ;
 . I $D(PSODIV)>9 D
 . . W !!?2,"Selected:"
 . . S X="" F  S X=$O(PSODIV(X)) Q:X=""  W !,?10,PSODIV(X)
 . . Q
 . ;
 . K DIC
 . S DIC=59
 . S DIC(0)="QEAM"
 . S DIC("A")="Select Pharmacy Division(s): "
 . W !
 . D ^DIC
 . ;
 . ; If "^" or timeout, clear array and Quit out.
 . ;
 . I $D(DIRUT) K PSODIV S PSODIV="",Y=0 W $C(7) Q
 . ;
 . ; If blank entry, conditionally clear out array and then Quit out.
 . ;
 . I $G(X)="" S Y=0 Q
 . ;
 . ; At this point, the user entered a division.  If it is already on the
 . ; list, allow user to delete from the list.  Otherwise, add to the list.
 . ;
 . I $D(PSODIV(+Y)) D
 . . ;
 . . ; Allow user to delete an entry already on the list.
 . . ;
 . . S Z=Y  ; Need to save the original value in case we delete from the list.
 . . K DIR
 . . S DIR(0)="S^Y:YES;N:NO",DIR("A")="Delete "_$P(Z,U,2)_" from your list?"
 . . S DIR("B")="NO"
 . . D ^DIR
 . . I $D(DIROUT) K PSODIV S PSODIV="",Y=0 W $C(7) Q
 . . I Y="Y" K PSODIV(+Z)
 . . Q
 . E  D
 . . ;
 . . ; Add the new entry to the PSODIV array.
 . . ;
 . . S PSODIV(+Y)=$P(Y,U,2)
 . . Q
 . Q
 ;
 I $D(PSODIV)<10 K PSODIV Q 0
 ;
 ; Display the list of divisions selected.  Build the string of
 ; selected divisions to display on report header.
 ;
 W !!?2,"Selected:"
 S X="" F  S X=$O(PSODIV(X)) Q:X=""  W !,?10,PSODIV(X)
 S PSODIV="",PSOX=""
 F  S PSOX=$O(PSODIV(PSOX)) Q:PSOX=""  D
 . I PSODIV'="" S PSODIV=PSODIV_", "
 . S PSODIV=PSODIV_PSODIV(PSOX)
 . Q
 ;
 Q 1
 ;
REPORT(PSOREPORT) ; Allow user to select report to run (Productivity or Revenue).
 ; Input: None.
 ; Output: PSOREPORT, set to one of the following.
 ;   PSOREPORT = "" if no selection was made.
 ;   PSOREPORT = "R" if user selected the RRR Revenue report.
 ;   PSOREPORT = "P" if user selected the Productivity Report.
 ; Function return values:
 ;   1 - The user selected one of the two reports.
 ;   0 - The user exited out.
 ;
 N DIR,DIRUT,Y
 ;
 S DIR(0)="S^R:RRR Revenue;P:Productivity"
 S DIR("A")="Select (R)RR Revenue or (P)roductivity Report"
 I $G(PSOREPORT)'="" S DIR("B")=PSOREPORT
 S DIR("?",1)="Enter a code from the list to indicate the type of report to run."
 S DIR("?",2)="     Select one of the following:"
 S DIR("?",3)="          R         RRR Revenue"
 S DIR("?",4)="          Includes: All fills for a prescription with a resolved RRR reject"
 S DIR("?",5)="                    and associated revenue"
 S DIR("?",6)="          P         Productivity"
 S DIR("?",7)="          Includes: Reports only on rejects for the original fills or refills"
 S DIR("?")="                    from the Pharmacy Worklist"
 D ^DIR
 I $D(DIRUT) W $C(7) Q 0
 S PSOREPORT=Y
 Q 1
 ;
STATUS(PSOSTATUS) ; Allow user to select statuses to include in report.
 ; Input: None.
 ; Output: PSOSTATUS, set to one of the following.
 ;   PSOSTATUS = "" if no selection was made.
 ;   PSOSTATUS = "P" if user selected Closed/Resolved - ePayable.
 ;   PSOSTATUS = "R" if user selected Closed/Resolved - eRejected.
 ;   PSOSTATUS = "B" if users opted to include both of the above.
 ;   PSOSTATUS(0) = String to display on report header.
 ; Function return values:
 ;   1 - A valid selection was made.
 ;   0 - The user exited out.
 ;
 N DIR,DIRUT,Y
 ;
 S DIR(0)="S^P:CLOSED/RESOLVED - E PAYABLE;R:CLOSED/RESOLVED - E REJECTED;B:BOTH"
 S DIR("A")="Select (P) Closed/Resolved - ePAYABLE, (R) Closed/Resolved - eREJECTED, (B)oth"
 I $G(PSOSTATUS)'="" S DIR("B")=PSOSTATUS
 E  S DIR("B")="B"
 S DIR("L",1)="     Select Status:"
 S DIR("L",2)=""
 S DIR("L",3)="          P         CLOSED/RESOLVED - E PAYABLE"
 S DIR("L",4)="          R         CLOSED/RESOLVED - E REJECTED"
 S DIR("L")="          B         BOTH"
 D ^DIR
 I $D(DIRUT) W $C(7) Q 0
 ;
 S PSOSTATUS=Y
 S PSOSTATUS(0)=Y(0)
 I PSOSTATUS="B" S PSOSTATUS(0)="CLOSED/RESOLVED - E PAYABLE, E REJECTED"
 ;
 Q 1
 ;
DATES(PSODTBEGIN,PSODTEND) ; Prompt user for a date range.
 ; Function return values:
 ;   1 - A valid date range was entered.
 ;   0 - A valid date range was not entered.
 ;
 N DIR,DIRUT,Y
 ;
 S DIR(0)="D^:DT:EX"
 S DIR("A")="Begin Date Resolved"
 I $G(PSODTBEGIN)'="" S DIR("B")=$$FMTE^XLFDT(PSODTBEGIN,2)
 E  S DIR("B")="T-90"
 S DIR("?",1)="The start and end dates for this report refer to"
 S DIR("?")="the date that the rejects were resolved."
 W !
 D ^DIR
 I $D(DIRUT)!'Y W $C(7) Q 0
 S PSODTBEGIN=Y
 ;
 K DIR
 S DIR(0)="D^"_PSODTBEGIN_":DT:EX"
 S DIR("A")="End Date Resolved"
 I $G(PSODTEND)'="" S DIR("B")=$$FMTE^XLFDT(PSODTEND,2)
 E  S DIR("B")="T"
 S DIR("?",1)="The start and end dates for this report refer to"
 S DIR("?")="the date that the rejects were resolved."
 W !
 D ^DIR
 I $D(DIRUT)!'Y W $C(7) Q 0
 S PSODTEND=Y
 Q 1
 ;
INCLUDE(PSOINCLUDE) ; Allow user to enter specific Patients, Drugs, etc., to include.
 ; Input: None.
 ; Output:
 ;   PSOINCLUDE, set to PATIENT, DRUG, RX, INSURANCE or REJECT CODE.
 ;   For the field selected by the user to include-by, the list of
 ;   entries to include will be at PSOINCLUDE(include-by,value)="",
 ;   for example PSOINCLUDE("RX",12345)="" to include RxIEN 12345.
 ;   All are defaulted to "ALL", e.g. PSOINCLUDE("RX")="ALL", and
 ;   only the one selected by the user may be reset to be a string
 ;   being a list of the external values of the items selected.
 ; Function return values:
 ;   1 - A valid selection was made.
 ;   0 - The user exited out.
 ;
 N DIR,DIRUT,PSOARRAY,PSOX,Y
INC ;
 S DIR(0)="S^P:Patient;D:Drug;R:Rx;I:Insurance;C:Reject Code"
 S DIR("A")="By (P)atient, (D)rug, (R)x, (I)nsurance or Reject (C)ode"
 I $G(PSOINCLUDE)'="" S DIR("B")=PSOINCLUDE
 E  S DIR("B")="P"
 D ^DIR
 I $D(DIRUT) W $C(7) Q 0
 ;
 ; Set PSOINCLUDE to the sort selected by the user.
 ;
 K PSOINCLUDE
 S PSOINCLUDE=$$UP^XLFSTR(Y(0))
 S PSOINCLUDE("PATIENT")="ALL"
 S PSOINCLUDE("DRUG")="ALL"
 S PSOINCLUDE("RX")="ALL"
 S PSOINCLUDE("INSURANCE")="ALL"
 S PSOINCLUDE("REJECT CODE")="ALL"
 ;
 ; Allow user to select which Patients to include.
 ;
 I PSOINCLUDE="PATIENT" D  I $G(PSOARRAY)="^" G INC
 . S PSOINCLUDE("PATIENT")=""
 . D SEL^PSOREJU1("PATIENT","^DPT(",.PSOARRAY)
 . I $G(PSOARRAY)="^" Q
 . M PSOINCLUDE("PATIENT")=PSOARRAY
 . S PSOX=""
 . F  S PSOX=$O(PSOINCLUDE("PATIENT",PSOX)) Q:PSOX=""  D
 . . I PSOINCLUDE("PATIENT")'="" S PSOINCLUDE("PATIENT")=PSOINCLUDE("PATIENT")_"; "
 . . S PSOINCLUDE("PATIENT")=PSOINCLUDE("PATIENT")_$$GET1^DIQ(2,PSOX,.01)
 . . Q
 . Q
 ;
 ; Allow user to select which Drugs to include.
 ;
 I PSOINCLUDE="DRUG" D  I $G(PSOARRAY)="^" G INC
 . S PSOINCLUDE("DRUG")=""
 . D SEL^PSOREJU1("DRUG","^PSDRUG(",.PSOARRAY)
 . I $G(PSOARRAY)="^" Q
 . M PSOINCLUDE("DRUG")=PSOARRAY
 . S PSOX=""
 . F  S PSOX=$O(PSOINCLUDE("DRUG",PSOX)) Q:PSOX=""  D
 . . I PSOINCLUDE("DRUG")'="" S PSOINCLUDE("DRUG")=PSOINCLUDE("DRUG")_", "
 . . S PSOINCLUDE("DRUG")=PSOINCLUDE("DRUG")_$$GET1^DIQ(50,PSOX,.01)
 . . Q
 . Q
 ;
 ; Allow user to select which Rx's to include.
 ;
 I PSOINCLUDE="RX" D  I $G(PSOARRAY)="^" G INC
 . S PSOINCLUDE("RX")=""
 . D SEL^PSOREJU1("PRESCRIPTION","^PSRX(",.PSOARRAY)
 . I $G(PSOARRAY)="^" Q
 . M PSOINCLUDE("RX")=PSOARRAY
 . S PSOX=""
 . F  S PSOX=$O(PSOINCLUDE("RX",PSOX)) Q:PSOX=""  D
 . . I PSOINCLUDE("RX")'="" S PSOINCLUDE("RX")=PSOINCLUDE("RX")_", "
 . . S PSOINCLUDE("RX")=PSOINCLUDE("RX")_$$GET1^DIQ(52,PSOX,.01)
 . . Q
 . Q
 ;
 ; Allow user to select which Insurances to include.
 ;
 I PSOINCLUDE="INSURANCE" D  I $G(PSOARRAY)="^" G INC
 . S PSOINCLUDE("INSURANCE")=""
 . D SEL^PSOREJU1("INSURANCE","^DIC(36,",.PSOARRAY)
 . I $G(PSOARRAY)="^" Q
 . M PSOINCLUDE("INSURANCE")=PSOARRAY
 . S PSOX=""
 . F  S PSOX=$O(PSOINCLUDE("INSURANCE",PSOX)) Q:PSOX=""  D
 . . I PSOINCLUDE("INSURANCE")'="" S PSOINCLUDE("INSURANCE")=PSOINCLUDE("INSURANCE")_", "
 . . S PSOINCLUDE("INSURANCE")=PSOINCLUDE("INSURANCE")_$$GET1^DIQ(36,PSOX,.01)
 . . Q
 . Q
 ;
 ; Allow user to select which Reject Codes to include.
 ;
 I PSOINCLUDE="REJECT CODE" D  I $G(PSOARRAY)="^" G INC
 . S PSOINCLUDE("REJECT CODE")=""
 . D SEL^PSOREJU1("REJECT CODE","^BPSF(9002313.93,",.PSOARRAY)  ; IA 4720.
 . I $G(PSOARRAY)="^" Q
 . M PSOINCLUDE("REJECT CODE")=PSOARRAY
 . S PSOX=""
 . F  S PSOX=$O(PSOINCLUDE("REJECT CODE",PSOX)) Q:PSOX=""  D
 . . I PSOINCLUDE("REJECT CODE")'="" S PSOINCLUDE("REJECT CODE")=PSOINCLUDE("REJECT CODE")_", "
 . . S PSOINCLUDE("REJECT CODE")=PSOINCLUDE("REJECT CODE")_$$GET1^DIQ(9002313.93,PSOX,.01)_" - "_$$GET1^DIQ(9002313.93,PSOX,.02)  ; IA 4720.
 . . Q
 . Q
 ;
 I PSOINCLUDE="" K PSOINCLUDE Q 0
 Q 1
 ;
SORT(PSOSORT) ; Prompt user for the sort order.
 ; Input: None.
 ; Output: PSOSORT, set to one of the following.
 ;   PSOSORT = "" if no selection was made.
 ;   PSOSORT = "D" if user selected Division.
 ;   PSOSORT = "R" if user selected Date Resolved.
 ;   PSOSORT = "B" if user selected Resolved By.
 ;   PSOSORT = "N" if user selected Drug Name.
 ;   PSOSORT = "C" if user selected Reject Code.
 ; Function return values:
 ;   1 - A valid selection was made.
 ;   0 - The user exited out.
 ;
 N DIR,DIRUT,Y
 ;
 S DIR(0)="S^D:Division;R:Date Resolved;B:Resolved By;N:Drug Name;C:Reject Code"
 S DIR("A")="Sort"
 I $G(PSOSORT)'="" S DIR("B")=PSOSORT
 E  S DIR("B")="Division"
 S DIR("L",1)="Enter a code from the list to indicate the sort order."
 S DIR("L",2)="     Select one of the following:"
 S DIR("L",3)=""
 S DIR("L",4)="          D         Division"
 S DIR("L",5)="          R         Date Resolved"
 S DIR("L",6)="          B         Resolved By"
 S DIR("L",7)="          N         Drug Name"
 S DIR("L")="          C         Reject Code"
 D ^DIR
 I $D(DIRUT) W $C(7) Q 0
 S PSOSORT=Y,PSOSORT(0)=$$UP^XLFSTR(Y(0))
 Q 1
 ;
PATIENT(PSOSHOWPAT) ; Display Patient Name on report?
 ; Input: None.
 ; Output: PSOSHOWPAT, set to one of the following.
 ;   1 - Yes, display Patient Name on the report.
 ;   0 - No, do not display the Patient Name.
 ;       * Note: The Patient Name will always be displayed if the user
 ;         requests output in Excel format.
 ; Function return values:
 ;   1 - User answered the Y/N question.
 ;   0 - User exited out.
 ;
 N DIR,DIRUT
 ;
 S DIR(0)="Y"
 S DIR("A")="Show PATIENT NAME (Y/N)"
 I $G(PSOSHOWPAT)=1 S DIR("B")="YES"
 E  S DIR("B")="NO"
 W !
 D ^DIR
 I $D(DIRUT) W $C(7) Q 0
 S PSOSHOWPAT=Y
 Q 1
 ;
EXCEL(PSOEXCEL) ; Export the report to MS Excel?
 ; Function return values:
 ;   1 - User made a valid selection.
 ;   0 - User exited out.
 ; This function allows the user to indicate whether the report should be
 ; printed in a format that could easily be imported into an Excel
 ; spreadsheet.  If the user wants that, the variable PSOEXCEL will be set
 ; to '1', otherwise PSOEXCEL will be set to '0'.
 ;
 N DIR,DIRUT,Y
 ;
 S DIR(0)="Y"
 S DIR("A")="Export the report to Microsoft Excel (Y/N)"
 I $G(PSOEXCEL)=1 S DIR("B")="YES"
 E  S DIR("B")="NO"
 S DIR("?",1)="If you want to capture the output from this report in a format that"
 S DIR("?",2)="could easily be imported into an Excel spreadsheet, then answer YES here."
 S DIR("?")="If you want a normal report output, then answer NO here."
 W !
 D ^DIR
 K DIR
 I $D(DIRUT) W $C(7) Q 0
 S PSOEXCEL=+Y
 Q 1
 ;
DEVICE() ; Prompt user for output device.
 ; Function return values:
 ;   1 - User selected a device.
 ;   0 - User exited out.
 ;
 N DIR,POP,PSORETURN,X,Y,ZTDESC,ZTQUEUED,ZTREQ,ZTRTN,ZTSAVE,ZTSK
 S PSORETURN=1
 ;
 I 'PSOEXCEL W !!,"This report is 132 characters wide.  Please choose an appropriate device.",!
 I PSOEXCEL D
 . W !!?5,"Before continuing, please set up your terminal to capture the"
 . W !?5,"detail report data and save the detail report data in a text file"
 . W !?5,"to a local drive. This report may take a while to run."
 . W !!?5,"Note: To avoid undesired wrapping of the data saved to the file,"
 . W !?11,"please enter '0;256;99999' at the 'DEVICE:' prompt.",!
 . Q
 ;
 S ZTRTN="EN^PSOPROD2"
 I PSOREPORT="P" S ZTDESC="Pharmacy Productivity Report"
 E  S ZTDESC="RRR Revenue Report"
 S ZTSAVE("PSO*")=""
 ;
 D EN^XUTMDEVQ(ZTRTN,ZTDESC,.ZTSAVE,"QM",1)
 I POP S PSORETURN=0
 I $G(ZTSK) W !!,"Report compilation has started with task# ",ZTSK,".",! S DIR(0)="E" D ^DIR
 Q PSORETURN
 ;
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSOPROD1   14875     printed  Sep 23, 2025@20:09:31                                                                                                                                                                                                   Page 2
PSOPROD1  ;ALB/MRD - Pharmacy Productivity and Revenue Report ;9/8/15
 +1       ;;7.0;OUTPATIENT PHARMACY;**448**;DEC 1997;Build 25
 +2       ;Reference to File 9002313.93 - BPS NCPDP REJECT CODES supported by IA 4720
 +3       ;
 +4        QUIT 
 +5       ;
EN        ; Main entry point for user prompts.
 +1       ;
 +2        WRITE @IOF,!,"Pharmacy Productivity/Revenue Report",!!
 +3       ;
 +4        NEW PSODIV,PSODTBEGIN,PSODTEND,PSOEXCEL,PSOINCLUDE,PSOREPORT,PSOSHOWPAT,PSOSORT,PSOSTATUS
 +5       ;
P1         IF '$$DIVISION(.PSODIV)
               GOTO EXIT
P2         IF '$$REPORT(.PSOREPORT)
               if $$STOP
                   GOTO EXIT
               GOTO P1
P3         IF PSOREPORT="P"
               SET PSOSTATUS="B"
               SET PSOSTATUS(0)=""
               GOTO P4
 +1        IF '$$STATUS(.PSOSTATUS)
               if $$STOP
                   GOTO EXIT
               GOTO P2
P4         IF '$$DATES(.PSODTBEGIN,.PSODTEND)
               if $$STOP
                   GOTO EXIT
               if PSOREPORT="P"
                   GOTO P2
               GOTO P3
P5         IF '$$INCLUDE(.PSOINCLUDE)
               if $$STOP
                   GOTO EXIT
               GOTO P4
P6         IF '$$SORT(.PSOSORT)
               if $$STOP
                   GOTO EXIT
               GOTO P5
P7         IF '$$PATIENT(.PSOSHOWPAT)
               if $$STOP
                   GOTO EXIT
               GOTO P6
P8         IF '$$EXCEL(.PSOEXCEL)
               if $$STOP
                   GOTO EXIT
               GOTO P7
 +1        IF '$$DEVICE()
               if $$STOP
                   GOTO EXIT
               GOTO P8
 +2       ;
EXIT      ; Exit point.
 +1        QUIT 
 +2       ;
STOP()    ; Determine if user wishes to exit out of the option entirely.
 +1       ; Function return values:
 +2       ;   1 - Yes, exit entirely.
 +3       ;   0 - No, do not exit but return to the previous question.
 +4       ;
 +5        NEW DIR,DIRUT,Y
 +6       ;
 +7        SET DIR(0)="Y"
 +8        SET DIR("A")="Do you want to exit out of this option entirely"
 +9        SET DIR("B")="YES"
 +10       SET DIR("?",1)="  Enter YES to immediately exit out of this option."
 +11       SET DIR("?")="  Enter NO to return to the previous question."
 +12       WRITE !
 +13       DO ^DIR
 +14       IF $DATA(DIRUT)
               SET Y=1
 +15       QUIT Y
 +16      ;
DIVISION(PSODIV) ; Allow user to select Divisions or All Divisions.
 +1       ; Input: None.
 +2       ; Output: PSODIV
 +3       ;   PSODIV = "ALL" if the user opted to include all divisions.
 +4       ;   PSODIV = "D" if the user selected specific division.  If that is
 +5       ;       the case, the selected pharmacies will be listed in PSODIV:
 +6       ;       PSODIV(IEN) = Division name, where IEN is a pointer to file#
 +7       ;       59, Outpatient Site.
 +8       ; Function return values:
 +9       ;   1 - A valid entry or entries were selected.
 +10      ;   0 - User has exited out (^).
 +11      ;
 +12       NEW DIC,DIR,DIROUT,DIRUT,X,Y,Z
 +13      ;
 +14      ; Allow user to indicate that all divisions should be included or
 +15      ; that they wish to enter specific divisions.
 +16      ;
 +17       SET DIR(0)="S^D:DIVISION;A:ALL"
 +18       SET DIR("A")="Select Pharmacy (D)ivisions or (A)LL"
 +19       IF $GET(PSODIV)'=""
               SET DIR("B")=$SELECT(PSODIV="ALL":"ALL",1:"D")
 +20       DO ^DIR
 +21       IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +22      ;
 +23      ; If user selected all divisions, Quit with 1.
 +24      ;
 +25       IF Y="A"
               KILL PSODIV
               SET PSODIV="ALL"
               QUIT 1
 +26      ;
 +27      ; Allow user to enter multiple specific divisions.
 +28      ;
 +29       FOR 
               Begin DoDot:1
 +30      ;
 +31      ; Display the list of divisions selected.
 +32      ;
 +33               IF $DATA(PSODIV)>9
                       Begin DoDot:2
 +34                       WRITE !!?2,"Selected:"
 +35                       SET X=""
                           FOR 
                               SET X=$ORDER(PSODIV(X))
                               if X=""
                                   QUIT 
                               WRITE !,?10,PSODIV(X)
 +36                       QUIT 
                       End DoDot:2
 +37      ;
 +38               KILL DIC
 +39               SET DIC=59
 +40               SET DIC(0)="QEAM"
 +41               SET DIC("A")="Select Pharmacy Division(s): "
 +42               WRITE !
 +43               DO ^DIC
 +44      ;
 +45      ; If "^" or timeout, clear array and Quit out.
 +46      ;
 +47               IF $DATA(DIRUT)
                       KILL PSODIV
                       SET PSODIV=""
                       SET Y=0
                       WRITE $CHAR(7)
                       QUIT 
 +48      ;
 +49      ; If blank entry, conditionally clear out array and then Quit out.
 +50      ;
 +51               IF $GET(X)=""
                       SET Y=0
                       QUIT 
 +52      ;
 +53      ; At this point, the user entered a division.  If it is already on the
 +54      ; list, allow user to delete from the list.  Otherwise, add to the list.
 +55      ;
 +56               IF $DATA(PSODIV(+Y))
                       Begin DoDot:2
 +57      ;
 +58      ; Allow user to delete an entry already on the list.
 +59      ;
 +60      ; Need to save the original value in case we delete from the list.
                           SET Z=Y
 +61                       KILL DIR
 +62                       SET DIR(0)="S^Y:YES;N:NO"
                           SET DIR("A")="Delete "_$PIECE(Z,U,2)_" from your list?"
 +63                       SET DIR("B")="NO"
 +64                       DO ^DIR
 +65                       IF $DATA(DIROUT)
                               KILL PSODIV
                               SET PSODIV=""
                               SET Y=0
                               WRITE $CHAR(7)
                               QUIT 
 +66                       IF Y="Y"
                               KILL PSODIV(+Z)
 +67                       QUIT 
                       End DoDot:2
 +68              IF '$TEST
                       Begin DoDot:2
 +69      ;
 +70      ; Add the new entry to the PSODIV array.
 +71      ;
 +72                       SET PSODIV(+Y)=$PIECE(Y,U,2)
 +73                       QUIT 
                       End DoDot:2
 +74               QUIT 
               End DoDot:1
               IF Y=0
                   QUIT 
 +75      ;
 +76       IF $DATA(PSODIV)<10
               KILL PSODIV
               QUIT 0
 +77      ;
 +78      ; Display the list of divisions selected.  Build the string of
 +79      ; selected divisions to display on report header.
 +80      ;
 +81       WRITE !!?2,"Selected:"
 +82       SET X=""
           FOR 
               SET X=$ORDER(PSODIV(X))
               if X=""
                   QUIT 
               WRITE !,?10,PSODIV(X)
 +83       SET PSODIV=""
           SET PSOX=""
 +84       FOR 
               SET PSOX=$ORDER(PSODIV(PSOX))
               if PSOX=""
                   QUIT 
               Begin DoDot:1
 +85               IF PSODIV'=""
                       SET PSODIV=PSODIV_", "
 +86               SET PSODIV=PSODIV_PSODIV(PSOX)
 +87               QUIT 
               End DoDot:1
 +88      ;
 +89       QUIT 1
 +90      ;
REPORT(PSOREPORT) ; Allow user to select report to run (Productivity or Revenue).
 +1       ; Input: None.
 +2       ; Output: PSOREPORT, set to one of the following.
 +3       ;   PSOREPORT = "" if no selection was made.
 +4       ;   PSOREPORT = "R" if user selected the RRR Revenue report.
 +5       ;   PSOREPORT = "P" if user selected the Productivity Report.
 +6       ; Function return values:
 +7       ;   1 - The user selected one of the two reports.
 +8       ;   0 - The user exited out.
 +9       ;
 +10       NEW DIR,DIRUT,Y
 +11      ;
 +12       SET DIR(0)="S^R:RRR Revenue;P:Productivity"
 +13       SET DIR("A")="Select (R)RR Revenue or (P)roductivity Report"
 +14       IF $GET(PSOREPORT)'=""
               SET DIR("B")=PSOREPORT
 +15       SET DIR("?",1)="Enter a code from the list to indicate the type of report to run."
 +16       SET DIR("?",2)="     Select one of the following:"
 +17       SET DIR("?",3)="          R         RRR Revenue"
 +18       SET DIR("?",4)="          Includes: All fills for a prescription with a resolved RRR reject"
 +19       SET DIR("?",5)="                    and associated revenue"
 +20       SET DIR("?",6)="          P         Productivity"
 +21       SET DIR("?",7)="          Includes: Reports only on rejects for the original fills or refills"
 +22       SET DIR("?")="                    from the Pharmacy Worklist"
 +23       DO ^DIR
 +24       IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +25       SET PSOREPORT=Y
 +26       QUIT 1
 +27      ;
STATUS(PSOSTATUS) ; Allow user to select statuses to include in report.
 +1       ; Input: None.
 +2       ; Output: PSOSTATUS, set to one of the following.
 +3       ;   PSOSTATUS = "" if no selection was made.
 +4       ;   PSOSTATUS = "P" if user selected Closed/Resolved - ePayable.
 +5       ;   PSOSTATUS = "R" if user selected Closed/Resolved - eRejected.
 +6       ;   PSOSTATUS = "B" if users opted to include both of the above.
 +7       ;   PSOSTATUS(0) = String to display on report header.
 +8       ; Function return values:
 +9       ;   1 - A valid selection was made.
 +10      ;   0 - The user exited out.
 +11      ;
 +12       NEW DIR,DIRUT,Y
 +13      ;
 +14       SET DIR(0)="S^P:CLOSED/RESOLVED - E PAYABLE;R:CLOSED/RESOLVED - E REJECTED;B:BOTH"
 +15       SET DIR("A")="Select (P) Closed/Resolved - ePAYABLE, (R) Closed/Resolved - eREJECTED, (B)oth"
 +16       IF $GET(PSOSTATUS)'=""
               SET DIR("B")=PSOSTATUS
 +17      IF '$TEST
               SET DIR("B")="B"
 +18       SET DIR("L",1)="     Select Status:"
 +19       SET DIR("L",2)=""
 +20       SET DIR("L",3)="          P         CLOSED/RESOLVED - E PAYABLE"
 +21       SET DIR("L",4)="          R         CLOSED/RESOLVED - E REJECTED"
 +22       SET DIR("L")="          B         BOTH"
 +23       DO ^DIR
 +24       IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +25      ;
 +26       SET PSOSTATUS=Y
 +27       SET PSOSTATUS(0)=Y(0)
 +28       IF PSOSTATUS="B"
               SET PSOSTATUS(0)="CLOSED/RESOLVED - E PAYABLE, E REJECTED"
 +29      ;
 +30       QUIT 1
 +31      ;
DATES(PSODTBEGIN,PSODTEND) ; Prompt user for a date range.
 +1       ; Function return values:
 +2       ;   1 - A valid date range was entered.
 +3       ;   0 - A valid date range was not entered.
 +4       ;
 +5        NEW DIR,DIRUT,Y
 +6       ;
 +7        SET DIR(0)="D^:DT:EX"
 +8        SET DIR("A")="Begin Date Resolved"
 +9        IF $GET(PSODTBEGIN)'=""
               SET DIR("B")=$$FMTE^XLFDT(PSODTBEGIN,2)
 +10      IF '$TEST
               SET DIR("B")="T-90"
 +11       SET DIR("?",1)="The start and end dates for this report refer to"
 +12       SET DIR("?")="the date that the rejects were resolved."
 +13       WRITE !
 +14       DO ^DIR
 +15       IF $DATA(DIRUT)!'Y
               WRITE $CHAR(7)
               QUIT 0
 +16       SET PSODTBEGIN=Y
 +17      ;
 +18       KILL DIR
 +19       SET DIR(0)="D^"_PSODTBEGIN_":DT:EX"
 +20       SET DIR("A")="End Date Resolved"
 +21       IF $GET(PSODTEND)'=""
               SET DIR("B")=$$FMTE^XLFDT(PSODTEND,2)
 +22      IF '$TEST
               SET DIR("B")="T"
 +23       SET DIR("?",1)="The start and end dates for this report refer to"
 +24       SET DIR("?")="the date that the rejects were resolved."
 +25       WRITE !
 +26       DO ^DIR
 +27       IF $DATA(DIRUT)!'Y
               WRITE $CHAR(7)
               QUIT 0
 +28       SET PSODTEND=Y
 +29       QUIT 1
 +30      ;
INCLUDE(PSOINCLUDE) ; Allow user to enter specific Patients, Drugs, etc., to include.
 +1       ; Input: None.
 +2       ; Output:
 +3       ;   PSOINCLUDE, set to PATIENT, DRUG, RX, INSURANCE or REJECT CODE.
 +4       ;   For the field selected by the user to include-by, the list of
 +5       ;   entries to include will be at PSOINCLUDE(include-by,value)="",
 +6       ;   for example PSOINCLUDE("RX",12345)="" to include RxIEN 12345.
 +7       ;   All are defaulted to "ALL", e.g. PSOINCLUDE("RX")="ALL", and
 +8       ;   only the one selected by the user may be reset to be a string
 +9       ;   being a list of the external values of the items selected.
 +10      ; Function return values:
 +11      ;   1 - A valid selection was made.
 +12      ;   0 - The user exited out.
 +13      ;
 +14       NEW DIR,DIRUT,PSOARRAY,PSOX,Y
INC       ;
 +1        SET DIR(0)="S^P:Patient;D:Drug;R:Rx;I:Insurance;C:Reject Code"
 +2        SET DIR("A")="By (P)atient, (D)rug, (R)x, (I)nsurance or Reject (C)ode"
 +3        IF $GET(PSOINCLUDE)'=""
               SET DIR("B")=PSOINCLUDE
 +4       IF '$TEST
               SET DIR("B")="P"
 +5        DO ^DIR
 +6        IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +7       ;
 +8       ; Set PSOINCLUDE to the sort selected by the user.
 +9       ;
 +10       KILL PSOINCLUDE
 +11       SET PSOINCLUDE=$$UP^XLFSTR(Y(0))
 +12       SET PSOINCLUDE("PATIENT")="ALL"
 +13       SET PSOINCLUDE("DRUG")="ALL"
 +14       SET PSOINCLUDE("RX")="ALL"
 +15       SET PSOINCLUDE("INSURANCE")="ALL"
 +16       SET PSOINCLUDE("REJECT CODE")="ALL"
 +17      ;
 +18      ; Allow user to select which Patients to include.
 +19      ;
 +20       IF PSOINCLUDE="PATIENT"
               Begin DoDot:1
 +21               SET PSOINCLUDE("PATIENT")=""
 +22               DO SEL^PSOREJU1("PATIENT","^DPT(",.PSOARRAY)
 +23               IF $GET(PSOARRAY)="^"
                       QUIT 
 +24               MERGE PSOINCLUDE("PATIENT")=PSOARRAY
 +25               SET PSOX=""
 +26               FOR 
                       SET PSOX=$ORDER(PSOINCLUDE("PATIENT",PSOX))
                       if PSOX=""
                           QUIT 
                       Begin DoDot:2
 +27                       IF PSOINCLUDE("PATIENT")'=""
                               SET PSOINCLUDE("PATIENT")=PSOINCLUDE("PATIENT")_"; "
 +28                       SET PSOINCLUDE("PATIENT")=PSOINCLUDE("PATIENT")_$$GET1^DIQ(2,PSOX,.01)
 +29                       QUIT 
                       End DoDot:2
 +30               QUIT 
               End DoDot:1
               IF $GET(PSOARRAY)="^"
                   GOTO INC
 +31      ;
 +32      ; Allow user to select which Drugs to include.
 +33      ;
 +34       IF PSOINCLUDE="DRUG"
               Begin DoDot:1
 +35               SET PSOINCLUDE("DRUG")=""
 +36               DO SEL^PSOREJU1("DRUG","^PSDRUG(",.PSOARRAY)
 +37               IF $GET(PSOARRAY)="^"
                       QUIT 
 +38               MERGE PSOINCLUDE("DRUG")=PSOARRAY
 +39               SET PSOX=""
 +40               FOR 
                       SET PSOX=$ORDER(PSOINCLUDE("DRUG",PSOX))
                       if PSOX=""
                           QUIT 
                       Begin DoDot:2
 +41                       IF PSOINCLUDE("DRUG")'=""
                               SET PSOINCLUDE("DRUG")=PSOINCLUDE("DRUG")_", "
 +42                       SET PSOINCLUDE("DRUG")=PSOINCLUDE("DRUG")_$$GET1^DIQ(50,PSOX,.01)
 +43                       QUIT 
                       End DoDot:2
 +44               QUIT 
               End DoDot:1
               IF $GET(PSOARRAY)="^"
                   GOTO INC
 +45      ;
 +46      ; Allow user to select which Rx's to include.
 +47      ;
 +48       IF PSOINCLUDE="RX"
               Begin DoDot:1
 +49               SET PSOINCLUDE("RX")=""
 +50               DO SEL^PSOREJU1("PRESCRIPTION","^PSRX(",.PSOARRAY)
 +51               IF $GET(PSOARRAY)="^"
                       QUIT 
 +52               MERGE PSOINCLUDE("RX")=PSOARRAY
 +53               SET PSOX=""
 +54               FOR 
                       SET PSOX=$ORDER(PSOINCLUDE("RX",PSOX))
                       if PSOX=""
                           QUIT 
                       Begin DoDot:2
 +55                       IF PSOINCLUDE("RX")'=""
                               SET PSOINCLUDE("RX")=PSOINCLUDE("RX")_", "
 +56                       SET PSOINCLUDE("RX")=PSOINCLUDE("RX")_$$GET1^DIQ(52,PSOX,.01)
 +57                       QUIT 
                       End DoDot:2
 +58               QUIT 
               End DoDot:1
               IF $GET(PSOARRAY)="^"
                   GOTO INC
 +59      ;
 +60      ; Allow user to select which Insurances to include.
 +61      ;
 +62       IF PSOINCLUDE="INSURANCE"
               Begin DoDot:1
 +63               SET PSOINCLUDE("INSURANCE")=""
 +64               DO SEL^PSOREJU1("INSURANCE","^DIC(36,",.PSOARRAY)
 +65               IF $GET(PSOARRAY)="^"
                       QUIT 
 +66               MERGE PSOINCLUDE("INSURANCE")=PSOARRAY
 +67               SET PSOX=""
 +68               FOR 
                       SET PSOX=$ORDER(PSOINCLUDE("INSURANCE",PSOX))
                       if PSOX=""
                           QUIT 
                       Begin DoDot:2
 +69                       IF PSOINCLUDE("INSURANCE")'=""
                               SET PSOINCLUDE("INSURANCE")=PSOINCLUDE("INSURANCE")_", "
 +70                       SET PSOINCLUDE("INSURANCE")=PSOINCLUDE("INSURANCE")_$$GET1^DIQ(36,PSOX,.01)
 +71                       QUIT 
                       End DoDot:2
 +72               QUIT 
               End DoDot:1
               IF $GET(PSOARRAY)="^"
                   GOTO INC
 +73      ;
 +74      ; Allow user to select which Reject Codes to include.
 +75      ;
 +76       IF PSOINCLUDE="REJECT CODE"
               Begin DoDot:1
 +77               SET PSOINCLUDE("REJECT CODE")=""
 +78      ; IA 4720.
                   DO SEL^PSOREJU1("REJECT CODE","^BPSF(9002313.93,",.PSOARRAY)
 +79               IF $GET(PSOARRAY)="^"
                       QUIT 
 +80               MERGE PSOINCLUDE("REJECT CODE")=PSOARRAY
 +81               SET PSOX=""
 +82               FOR 
                       SET PSOX=$ORDER(PSOINCLUDE("REJECT CODE",PSOX))
                       if PSOX=""
                           QUIT 
                       Begin DoDot:2
 +83                       IF PSOINCLUDE("REJECT CODE")'=""
                               SET PSOINCLUDE("REJECT CODE")=PSOINCLUDE("REJECT CODE")_", "
 +84      ; IA 4720.
                           SET PSOINCLUDE("REJECT CODE")=PSOINCLUDE("REJECT CODE")_$$GET1^DIQ(9002313.93,PSOX,.01)_" - "_$$GET1^DIQ(9002313.93,PSOX,.02)
 +85                       QUIT 
                       End DoDot:2
 +86               QUIT 
               End DoDot:1
               IF $GET(PSOARRAY)="^"
                   GOTO INC
 +87      ;
 +88       IF PSOINCLUDE=""
               KILL PSOINCLUDE
               QUIT 0
 +89       QUIT 1
 +90      ;
SORT(PSOSORT) ; Prompt user for the sort order.
 +1       ; Input: None.
 +2       ; Output: PSOSORT, set to one of the following.
 +3       ;   PSOSORT = "" if no selection was made.
 +4       ;   PSOSORT = "D" if user selected Division.
 +5       ;   PSOSORT = "R" if user selected Date Resolved.
 +6       ;   PSOSORT = "B" if user selected Resolved By.
 +7       ;   PSOSORT = "N" if user selected Drug Name.
 +8       ;   PSOSORT = "C" if user selected Reject Code.
 +9       ; Function return values:
 +10      ;   1 - A valid selection was made.
 +11      ;   0 - The user exited out.
 +12      ;
 +13       NEW DIR,DIRUT,Y
 +14      ;
 +15       SET DIR(0)="S^D:Division;R:Date Resolved;B:Resolved By;N:Drug Name;C:Reject Code"
 +16       SET DIR("A")="Sort"
 +17       IF $GET(PSOSORT)'=""
               SET DIR("B")=PSOSORT
 +18      IF '$TEST
               SET DIR("B")="Division"
 +19       SET DIR("L",1)="Enter a code from the list to indicate the sort order."
 +20       SET DIR("L",2)="     Select one of the following:"
 +21       SET DIR("L",3)=""
 +22       SET DIR("L",4)="          D         Division"
 +23       SET DIR("L",5)="          R         Date Resolved"
 +24       SET DIR("L",6)="          B         Resolved By"
 +25       SET DIR("L",7)="          N         Drug Name"
 +26       SET DIR("L")="          C         Reject Code"
 +27       DO ^DIR
 +28       IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +29       SET PSOSORT=Y
           SET PSOSORT(0)=$$UP^XLFSTR(Y(0))
 +30       QUIT 1
 +31      ;
PATIENT(PSOSHOWPAT) ; Display Patient Name on report?
 +1       ; Input: None.
 +2       ; Output: PSOSHOWPAT, set to one of the following.
 +3       ;   1 - Yes, display Patient Name on the report.
 +4       ;   0 - No, do not display the Patient Name.
 +5       ;       * Note: The Patient Name will always be displayed if the user
 +6       ;         requests output in Excel format.
 +7       ; Function return values:
 +8       ;   1 - User answered the Y/N question.
 +9       ;   0 - User exited out.
 +10      ;
 +11       NEW DIR,DIRUT
 +12      ;
 +13       SET DIR(0)="Y"
 +14       SET DIR("A")="Show PATIENT NAME (Y/N)"
 +15       IF $GET(PSOSHOWPAT)=1
               SET DIR("B")="YES"
 +16      IF '$TEST
               SET DIR("B")="NO"
 +17       WRITE !
 +18       DO ^DIR
 +19       IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +20       SET PSOSHOWPAT=Y
 +21       QUIT 1
 +22      ;
EXCEL(PSOEXCEL) ; Export the report to MS Excel?
 +1       ; Function return values:
 +2       ;   1 - User made a valid selection.
 +3       ;   0 - User exited out.
 +4       ; This function allows the user to indicate whether the report should be
 +5       ; printed in a format that could easily be imported into an Excel
 +6       ; spreadsheet.  If the user wants that, the variable PSOEXCEL will be set
 +7       ; to '1', otherwise PSOEXCEL will be set to '0'.
 +8       ;
 +9        NEW DIR,DIRUT,Y
 +10      ;
 +11       SET DIR(0)="Y"
 +12       SET DIR("A")="Export the report to Microsoft Excel (Y/N)"
 +13       IF $GET(PSOEXCEL)=1
               SET DIR("B")="YES"
 +14      IF '$TEST
               SET DIR("B")="NO"
 +15       SET DIR("?",1)="If you want to capture the output from this report in a format that"
 +16       SET DIR("?",2)="could easily be imported into an Excel spreadsheet, then answer YES here."
 +17       SET DIR("?")="If you want a normal report output, then answer NO here."
 +18       WRITE !
 +19       DO ^DIR
 +20       KILL DIR
 +21       IF $DATA(DIRUT)
               WRITE $CHAR(7)
               QUIT 0
 +22       SET PSOEXCEL=+Y
 +23       QUIT 1
 +24      ;
DEVICE()  ; Prompt user for output device.
 +1       ; Function return values:
 +2       ;   1 - User selected a device.
 +3       ;   0 - User exited out.
 +4       ;
 +5        NEW DIR,POP,PSORETURN,X,Y,ZTDESC,ZTQUEUED,ZTREQ,ZTRTN,ZTSAVE,ZTSK
 +6        SET PSORETURN=1
 +7       ;
 +8        IF 'PSOEXCEL
               WRITE !!,"This report is 132 characters wide.  Please choose an appropriate device.",!
 +9        IF PSOEXCEL
               Begin DoDot:1
 +10               WRITE !!?5,"Before continuing, please set up your terminal to capture the"
 +11               WRITE !?5,"detail report data and save the detail report data in a text file"
 +12               WRITE !?5,"to a local drive. This report may take a while to run."
 +13               WRITE !!?5,"Note: To avoid undesired wrapping of the data saved to the file,"
 +14               WRITE !?11,"please enter '0;256;99999' at the 'DEVICE:' prompt.",!
 +15               QUIT 
               End DoDot:1
 +16      ;
 +17       SET ZTRTN="EN^PSOPROD2"
 +18       IF PSOREPORT="P"
               SET ZTDESC="Pharmacy Productivity Report"
 +19      IF '$TEST
               SET ZTDESC="RRR Revenue Report"
 +20       SET ZTSAVE("PSO*")=""
 +21      ;
 +22       DO EN^XUTMDEVQ(ZTRTN,ZTDESC,.ZTSAVE,"QM",1)
 +23       IF POP
               SET PSORETURN=0
 +24       IF $GET(ZTSK)
               WRITE !!,"Report compilation has started with task# ",ZTSK,".",!
               SET DIR(0)="E"
               DO ^DIR
 +25       QUIT PSORETURN
 +26      ;