RORX009 ;HCIOFO/SG - PHARMACY PRESCRIPTION UTILIZATION ;11/16/05 10:49am
 ;;1.5;CLINICAL CASE REGISTRIES;**21,31**;Feb 17, 2006;Build 62
 ;
 ;******************************************************************************
 ;                       --- ROUTINE MODIFICATION LOG ---
 ;        
 ;PKG/PATCH    DATE        DEVELOPER    MODIFICATION
 ;-----------  ----------  -----------  ----------------------------------------
 ;ROR*1.5*21   SEP 2013    T KOPP       Added ICN as last report column if
 ;                                      additional identifier option selected
 ;ROR*1.5*31   MAY 2017    M FERRARESE  Adding PACT, PCP, and AGE/DOB as additional
 ;                                      identifiers.
 ;******************************************************************************
 ;
 Q
 ;
 ;***** OUTPUTS THE REPORT HEADER
 ;
 ; PARTAG        Reference (IEN) to the parent tag
 ;
 ; Return Values:
 ;       <0  Error code
 ;       >0  IEN of the HEADER element
 ;
 ;;DOSES(NP,IPNRX)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT")
 ;;DRUGS_DOSES(#,NAME,NP,IPNRX,MAXNRPP,MAXNP)
 ;;DRUGS_FILLS(#,NAME,NP,OPNRX,MAXNRPP,MAXNP)
 ;;FILLS(NP,OPNRX)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT")
 ;;HU_DOSES(#,NAME,LAST4,DOD,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
 ;;HU_DOSES(#,NAME,LAST4,AGE,DOD,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
 ;;HU_DOSES(#,NAME,LAST4,DOB,DOD,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
 ;;HU_FILLS(#,NAME,LAST4,DOD,OPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
 ;;HU_FILLS(#,NAME,LAST4,AGE,DOD,OPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
 ;;HU_FILLS(#,NAME,LAST4,DOB,DOD,OPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
 ;;HU_NRX(#,NAME,LAST4,DOD,OPNRX,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
 ;;HU_NRX(#,NAME,LAST4,AGE,DOD,OPNRX,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
 ;;HU_NRX(#,NAME,LAST4,DOB,DOD,OPNRX,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
 ;
 N HEADER,RC
 S HEADER=$$HEADER^RORXU002(.RORTSK,PARTAG)
 Q:HEADER<0 HEADER
 S RC=$$TBLDEF^RORXU002("HEADER^RORX009",HEADER)
 Q $S(RC<0:RC,1:HEADER)
 ;
 ;***** OUTPUTS THE PARAMETERS TO THE REPORT
 ;
 ; PARTAG        Reference (IEN) to the parent tag
 ;
 ; [.STDT]       Start and end dates of the report
 ; [.ENDT]       are returned via these parameters
 ;
 ; [.FLAGS]      Flags for the $$SKIP^RORXU005 are
 ;               returned via this parameter
 ;
 ; Return Values:
 ;       <0  Error code
 ;       >0  IEN of the PARAMETERS element
 ;
PARAMS(PARTAG,STDT,ENDT,FLAGS) ;
 N NAME,PARAMS,TMP
 S PARAMS=$$PARAMS^RORXU002(.RORTSK,PARTAG,.STDT,.ENDT,.FLAGS)
 Q:PARAMS<0 PARAMS
 ;--- Process the drug list and options
 S TMP=$$DRUGLST^RORXU007(.RORTSK,PARAMS,.RORXL,.RORXGRP)
 Q:TMP<0 TMP
 ;--- Additional parameters
 F NAME="MAXUTNUM"  D
 . S TMP=$$PARAM^RORTSK01(NAME)
 . D:TMP'="" ADDVAL^RORTSK11(RORTSK,NAME,TMP,PARAMS)
 ;---
 Q PARAMS
 ;
 ;***** COMPILES THE "PHARMACY PRESCRIPTION UTILIZATION" REPORT
 ; REPORT CODE: 009
 ;
 ; .RORTSK       Task number and task parameters
 ;
 ; The ^TMP("RORX009",$J) global node is used by this function.
 ;
 ; ^TMP("RORX009",$J,
 ;
 ;     "IP",             Number of inpatients
 ;       DFN,            Patient's data
 ;                         ^01: Last 4 digits of SSN
 ;                         ^02: Name
 ;                         ^03: Date of Death
 ;                         ^04: Total number of doses
 ;                         ^05: Number of different drugs
 ;                         ^06: National ICN
 ;                         ^07: PACT Patient care team
 ;                         ^08: PCP Primary care physician
 ;                         ^09: AGE/DOB
 ;         "D",
 ;           DrugIEN)    Quantity
 ;
 ;     "IPD",            Number of different drugs
 ;       DrugIEN,        Drug Name
 ;         "D")          Number of doses
 ;         "M")          Maximum
 ;                         ^01: Maximum number of doses
 ;                         ^02: Number of patients
 ;         "P")          Number of patients
 ;       "B",
 ;         NumOfDoses,
 ;           DrugName,
 ;             DrugIEN)  ""
 ;
 ;     "IPRX",           Total number of doses
 ;       NumOfDoses,     Number of patients
 ;         PatientName,
 ;           DFN)        ""
 ;
 ;     "OP",             Number of outpatients
 ;       DFN,            Patient's data
 ;                         ^01: Last 4 digits of SSN
 ;                         ^02: Name
 ;                         ^03: Date of Death
 ;                         ^04: Total number of fills
 ;                         ^05: Number of different drugs
 ;                         ^06: National ICN
 ;                         ^07: PACT Patient care team
 ;                         ^08: PCP Primary care physician
 ;                         ^09: AGE/DOB
 ;         "D",
 ;           DrugIEN)    Quantity
 ;
 ;     "OPD",            Number of different drugs
 ;       DrugIEN,        Drug Name
 ;         "D")          Number of fills
 ;         "M")          Maximum
 ;                         ^01: Maximum number of fills
 ;                         ^02: Number of patients
 ;         "P")          Number of patients
 ;       "B",
 ;         NumOfFills,
 ;           DrugName,
 ;             DrugIEN)  ""
 ;
 ;     "OPRX",           Total number of fills
 ;       NumOfFills,     Number of patients
 ;         PatientName,
 ;           DFN)        ""
 ;
 ;     "SUMRX",
 ;       NumberOfRX,     Number of patients
 ;         PatientName,
 ;           DFN,        Number of different drugs
 ;             "IP")
 ;             "OP")
 ;
 ; Return Values:
 ;       <0  Error code
 ;        0  Ok
 ;
RXUTIL(RORTSK) ;
 N ROREDT        ; End date
 N RORREG        ; Registry IEN
 N RORSDT        ; Start date
 N RORXGRP       ; List of drug groups
 N RORXL         ; List of drugs for the pharmacy search API
 ;
 N ECNT,RC,REPORT,SFLAGS,TMP
 S RORXL="",(ECNT,RC)=0
 K ^TMP("RORX009",$J)
 ;--- Root node of the report
 S REPORT=$$ADDVAL^RORTSK11(RORTSK,"REPORT")
 Q:REPORT<0 REPORT
 ;
 D
 . ;--- Get and prepare the report parameters
 . S RORREG=$$PARAM^RORTSK01("REGIEN")
 . S RC=$$PARAMS(REPORT,.RORSDT,.ROREDT,.SFLAGS)  Q:RC<0
 . ;--- Report header
 . S RC=$$HEADER(REPORT)  Q:RC<0
 . ;--- Query the registry
 . D TPPSETUP^RORTSK01(80)
 . S RC=$$QUERY^RORX009A(SFLAGS)
 . I RC  Q:RC<0  S ECNT=ECNT+RC
 . ;--- Sort the data
 . D TPPSETUP^RORTSK01(10)
 . S RC=$$SORT^RORX009A()
 . I RC  Q:RC<0  S ECNT=ECNT+RC
 . ;--- Store the results
 . D TPPSETUP^RORTSK01(10)
 . S RC=$$STORE^RORX009C(REPORT)
 . I RC  Q:RC<0  S ECNT=ECNT+RC
 ;
 ;--- Cleanup
 K ^TMP("RORX009",$J)
 D FREE^RORTMP(RORXL)
 Q $S(RC<0:RC,ECNT>0:-43,1:0)
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORX009   7518     printed  Sep 23, 2025@19:20:30                                                                                                                                                                                                     Page 2
RORX009   ;HCIOFO/SG - PHARMACY PRESCRIPTION UTILIZATION ;11/16/05 10:49am
 +1       ;;1.5;CLINICAL CASE REGISTRIES;**21,31**;Feb 17, 2006;Build 62
 +2       ;
 +3       ;******************************************************************************
 +4       ;                       --- ROUTINE MODIFICATION LOG ---
 +5       ;        
 +6       ;PKG/PATCH    DATE        DEVELOPER    MODIFICATION
 +7       ;-----------  ----------  -----------  ----------------------------------------
 +8       ;ROR*1.5*21   SEP 2013    T KOPP       Added ICN as last report column if
 +9       ;                                      additional identifier option selected
 +10      ;ROR*1.5*31   MAY 2017    M FERRARESE  Adding PACT, PCP, and AGE/DOB as additional
 +11      ;                                      identifiers.
 +12      ;******************************************************************************
 +13      ;
 +14       QUIT 
 +15      ;
 +16      ;***** OUTPUTS THE REPORT HEADER
 +17      ;
 +18      ; PARTAG        Reference (IEN) to the parent tag
 +19      ;
 +20      ; Return Values:
 +21      ;       <0  Error code
 +22      ;       >0  IEN of the HEADER element
 +23      ;
 +1       ;;DOSES(NP,IPNRX)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT")
 +2       ;;DRUGS_DOSES(#,NAME,NP,IPNRX,MAXNRPP,MAXNP)
 +3       ;;DRUGS_FILLS(#,NAME,NP,OPNRX,MAXNRPP,MAXNP)
 +4       ;;FILLS(NP,OPNRX)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT")
 +5       ;;HU_DOSES(#,NAME,LAST4,DOD,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
 +6       ;;HU_DOSES(#,NAME,LAST4,AGE,DOD,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
 +7       ;;HU_DOSES(#,NAME,LAST4,DOB,DOD,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
 +8       ;;HU_FILLS(#,NAME,LAST4,DOD,OPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
 +9       ;;HU_FILLS(#,NAME,LAST4,AGE,DOD,OPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
 +10      ;;HU_FILLS(#,NAME,LAST4,DOB,DOD,OPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
 +11      ;;HU_NRX(#,NAME,LAST4,DOD,OPNRX,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
 +12      ;;HU_NRX(#,NAME,LAST4,AGE,DOD,OPNRX,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
 +13      ;;HU_NRX(#,NAME,LAST4,DOB,DOD,OPNRX,IPNRX,ND,ICN,PACT,PCP)^I $$PARAM^RORTSK01("PATIENTS","OUTPATIENT"),$$PARAM^RORTSK01("PATIENTS","INPATIENT"),$$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
 +14      ;
 +15       NEW HEADER,RC
 +16       SET HEADER=$$HEADER^RORXU002(.RORTSK,PARTAG)
 +17       if HEADER<0
               QUIT HEADER
 +18       SET RC=$$TBLDEF^RORXU002("HEADER^RORX009",HEADER)
 +19       QUIT $SELECT(RC<0:RC,1:HEADER)
 +20      ;
 +21      ;***** OUTPUTS THE PARAMETERS TO THE REPORT
 +22      ;
 +23      ; PARTAG        Reference (IEN) to the parent tag
 +24      ;
 +25      ; [.STDT]       Start and end dates of the report
 +26      ; [.ENDT]       are returned via these parameters
 +27      ;
 +28      ; [.FLAGS]      Flags for the $$SKIP^RORXU005 are
 +29      ;               returned via this parameter
 +30      ;
 +31      ; Return Values:
 +32      ;       <0  Error code
 +33      ;       >0  IEN of the PARAMETERS element
 +34      ;
PARAMS(PARTAG,STDT,ENDT,FLAGS) ;
 +1        NEW NAME,PARAMS,TMP
 +2        SET PARAMS=$$PARAMS^RORXU002(.RORTSK,PARTAG,.STDT,.ENDT,.FLAGS)
 +3        if PARAMS<0
               QUIT PARAMS
 +4       ;--- Process the drug list and options
 +5        SET TMP=$$DRUGLST^RORXU007(.RORTSK,PARAMS,.RORXL,.RORXGRP)
 +6        if TMP<0
               QUIT TMP
 +7       ;--- Additional parameters
 +8        FOR NAME="MAXUTNUM"
               Begin DoDot:1
 +9                SET TMP=$$PARAM^RORTSK01(NAME)
 +10               if TMP'=""
                       DO ADDVAL^RORTSK11(RORTSK,NAME,TMP,PARAMS)
               End DoDot:1
 +11      ;---
 +12       QUIT PARAMS
 +13      ;
 +14      ;***** COMPILES THE "PHARMACY PRESCRIPTION UTILIZATION" REPORT
 +15      ; REPORT CODE: 009
 +16      ;
 +17      ; .RORTSK       Task number and task parameters
 +18      ;
 +19      ; The ^TMP("RORX009",$J) global node is used by this function.
 +20      ;
 +21      ; ^TMP("RORX009",$J,
 +22      ;
 +23      ;     "IP",             Number of inpatients
 +24      ;       DFN,            Patient's data
 +25      ;                         ^01: Last 4 digits of SSN
 +26      ;                         ^02: Name
 +27      ;                         ^03: Date of Death
 +28      ;                         ^04: Total number of doses
 +29      ;                         ^05: Number of different drugs
 +30      ;                         ^06: National ICN
 +31      ;                         ^07: PACT Patient care team
 +32      ;                         ^08: PCP Primary care physician
 +33      ;                         ^09: AGE/DOB
 +34      ;         "D",
 +35      ;           DrugIEN)    Quantity
 +36      ;
 +37      ;     "IPD",            Number of different drugs
 +38      ;       DrugIEN,        Drug Name
 +39      ;         "D")          Number of doses
 +40      ;         "M")          Maximum
 +41      ;                         ^01: Maximum number of doses
 +42      ;                         ^02: Number of patients
 +43      ;         "P")          Number of patients
 +44      ;       "B",
 +45      ;         NumOfDoses,
 +46      ;           DrugName,
 +47      ;             DrugIEN)  ""
 +48      ;
 +49      ;     "IPRX",           Total number of doses
 +50      ;       NumOfDoses,     Number of patients
 +51      ;         PatientName,
 +52      ;           DFN)        ""
 +53      ;
 +54      ;     "OP",             Number of outpatients
 +55      ;       DFN,            Patient's data
 +56      ;                         ^01: Last 4 digits of SSN
 +57      ;                         ^02: Name
 +58      ;                         ^03: Date of Death
 +59      ;                         ^04: Total number of fills
 +60      ;                         ^05: Number of different drugs
 +61      ;                         ^06: National ICN
 +62      ;                         ^07: PACT Patient care team
 +63      ;                         ^08: PCP Primary care physician
 +64      ;                         ^09: AGE/DOB
 +65      ;         "D",
 +66      ;           DrugIEN)    Quantity
 +67      ;
 +68      ;     "OPD",            Number of different drugs
 +69      ;       DrugIEN,        Drug Name
 +70      ;         "D")          Number of fills
 +71      ;         "M")          Maximum
 +72      ;                         ^01: Maximum number of fills
 +73      ;                         ^02: Number of patients
 +74      ;         "P")          Number of patients
 +75      ;       "B",
 +76      ;         NumOfFills,
 +77      ;           DrugName,
 +78      ;             DrugIEN)  ""
 +79      ;
 +80      ;     "OPRX",           Total number of fills
 +81      ;       NumOfFills,     Number of patients
 +82      ;         PatientName,
 +83      ;           DFN)        ""
 +84      ;
 +85      ;     "SUMRX",
 +86      ;       NumberOfRX,     Number of patients
 +87      ;         PatientName,
 +88      ;           DFN,        Number of different drugs
 +89      ;             "IP")
 +90      ;             "OP")
 +91      ;
 +92      ; Return Values:
 +93      ;       <0  Error code
 +94      ;        0  Ok
 +95      ;
RXUTIL(RORTSK) ;
 +1       ; End date
           NEW ROREDT
 +2       ; Registry IEN
           NEW RORREG
 +3       ; Start date
           NEW RORSDT
 +4       ; List of drug groups
           NEW RORXGRP
 +5       ; List of drugs for the pharmacy search API
           NEW RORXL
 +6       ;
 +7        NEW ECNT,RC,REPORT,SFLAGS,TMP
 +8        SET RORXL=""
           SET (ECNT,RC)=0
 +9        KILL ^TMP("RORX009",$JOB)
 +10      ;--- Root node of the report
 +11       SET REPORT=$$ADDVAL^RORTSK11(RORTSK,"REPORT")
 +12       if REPORT<0
               QUIT REPORT
 +13      ;
 +14       Begin DoDot:1
 +15      ;--- Get and prepare the report parameters
 +16           SET RORREG=$$PARAM^RORTSK01("REGIEN")
 +17           SET RC=$$PARAMS(REPORT,.RORSDT,.ROREDT,.SFLAGS)
               if RC<0
                   QUIT 
 +18      ;--- Report header
 +19           SET RC=$$HEADER(REPORT)
               if RC<0
                   QUIT 
 +20      ;--- Query the registry
 +21           DO TPPSETUP^RORTSK01(80)
 +22           SET RC=$$QUERY^RORX009A(SFLAGS)
 +23           IF RC
                   if RC<0
                       QUIT 
                   SET ECNT=ECNT+RC
 +24      ;--- Sort the data
 +25           DO TPPSETUP^RORTSK01(10)
 +26           SET RC=$$SORT^RORX009A()
 +27           IF RC
                   if RC<0
                       QUIT 
                   SET ECNT=ECNT+RC
 +28      ;--- Store the results
 +29           DO TPPSETUP^RORTSK01(10)
 +30           SET RC=$$STORE^RORX009C(REPORT)
 +31           IF RC
                   if RC<0
                       QUIT 
                   SET ECNT=ECNT+RC
           End DoDot:1
 +32      ;
 +33      ;--- Cleanup
 +34       KILL ^TMP("RORX009",$JOB)
 +35       DO FREE^RORTMP(RORXL)
 +36       QUIT $SELECT(RC<0:RC,ECNT>0:-43,1:0)