PSOBPSR1 ;BHM/LE - continued Ignored Claims Report ;03/01/07
;;7.0;OUTPATIENT PHARMACY;**260**;13 Feb 97;Build 84
;External reference to File ^PS(55 supported by DBIA 2228
;External reference to $$GET1^DIQ is supported by DBIA 2056
;External reference to ^VADPT is supported by DBIA 10061
;External reference to ^XLFDT is supported by DBIA 10103
;External reference to ^%ZISC is supported by DBIA 10089
;
EN N CLOSE,CDATE,DFN,DRG,RXIEN,PAG,PCNT,PRTD,PNAM,I,II,J,Y,X,XX,S1,S2,S3,S4,S5,FCNT,CBYI
N SP1,SP2,SEQ2,CINFO,RDATE,RSEQ,PSORX,RXINFO,DNAMI,CDIV,CDIVN,OCDIV,RXNUMB,PSORXN,RXE
U IO K ^TMP("PSOBPSRP",$J),^TMP("PSOBPSRC",$J)
S (SP1,SP2)="",$P(SP1,"=",81)="",$P(SP2,"-",81)=""
;
; - Loop through reject dates xref
S (RXIEN,PCNT,FCNT,PRTD)=0 K DIRUT
S RDATE=PSOSD
;
DATE ;
S RDATE=$O(^PSRX("REJDAT",RDATE)) G NEXT:RDATE=""!(RDATE>PSOED)
RX ;
S RXIEN=$O(^PSRX("REJDAT",RDATE,RXIEN)) G DATE:RXIEN=""
S (DFN,DRG,PNAM,DNAM,DNAMI,RXE)=""
K RXINFO D GETS^DIQ(52,RXIEN_",",".01;2;6","IE","RXINFO")
S PNAM=$G(RXINFO(52,RXIEN_",",2,"E")),DNAM=$G(RXINFO(52,RXIEN_",",6,"E"))
S DFN=$G(RXINFO(52,RXIEN_",",2,"I")),DNAMI=$G(RXINFO(52,RXIEN_",",6,"I"))
S RXE=$G(RXINFO(52,RXIEN_",",.01,"E"))_" "
I '$G(PSOAPT),'$D(PSOPT(DFN)) G RX ;user selected specific patients
I '$G(PSODRUG),'$D(PSODRG(DNAMI)) G RX
;
;look for ignored rejects
S SEQ2=0 F S SEQ2=$O(^PSRX(RXIEN,"REJ",SEQ2)) Q:'SEQ2&(SEQ2'?1N.N) D
. S (CDATE,CBY,CBYI,CFILL,CDIV)=""
. K CLOSE D GETS^DIQ(52.25,SEQ2_","_RXIEN_",","5;10;11;12","IE","CLOSE")
. S CDATE=$G(CLOSE(52.25,SEQ2_","_RXIEN_",",10,"I"))
. S CFILL=$G(CLOSE(52.25,SEQ2_","_RXIEN_",",5,"I"))
. S CDIV=$$RXSITE^PSOBPSUT(RXIEN,CFILL)
. I '$G(PSOSIT)&'$D(PSODIV(CDIV)) Q
. I $G(CLOSE(52.25,SEQ2_","_RXIEN_",",12,"I"))=6,(CDATE'<PSOSD&(CDATE'>PSOED)) D
. . S CBY=$G(CLOSE(52.25,SEQ2_","_RXIEN_",",11,"E"))
. . S CBYI=$G(CLOSE(52.25,SEQ2_","_RXIEN_",",11,"I"))
. . I '$G(PSOUSER),'$D(PSOU(CBYI)) Q ;user selected specific user for "ignored by" column in report
. . D SET
G RX
;
NEXT ; - If not Sorting (already printed), SKIP, otherwise, print the report
I '$D(^TMP("PSOBPSRP")) G NDTP
S (S1,S2,S3,DFN,RSEQ,PSORX,PSORXN,RXNUMB,CDIV,OCDIV,CDIVN)=""
F S CDIV=$O(^TMP("PSOBPSRP",$J,CDIV)) Q:CDIV="" D Q:$D(DIRUT)
. F S S1=$O(^TMP("PSOBPSRP",$J,CDIV,S1)) Q:S1="" D Q:$D(DIRUT)
. . F S S2=$O(^TMP("PSOBPSRP",$J,CDIV,S1,S2)) Q:S2="" D Q:$D(DIRUT)
. . . F S S3=$O(^TMP("PSOBPSRP",$J,CDIV,S1,S2,S3)) Q:S3="" D Q:$D(DIRUT)
. . . . F S DFN=$O(^TMP("PSOBPSRP",$J,CDIV,S1,S2,S3,DFN)) Q:DFN="" D Q:$D(DIRUT)
. . . . . F S PSORXN=$O(^TMP("PSOBPSRP",$J,CDIV,S1,S2,S3,DFN,PSORXN)) Q:PSORXN="" D Q:$D(DIRUT)
. . . . . . F S RSEQ=$O(^TMP("PSOBPSRP",$J,CDIV,S1,S2,S3,DFN,PSORXN,RSEQ)) Q:RSEQ="" D Q:$D(DIRUT)
. . . . . . . I $Y>(IOSL-7)&($E(IOST)="C") D HDR I $D(DIRUT) Q
. . . . . . . I $Y>(IOSL-12)&($E(IOST)'="C") D HDR I $D(DIRUT) Q
. . . . . . . S (RXNUMB,PSORX)="",RXNUMB=$E(PSORXN,1,$L(PSORXN)-1),PSORX=$O(^PSRX("B",RXNUMB,PSORX))
. . . . . . . D PRINT(DFN,PSORX)
. . . I '$D(DIRUT),S2'=0,$O(^TMP("PSOBPSRP",$J,CDIV,S1,S2))'="" W SP2
. . I '$D(DIRUT),$O(^TMP("PSOBPSRP",$J,CDIV,S1))'="" W !,SP1
G CLOSE:$D(DIRUT)
;
NDTP I 'PRTD D HDR W !!?18,"********** NO DATA TO PRINT **********"
I $G(PCNT) D
. W !,SP1
. W !,"Total: ",PCNT," patient",$S(PCNT>1:"s",1:"")
. W " and ",FCNT," prescription fill",$S(FCNT>1:"s",1:""),"."
;
CLOSE ;
D ^%ZISC S:$D(ZTQUEUED) ZTREQ="@"
END K ^TMP("PSOBPSRP",$J),^TMP("PSOBPSRC",$J)
K PSOAPT,PSODRUG,PSOUSER,PSOU,PSODRG,PSOPT,PSOSRT,PSOED,PSOSD,PSODIV,PSOSIT
Q
;
SET ;
S (S1,S2,S3)=0
F I=1:1:$L(PSOSRT,",") D
. S Y=$P(PSOSRT,",",I)
. S @("S"_I)=$S(Y=1:PNAM,Y=2:DNAM,Y=3:CBY)
S ^TMP("PSOBPSRP",$J,CDIV,S1,S2,S3,DFN,RXE,SEQ2)=""
Q
;
PRINT(DFN,RXIEN) ; - Print
;Input: DFN-Patient;RXIEN=Prescription IEN
N X,XX,K,PNAM,PSSN,II,J,STR,CCOM,PMES,CBY,CREAS,CDAT,CFILL,RXNUM,DNAM,CINFO
S (CDAT,CREAS,CBY,DNAM,PNAM,PMES,PSSN,CCOM,CINFO,RXNUM)=""
;
I OCDIV'=CDIV!(OCDIV="") D HDR I $D(DIRUT) Q
S OCDIV=CDIV
;
D DEM^VADPT S PSSN=$P($G(VADM(2)),"^",2) K VADM
K RXINFO D GETS^DIQ(52,RXIEN_",",".01;2;6","EI","RXINFO")
S PNAM=RXINFO(52,RXIEN_",",2,"E"),DNAM=RXINFO(52,RXIEN_",",6,"E")
D GETS^DIQ(52.25,RSEQ_","_RXIEN_",","5;10;11;12;2;13","IE","CINFO")
S:$D(RXINFO(52,RXIEN_",",.01,"E")) RXNUM=RXINFO(52,RXIEN_",",.01,"E")
S:$D(CINFO(52.25,RSEQ_","_RXIEN_",",10,"I")) CDAT=CINFO(52.25,RSEQ_","_RXIEN_",",10,"I")
S CDAT=$$DT(CDAT)
S:$D(CINFO(52.25,RSEQ_","_RXIEN_",",12,"I")) CREAS=CINFO(52.25,RSEQ_","_RXIEN_",",12,"E")
S:$D(CINFO(52.25,RSEQ_","_RXIEN_",",11,"E")) CBY=CINFO(52.25,RSEQ_","_RXIEN_",",11,"E")
S:$D(CINFO(52.25,RSEQ_","_RXIEN_",",2,"E")) PMES=CINFO(52.25,RSEQ_","_RXIEN_",",2,"E")
D TEXT(.PMES,PMES,65)
S:$D(CINFO(52.25,RSEQ_","_RXIEN_",",13,"E")) CCOM=CINFO(52.25,RSEQ_","_RXIEN_",",13,"E")
D TEXT(.CCOM,CCOM,65)
S:$D(CINFO(52.25,RSEQ_","_RXIEN_",",5,"I")) CFILL=CINFO(52.25,RSEQ_","_RXIEN_",",5,"I")
;
W !,RXNUM_"/"_CFILL,?15,$E(DNAM,1,21),?37,$E(PNAM,1,13)_"("_$P(PSSN,"-",3)_")",?57,CDAT,?66,$E(CBY,1,14)
S II="" F S II=$O(CCOM(II)) Q:II="" D
. W:II=1 !," Comments: "
. W:$D(CCOM(II)) ?15,CCOM(II),!
S II="" F S II=$O(PMES(II)) Q:II="" D
. W:II=1 "Payer Message: "
. W:$D(PMES(II)) ?15,PMES(II),!
;
S:'$D(^TMP("PSOBPSRC",$J,DFN)) PCNT=PCNT+1 S ^TMP("PSOBPSRC",$J,DFN)=""
;
S PRTD=1,FCNT=FCNT+1
Q
;
TEXT(TEXT,STR,L) ; Formats STR into TEXT array, lines lenght = L
N J,WORD,K S K=+$O(TEXT(""),-1) S:'K K=1
F J=1:1:$L(STR," ") D
. S WORD=$P(STR," ",J) I ($L($G(TEXT(K))_WORD))>L S K=K+1
. S TEXT(K)=$G(TEXT(K))_WORD_" "
Q
;
HDR ; - Prints the Header
N X,DIR,CDIVN S PAG=$G(PAG)+1
S CDIVN=$$GET1^DIQ(59,$G(CDIV)_",",".01")
I PAG>1,$E(IOST)="C" D Q:$D(DIRUT)
. S DIR(0)="E",DIR("A")=" Press ENTER to Continue or ^ to Exit" D ^DIR
;
W @IOF,"Ignored Rejects Report",?71,"Page: ",$J(PAG,3)
W !,"Sorted by",$$SRT(PSOSRT),?48,"Division: ",CDIVN
W !,"Date Range: "_$$DT(PSOSD+1\1)_" - "_$$DT(PSOED\1)
W ?48,"Run Date: "_$$FMTE^XLFDT($$NOW^XLFDT())
S X="",$P(X,"-",81)="" W !,X
W !,"RX#/FILL",?15,"DRUG",?37,"PATIENT",?56,"IGNORE DT",?66,"IGNORED BY"
W !,"--------------",?15,"---------------------",?37,"------------------",?56,"---------",?66,"--------------"
Q
;
SRT(ST) ; - Convert the "2,1" (example) to "DRUG,PATIENT"
;Input: ST-String with the Sorting fields by number
;Output: ST-String with the Sorting fields by name
N I,X,STR,FLD
S STR="PATIENT^DRUG^USER"
F I=1:1:$L(ST,",") D
. S FLD=+$P(ST,",",I),X=$P(STR,"^",FLD)
. S $P(ST,",",I)=" "_X
Q ST
;
DT(DT) ; - Convert FM Date to MM/DD/YYYY
I 'DT Q ""
I '(DT#10000) Q (1700+$E(DT,1,3))
I '(DT#100) Q $E(DT,4,5)_"/"_(1700+$E(DT,1,3))
Q $E(DT,4,5)_"/"_$E(DT,6,7)_"/"_$E((1700+$E(DT,1,3)),3,4)
;
PSOBPSR1 ;BHM/LE - continued Ignored Claims Report ;03/01/07
+1 ;;7.0;OUTPATIENT PHARMACY;**260**;13 Feb 97;Build 84
+2 ;External reference to File ^PS(55 supported by DBIA 2228
+3 ;External reference to $$GET1^DIQ is supported by DBIA 2056
+4 ;External reference to ^VADPT is supported by DBIA 10061
+5 ;External reference to ^XLFDT is supported by DBIA 10103
+6 ;External reference to ^%ZISC is supported by DBIA 10089
+7 ;
EN NEW CLOSE,CDATE,DFN,DRG,RXIEN,PAG,PCNT,PRTD,PNAM,I,II,J,Y,X,XX,S1,S2,S3,S4,S5,FCNT,CBYI
+1 NEW SP1,SP2,SEQ2,CINFO,RDATE,RSEQ,PSORX,RXINFO,DNAMI,CDIV,CDIVN,OCDIV,RXNUMB,PSORXN,RXE
+2 USE IO
KILL ^TMP("PSOBPSRP",$JOB),^TMP("PSOBPSRC",$JOB)
+3 SET (SP1,SP2)=""
SET $PIECE(SP1,"=",81)=""
SET $PIECE(SP2,"-",81)=""
+4 ;
+5 ; - Loop through reject dates xref
+6 SET (RXIEN,PCNT,FCNT,PRTD)=0
KILL DIRUT
+7 SET RDATE=PSOSD
+8 ;
DATE ;
+1 SET RDATE=$ORDER(^PSRX("REJDAT",RDATE))
IF RDATE=""!(RDATE>PSOED)
GOTO NEXT
RX ;
+1 SET RXIEN=$ORDER(^PSRX("REJDAT",RDATE,RXIEN))
IF RXIEN=""
GOTO DATE
+2 SET (DFN,DRG,PNAM,DNAM,DNAMI,RXE)=""
+3 KILL RXINFO
DO GETS^DIQ(52,RXIEN_",",".01;2;6","IE","RXINFO")
+4 SET PNAM=$GET(RXINFO(52,RXIEN_",",2,"E"))
SET DNAM=$GET(RXINFO(52,RXIEN_",",6,"E"))
+5 SET DFN=$GET(RXINFO(52,RXIEN_",",2,"I"))
SET DNAMI=$GET(RXINFO(52,RXIEN_",",6,"I"))
+6 SET RXE=$GET(RXINFO(52,RXIEN_",",.01,"E"))_" "
+7 ;user selected specific patients
IF '$GET(PSOAPT)
IF '$DATA(PSOPT(DFN))
GOTO RX
+8 IF '$GET(PSODRUG)
IF '$DATA(PSODRG(DNAMI))
GOTO RX
+9 ;
+10 ;look for ignored rejects
+11 SET SEQ2=0
FOR
SET SEQ2=$ORDER(^PSRX(RXIEN,"REJ",SEQ2))
IF 'SEQ2&(SEQ2'?1N.N)
QUIT
Begin DoDot:1
+12 SET (CDATE,CBY,CBYI,CFILL,CDIV)=""
+13 KILL CLOSE
DO GETS^DIQ(52.25,SEQ2_","_RXIEN_",","5;10;11;12","IE","CLOSE")
+14 SET CDATE=$GET(CLOSE(52.25,SEQ2_","_RXIEN_",",10,"I"))
+15 SET CFILL=$GET(CLOSE(52.25,SEQ2_","_RXIEN_",",5,"I"))
+16 SET CDIV=$$RXSITE^PSOBPSUT(RXIEN,CFILL)
+17 IF '$GET(PSOSIT)&'$DATA(PSODIV(CDIV))
QUIT
+18 IF $GET(CLOSE(52.25,SEQ2_","_RXIEN_",",12,"I"))=6
IF (CDATE'<PSOSD&(CDATE'>PSOED))
Begin DoDot:2
+19 SET CBY=$GET(CLOSE(52.25,SEQ2_","_RXIEN_",",11,"E"))
+20 SET CBYI=$GET(CLOSE(52.25,SEQ2_","_RXIEN_",",11,"I"))
+21 ;user selected specific user for "ignored by" column in report
IF '$GET(PSOUSER)
IF '$DATA(PSOU(CBYI))
QUIT
+22 DO SET
End DoDot:2
End DoDot:1
+23 GOTO RX
+24 ;
NEXT ; - If not Sorting (already printed), SKIP, otherwise, print the report
+1 IF '$DATA(^TMP("PSOBPSRP"))
GOTO NDTP
+2 SET (S1,S2,S3,DFN,RSEQ,PSORX,PSORXN,RXNUMB,CDIV,OCDIV,CDIVN)=""
+3 FOR
SET CDIV=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV))
IF CDIV=""
QUIT
Begin DoDot:1
+4 FOR
SET S1=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1))
IF S1=""
QUIT
Begin DoDot:2
+5 FOR
SET S2=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1,S2))
IF S2=""
QUIT
Begin DoDot:3
+6 FOR
SET S3=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1,S2,S3))
IF S3=""
QUIT
Begin DoDot:4
+7 FOR
SET DFN=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1,S2,S3,DFN))
IF DFN=""
QUIT
Begin DoDot:5
+8 FOR
SET PSORXN=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1,S2,S3,DFN,PSORXN))
IF PSORXN=""
QUIT
Begin DoDot:6
+9 FOR
SET RSEQ=$ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1,S2,S3,DFN,PSORXN,RSEQ))
IF RSEQ=""
QUIT
Begin DoDot:7
+10 IF $Y>(IOSL-7)&($EXTRACT(IOST)="C")
DO HDR
IF $DATA(DIRUT)
QUIT
+11 IF $Y>(IOSL-12)&($EXTRACT(IOST)'="C")
DO HDR
IF $DATA(DIRUT)
QUIT
+12 SET (RXNUMB,PSORX)=""
SET RXNUMB=$EXTRACT(PSORXN,1,$LENGTH(PSORXN)-1)
SET PSORX=$ORDER(^PSRX("B",RXNUMB,PSORX))
+13 DO PRINT(DFN,PSORX)
End DoDot:7
IF $DATA(DIRUT)
QUIT
End DoDot:6
IF $DATA(DIRUT)
QUIT
End DoDot:5
IF $DATA(DIRUT)
QUIT
End DoDot:4
IF $DATA(DIRUT)
QUIT
+14 IF '$DATA(DIRUT)
IF S2'=0
IF $ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1,S2))'=""
WRITE SP2
End DoDot:3
IF $DATA(DIRUT)
QUIT
+15 IF '$DATA(DIRUT)
IF $ORDER(^TMP("PSOBPSRP",$JOB,CDIV,S1))'=""
WRITE !,SP1
End DoDot:2
IF $DATA(DIRUT)
QUIT
End DoDot:1
IF $DATA(DIRUT)
QUIT
+16 IF $DATA(DIRUT)
GOTO CLOSE
+17 ;
NDTP IF 'PRTD
DO HDR
WRITE !!?18,"********** NO DATA TO PRINT **********"
+1 IF $GET(PCNT)
Begin DoDot:1
+2 WRITE !,SP1
+3 WRITE !,"Total: ",PCNT," patient",$SELECT(PCNT>1:"s",1:"")
+4 WRITE " and ",FCNT," prescription fill",$SELECT(FCNT>1:"s",1:""),"."
End DoDot:1
+5 ;
CLOSE ;
+1 DO ^%ZISC
IF $DATA(ZTQUEUED)
SET ZTREQ="@"
END KILL ^TMP("PSOBPSRP",$JOB),^TMP("PSOBPSRC",$JOB)
+1 KILL PSOAPT,PSODRUG,PSOUSER,PSOU,PSODRG,PSOPT,PSOSRT,PSOED,PSOSD,PSODIV,PSOSIT
+2 QUIT
+3 ;
SET ;
+1 SET (S1,S2,S3)=0
+2 FOR I=1:1:$LENGTH(PSOSRT,",")
Begin DoDot:1
+3 SET Y=$PIECE(PSOSRT,",",I)
+4 SET @("S"_I)=$SELECT(Y=1:PNAM,Y=2:DNAM,Y=3:CBY)
End DoDot:1
+5 SET ^TMP("PSOBPSRP",$JOB,CDIV,S1,S2,S3,DFN,RXE,SEQ2)=""
+6 QUIT
+7 ;
PRINT(DFN,RXIEN) ; - Print
+1 ;Input: DFN-Patient;RXIEN=Prescription IEN
+2 NEW X,XX,K,PNAM,PSSN,II,J,STR,CCOM,PMES,CBY,CREAS,CDAT,CFILL,RXNUM,DNAM,CINFO
+3 SET (CDAT,CREAS,CBY,DNAM,PNAM,PMES,PSSN,CCOM,CINFO,RXNUM)=""
+4 ;
+5 IF OCDIV'=CDIV!(OCDIV="")
DO HDR
IF $DATA(DIRUT)
QUIT
+6 SET OCDIV=CDIV
+7 ;
+8 DO DEM^VADPT
SET PSSN=$PIECE($GET(VADM(2)),"^",2)
KILL VADM
+9 KILL RXINFO
DO GETS^DIQ(52,RXIEN_",",".01;2;6","EI","RXINFO")
+10 SET PNAM=RXINFO(52,RXIEN_",",2,"E")
SET DNAM=RXINFO(52,RXIEN_",",6,"E")
+11 DO GETS^DIQ(52.25,RSEQ_","_RXIEN_",","5;10;11;12;2;13","IE","CINFO")
+12 IF $DATA(RXINFO(52,RXIEN_",",.01,"E"))
SET RXNUM=RXINFO(52,RXIEN_",",.01,"E")
+13 IF $DATA(CINFO(52.25,RSEQ_","_RXIEN_",",10,"I"))
SET CDAT=CINFO(52.25,RSEQ_","_RXIEN_",",10,"I")
+14 SET CDAT=$$DT(CDAT)
+15 IF $DATA(CINFO(52.25,RSEQ_","_RXIEN_",",12,"I"))
SET CREAS=CINFO(52.25,RSEQ_","_RXIEN_",",12,"E")
+16 IF $DATA(CINFO(52.25,RSEQ_","_RXIEN_",",11,"E"))
SET CBY=CINFO(52.25,RSEQ_","_RXIEN_",",11,"E")
+17 IF $DATA(CINFO(52.25,RSEQ_","_RXIEN_",",2,"E"))
SET PMES=CINFO(52.25,RSEQ_","_RXIEN_",",2,"E")
+18 DO TEXT(.PMES,PMES,65)
+19 IF $DATA(CINFO(52.25,RSEQ_","_RXIEN_",",13,"E"))
SET CCOM=CINFO(52.25,RSEQ_","_RXIEN_",",13,"E")
+20 DO TEXT(.CCOM,CCOM,65)
+21 IF $DATA(CINFO(52.25,RSEQ_","_RXIEN_",",5,"I"))
SET CFILL=CINFO(52.25,RSEQ_","_RXIEN_",",5,"I")
+22 ;
+23 WRITE !,RXNUM_"/"_CFILL,?15,$EXTRACT(DNAM,1,21),?37,$EXTRACT(PNAM,1,13)_"("_$PIECE(PSSN,"-",3)_")",?57,CDAT,?66,$EXTRACT(CBY,1,14)
+24 SET II=""
FOR
SET II=$ORDER(CCOM(II))
IF II=""
QUIT
Begin DoDot:1
+25 IF II=1
WRITE !," Comments: "
+26 IF $DATA(CCOM(II))
WRITE ?15,CCOM(II),!
End DoDot:1
+27 SET II=""
FOR
SET II=$ORDER(PMES(II))
IF II=""
QUIT
Begin DoDot:1
+28 IF II=1
WRITE "Payer Message: "
+29 IF $DATA(PMES(II))
WRITE ?15,PMES(II),!
End DoDot:1
+30 ;
+31 IF '$DATA(^TMP("PSOBPSRC",$JOB,DFN))
SET PCNT=PCNT+1
SET ^TMP("PSOBPSRC",$JOB,DFN)=""
+32 ;
+33 SET PRTD=1
SET FCNT=FCNT+1
+34 QUIT
+35 ;
TEXT(TEXT,STR,L) ; Formats STR into TEXT array, lines lenght = L
+1 NEW J,WORD,K
SET K=+$ORDER(TEXT(""),-1)
IF 'K
SET K=1
+2 FOR J=1:1:$LENGTH(STR," ")
Begin DoDot:1
+3 SET WORD=$PIECE(STR," ",J)
IF ($LENGTH($GET(TEXT(K))_WORD))>L
SET K=K+1
+4 SET TEXT(K)=$GET(TEXT(K))_WORD_" "
End DoDot:1
+5 QUIT
+6 ;
HDR ; - Prints the Header
+1 NEW X,DIR,CDIVN
SET PAG=$GET(PAG)+1
+2 SET CDIVN=$$GET1^DIQ(59,$GET(CDIV)_",",".01")
+3 IF PAG>1
IF $EXTRACT(IOST)="C"
Begin DoDot:1
+4 SET DIR(0)="E"
SET DIR("A")=" Press ENTER to Continue or ^ to Exit"
DO ^DIR
End DoDot:1
IF $DATA(DIRUT)
QUIT
+5 ;
+6 WRITE @IOF,"Ignored Rejects Report",?71,"Page: ",$JUSTIFY(PAG,3)
+7 WRITE !,"Sorted by",$$SRT(PSOSRT),?48,"Division: ",CDIVN
+8 WRITE !,"Date Range: "_$$DT(PSOSD+1\1)_" - "_$$DT(PSOED\1)
+9 WRITE ?48,"Run Date: "_$$FMTE^XLFDT($$NOW^XLFDT())
+10 SET X=""
SET $PIECE(X,"-",81)=""
WRITE !,X
+11 WRITE !,"RX#/FILL",?15,"DRUG",?37,"PATIENT",?56,"IGNORE DT",?66,"IGNORED BY"
+12 WRITE !,"--------------",?15,"---------------------",?37,"------------------",?56,"---------",?66,"--------------"
+13 QUIT
+14 ;
SRT(ST) ; - Convert the "2,1" (example) to "DRUG,PATIENT"
+1 ;Input: ST-String with the Sorting fields by number
+2 ;Output: ST-String with the Sorting fields by name
+3 NEW I,X,STR,FLD
+4 SET STR="PATIENT^DRUG^USER"
+5 FOR I=1:1:$LENGTH(ST,",")
Begin DoDot:1
+6 SET FLD=+$PIECE(ST,",",I)
SET X=$PIECE(STR,"^",FLD)
+7 SET $PIECE(ST,",",I)=" "_X
End DoDot:1
+8 QUIT ST
+9 ;
DT(DT) ; - Convert FM Date to MM/DD/YYYY
+1 IF 'DT
QUIT ""
+2 IF '(DT#10000)
QUIT (1700+$EXTRACT(DT,1,3))
+3 IF '(DT#100)
QUIT $EXTRACT(DT,4,5)_"/"_(1700+$EXTRACT(DT,1,3))
+4 QUIT $EXTRACT(DT,4,5)_"/"_$EXTRACT(DT,6,7)_"/"_$EXTRACT((1700+$EXTRACT(DT,1,3)),3,4)
+5 ;