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

PSXRPPL2.m

Go to the documentation of this file.
  1. PSXRPPL2 ;BIR/WPB - Print From Suspense Utilities ;06/10/08
  1. ;;2.0;CMOP;**65,69,73,74,79,81,83,87,91,92,93,95**;11 Apr 97;Build 16
  1. ; Reference to ^PSRX( in ICR #1977
  1. ; Reference to ^PS(52.5, in ICR #1978
  1. ; Reference to ^PSSLOCK in ICR #2789
  1. ; Reference to ^PSOBPSUT in ICR #4701
  1. ; Reference to ^PSOBPSU1 in ICR #4702
  1. ; Reference to ^PSOBPSU2 in ICR #4970
  1. ; Reference to ^PSOBPSU4 in ICR #7212
  1. ; Reference to ^PSOREJUT in ICR #4706
  1. ; Reference to ^PSOREJU3 in ICR #5186
  1. ; Reference to CHANGE^PSOSUCH1 in ICR #5427
  1. ; Reference to PREVRX^PSOREJP2 in ICR #5912
  1. ; Reference to $$BILLABLE^IBNCPDP in ICR #6243
  1. ; Reference to LOG^BPSOSL in ICR #6764
  1. ; Reference to IEN59^BPSOSRX in ICR #4412
  1. ;
  1. ; CHKDFN makes a second pass through the suspense queue, looking for
  1. ; any additional prescriptions for patients who already have an Rx
  1. ; included in the current batch. To accomplish this, it loops through
  1. ; all the patients in the batch - ^PSX(550.2,Batch,15,"C",Name,DFN) -
  1. ; and then loops through the suspense queue, starting with the day
  1. ; after the through date used by SBTECME^PSXRPPL1 and going through
  1. ; that date plus the 'look ahead' date in the site parameters (see
  1. ; DRIV^PSXRSUS). The logic inside the loops is largely identical to
  1. ; that in SBTECME^PSXRPPL1.
  1. ;
  1. CHKDFN(THRDT) ;
  1. ;Input: THRDT - THROUGH DATE to run CMOP transmission
  1. ;
  1. ; This procedure assumes the following variables to exist:
  1. ; PRTDT = Transmit/Print data through this date
  1. ; PSXBAT = Batch, pointer to file#550.2, CMOP Transmission
  1. ; PSXDTRG = Pull ahead through date
  1. ; PSXTDIV = Division
  1. ; PSXTYP = "C" if running for Controlled Substance, "N" otherwise
  1. ;
  1. N PSOLRX,PSXPTNM,REC,RESP,RFL,RX,SBTECME,SDT,XDFN
  1. ;
  1. ; If there are no prescriptions in the current batch, then Quit.
  1. ;
  1. I '$D(^PSX(550.2,PSXBAT,15,"C")) Q
  1. ;
  1. S SBTECME=0
  1. K ^TMP("PSXEPHDFN",$J)
  1. S PSXPTNM=""
  1. F S PSXPTNM=$O(^PSX(550.2,PSXBAT,15,"C",PSXPTNM)) Q:PSXPTNM="" D
  1. . S XDFN=0
  1. . F S XDFN=$O(^PSX(550.2,PSXBAT,"15","C",PSXPTNM,XDFN)) Q:(XDFN'>0) D
  1. . . S SDT=PRTDT
  1. . . F S SDT=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT)) Q:(SDT>PSXDTRG)!(SDT="") D
  1. . . . S REC=0
  1. . . . F S REC=$O(^PS(52.5,"CMP","Q",PSXTYP,PSXTDIV,SDT,XDFN,REC)) Q:REC'>0 D
  1. . . . . S (PSOLRX,RX)=+$$GET1^DIQ(52.5,REC,.01,"I") I 'RX Q
  1. . . . . S RFL=$$GET1^DIQ(52.5,REC,9,"I") I RFL="" S RFL=$$LSTRFL^PSOBPSU1(RX)
  1. . . . . I $$XMIT^PSXBPSUT(REC) D
  1. . . . . . I SDT>THRDT,'$D(^TMP("PSXEPHDFN",$J,XDFN)) Q
  1. . . . . . I $$PATCH^XPDUTL("PSO*7.0*148") D
  1. . . . . . . I $$RETRX^PSOBPSUT(RX,RFL),SDT>DT Q
  1. . . . . . . I $$DOUBLE^PSXRPPL1(RX,RFL) Q
  1. . . . . . . I $$FIND^PSOREJUT(RX,RFL,,"79,88,943",,1) Q
  1. . . . . . . ;
  1. . . . . . . ; If TRI/CVA and the Rx already has a closed eT/eC
  1. . . . . . . ; pseudo-reject, then do not send another claim.
  1. . . . . . . ;
  1. . . . . . . I $$TRICVANB^PSXRPPL1(RX,RFL) D Q
  1. . . . . . . . D LOG^BPSOSL($$IEN59^BPSOSRX(RX,RFL),$T(+0)_"-CHKDFN, $$TRICVANB returned 1") ; ICR #4412,6764
  1. . . . . . . ;
  1. . . . . . . I '$$RETRX^PSOBPSUT(RX,RFL),'$$ECMESTAT(RX,RFL) Q
  1. . . . . . . I $$PATCH^XPDUTL("PSO*7.0*289") Q:'$$DUR(RX,RFL) ; ePharm Host error hold
  1. . . . . . . I $$PATCH^XPDUTL("PSO*7.0*289") Q:'$$DSH(REC,1) ; ePharm 3/4 days supply
  1. . . . . . . ;
  1. . . . . . . ; ECMESND^PSOBPSU1 initiates the claim submission process.
  1. . . . . . . ;
  1. . . . . . . D ECMESND^PSOBPSU1(RX,RFL,"","PC",,1,,,,.RESP)
  1. . . . . . . ;
  1. . . . . . . D LOG^BPSOSL($$IEN59^BPSOSRX(RX,RFL),$T(+0)_"-CHKDFN, RESP="_$G(RESP)) ; ICR #4412,6764
  1. . . . . . . ;
  1. . . . . . . I $G(RESP)'["IN PROGRESS",$$PATCH^XPDUTL("PSO*7.0*287"),$$TRISTA^PSOREJU3(RX,RFL,.RESP,"PC") S ^TMP("PSXEPHNB",$J,RX,RFL)=$G(RESP)
  1. . . . . . . ;
  1. . . . . . . I $D(RESP),'RESP S SBTECME=SBTECME+1
  1. . . . . . . S ^TMP("PSXEPHDFN",$J,XDFN)=""
  1. . . . . D PSOUL^PSSLOCK(PSOLRX)
  1. K ^TMP("PSXEPHDFN",$J)
  1. I SBTECME>0 H 60+$S((SBTECME*15)>7200:7200,1:(SBTECME*15))
  1. Q
  1. ;
  1. ; EPHARM is called only by GETDATA^PSXRPPL. The variable EPHQT is
  1. ; Newed in GETDATA. If EPHQT is set to 1 here, then GETDATA does
  1. ; not continue processing the current Rx/Fill; this Rx/Fill will
  1. ; not be sent to CMOP if EPHQT is set to 1 here.
  1. ;
  1. EPHARM ; - ePharmacy checks for third party billing
  1. ;
  1. ; If CMOP is still processing the previous fill ($$DOUBLE), or if the
  1. ; RE-TRANSMIT flag is 'Yes' and the send date is in the future, or if
  1. ; this prescription has an unresolved 79,88,943, or RRR reject, then
  1. ; Set EPHQT to 1 and Quit. This Rx/Fill will not be sent to CMOP.
  1. ;
  1. I $$DOUBLE^PSXRPPL1(RXN,RFL) S EPHQT=1 Q
  1. I $$RETRX^PSOBPSUT(RXN,RFL),SDT>DT S EPHQT=1 Q
  1. I $$FIND^PSOREJUT(RXN,RFL,,"79,88,943",,1) S EPHQT=1 Q
  1. ;
  1. ; If an Open/Unresolved eC/eT reject on claim, don't send to CMOP.
  1. ;
  1. I $$ECETREJ(RXN) D EPH Q
  1. ;
  1. ; $$TRISTA performs checks specific to TRICARE/CHAMPVA. If the claim
  1. ; was rejected or is still "IN PROGRESS", or if it is non-billable,
  1. ; then add this Rx to the ^TMP("PSXEPHIN") array and quit.
  1. ;
  1. I $$PATCH^XPDUTL("PSO*7.0*287"),$$TRISTA^PSOREJU3(RXN,RFL,.RESP,"PC") D EPH Q
  1. I $$PATCH^XPDUTL("PSO*7.0*287"),$D(^TMP("PSXEPHNB",$J,RXN,RFL)) D EPH Q
  1. ;
  1. ; If the claim is still "IN PROGRESS", then add this Rx to the
  1. ; ^TMP("PSXEPHIN") array and quit.
  1. ;
  1. I $$STATUS^PSOBPSUT(RXN,RFL)="IN PROGRESS" D EPH Q
  1. ;
  1. ; If this Prescription violates the 3/4 supply (i.e. if it is too soon
  1. ; to refill), then Set EPHQT to 1 and Quit. This Rx/Fill will not be
  1. ; sent to CMOP.
  1. ;
  1. I $$PATCH^XPDUTL("PSO*7.0*289"),'$$DSH(REC,0) D S EPHQT=1 Q
  1. . D LOG^BPSOSL($$IEN59^BPSOSRX(RXN,RFL),$T(+0)_"-EPHARM, Failed DSH") ; ICR #4412,6764
  1. ;
  1. ; If there is a host reject for this Rx/Fill, then add this Rx to the
  1. ; ^TMP("PSXEPHIN") array and quit.
  1. ;
  1. I $$PATCH^XPDUTL("PSO*7.0*289"),'$$DUR(RXN,RFL) D EPH Q
  1. Q
  1. ;
  1. ; EPH is called only by EPHARM, above. It adds a prescriptions to the
  1. ; ^TMP("PSXEPHIN") array. Of those Prescriptions not sent to the CMOP
  1. ; facility and left in the suspense queue, some are added to this
  1. ; array. Those in this array will be listed in the email sent to users
  1. ; indicating that they were left in the queue (see ^PSXBPSMS). That
  1. ; email states these Rxs were not transmitted to the CMOP facility
  1. ; because either a) a response from the payer was not received, or b)
  1. ; the Rx is non-billable.
  1. ;
  1. EPH ; - Store Rx not xmitted to CMOP in XTMP file for MailMan message.
  1. S ^TMP("PSXEPHIN",$J,$$RXSITE^PSOBPSUT(RXN),RXN)=RFL,EPHQT=1
  1. Q
  1. ;
  1. ; ECMESTAT checks the Rx's ECME Status to determine if it's acceptable
  1. ; to resubmit based on reject codes associated with a previous
  1. ; submission. If Rx was rejected with host reject errors, and no other
  1. ; rejects exist, then it's OK to resubmit to ECME.
  1. ; Input:
  1. ; RX = Prescription file #52 IEN
  1. ; RFL = Refill number
  1. ; Returns:
  1. ; 1 = OK to resubmit
  1. ; 0 = Don't resubmit
  1. ;
  1. ECMESTAT(RX,RFL) ;
  1. I '$$PATCH^XPDUTL("PSO*7.0*148") Q 0
  1. N CHDAT,HERR,PSXECET,PSXIEN,PSXREJ,STATUS
  1. ;
  1. ; If an Open/Unresolved eC/eT reject on claim, don't resubmit
  1. I $$ECETREJ(RX) Q 0
  1. ;
  1. S STATUS=$$STATUS^PSOBPSUT(RX,RFL)
  1. ; Never submitted before, OK to resubmit
  1. I STATUS=""!(STATUS["UNSTRANDED") Q 1
  1. ; If status other than E REJECTED, don't resubmit
  1. I STATUS'="E REJECTED" Q 0
  1. ;
  1. ; check for a previous host reject:
  1. ; 0 - if not expired, don't resubmit
  1. ; 1 - if host reject & date expired, allow to resubmit
  1. ; 2 - if not defined, allow to continue with evaluation for new host reject
  1. S CHDAT=$$CHHEDT(RX,RFL)
  1. I CHDAT=0 Q 0 ; The host reject has not expired, so do not resubmit.
  1. ;
  1. ;*****************************************************************************************************
  1. ; NOTE: MAKE SURE THAT IGNORED REJECTS WILL PROCESS WHENEVER MODIFICATIONS ARE MADE TO HOST REJECT
  1. ; Ignored rejects are handled by default when this subroutine Q 0 at the end.
  1. ;*****************************************************************************************************
  1. ; check host rejects
  1. S HERR=$$HOSTREJ(RX,RFL,0)
  1. I HERR&(CHDAT=2) D SHDTLOG(RX,RFL) Q 0 ;Host reject and no suspense hold date defined yet; define it and don't resubmit
  1. I HERR&(CHDAT) Q 1 ;Host reject & suspense hold date has expired; resubmit
  1. Q 0 ;NOTE - IF YOU CHANGE THIS Q 0, IGNORED REJECTS WILL RESUBMIT AND REJECT AGAIN WHICH IS VERY BAD.
  1. ;
  1. ; DSH determines whether a prescription has a 3/4 days supply hold
  1. ; condition.
  1. ; Input: REC = Pointer to Suspense file (#52.5)
  1. ; ACT = 1 or 0, indicating whether an entry should be made
  1. ; in the activity log if the 3/4 logic is bypassed.
  1. ; Returns: 1 or 0
  1. ; 1 (one) if 3/4 of days supply has elapsed.
  1. ; 0 (zero) if 3/4 of days supply has not elapsed.
  1. ;
  1. DSH(REC,ACT) ;ePharmacy API to check for 3/4 days supply hold
  1. ;
  1. N COMM,DA,DAYSSUP,DIE,DR,DSHDT,DSHOLD
  1. N PREVRX,PSARR,PSINSUR,PSXCOMMENT,RFL,RXIEN,SDT,SFN,SHDT
  1. ;
  1. S DSHOLD=1
  1. S RXIEN=$$GET1^DIQ(52.5,REC,.01,"I")
  1. S RFL=$$GET1^DIQ(52.5,REC,9,"I")
  1. I RFL="" S RFL=$$LSTRFL^PSOBPSU1(RXIEN)
  1. ;
  1. ; If the Rx/Fill is not e-billable, then Quit out.
  1. ;
  1. I '$$EBILLABLE^PSOSULB2(RXIEN,RFL) Q DSHOLD
  1. ;
  1. ; If the Bypass 3/4 Day Supply flag is set to "YES", then Quit with
  1. ; 1 after adding a comment to the Activity Log.
  1. ;
  1. I $$FLAG^PSOBPSU4(RXIEN,RFL)="YES" D Q DSHOLD ; ICR #7212
  1. . I '$G(ACT) Q
  1. . S PSXCOMMENT="3/4 Day Supply logic bypassed during CMOP processing"
  1. . D RXACT^PSOBPSU2(RXIEN,RFL,PSXCOMMENT,"S",DUZ)
  1. . Q
  1. ;
  1. S DSHDT=$$DSHDT(RXIEN,RFL) ; 3/4 of days supply date
  1. S PREVRX=$P(DSHDT,U,2)
  1. S DSHDT=$P(DSHDT,U)
  1. I DSHDT>DT S DSHOLD=0 D
  1. . I DSHDT'=$$GET1^DIQ(52.5,REC,10,"I") D ; Update Suspense Hold Date and Activity Log
  1. . . ; If a previous Rx is used in the 3/4 days' supply calculation,
  1. . . ; capture that Rx in the activity log.
  1. . . S COMM="3/4 of Days Supply SUSPENSE HOLD until "_$$FMTE^XLFDT(DSHDT,"2D")
  1. . . I PREVRX'="" S COMM=COMM_" (prior Rx "_PREVRX_")"
  1. . . S COMM=COMM_"."
  1. . . S DAYSSUP=$$LFDS(RXIEN)
  1. . . D RXACT^PSOBPSU2(RXIEN,RFL,COMM,"S",+$G(DUZ)) ; Update Activity Log
  1. . . S DR="10///^S X=DSHDT",DIE="^PS(52.5,",DA=REC D ^DIE ; File Suspense Hold Date
  1. . . N DA,DIE,DR,PSOX,SFN,INDT,DEAD,SUB,XOK,OLD
  1. . . S DA=REC,DIE="^PS(52.5,",DR=".02///"_DSHDT D ^DIE
  1. . . S SFN=REC,DEAD=0,INDT=DSHDT D CHANGE^PSOSUCH1(RXIEN,RFL)
  1. . . Q
  1. . Q
  1. ;
  1. Q DSHOLD
  1. ;
  1. DSHDT(RXIEN,RFL) ; ePharmacy function to determine the 3/4 of the days supply date
  1. ; Input: RXIEN = Prescription file #52 ien
  1. ; RFL = fill#
  1. ; Returns: DATE value of last date of service plus 3/4 of days supply
  1. ; PREVRX = Previous Rx if PREVRX^PSOREJP2 identified one that
  1. ; should be used in the 3/4 days' supply calculation.
  1. ;
  1. N FILLDT,DAYSSUP,DSH34,PREVRX
  1. I '$D(^PSRX(RXIEN,0)) Q -1
  1. I $G(RFL)="" Q -1
  1. ;
  1. D PREVRX^PSOREJP2(RXIEN,RFL,,.FILLDT,.DAYSSUP,.PREVRX)
  1. I FILLDT="" Q -1
  1. ;
  1. S DSH34=DAYSSUP*.75 ; 3/4 of Days Supply
  1. S:DSH34["." DSH34=(DSH34+1)\1
  1. ; Return last date of service plus 3/4 of Days Supply date
  1. ; and the previous Rx used in the calculation, if any.
  1. Q $$FMADD^XLFDT(FILLDT,DSH34)_U_PREVRX
  1. ;
  1. ; LFDS returns the DAYS SUPPLY for the latest fill for a prescription.
  1. ; Input: RXIEN = Prescription file #52 IEN
  1. ; Returns: DAYS SUPPLY for the latest fill
  1. ; -1 if RXIEN is not valid
  1. LFDS(RXIEN) ;
  1. N RXFIL
  1. Q:'$D(^PSRX(RXIEN)) -1
  1. S RXFIL=$$LSTRFL^PSOBPSU1(RXIEN)
  1. Q $S(RXFIL=0:$P(^PSRX(RXIEN,0),U,8),1:$P(^PSRX(RXIEN,1,RXFIL,0),U,10))
  1. ;
  1. ; DUR checks for host errors and the suspense hold date.
  1. ; Input:
  1. ; RX = Prescription file #52 IEN
  1. ; RFL = Refill number
  1. ; Returns: A value of 0 (zero) will be returned when reject code M6,
  1. ; M8, NN, or 99 are present OR if on susp hold which means the
  1. ; prescription should not be sent to CMOP.
  1. ; Otherwise, a value of 1(one) will be returned.
  1. DUR(RX,RFL) ;
  1. N REJ,IDX,TXT,CODE,SHCODE,SHDT,CHDAT1
  1. S IDX=""
  1. I '$D(RFL) S RFL=$$LSTRFL^PSOBPSU1(RX)
  1. ;
  1. ; check for a previous host reject:
  1. ; 0 - host reject date not expired; don't print
  1. ; 1 - host reject date expired; allow to print
  1. ; 2 - host reject not define; allow to continue with evaluation
  1. ; for new host reject
  1. S CHDAT1=$$CHHEDT(RX,RFL)
  1. I CHDAT1=1 Q 1
  1. I CHDAT1=0 Q 0
  1. ;
  1. ; If a host reject exists and no previous Susp Hold Date or log entry,
  1. ; create the log entry and hold rx/fill.
  1. S HERR=$$HOSTREJ(RX,RFL,1)
  1. I HERR,SHDT="" D SHDTLOG(RX,RFL)
  1. I HERR Q 0
  1. Q 1
  1. ;
  1. CHHEDT(RX,RFL) ;
  1. ; RX = Prescription File IEN
  1. ; RFL = Refill
  1. ;Returns:
  1. ; 0 = host reject date not expired
  1. ; 1 = host reject has expired
  1. ; 2 = host reject not defined
  1. ;
  1. S SHDT=$$SHDT(RX,RFL) ; Get suspense hold date for rx/refill
  1. I SHDT="" Q 2
  1. I DT'<SHDT Q 1
  1. Q 0
  1. ;
  1. ; HOSTREJ checks an RX/FILL for Host Reject Errors returned from
  1. ; previous ECME submissions. The host reject errors checked are M6,
  1. ; M8, NN, and 99. Host reject errors do not pass to the pharmacy
  1. ; worklist so it's necessary to check ECME for these type errors.
  1. ; Input:
  1. ; RX = Prescription File IEN
  1. ; RFL = Refill
  1. ; ONE = Either 1 or 0 - Defaults to 1
  1. ; If 1, At least ONE reject code associated with the RX/FILL must
  1. ; match either M6, M8, NN, or 99.
  1. ; If 0, ALL reject codes must match either M6, M8, NN, or 99
  1. ; Return:
  1. ; RETV = 1 OR 0
  1. ; 1 = host reject exists based on ONE parameter
  1. ; 0 = no host rejects exists based on ONE parameter
  1. HOSTREJ(RX,RFL,ONE) ;
  1. N REJ,IDX,TXT,CODE,HRCODE,HRQUIT,RETV
  1. S IDX="",(RETV,HRQUIT)=0
  1. I ONE="" S ONE=1
  1. D DUR1^BPSNCPD3(RX,RFL,.REJ) ; Get reject list from last submission
  1. F S IDX=$O(REJ(IDX)) Q:IDX="" D Q:HRQUIT
  1. . S TXT=$G(REJ(IDX,"REJ CODE LST"))
  1. . F I=1:1:$L(TXT,",") S CODE=$P(TXT,",",I) D Q:HRQUIT
  1. . . F HRCODE="M6","M8","NN",99 D Q:HRQUIT
  1. . . . I CODE=HRCODE S RETV=1 I ONE S HRQUIT=1 Q
  1. . . . I CODE'=HRCODE,RETV=1 S RETV=0,HRQUIT=1 Q
  1. Q RETV
  1. ;
  1. ; SHDTLOG sets the EPHARMACY SUSPENSE HOLD DATE field for the rx or
  1. ; refill to tomorrow and adds an entry to the SUSPENSE Activity Log.
  1. ; Input: RX = Prescription File IEN
  1. ; RFL = Refill
  1. SHDTLOG(RX,RFL) ;
  1. N DA,DIE,DR,COMM,SHDT
  1. I '$D(RFL) S RFL=$$LSTRFL^PSOBPSU1(RX)
  1. S SHDT=$$FMADD^XLFDT(DT,1)
  1. S COMM="SUSPENSE HOLD until "_$$FMTE^XLFDT(SHDT,"2D")_" due to host reject error."
  1. I RFL=0 S DA=RX,DIE="^PSRX(",DR="86///"_SHDT D ^DIE
  1. E S DA=RFL,DA(1)=RX,DIE="^PSRX("_DA(1)_",1,",DR="86///"_SHDT D ^DIE
  1. D RXACT^PSOBPSU2(RX,RFL,COMM,"S",+$G(DUZ)) ; Create Activity Log entry
  1. Q
  1. ;
  1. ; SHDT returns the EPHARMACY SUSPENSE HOLD DATE field for the rx or
  1. ; the refill
  1. ; Input: RX = Prescription File IEN
  1. ; RFL = Refill
  1. SHDT(RX,RFL) ;
  1. N FILE,IENS
  1. I '$D(RFL) S RFL=$$LSTRFL^PSOBPSU1(RX)
  1. S FILE=$S(RFL=0:52,1:52.1),IENS=$S(RFL=0:RX_",",1:RFL_","_RX_",")
  1. Q $$GET1^DIQ(FILE,IENS,86,"I")
  1. ;
  1. ;
  1. ; ECETREJ checks for open/unresolved eC/eT reject on the Rx
  1. ; Input: (r) RX - Prescription IEN
  1. ; Output: 0 - No open/unresovled eC/eT Reject on Rx
  1. ; 1 - Open/unresolved eC/eT Reject on Rx
  1. ECETREJ(RX) ;
  1. N PSXECET,PSXIEN,PSXREJ
  1. S PSXREJ=0
  1. F PSXECET="eC","eT" S PSXIEN="" D
  1. . F S PSXIEN=$O(^PSRX(RX,"REJ","B",PSXECET,PSXIEN)) Q:'PSXIEN D
  1. . . I $$GET1^DIQ(52.25,PSXIEN_","_RX,9,"I")=0 S PSXREJ=1
  1. Q PSXREJ
  1. ;