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

IBARXMC.m

Go to the documentation of this file.
  1. IBARXMC ;LL/ELZ-PHARMACY COPAY CAP FUNCTIONS ; 03 Mar 2021
  1. ;;2.0;INTEGRATED BILLING;**156,186,237,552,563,676**;21-MAR-94;Build 34
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. NEW(IBQ,IBC,IBD,IBB,IBN) ; used to compute new bills amount above cap
  1. ; DFN is assumed
  1. ; IBQ = quantity
  1. ; IBC = charge per item
  1. ; IBD = effective date
  1. ; Return:
  1. ; IBB = Amount to bill
  1. ; IBN = Amount NOT to bill
  1. ;
  1. N IBA,IBA,IBZ,IBP,IBE,IBY,IBFD,IBTD
  1. ;
  1. S IBP=$$PRIORITY^IBARXMU(DFN)
  1. ; - if the patient has no Priority Group (not enrolled), assume the highest PG
  1. I 'IBP S IBP=8
  1. D CAP(IBD,IBP,.IBZ,.IBY,.IBFD,.IBTD)
  1. S IBA=$$BILLED(DFN,IBD,IBFD,IBTD),IBE=$P(IBA,"^",2)
  1. S IBB=IBQ*IBC
  1. S IBB=$S('IBZ:IBB,IBB+IBA>IBZ:$S(IBZ-IBA>0:IBZ-IBA,1:0),1:IBB) ; monthly
  1. I IBB,IBY S IBB=$S(IBB+IBE>IBY:$S(IBY-IBE>0:IBY-IBE,1:0),1:IBB) ; yearly
  1. S IBN=$S(IBQ*IBC=IBB:0,1:IBQ*IBC-IBB)
  1. ;
  1. Q
  1. ;
  1. BILLED(DFN,IBD,IBFD,IBTD) ; returns about billed, format: month^year
  1. ; IBD = transaction date, IBFD = from date, IBTD = to date
  1. N IBFY,IBX,IBM,IBY,IBZ
  1. F IBX="IBD","IBFD","IBTD" S @IBX=$E(@IBX,1,5)_"00"
  1. S IBX=+$O(^IBAM(354.7,DFN,1,"B",IBD,0))
  1. S IBM=+$P($G(^IBAM(354.7,DFN,1,IBX,0)),"^",2)
  1. S IBY=0,IBZ=IBFD-1 F S IBZ=$O(^IBAM(354.7,DFN,1,"B",IBZ)) Q:IBZ<1!(IBZ>IBTD) S IBX=$O(^IBAM(354.7,DFN,1,"B",IBZ,0)) I IBX S IBY=IBY+$P($G(^IBAM(354.7,DFN,1,IBX,0)),"^",2)
  1. Q IBM_"^"_IBY
  1. ;
  1. CAP(IBD,IBP,IBM,IBY,IBF,IBT) ; returns the cap amount and dates
  1. ; IBD = date of transaction
  1. ; IBP = priority level of patient
  1. ; return (by reference):
  1. ; IBM = monthly cap amount
  1. ; IBY = yearly cap amount
  1. ; IBF = from date for yearly cap determination
  1. ; IBT = to date for yearly cap determination
  1. N IBX,IBDT
  1. I $D(^IBAM(354.75,"AC",IBP,IBD)) S IBX=+$O(^(IBD,0)) G CAPC
  1. S IBDT=+$O(^IBAM(354.75,"AC",IBP,IBD),-1),IBX=+$O(^(IBDT,0))
  1. CAPC ;
  1. S IBX=$G(^IBAM(354.75,IBX,0))
  1. I 'IBX!($P(IBX,"^",5)&(IBD>$P(IBX,"^",5))) S (IBM,IBY,IBF,IBT)=0 Q
  1. S IBM=$P(IBX,"^",3),IBY=$P(IBX,"^",4)
  1. S IBDT=$P($$FYCY^IBCU8(IBD),"^",$S($P(IBX,"^",6)="C":1,1:3),$S($P(IBX,"^",6)="C":2,1:4))
  1. S IBF=$S($P(IBDT,"^")>IBX:$P(IBDT,"^"),1:+IBX)
  1. S IBT=$S('$P(IBX,"^",5):$P(IBDT,"^",2),$P(IBDT,"^",2)<$P(IBX,"^",5):$P(IBDT,"^",2),1:$P(IBX,"^",5))
  1. ;
  1. Q
  1. ;
  1. FLAG(DFN,IBD) ; flag account if at or above cap
  1. ; IBD = date of transaction (mo/year fm format)
  1. ; flag in account is set to: 2 = cap exceeded, some copays not billed
  1. ; 1 = cap reached
  1. ; 0 = below cap
  1. ;
  1. N IBC,IBB,IBZ,IBF,IBX,DIE,DR,DA,X,Y,IBFD,IBTD,IBY
  1. S IBX=+$O(^IBAM(354.7,DFN,1,"B",IBD,0)) Q:'IBX
  1. S IBZ=$G(^IBAM(354.7,DFN,1,IBX,0))
  1. D CAP(IBD+1,+$$PRIORITY^IBARXMU(DFN),.IBC,.IBY,.IBFD,.IBTD)
  1. S IBB=$$BILLED(DFN,IBD,IBFD,IBTD)
  1. S IBF=$S('IBC&('IBY):0,$P(IBZ,"^",4):2,IBC=+IBB:1,IBY=$P(IBB,"^",2):1,1:0)
  1. I IBF'=$P(IBZ,"^",3) S DIE="^IBAM(354.7,"_DFN_",1,",DA=IBX,DR=".03///^S X=IBF",DA(1)=DFN L +^IBAM(354.7,DFN):10 I $T D ^DIE L -^IBAM(354.7,DFN)
  1. Q
  1. ;
  1. PARENT(X) ; returns the parent entry in 354.71 for a transaction
  1. Q +$P($G(^IBAM(354.71,X,0)),"^",10)
  1. ;
  1. NET(X) ; returns net amount billed for a parent and its children
  1. ; X = ien from 354.71 (parent or child) output: billed ^ un-billed
  1. ;
  1. N Y,Z,B,N,P S P=$$PARENT(X),(Y,B,N)=0 F S Y=$O(^IBAM(354.71,"AF",P,Y)) Q:Y<1 S Z=^IBAM(354.71,Y,0),B=B+$P(Z,"^",11),N=N+$P(Z,"^",12)
  1. Q B_"^"_N
  1. ;
  1. CANCEL(DFN,IBDT) ; receives notification of a cancellation and determines
  1. ; if more need to be billed. IBDT should be in fm format date to check
  1. ;
  1. N IBT,IBTFL,IBX,IBD,IBFD,IBTD,IBDTQ,IBBIL,IBS,IBS1,IBS2
  1. ;
  1. C1 ; get starting values
  1. S IBS=+$P($$SITE^IBARXMU,"^",3) ;676;Need to use Site ID not IEN
  1. S IBP=+$$PRIORITY^IBARXMU(DFN)
  1. D CAP(IBDT+1,IBP,.IBZ,.IBY,.IBFD,.IBTD)
  1. I ('IBY&('IBZ))!('IBFD)!('IBTD) Q
  1. S IBA=$$BILLED(DFN,IBDT+1,IBFD,IBTD),IBE=$P(IBA,"^",2)
  1. ;
  1. ; query (if any) other facilities to see what is there.
  1. C2 S IBT=$$TFL^IBARXMU(DFN,.IBTFL,2)
  1. I IBT W:'$D(ZTQUEUED) !,"This patient is being seen at other VA treating facilities. I need to make",!,"sure there are no Rx fills that have not been billed elsewhere." S IBX=0 F S IBX=$O(IBTFL(IBX)) Q:IBX<1 D
  1. . I '$D(ZTQUEUED) U IO W !,"Now sending queries to ",$P(IBTFL(IBX),"^",2)," ..."
  1. . ;676;BL; Send request to Cerner Separate response message returns transactions
  1. . I $P(IBTFL(IBX),"^",1)["200CRNR" D Q
  1. . . D EN^IBARXCQR(DFN,$E(IBFD,1,5)_"00")
  1. . S IBDTQ=IBFD F D S IBDTQ=$$NEXTMO(IBDTQ) Q:IBDTQ>IBTD
  1. .. D UQUERY^IBARXMU(DFN,$E(IBDTQ,1,5)_"00",+IBTFL(IBX),.IBD)
  1. .. I $P(IBD(0),"^")=-1!(-1=+IBD) K IBD Q
  1. .. S X=1 F S X=$O(IBD(X)) Q:X<1 S IBD=$$ADD^IBARXMN(DFN,IBD(X))
  1. .. K IBD
  1. I '$D(ZTQUEUED) U IO
  1. ;
  1. C3 K ^TMP("IBD",$J)
  1. ; now lets see if there are some unbilled that can be billed.
  1. S IBDTQ=IBFD F D S IBDTQ=$$NEXTMO(IBDTQ) Q:IBDTQ>IBTD
  1. . S IBX=0 F S IBX=$O(^IBAM(354.71,"AD",DFN,$E(IBDTQ,1,5)_"00",IBX)) Q:IBX<1 D
  1. .. N IBZ S IBZ=^IBAM(354.71,IBX,0)
  1. .. ;
  1. .. ; check, am I the parent and still have some unbilled
  1. .. I $P(IBZ,"^",10)'=IBX!('$P($$NET(IBX),"^",2)) Q
  1. .. ;
  1. .. ; ^TMP("IBD",$J format(date of transaction,date/time entry added,ien)
  1. .. S ^TMP("IBD",$J,$P(IBZ,"^",3),$P(IBZ,"^",15),IBX)=IBZ
  1. ;
  1. I '$D(^TMP("IBD",$J)) W:'$D(ZTQUEUED) !,"No un-billed transactions exist" Q
  1. ;
  1. ; how much more can we bill
  1. C4 S IBB=$S('IBZ&('IBY):9999999,IBZ&((IBZ-IBA)<(IBY-IBE)):IBZ-IBA,1:IBY-IBE)
  1. ;
  1. ; we now have to bill some of the unbilled ones
  1. S IBS1=0 F S IBS1=$O(^TMP("IBD",$J,IBS1)) Q:IBS1<1 S IBS2=0 F S IBS2=$O(^TMP("IBD",$J,IBS1,IBS2)) Q:IBS2<1 S IBX=0 F S IBX=$O(^TMP("IBD",$J,IBS1,IBS2,IBX)) Q:IBX<1 D
  1. . S IBZ=^TMP("IBD",$J,IBS1,IBS2,IBX)
  1. . ;
  1. C5 . ; determine how much to bill (if any)
  1. . S IBA=$$NET(IBX)
  1. . S IBBIL=$S(IBB>$P(IBA,"^",2):$P(IBA,"^",2),1:IBB)
  1. . I 'IBBIL S IBS1=9999999999 Q
  1. . S IBB=IBB-IBBIL
  1. . ;quit if IBBIL is less than zero IB*552 ticket 956230
  1. . Q:IBBIL<0
  1. . ;676;If Cerner send HL7
  1. . I +$P(IBZ,"^",1)=200 D EN^IBARXCBK(IBX,IBBIL) Q
  1. . ;
  1. . D @($S(IBS=+IBZ:"BILL",1:"SEND")_"^IBARXMB($P(IBZ,""^""),IBBIL)")
  1. K ^TMP("IBD",$J)
  1. Q
  1. ;
  1. NEXTMO(DATE) ; returns first date of next month
  1. N X S X="",DATE=$G(DATE)\1 I DATE'?7N G NEXTMOQ
  1. S X=$S($E(DATE,4,5)<12:$E(DATE,1,5)+1_"01",1:$E(DATE,1,3)+1_"0101")
  1. NEXTMOQ Q X
  1. ;
  1. QCAN(DFN,IBCAP,IBSAVXMC) ; queue off job to look for back billing in the background
  1. N ZTRTN,ZTDTH,ZTIO,ZTDESC,ZTSK,ZTSAVE,Y,IBTAG
  1. ;
  1. S ZTRTN="DQCAN^IBARXMC",ZTDESC="IB Back Billing of Rx Copay Charges"
  1. S ZTDTH=$$FMTH^XLFDT($$FMADD^XLFDT($$NOW^XLFDT,"","",10))
  1. S (ZTSAVE("DFN"),ZTSAVE("IBCAP("),ZTSAVE("IBSAVXMC("),ZTIO)="" D ^%ZTLOAD
  1. ;
  1. I ZTSK<1 S IBTAG=3,Y="^^Error when trying to queue back billing job." D BULL^IBAERR
  1. ;
  1. Q
  1. ;
  1. DQCAN ; entry point for queued back billing job
  1. N IBD,IBL,IBPAT,IBREF,IBSSN,IBTAG,Y
  1. ;
  1. ; try to get a lock
  1. S IBL=0 F X=1:1:10 L +^IBAM(354.7,"APAT",DFN):10 H:'$T 600 I $T S IBL=1 Q
  1. I 'IBL D Q
  1. .S IBTAG=3
  1. .S IBPAT=$P($G(^DPT(DFN,0)),"^",1) I IBPAT="" S IBPAT=DFN
  1. .S IBSSN=$P($G(^DPT(DFN,0)),"^",9) I IBSSN="" S IBSSN="????"
  1. .S (X,IBREF)=""
  1. .F S X=$O(IBSAVXMC(X)) Q:X="" D
  1. ..I IBREF'="" S IBREF=IBREF_", "_$P(IBSAVXMC(X),"^",1)
  1. ..I IBREF="" S IBREF=$P(IBSAVXMC(X),"^",1)
  1. .S Y="^^Unable to lock the IB PATIENT COPAY ACCOUNT (#354.7) file for back billing job related to "_IBPAT_" ("_IBSSN_") and IB reference number(s): "_IBREF_"."
  1. .D ^IBAERR Q
  1. ;
  1. ; do query/back billing
  1. S IBD=0 F S IBD=$O(IBCAP(IBD)) Q:IBD<1 D CANCEL(DFN,IBD) H 120 ;Delay between backbilling months
  1. ;
  1. ; remove lock
  1. L -^IBAM(354.7,"APAT",DFN)
  1. ;
  1. Q