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

PSDPAT2.m

Go to the documentation of this file.
PSDPAT2 ;B'ham ISC/JPW - Print Patient/Drug Report (summary) ; 1 Feb 94
 ;;3.0;CONTROLLED SUBSTANCES ;**68,72**;13 Feb 97;Build 8
 D NOW^%DTC S Y=+$E(%,1,12) X ^DD("DD") S RPDT=Y
 S (PG,PSDOUT)=0,$P(LN,"-",80)=""
 I '$D(^TMP("PSDPATL",$J)) D HDR W !!,?45,"****  NO DISPENSING SUMMARY  ****" Q
PRINT ;prints data for dispensing
 D HDR Q:PSDOUT
 S LOOP="" F  S LOOP=$O(^TMP("PSDPATL",$J,LOOP)) Q:LOOP=""!(PSDOUT)  D:$Y+4>IOSL HDR Q:PSDOUT  D  Q:PSDOUT
 .W !,LOOP,?55,$J(+$P(^TMP("PSDPATL",$J,LOOP),"^",3),6),?70,$J(+$P(^(LOOP),"^",2),6),!
DONE I SUM,$E(IOST)'="C" W @IOF
 Q
HDR ;lists header information
 I $E(IOST,1,2)="C-",PG W ! K DA,DIR S DIR(0)="E" D ^DIR K DIR I 'Y S PSDOUT=1 Q
 W:$Y @IOF S PG=PG+1 W !,?22,"ACTIVITY",?70,"PG "_PG,!,?29,"** SUMMARY **",!,?27,"Date: ",$P(PSDATE,"^")," to ",$P(PSDATE,"^",2),!!,"NAOU: ",NAOUN,!!
 W "DRUG",?55,"QUANTITY USED",?70,"BALANCE",!,LN,!
 Q
 ;; ADDED FOR 3*68 - RJS
SET ;sets data
 N PSDREA
 Q:'$D(^PSD(58.81,PSDA,0))  S PSD0=^(0),PSDQTY=+$P(PSD0,U,6),PSD=$P(PSD0,U,4),PSDREA=$P(PSD0,U,16)
 S PSD9=$G(^PSD(58.81,PSDA,9)) S PSDSOQT=+$P(PSD9,U,3),PSDWQT=+$P(PSD9,U,4)
 I +$P(PSD0,U,5) S PSDDRG1=+$P(PSD0,U,5)
 I PSDTYP=17,'+$P(^PSD(58.81,PSDA,9),"^",1) D
 .S PSDTYP=9,PSDQTY=PSDQTY*-1,PSDREA="DEFECTIVE DOSE"
 I PSDTYP=17 S $P(PSDRG(+PSDRUG),U,2)=+$P(PSDRG(+PSDRUG),U,2)+PSDSOQT+PSDWQT
 S PSD3=$G(^PSD(58.81,PSDA,3)) S PSDRET=+$P(PSD3,U),PSDRQT=+$P(PSD3,U,2),PSDRRE=$P(PSD3,U,3),PSDDQT=+$P(PSD3,U,5),PSDDRE=$P(PSD3,U,6),PSDDT=+$P(PSD3,U,4)
 S DFN=+$P($G(PSD9),U) D DEM^VADPT
 S PSDPAT=$S(PSDTYP=18:"WASTED AMOUNT",PSDTYP=11:"INITIALIZE BALANCE",PSDTYP=9:"BALANCE ADJUSTMENT",PSDTYP=23:"COUNT VERIFICATION",'VAERR:VADM(1),1:"UNKNOWN")
 S:PSDTYP=2!(PSDTYP=3) PSDPAT="PHARMACY DISP#"_$P(PSD0,U,17),PSDTYP=0,PSDTR=PSDA
 S PSDNR1=$S($P(PSD9,U,2)'="":$P(PSD9,U,2),1:$P(PSD0,U,7))
 S:PSDNR1'=$P(PSD0,U,7) PSDNR1(1)=$P(PSD0,U,7)
 S:+$G(PSDNR1) PSDNR1=$S($P($G(^VA(200,+PSDNR1,0)),U)]"":$P(^(0),U),1:"UNKNOWN")
 S PSDNR2=$P($G(PSD9),U,6) S:PSDNR2 PSDNR2=$S($P($G(^VA(200,+PSDNR2,0)),U)]"":$P(^(0),U),1:"")
 S PSDRN=$S($P($G(^PSDRUG(+PSDRUG,0)),U)]"":$P(^(0),U),1:"ZZ/"_PSDRUG_" NAME MISSING")
SET1 ;sets ^TMP("PSDPAT"
 I PSDTYP=17,'+$P(^PSD(58.81,PSDA,9),"^",1) S PSDTYP=9
 I $G(^PSD(58.81,PSDA,1)),$P(PSD3,U,1)'="" D CHKRET Q:PSD<PSDSD
 I $P(PSD3,U,4)'="" D CHKDEST
 I PSDTYP=0 D CHKNOD7
 S PSDQTY=$S(PSDTYP=17:0,1:PSDQTY),PSDRQT=$S(PSDTYP=17:PSDRQT,1:-PSDRQT)
 I PSD>PSDED N PSDEND S PSDEND=1
 I '$G(PSDEND) D
 .Q:PSD<PSDSD
 .K PSDATA
 .I '$D(PSDREA) N PSDREA S PSDREA=$P(PSD0,U,16)
 .S PSDATA=PSDQTY_U_PSDNR1_U_PSDNR2_U_PSDTYP_U_PSDWQT_U_PSDREA_U_PSDBAL_U_$G(PSDNR1(1))_U_PSDRQT_U_PSDRRE_U_PSDDRG1_U_PSDSOQT_"^^^"_PSDRET_U_PSDDT
 .S PSDCNT=PSDCNT+1 D PSDPAT,PSDPATL I $P(PSD3,U,4)'=""
 I $G(PSDEND) D
 .Q:PSD<PSDSD
 .S PSDATA=1 D PSDPATL
 I $G(PSDTRQT),PSDTFDT<PSDED D
 .I '$G(PSDEND) D
 ..I PSD<PSDED,PSD>PSDSD S PSDATA="0^^^"_PSDTYP_"^^^"_PSDBAL_"^^^^^^^^^"_U_PSDTFDT_U_PSDNR1_U_PSDT2N_U_PSDTTDT_U_PSDTTNR_U_PSDTPRV_U_PSDTRQT_U_PSDSTAT
 ..S PSDQTY=PSDTRQT*-1
 ..N PSD S PSD=PSDTFDT,PSDCNT=PSDCNT+1 D PSDPAT,PSDPATL
 . I $G(PSDEND) S PSDATA=1 D PSDPATL
 .S PSDEND=$G(^TMP("PSDPAT1",$J,PSDRUG,PSDA))
 I $G(PSDTRQT),(PSDTFDT>PSDED!(PSDTFDT=PSDED)) N PSDEND S PSDQTY=PSDTRQT*-1,PSDEND=1 D
 .I $G(PSDEND) S PSDATA=1 D PSDPATL
 K PSDATA,PSDQTY,PSDTRQT,PSDNR1,PSDNR2,PSD0,PSD3,PSD7,PSDTR Q
SET2 ;SETS ^TMP("PSDPAT"
 N PSDTRDT,PSDPAT
 S PSD0=$G(^PSD(58.81,PSDA,0)),PSDRN=$S($P($G(^PSDRUG(+PSDRUG,0)),U)]"":$P(^(0),U),1:"ZZ/"_PSDRUG_" NAME MISSING")
 S PSDTRDT=$P(^PSD(58.81,PSDA,1),U,4),PSDPAT="PHARMACY DISP #"_$P(PSD0,U,17),PSD=$P(PSD0,U,4)
 Q:$D(^TMP("PSDPAT",$J,PSDRN,PSDTRDT))
 I PSDTYP=5 S PSD7=$G(^PSD(58.81,+PSDA,7)) D NODE7
 S PSDTR=PSDA D
 .D CHKNOD7
 .I $G(PSDTRQT) D
 ..I PSD<PSDED,PSD>PSDSD S PSDEND=0
 ..I '$G(PSDEND) D
 ...K PSDATA
 ...S PSDCNT=PSDCNT+1,PSDPAT="PHARMACY DISP #"_$P(PSD0,U,17),PSDATA="^^^0^^^^^^^^^^^^^"_PSDTFDT_U_PSDTFN_U_PSDT2N_U_PSDTTDT_U_PSDTTNR_U_PSDTPRV_U_PSDTRQT_U_PSDSTAT
 ...D PSDPAT,PSDPATL
 ..S PSDEND=$G(^TMP("PSDPAT1",$J,PSDRUG,PSDA))
 K PSDATA,PSDQTY,PSDTRQT,PSDNR1,PSDNR2,PSD0,PSD3,PSD7,PSDTR
 Q
CHKNOD7 ; COLLECTS TRANSFER DATA
 S PSD7=$G(^PSD(58.81,+PSDTR,7)) Q:$G(PSD7)=""
 S PSDSTAT=$P($G(^PSD(58.81,+PSDTR,0)),U,11)
 S PSDTFDT=+$P(PSD7,U),PSDTTON=+$P(PSD7,U,3),PSDT2N=$P($G(^PSD(58.8,PSDTTON,0)),U),PSDTTDT=+$P(PSD7,U,4),PSDTPRV=+$P(PSD7,U,6),PSDTRQT=+$P(PSD7,U,7)
 S PSDTFN=$S($P(PSD7,U,2):$P(PSD7,U,2),1:$P(PSD0,U,7))
 S:PSDTFN'=$P(PSD0,U,7) PSDTFN(1)=$P(PSD0,U,7) S PSDTFN=$S($P($G(^VA(200,+PSDTFN,0)),U)]"":$P(^(0),U),1:"UNKNOWN")
 S PSDTTNR=$P($G(PSD7),U,5) S:PSDTTNR PSDTTNR=$S($P($G(^VA(200,+PSDTTNR,0)),U)]"":$P(^(0),U),1:"")
 Q
NODE7 ; SETS TRANSFERS BETWEEN NAOU'S
 I $P(PSD3,U,1)'="" D CHKRET Q:PSD<PSDSD
 I $P(PSD3,U,4)'="" D CHKDEST Q:PSD<PSDSD
 S (PSDTFDT,PSDTFN,PSDTTDT,PSDTTNR,PSDTPRV,PSDTRQT,PSDSTAT)=""
 S PSDTTON=+$P(^PSD(58.81,$P(PSD7,U,6),0),U,18),PSDT2N=$P($G(^PSD(58.8,PSDTTON,0)),U),PSDTRQT=+PSDQTY
 I PSD<PSDED,PSD>PSDSD S PSDEND=0
 I '$G(PSDEND) D
 .S PSDTFN=+$P(^PSD(58.81,$P(PSD7,U,6),7),U,2) S:PSDTFN PSDTFN=$S($P($G(^VA(200,+PSDTFN,0)),U)]"":$P(^(0),U),1:"")
 .S PSDTRQT=$P(^PSD(58.81,$P(PSD7,U,6),7),U,7)
 .K PSDATA S PSDATA=PSDQTY_U_PSDNR1_U_PSDNR2_U_PSDTYP_U_PSDWQT_U_$P(PSD0,U,16)_"^^"_$G(PSDNR1(1))_U_PSDRQT_U_PSDRRE
 .S PSDATA=PSDATA_U_PSDDRG1_U_PSDSOQT_"^^^^^^^"_PSDT2N_U_U_PSDTFN_"^^"_PSDTRQT_U,PSDCNT=PSDCNT+1
 .Q:PSD<PSDSD
 .D PSDPAT,PSDPATL
 .S PSDEND=$G(^TMP("PSDPAT1",$J,PSDRUG,PSDA))
 I $G(PSDEND) D PSDPAT,PSDPATL
 I $P(PSD7,U,1) S PSDTR=PSDA D
 .D CHKNOD7
 .I PSD<PSDED,PSD>PSDSD S PSDEND=0
 .I '$G(PSDEND) D
 ..K PSDATA
 ..S $P(PSDATA,U,4)=PSDTYP,$P(PSDATA,U,17)=PSDTFDT,PSDATA=PSDATA_U_PSDTFN_U_PSDT2N_U_PSDTTDT_U_PSDTTNR_U_PSDTPRV_U_PSDTRQT_U_PSDSTAT
 ..S PSDCNT=PSDCNT+1,PSDQTY=PSDTRQT*-1 D PSDPAT,PSDPATL
 .S PSDEND=$G(^TMP("PSDPAT1",$J,PSDRUG,PSDA))
 I $G(PSDEND) s PSDATA=1 D PSDPATL
 Q
CHKRET ; SETS RETURNED ITEM INFORMATION
 N PSD,PSDNR1,PSDNR2,PSDQTY S PSD=$P(^PSD(58.81,PSDA,0),U,19),(PSDQTY,PSDWQT,PSDSOQT,PSDDQT,PSDDRE)=0
 S PSDNR1=+$P(^PSD(58.81,PSDA,1),U,10),PSDNR1=$S($P($G(^VA(200,+PSDNR1,0)),U)]"":$P(^(0),U),1:"UNKNOWN")
 S PSDNR2=+$P(^PSD(58.81,PSDA,1),U,14) S:PSDNR2 PSDNR2=$S($P($G(^VA(200,+PSDNR2,0)),U)]"":$P(^(0),U),1:"")
 S PSDRET=+$P(PSD3,U),PSDRQT=+$P(PSD3,U,2),PSDRRE=$P(PSD3,U,3),PSDDQT=+$P(PSD3,U,5),PSDDRE=$P(PSD3,U,6),PSDDT=+$P(PSD3,U,4)
 K PSDATA
 S PSDQTY=PSDRQT*-1
 I PSD>PSDED N PSDEND S PSDEND=1
 I '$G(PSDEND) D
 .I PSD<PSDED D
 ..S PSDATA="0^"_PSDNR1_U_PSDNR2_"^99^0^"_$P(PSD0,U,16)_"^0^^"_PSDRQT_U_PSDRRE_U_PSDDRG1_"^0^0^0^"_PSDRET
 ..S PSDCNT=PSDCNT+1
 ..D PSDPAT,PSDPATL
 ..S PSDRQT=0,(PSDRRE,PSDRET)=""
 I $G(PSDEND) D
 .Q:PSD<PSDSD
 .S PSDATA=1 D PSDPATL
 S PSDRQT=0,PSDRRE="" K PSDATA
 Q 
CHKDEST ; SETS DESTROYED ITEM INFORMATION
 N PSD,PSDNR1,PSDNR2,PSDQTY  S PSD=$P(PSD3,U,4)
 S PSDNR1=+$P(^PSD(58.81,PSDA,1),U,10),PSDNR1=$S($P($G(^VA(200,+PSDNR1,0)),U)]"":$P(^(0),U),1:"UNKNOWN")
 S PSDNR2=+$P(^PSD(58.81,PSDA,1),U,14) S:PSDNR2 PSDNR2=$S($P($G(^VA(200,+PSDNR2,0)),U)]"":$P(^(0),U),1:"")
 S PSDDQT=$P(PSD3,U,5),PSDDRE=$P(PSD3,U,6) K PSDATA
 I PSD>PSDED N PSDEND S PSDEND=1
 I '$G(PSDEND) D
 .Q:PSD<PSDSD
 .S PSDATA="0^"_PSDNR1_U_PSDNR2_"^4^0^"_$P(PSD0,U,16)_"^0^^0^0^"_PSDDRG1_"^0^"_PSDDQT_U_PSDDRE
 .S PSDCNT=PSDCNT+1 D PSDPAT
 .S PSDQTY=PSDDQT*-1,PSDATA=1 D PSDPATL
 I $G(PSDEND) S PSDQTY=PSDDQT*-1,PSDATA=1 D PSDPATL
 K PSDATA
 Q 
PSDPAT ;sets ^TMP("PSDPAT"
 Q:'$D(PSDATA)
 S ^TMP("PSDPAT",$J,PSDRN,PSD,PSDPAT,PSDCNT)=PSDATA
 Q
PSDPATL ;sets ^TMP("PSDPATL"
 Q:'$D(PSDATA)
 S:'$D(^TMP("PSDPATL",$J,PSDRN)) ^TMP("PSDPATL",$J,PSDRN)=0
 S ^TMP("PSDPATL",$J,PSDRN)=+^TMP("PSDPATL",$J,PSDRN)+($S(PSDTYP=18:-PSDQTY,PSDTYP=17:-((PSDSOQT+PSDWQT)-PSDRQT),1:PSDQTY)),$P(^(PSDRN),U,2)=+PSDRG(PSDRUG)
 S $P(^TMP("PSDPATL",$J,PSDRN),U,3)=+$P(^TMP("PSDPATL",$J,PSDRN),U,3)+$P(PSDRG(+PSDRUG),U,2)
 Q