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

APSPCTR1.m

Go to the documentation of this file.
APSPCTR1 ; IHS/DSD/ENM - CONTROLLED DRUG REPORT PRINTOUT ;11-Nov-2009 10:11;SM
 ;;7.0;IHS PHARMACY MODIFICATIONS;**1008**;Sep 23, 2004
 ;THIS ROUTINE PRINTS THE PHARMACY CONTROLLED DRUG LISTING
 ;IT IS CALLED BY ^APSPCTR
 ;Modified - IHS/MSC/PLS - 12/30/08 - Patch 1008 - Routine updated
 Q
PRINT ;EP
 N APSPPG,DFLG,NEWPG,DPARTIAL,TPARTIAL,DNEW,DREFILL,APSPGT,APSPT
 S (APSPPG,DFLG,NEWPG,APSPGT)=0
 S (DCOUNT,TCOUNT,DNEW,TNEW,DREFILL,DPARTIAL,TPARTIAL,TREFILL,TQTY)=0
 D PRINT1
 W:'DFLG !,"No data found..."
 Q
 ;
PRINT1 ;EP
 N DIV,SUB1,SUB2,SUB3,SUB4,SUB5,VAL,LP,LSTFDT,APSPSH
 S LSTFDT=0
 S APSP(2)=0,APSP("3-5")=0,(APSPT(2),APSPT(35))=0
 S DIV=0 F  S DIV=$O(^TMP($J,"XREF",DIV)) Q:'DIV  D
 .D HDR
 .I APSPDTDR=2 D  ; Drug Name
 ..S SUB1="" F  S SUB1=$O(^TMP($J,"XREF",DIV,"DRUG",SUB1)) Q:SUB1=""  D  ; Drug Name
 ...S SUB2="" F  S SUB2=$O(^TMP($J,"XREF",DIV,"DRUG",SUB1,SUB2)) Q:SUB2=""  D  ; Drug Class
 ....S APSPSH=SUB2
 ....S SUB3=0 F  S SUB3=$O(^TMP($J,"XREF",DIV,"DRUG",SUB1,SUB2,SUB3)) Q:'SUB3  D  ; Fill Date
 .....S SUB4=0 F  S SUB4=$O(^TMP($J,"XREF",DIV,"DRUG",SUB1,SUB2,SUB3,SUB4)) Q:'SUB4  D  ; Data Node
 ......D PRINT2(^TMP($J,"DATA",SUB4))
 ......S DFLG=1
 ......D TOTALS
 ....D SUB2
 ..D DIVSUB
 .E  D  ; Fill Date
 ..S SUB1=0 F  S SUB1=$O(^TMP($J,"XREF",DIV,"FDT",SUB1)) Q:'SUB1  D  ; Fill Date
 ...S SUB2="" F  S SUB2=$O(^TMP($J,"XREF",DIV,"FDT",SUB1,SUB2)) Q:SUB2=""  D  ; Drug Class
 ....S APSPSH=SUB2
 ....S SUB3="" F  S SUB3=$O(^TMP($J,"XREF",DIV,"FDT",SUB1,SUB2,SUB3)) Q:SUB3=""  D  ; Data Name
 .....S SUB4=0 F  S SUB4=$O(^TMP($J,"XREF",DIV,"FDT",SUB1,SUB2,SUB3,SUB4)) Q:'SUB4  D  ; Data Node
 ......D PRINT2(^TMP($J,"DATA",SUB4))
 ......S DFLG=1
 ......D TOTALS
 ....D SUB
 ..D DIVSUB1
 Q
 ; Print the line
PRINT2(DATA) ; EP -
 N RX,DFN,HRN
 S RX=+DATA
 S DFN=$$GET1^DIQ(52,RX,2,"I")
 S HRN=$$HRN^AUPNPAT(DFN,DUZ(2))
 S TQTY=TQTY+$P(DATA,U,6)
 S DCOUNT=DCOUNT+1
 I $P(DATA,U,3)="ADP" D
 .S DPARTIAL=DPARTIAL+1
 E  D
 .I $P(DATA,U,4) D
 ..S DREFILL=DREFILL+1
 .E  S DNEW=DNEW+1
 ;                1            2             3                  4             5            6       7         8         9       10      11         12          13          14        15       16
 ;Format: Prescription IEN^Fill Date^Xref ("AD" or "ADP")^Fill SubIEN^Prescription Number^QTY^Drug Class^Drug Name^Fill Type^RI Flg^Drug IEN^RX Division^Days Supply^Prescriber^Pharmacist^Clerk
 W !,$P(DATA,U,5),?15,$P(DATA,U,8),?57,$P(DATA,U,6),?64,$$GET1^DIQ(200,$P(DATA,U,14),.01),?83,$$FMTE^XLFDT($P(DATA,U,2),"5Z"),?98,$E($$GET1^DIQ(2,DFN,.01),1,18),?118,HRN,?127,$$GET1^DIQ(200,$P(DATA,U,16),1)
 D PRINT3 ;check page length
 Q
 ; Check page length and optionally print blank line
 ;
PRINT3 ;EP
 D:$Y+8>IOSL HDR
 Q
 ;Date order loop
LOOP F APSPD=0:0 S APSPD=$O(^TMP("APSP",$J,APSPDIV,APSPD)) Q:APSPD=""  F APSPSH=0:0 S APSPSH=$O(^TMP("APSP",$J,APSPDIV,APSPD,APSPSH)) Q:'APSPSH  D LOOP1,SUB
 Q
LOOP1 F APSPDR=0:0 S APSPDR=$O(^TMP("APSP",$J,APSPDIV,APSPD,APSPSH,APSPDR)) Q:'APSPDR  F APSPN=0:0 S APSPN=$O(^TMP("APSP",$J,APSPDIV,APSPD,APSPSH,APSPDR,APSPN)) Q:'APSPN  D PRINT,TOTALS
 Q
 ;Drug order loop
LOP F APSPDR=0:0 S APSPDR=$O(^TMP("APSP",$J,APSPDIV,APSPDR)) Q:APSPDR=""  F APSPSH=0:0 S APSPSH=$O(^TMP("APSP",$J,APSPDIV,APSPDR,APSPSH)) Q:'APSPSH  D LOP1,SUB2
 Q
LOP1 F APSPD=0:0 S APSPD=$O(^TMP("APSP",$J,APSPDIV,APSPDR,APSPSH,APSPD)) Q:'APSPD  F APSPN=0:0 S APSPN=$O(^TMP("APSP",$J,APSPDIV,APSPDR,APSPSH,APSPD,APSPN)) Q:'APSPN  D PRINT,TOTALS
 Q
DIVSUB ;PRINT TOTAL PRESCRIPTIONS/REFILLS
 W ! F I=1:1:IOM W "-"
 W !,"TOTAL # OF PRESCRIPTIONS : ",APSPGT
 W ?($X+5),"TOTAL # NEW RX'S : ",TNEW
 W ?($X+5),"TOTAL # REFILLS : ",TREFILL
 W ?($X+5),"TOTAL # PARTIALS : ",TPARTIAL
 S (APSP("PAGE"),APSPGT,TNEW,TREFILL,TPARTIAL)=0
 I $E(IOST,1,2)="P-" W !,@IOF
 Q
DIVSUB1 ;PRINT TOTAL SPECIAL HANDLING CODES
 W ! F I=1:1:IOM W "-"
 W !,"TOTAL # OF PRESCRIPTIONS : ",APSPGT
 W ?($X+5),"TOTAL # CODE 2's : ",APSPT(2)
 W ?($X+5),"TOTAL # CODES 3-5 : ",APSPT(35)
 S (APSP("PAGE"),APSPT(2),APSPT(35),APSPGT)=0
 I $E(IOST,1,2)="P-" W !,@IOF
 Q
SUB ;W ! F I=1:1:43 W "-"
 S APSP("2")=0,APSP("3-5")=0
 Q
SUB2 W ! F I=1:1:43 W "-"
 W !,"SUB-TOTAL # OF RX's : ",TCOUNT
 W ?($X+5),"TOTAL QTY : ",TQTY,!
 S TCOUNT=0,TQTY=0
 Q
TOTALS ;
 I APSPDTDR=1,"345"[+APSPSH S APSP("3-5")=APSP("3-5")+1,APSPT(35)=APSPT(35)+1
 I APSPDTDR=1,+APSPSH=2 S APSP(2)=APSP(2)+1,APSPT(2)=APSPT(2)+1
 S TCOUNT=TCOUNT+DCOUNT,APSPGT=APSPGT+DCOUNT,DCOUNT=0
 S TNEW=TNEW+DNEW,DNEW=0
 S TREFILL=TREFILL+DREFILL,DREFILL=0
 S TPARTIAL=TPARTIAL+DPARTIAL,DPARTIAL=0
 Q
HDR ;EP
 W @IOF
 S APSPPG=APSPPG+1
 S APSPDV=$P(^PS(59,DIV,0),U)
 W !!,APSPDV," CONTROLLED DRUG USE LIST (By ",$S(APSPDTDR=1:"DATE",APSPDTDR=2:"Drug",1:"")_" Order)"
 W ?73,"Page ",APSPPG
 W !,"DATE OF LISTING: "
 W $$FMTE^XLFDT($$DT^XLFDT(),"5Z")
 W !,"Drug Class: "_APSPDCTN(APSPDCLS)
 K X,Y
 I APSPDIV="*" W !,"All Divisions for: ",$P(^DIC(4,DUZ(2),0),U,1)
 W !,"Division: ",$G(APSPDV)
 W !!,"This list will include all Prescriptions for any controlled"
 W " medications dispensed from "
 W APSPBDF," through ",APSPEDF,!!
 W !!,"RX #",?13,"DRUG",?57,"QTY",?64,"PHYSICIAN"
 W ?83,"DATE FILLED",?98,"PATIENT",?118,"CHART #",?127,"CLERK"
 W ! F I=1:1:IOM W "-"
 I '$D(^TMP($J,"DATA")) W !!?20,"NO PATIENTS RECEIVED MEDICATION"
 W !
 Q