APCDDVL5 ; IHS/CMI/LAB - report on T/C VISITS WITH ANCILLARY ;
;;2.0;IHS PCC SUITE;;MAY 14, 2009
;IHS/CMI/LAB - patch 1 Y2K
;
;
START ;
D EOJ
D INFORM
GETDATES ;
BD ;get beginning date
W ! S DIR(0)="D^:DT:EP",DIR("A")="Enter beginning Visit Date" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
I $D(DIRUT) G EOJ
S APCDBD=Y
ED ;get ending date
W ! S DIR(0)="DA^"_APCDBD_":DT:EP",DIR("A")="Enter ending Visit Date: " S Y=APCDBD D DD^%DT S Y="" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
I $D(DIRUT) G BD
S APCDED=Y
;
SORT ;
S APCDCSRT=""
S DIR(0)="S^T:Terminal Digit Order;H:Health Record Number Order;D:Visit Date Order",DIR("A")="Sort the report by",DIR("B")="T" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
I $D(DIRUT) G ED
S APCDCSRT=Y
ZIS ;call to XBDBQUE
S XBRP="PRINT^APCDDVL5",XBRC="PROCESS^APCDDVL5",XBRX="EOJ^APCDDVL5",XBNS="APCD"
D ^XBDBQUE
D EOJ
Q
;
EOJ ;
D EN^XBVK("APCD")
Q
PROCESS ;EP - called from XBDBQUE
S ^XTMP("APCDDVL5",0)=$$FMADD^XLFDT(DT,14)_"^"_DT_"^"_"APCD - RETURN TO STOCK MEDS"
S APCDJ=$J,APCDBT=$H
S APCDT=APCDBD-.0001,APCDEND=APCDED+.2400
F S APCDT=$O(^AUPNVSIT("B",APCDT)) Q:'APCDT!(APCDT>APCDEND) D
. S APCDV=0
. F S APCDV=$O(^AUPNVSIT("B",APCDT,APCDV)) Q:'APCDV D
.. S G=0
.. I '$$RTS(APCDV) Q
.. Q:$P(^AUPNVSIT(APCDV,0),U,7)="C"
.. Q:$P(^AUPNVSIT(APCDV,0),U,7)="T"
.. Q:$$CLINIC^APCLV(APCDV,"C")=51
.. Q:$$CLINIC^APCLV(APCDV,"C")=52
.. S APCDSORT="" D GETSORT I APCDSORT="" S APCDSORT="??"
.. S ^XTMP("APCDDVL5",APCDJ,APCDBT,"VISITS",APCDSORT,APCDV)=""
.. Q
. Q
Q
RTS(V) ;
NEW G,X,C
;if all have returned to stock
S G=0,X=0,C=0
F S X=$O(^AUPNVMED("AD",V,X)) Q:X'=+X D
.S C=C+1 ;# OF VMEDS
.I $P($G(^AUPNVMED(X,11)),U)["RETURNED TO STOCK" S G=G+1
.Q
I 'G Q 0
Q 1
GETSORT ;get sort value
I APCDCSRT="D" S APCDSORT=$P(^AUPNVSIT(APCDV,0),U) Q
;I APCDCSRT="C" S APCDSORT=$$CLINIC^APCLV(APCDV,"C") Q ;clinic code
;hrn sort values
S APCDSORT=$$HRN^AUPNPAT($P(^AUPNVSIT(APCDV,0),U,5),DUZ(2))
Q:APCDCSRT'="T"
S APCDSORT=APCDSORT+10000000,APCDSORT=$E(APCDSORT,7,8)_"-"_+$E(APCDSORT,2,8)
Q
PRINT ;EP - called from XBDBQUE
S APCDQUIT="",APCDPG=0 D HDR
I '$D(^XTMP("APCDDVL5",APCDJ,APCDBT)) D HDR W !!,"NO DATA TO REPORT",! G DONE
S APCDSORT="" F S APCDSORT=$O(^XTMP("APCDDVL5",APCDJ,APCDBT,"VISITS",APCDSORT)) Q:APCDSORT=""!(APCDQUIT) D
. S APCDV=0 F S APCDV=$O(^XTMP("APCDDVL5",APCDJ,APCDBT,"VISITS",APCDSORT,APCDV)) Q:APCDV'=+APCDV!(APCDQUIT) D
.. I $Y>(IOSL-4) D HDR Q:APCDQUIT
.. S APCDVR=^AUPNVSIT(APCDV,0)
.. W !,$E($P(^DPT($P(APCDVR,U,5),0),U),1,15),?16,$$HRN^AUPNPAT($P(APCDVR,U,5),DUZ(2)),?24,$$DATE($P($P(APCDVR,U),".")),?36,$P(APCDVR,U,7),?39,$$CLINIC^APCLV(APCDV,"C") ;Y2000
.. S APCDC=0,APCDM=0 F S APCDM=$O(^AUPNVMED("AD",APCDV,APCDM)) Q:APCDM'=+APCDM!(APCDQUIT) D
... S APCDC=APCDC+1
... I $Y>(IOSL-3) D HDR Q:APCDQUIT
... W:APCDC>1 !
... W ?45,$E($$VAL^XBDIQ1(9000010.14,APCDM,.01),1,28)
... I $P($G(^AUPNVMED(APCDM,11)),U)["RETURNED TO STOCK" W ?75,"Yes" I 1
... E W ?75,"No"
.Q
DONE ;
K ^XTMP("APCDDVL5",APCDJ,APCDBT),APCDJ,APCDBT
I $E(IOST)="C",IO=IO(0) S DIR(0)="EO",DIR("A")="End of report. PRESS ENTER" D ^DIR K DIR S:$D(DUOUT) DIRUT=1
W:$D(IOF) @IOF
Q
DATE(D) ;
I D="" Q ""
Q $E(D,4,5)_"/"_$E(D,6,7)_"/"_(1700+$E(D,1,3))
HDR ;header for report
I 'APCDPG G HDR1
I $E(IOST)="C",IO=IO(0) W ! S DIR(0)="EO" D ^DIR K DIR I Y=0!(Y="^")!($D(DTOUT)) S APCDQUIT=1 Q
HDR1 ;
W:$D(IOF) @IOF S APCDPG=APCDPG+1
W $P(^VA(200,DUZ,0),U,2),$$CTR($$FMTE^XLFDT(DT)),?71,"Page ",APCDPG,!
W $$CTR($$LOC),!
W $$CTR("Visits with a RETURNED TO STOCK Medication"),!
W !?3,"PATIENT NAME",?17,"HRN",?24,"VISIT DATE",?36,"SC",?39,"CL",?45,"DRUG",?75,"RTS?",!
W $TR($J(" ",80)," ","-"),!
Q
CTR(X,Y) ;EP - Center X in a field Y wide.
Q $J("",$S($D(Y):Y,1:IOM)-$L(X)\2)_X
;----------
USR() ;EP - Return name of current user from ^VA(200.
Q $S($G(DUZ):$S($D(^VA(200,DUZ,0)):$P(^(0),U),1:"UNKNOWN"),1:"DUZ UNDEFINED OR 0")
;----------
LOC() ;EP - Return location name from file 4 based on DUZ(2).
Q $S($G(DUZ(2)):$S($D(^DIC(4,DUZ(2),0)):$P(^(0),U),1:"UNKNOWN"),1:"DUZ(2) UNDEFINED OR 0")
;----------
INFORM ;let user know what is gong on
W:$D(IOF) @IOF
W !!,$$CTR($$LOC,80)
W !,$$CTR($$USR,80),!!
F I=1:1 S X=$P($T(INTRO+I),";;",2) Q:X="END" W !,X
K I,X
Q
INTRO ;;
;;This report will list all non chart review/telephone call visits
;;with a V Medication that is flagged as RETURN TO STOCK.
;;
;;
;;
;;END
S X=$$ADD^XPDMENU("APCDDVR","APCD C T VISITS W ANCILLARY","CTA")
I 'X W "Attempt to add update option failed." H 3
Q
APCDDVL5 ; IHS/CMI/LAB - report on T/C VISITS WITH ANCILLARY ;
+1 ;;2.0;IHS PCC SUITE;;MAY 14, 2009
+2 ;IHS/CMI/LAB - patch 1 Y2K
+3 ;
+4 ;
START ;
+1 DO EOJ
+2 DO INFORM
GETDATES ;
BD ;get beginning date
+1 WRITE !
SET DIR(0)="D^:DT:EP"
SET DIR("A")="Enter beginning Visit Date"
DO ^DIR
KILL DIR
IF $DATA(DUOUT)
SET DIRUT=1
+2 IF $DATA(DIRUT)
GOTO EOJ
+3 SET APCDBD=Y
ED ;get ending date
+1 WRITE !
SET DIR(0)="DA^"_APCDBD_":DT:EP"
SET DIR("A")="Enter ending Visit Date: "
SET Y=APCDBD
DO DD^%DT
SET Y=""
DO ^DIR
KILL DIR
IF $DATA(DUOUT)
SET DIRUT=1
+2 IF $DATA(DIRUT)
GOTO BD
+3 SET APCDED=Y
+4 ;
SORT ;
+1 SET APCDCSRT=""
+2 SET DIR(0)="S^T:Terminal Digit Order;H:Health Record Number Order;D:Visit Date Order"
SET DIR("A")="Sort the report by"
SET DIR("B")="T"
DO ^DIR
KILL DIR
IF $DATA(DUOUT)
SET DIRUT=1
+3 IF $DATA(DIRUT)
GOTO ED
+4 SET APCDCSRT=Y
ZIS ;call to XBDBQUE
+1 SET XBRP="PRINT^APCDDVL5"
SET XBRC="PROCESS^APCDDVL5"
SET XBRX="EOJ^APCDDVL5"
SET XBNS="APCD"
+2 DO ^XBDBQUE
+3 DO EOJ
+4 QUIT
+5 ;
EOJ ;
+1 DO EN^XBVK("APCD")
+2 QUIT
PROCESS ;EP - called from XBDBQUE
+1 SET ^XTMP("APCDDVL5",0)=$$FMADD^XLFDT(DT,14)_"^"_DT_"^"_"APCD - RETURN TO STOCK MEDS"
+2 SET APCDJ=$JOB
SET APCDBT=$HOROLOG
+3 SET APCDT=APCDBD-.0001
SET APCDEND=APCDED+.2400
+4 FOR
SET APCDT=$ORDER(^AUPNVSIT("B",APCDT))
IF 'APCDT!(APCDT>APCDEND)
QUIT
Begin DoDot:1
+5 SET APCDV=0
+6 FOR
SET APCDV=$ORDER(^AUPNVSIT("B",APCDT,APCDV))
IF 'APCDV
QUIT
Begin DoDot:2
+7 SET G=0
+8 IF '$$RTS(APCDV)
QUIT
+9 IF $PIECE(^AUPNVSIT(APCDV,0),U,7)="C"
QUIT
+10 IF $PIECE(^AUPNVSIT(APCDV,0),U,7)="T"
QUIT
+11 IF $$CLINIC^APCLV(APCDV,"C")=51
QUIT
+12 IF $$CLINIC^APCLV(APCDV,"C")=52
QUIT
+13 SET APCDSORT=""
DO GETSORT
IF APCDSORT=""
SET APCDSORT="??"
+14 SET ^XTMP("APCDDVL5",APCDJ,APCDBT,"VISITS",APCDSORT,APCDV)=""
+15 QUIT
End DoDot:2
+16 QUIT
End DoDot:1
+17 QUIT
RTS(V) ;
+1 NEW G,X,C
+2 ;if all have returned to stock
+3 SET G=0
SET X=0
SET C=0
+4 FOR
SET X=$ORDER(^AUPNVMED("AD",V,X))
IF X'=+X
QUIT
Begin DoDot:1
+5 ;# OF VMEDS
SET C=C+1
+6 IF $PIECE($GET(^AUPNVMED(X,11)),U)["RETURNED TO STOCK"
SET G=G+1
+7 QUIT
End DoDot:1
+8 IF 'G
QUIT 0
+9 QUIT 1
GETSORT ;get sort value
+1 IF APCDCSRT="D"
SET APCDSORT=$PIECE(^AUPNVSIT(APCDV,0),U)
QUIT
+2 ;I APCDCSRT="C" S APCDSORT=$$CLINIC^APCLV(APCDV,"C") Q ;clinic code
+3 ;hrn sort values
+4 SET APCDSORT=$$HRN^AUPNPAT($PIECE(^AUPNVSIT(APCDV,0),U,5),DUZ(2))
+5 IF APCDCSRT'="T"
QUIT
+6 SET APCDSORT=APCDSORT+10000000
SET APCDSORT=$EXTRACT(APCDSORT,7,8)_"-"_+$EXTRACT(APCDSORT,2,8)
+7 QUIT
PRINT ;EP - called from XBDBQUE
+1 SET APCDQUIT=""
SET APCDPG=0
DO HDR
+2 IF '$DATA(^XTMP("APCDDVL5",APCDJ,APCDBT))
DO HDR
WRITE !!,"NO DATA TO REPORT",!
GOTO DONE
+3 SET APCDSORT=""
FOR
SET APCDSORT=$ORDER(^XTMP("APCDDVL5",APCDJ,APCDBT,"VISITS",APCDSORT))
IF APCDSORT=""!(APCDQUIT)
QUIT
Begin DoDot:1
+4 SET APCDV=0
FOR
SET APCDV=$ORDER(^XTMP("APCDDVL5",APCDJ,APCDBT,"VISITS",APCDSORT,APCDV))
IF APCDV'=+APCDV!(APCDQUIT)
QUIT
Begin DoDot:2
+5 IF $Y>(IOSL-4)
DO HDR
IF APCDQUIT
QUIT
+6 SET APCDVR=^AUPNVSIT(APCDV,0)
+7 ;Y2000
WRITE !,$EXTRACT($PIECE(^DPT($PIECE(APCDVR,U,5),0),U),1,15),?16,$$HRN^AUPNPAT($PIECE(APCDVR,U,5),DUZ(2)),?24,$$DATE($PIECE($PIECE(APCDVR,U),".")),?36,$PIECE(APCDVR,U,7),?39,$$CLINIC^APCLV(APCDV,"C")
+8 SET APCDC=0
SET APCDM=0
FOR
SET APCDM=$ORDER(^AUPNVMED("AD",APCDV,APCDM))
IF APCDM'=+APCDM!(APCDQUIT)
QUIT
Begin DoDot:3
+9 SET APCDC=APCDC+1
+10 IF $Y>(IOSL-3)
DO HDR
IF APCDQUIT
QUIT
+11 IF APCDC>1
WRITE !
+12 WRITE ?45,$EXTRACT($$VAL^XBDIQ1(9000010.14,APCDM,.01),1,28)
+13 IF $PIECE($GET(^AUPNVMED(APCDM,11)),U)["RETURNED TO STOCK"
WRITE ?75,"Yes"
IF 1
+14 IF '$TEST
WRITE ?75,"No"
End DoDot:3
End DoDot:2
+15 QUIT
End DoDot:1
DONE ;
+1 KILL ^XTMP("APCDDVL5",APCDJ,APCDBT),APCDJ,APCDBT
+2 IF $EXTRACT(IOST)="C"
IF IO=IO(0)
SET DIR(0)="EO"
SET DIR("A")="End of report. PRESS ENTER"
DO ^DIR
KILL DIR
IF $DATA(DUOUT)
SET DIRUT=1
+3 IF $DATA(IOF)
WRITE @IOF
+4 QUIT
DATE(D) ;
+1 IF D=""
QUIT ""
+2 QUIT $EXTRACT(D,4,5)_"/"_$EXTRACT(D,6,7)_"/"_(1700+$EXTRACT(D,1,3))
HDR ;header for report
+1 IF 'APCDPG
GOTO HDR1
+2 IF $EXTRACT(IOST)="C"
IF IO=IO(0)
WRITE !
SET DIR(0)="EO"
DO ^DIR
KILL DIR
IF Y=0!(Y="^")!($DATA(DTOUT))
SET APCDQUIT=1
QUIT
HDR1 ;
+1 IF $DATA(IOF)
WRITE @IOF
SET APCDPG=APCDPG+1
+2 WRITE $PIECE(^VA(200,DUZ,0),U,2),$$CTR($$FMTE^XLFDT(DT)),?71,"Page ",APCDPG,!
+3 WRITE $$CTR($$LOC),!
+4 WRITE $$CTR("Visits with a RETURNED TO STOCK Medication"),!
+5 WRITE !?3,"PATIENT NAME",?17,"HRN",?24,"VISIT DATE",?36,"SC",?39,"CL",?45,"DRUG",?75,"RTS?",!
+6 WRITE $TRANSLATE($JUSTIFY(" ",80)," ","-"),!
+7 QUIT
CTR(X,Y) ;EP - Center X in a field Y wide.
+1 QUIT $JUSTIFY("",$SELECT($DATA(Y):Y,1:IOM)-$LENGTH(X)\2)_X
+2 ;----------
USR() ;EP - Return name of current user from ^VA(200.
+1 QUIT $SELECT($GET(DUZ):$SELECT($DATA(^VA(200,DUZ,0)):$PIECE(^(0),U),1:"UNKNOWN"),1:"DUZ UNDEFINED OR 0")
+2 ;----------
LOC() ;EP - Return location name from file 4 based on DUZ(2).
+1 QUIT $SELECT($GET(DUZ(2)):$SELECT($DATA(^DIC(4,DUZ(2),0)):$PIECE(^(0),U),1:"UNKNOWN"),1:"DUZ(2) UNDEFINED OR 0")
+2 ;----------
INFORM ;let user know what is gong on
+1 IF $DATA(IOF)
WRITE @IOF
+2 WRITE !!,$$CTR($$LOC,80)
+3 WRITE !,$$CTR($$USR,80),!!
+4 FOR I=1:1
SET X=$PIECE($TEXT(INTRO+I),";;",2)
IF X="END"
QUIT
WRITE !,X
+5 KILL I,X
+6 QUIT
INTRO ;;
+1 ;;This report will list all non chart review/telephone call visits
+2 ;;with a V Medication that is flagged as RETURN TO STOCK.
+3 ;;
+4 ;;
+5 ;;
+6 ;;END
+1 SET X=$$ADD^XPDMENU("APCDDVR","APCD C T VISITS W ANCILLARY","CTA")
+2 IF 'X
WRITE "Attempt to add update option failed."
HANG 3
+3 QUIT