ABSPOSBW ; IHS/FCS/DRS - Billing - FSI/ILC A/R v1,2;
;;1.0;PHARMACY POINT OF SALE;**48**;JUN 21, 2001;Build 38
Q
; Billing interface for FSI/ILC Accounts Receivable,
; Versions 1 and 2
;
; Called at tag POST from ABSPOSBB
; with the variable ABSP57 pointing to 9002313.57, the transaction
; You must return a value - that value is stuffed into field .15
; of the transaction record
; and indexed by ^ABSPTL("AR",value,IEN57)
;
; Many useful utilities are available in ABSPOS57
; need to write
; DO LOG57^ABSPOS57(text) puts text into the claim's log file
;
; Note about this billing interface and interlocks:
; We have another background job to actually post charges.
; A job is scheduled for each visit - to run ABSPOSBX.
; That posting job uses the same interlock as the main
; background billing. So you can freely use the "AR" index
; and everything else.
;
POST() ; EP - from ABSPOSBB
N IEN57 S IEN57=ABSP57 ; now you can $$label^ABSPOS57
N PREV57 D
. S X=$P(^ABSPTL(IEN57,0),U) ; 1234567.000rt
. S PREV57=$O(^ABSPTL("B",X,IEN57),-1)
N RESULT,RETVAL S RETVAL=""
S RESULT=$$GET1^DIQ(9002313.57,ABSP57_",","RESULT WITH REVERSAL")
;
; RESULT can by E PAYABLE, E REJECTED, E CAPTURED, PAPER
; or E REVERSAL ACCEPTED or PAPER REVERSAL
; or E REVERSAL REJECTED
;
N VISITIEN S VISITIEN=$$VISITIEN^ABSPOS57
;
; We want to group all the claims for a single visit and
; then post them together on a single bill (well, more bills if
; some of the claims have different insurers. One per insurer.)
;
; So for this phase, we simply schedule a billing job for the visit
; for some time from now (30 minutes?). At that time, we check to
; see if all the collected charges for the visit are at least
; (15 minutes?) old. If so, we post. If not, we reschedule for later.
;
; But reversals, we handle those right now:
; The original charge might not yet be posted! It could still be
; in ^ABSPOS("AR",KEY15, waiting.
;
I RESULT["REVERSAL" D
. D REVERSAL ; IEN57 is a reversal
E D ; it's a charge to be posted
. S RETVAL=$$KEY15 ; make sure posting job is scheduled
Q RETVAL ; caller stuffs this into 9002313.57 field #.15 for us
;
;
;
; ^ABSPTL("AR",key,ien57)
; What to use for the key?
; For claims awaiting posting,
; visitien/insien/time scheduled to post
; For claims already posted:
; "" (so it disappears from the index)
; or ?1N.N (another pointer to where it was posted
;
; So to get the vis/ins/time ones,
; $O(^ABSPTL("AR"," "))
;
KEY15() N X,Y S X=$$VISITIEN^ABSPOS57_"/"_$$INSIEN^ABSPOS57_"/"
S Y=$O(^ABSPTL("AR",X))
I $P(Y,"/",1,2)=$P(X,"/",1,2) D ; posting already scheduled
. S $P(X,"/",3)=$P(Y,"/",3) ; so take the same posting time
E D ; posting not yet scheduled for this visit+insurer
. S $P(X,"/",3)=$$TADDNOWS^ABSPOSUD($$DELAY1)
. D SCHED(X)
Q X
SCHED(KEY15) ; schedule posting job for transaction as directed by X
; X = format of $$KEY15, above
S KEY15=$P(KEY15,"/",1,3)
N ZTDTH,ZTSAVE,ZTIO
S ZTDTH=$P(KEY15,"/",3)
S ZTRTN="EN^ABSPOSBX",ZTIO="",ZTSAVE("KEY15")=""
D ^%ZTLOAD
Q
REVERSAL ; IEN57 is a reversal - handle it and set RETVAL
S RETVAL="" ; until we say otherwise
D LOG("Transaction "_IEN57_" is a reversal; previous transaction was "_PREV57_".")
I 'PREV57 D Q
. D LOG(" ??No record of any previous charge. Nothing done.")
;
; Find where the previous charge was posted.
;
N PCNDFN S PCNDFN=$P(^ABSPTL(PREV57,0),U,3)
;
; Perhaps it wasn't posted yet. This would be typical if the
; reversal is made immediately after the original charge is posted.
; The original charge is probably in Taskman now waiting for other
; charges that might come along for the same visit. At that time,
; the reversal will be detected and posting of charge will be skipped.
;
I 'PCNDFN D Q ; it wasn't posted the first time around
. D LOG^ABSPOSL("Original charge not posted; no adjustment needed.")
;
; The original charge was posted, to PCNDFN.
; Put an adjustment and make a comment on the account.
;
N WHEN S WHEN=$$GET1^DIQ(9002313.57,IEN57_",",7,"I")_"0000"
S WHEN=$E(WHEN,4,5)_"/"_$E(WHEN,6,7)_"/"_$E(WHEN,2,3)
S WHEN=WHEN_"@"_$E(WHEN,9,10)_":"_$E(WHEN,11,12)
;
; if failed reversal, make a comment
;
I RESULT'="E REVERSAL ACCEPTED",RESULT'="PAPER REVERSAL" D Q
. D COMMENT^ABSPOSBF(PCNDFN,"CLAIM REVERSED on "_WHEN)
. D LOG^ABSPOSL("Comment made on `"_PCNDFN_" for "_RESULT)
;
; if successful reversal, write off the old charge
;
N AMTOLD S AMTOLD=$P(^ABSPTL(PREV57,5),U,5) ; original charge amount
N REASON S REASON=RESULT_" on "_WHEN
D ADJUST^ABSPOSBX(PCNDFN,AMTOLD,REASON)
N FDA,MSG ; mark transaction as having been posted to A/R.
S FDA(9002313.57,IEN57_",",2)=PCNDFN
S FDA(9002313.57,IEN57_",",.15)=PCNDFN
R88 D FILE^DIE(,"FDA","MSG")
I $D(MSG) D LOG^ABSPOSL2("R88^ABSPOSBW",.MSG) ; /IHS/OIT/RAM ; 12 JUN 17 ; AND LOG IT IF AN ERROR OCCURS.
I $D(MSG) D G R88:$$IMPOSS^ABSPOSUE("FM","TRI","FILE^DIE failed",.MSG,"REVERSAL",$T(+0))
. D LOGARRAY^ABSPOSL("FDA")
. D LOGARRAY^ABSPOSL("MSG")
Q
;
;
DELAY1() Q 30*60 ; how many seconds to wait before posting
DELAY2() ;EP -
Q $$DELAY1/2 ; how many seconds quiet time before it's safe to post
; (that is, if any additional charges in the past xxx time,
; reschedule the posting for later)
LOG(X) D LOG^ABSPOSL(X) Q
ABSPOSBW ; IHS/FCS/DRS - Billing - FSI/ILC A/R v1,2;
+1 ;;1.0;PHARMACY POINT OF SALE;**48**;JUN 21, 2001;Build 38
+2 QUIT
+3 ; Billing interface for FSI/ILC Accounts Receivable,
+4 ; Versions 1 and 2
+5 ;
+6 ; Called at tag POST from ABSPOSBB
+7 ; with the variable ABSP57 pointing to 9002313.57, the transaction
+8 ; You must return a value - that value is stuffed into field .15
+9 ; of the transaction record
+10 ; and indexed by ^ABSPTL("AR",value,IEN57)
+11 ;
+12 ; Many useful utilities are available in ABSPOS57
+13 ; need to write
+14 ; DO LOG57^ABSPOS57(text) puts text into the claim's log file
+15 ;
+16 ; Note about this billing interface and interlocks:
+17 ; We have another background job to actually post charges.
+18 ; A job is scheduled for each visit - to run ABSPOSBX.
+19 ; That posting job uses the same interlock as the main
+20 ; background billing. So you can freely use the "AR" index
+21 ; and everything else.
+22 ;
POST() ; EP - from ABSPOSBB
+1 ; now you can $$label^ABSPOS57
NEW IEN57
SET IEN57=ABSP57
+2 NEW PREV57
Begin DoDot:1
+3 ; 1234567.000rt
SET X=$PIECE(^ABSPTL(IEN57,0),U)
+4 SET PREV57=$ORDER(^ABSPTL("B",X,IEN57),-1)
End DoDot:1
+5 NEW RESULT,RETVAL
SET RETVAL=""
+6 SET RESULT=$$GET1^DIQ(9002313.57,ABSP57_",","RESULT WITH REVERSAL")
+7 ;
+8 ; RESULT can by E PAYABLE, E REJECTED, E CAPTURED, PAPER
+9 ; or E REVERSAL ACCEPTED or PAPER REVERSAL
+10 ; or E REVERSAL REJECTED
+11 ;
+12 NEW VISITIEN
SET VISITIEN=$$VISITIEN^ABSPOS57
+13 ;
+14 ; We want to group all the claims for a single visit and
+15 ; then post them together on a single bill (well, more bills if
+16 ; some of the claims have different insurers. One per insurer.)
+17 ;
+18 ; So for this phase, we simply schedule a billing job for the visit
+19 ; for some time from now (30 minutes?). At that time, we check to
+20 ; see if all the collected charges for the visit are at least
+21 ; (15 minutes?) old. If so, we post. If not, we reschedule for later.
+22 ;
+23 ; But reversals, we handle those right now:
+24 ; The original charge might not yet be posted! It could still be
+25 ; in ^ABSPOS("AR",KEY15, waiting.
+26 ;
+27 IF RESULT["REVERSAL"
Begin DoDot:1
+28 ; IEN57 is a reversal
DO REVERSAL
End DoDot:1
+29 ; it's a charge to be posted
IF '$TEST
Begin DoDot:1
+30 ; make sure posting job is scheduled
SET RETVAL=$$KEY15
End DoDot:1
+31 ; caller stuffs this into 9002313.57 field #.15 for us
QUIT RETVAL
+32 ;
+33 ;
+34 ;
+35 ; ^ABSPTL("AR",key,ien57)
+36 ; What to use for the key?
+37 ; For claims awaiting posting,
+38 ; visitien/insien/time scheduled to post
+39 ; For claims already posted:
+40 ; "" (so it disappears from the index)
+41 ; or ?1N.N (another pointer to where it was posted
+42 ;
+43 ; So to get the vis/ins/time ones,
+44 ; $O(^ABSPTL("AR"," "))
+45 ;
KEY15() NEW X,Y
SET X=$$VISITIEN^ABSPOS57_"/"_$$INSIEN^ABSPOS57_"/"
+1 SET Y=$ORDER(^ABSPTL("AR",X))
+2 ; posting already scheduled
IF $PIECE(Y,"/",1,2)=$PIECE(X,"/",1,2)
Begin DoDot:1
+3 ; so take the same posting time
SET $PIECE(X,"/",3)=$PIECE(Y,"/",3)
End DoDot:1
+4 ; posting not yet scheduled for this visit+insurer
IF '$TEST
Begin DoDot:1
+5 SET $PIECE(X,"/",3)=$$TADDNOWS^ABSPOSUD($$DELAY1)
+6 DO SCHED(X)
End DoDot:1
+7 QUIT X
SCHED(KEY15) ; schedule posting job for transaction as directed by X
+1 ; X = format of $$KEY15, above
+2 SET KEY15=$PIECE(KEY15,"/",1,3)
+3 NEW ZTDTH,ZTSAVE,ZTIO
+4 SET ZTDTH=$PIECE(KEY15,"/",3)
+5 SET ZTRTN="EN^ABSPOSBX"
SET ZTIO=""
SET ZTSAVE("KEY15")=""
+6 DO ^%ZTLOAD
+7 QUIT
REVERSAL ; IEN57 is a reversal - handle it and set RETVAL
+1 ; until we say otherwise
SET RETVAL=""
+2 DO LOG("Transaction "_IEN57_" is a reversal; previous transaction was "_PREV57_".")
+3 IF 'PREV57
Begin DoDot:1
+4 DO LOG(" ??No record of any previous charge. Nothing done.")
End DoDot:1
QUIT
+5 ;
+6 ; Find where the previous charge was posted.
+7 ;
+8 NEW PCNDFN
SET PCNDFN=$PIECE(^ABSPTL(PREV57,0),U,3)
+9 ;
+10 ; Perhaps it wasn't posted yet. This would be typical if the
+11 ; reversal is made immediately after the original charge is posted.
+12 ; The original charge is probably in Taskman now waiting for other
+13 ; charges that might come along for the same visit. At that time,
+14 ; the reversal will be detected and posting of charge will be skipped.
+15 ;
+16 ; it wasn't posted the first time around
IF 'PCNDFN
Begin DoDot:1
+17 DO LOG^ABSPOSL("Original charge not posted; no adjustment needed.")
End DoDot:1
QUIT
+18 ;
+19 ; The original charge was posted, to PCNDFN.
+20 ; Put an adjustment and make a comment on the account.
+21 ;
+22 NEW WHEN
SET WHEN=$$GET1^DIQ(9002313.57,IEN57_",",7,"I")_"0000"
+23 SET WHEN=$EXTRACT(WHEN,4,5)_"/"_$EXTRACT(WHEN,6,7)_"/"_$EXTRACT(WHEN,2,3)
+24 SET WHEN=WHEN_"@"_$EXTRACT(WHEN,9,10)_":"_$EXTRACT(WHEN,11,12)
+25 ;
+26 ; if failed reversal, make a comment
+27 ;
+28 IF RESULT'="E REVERSAL ACCEPTED"
IF RESULT'="PAPER REVERSAL"
Begin DoDot:1
+29 DO COMMENT^ABSPOSBF(PCNDFN,"CLAIM REVERSED on "_WHEN)
+30 DO LOG^ABSPOSL("Comment made on `"_PCNDFN_" for "_RESULT)
End DoDot:1
QUIT
+31 ;
+32 ; if successful reversal, write off the old charge
+33 ;
+34 ; original charge amount
NEW AMTOLD
SET AMTOLD=$PIECE(^ABSPTL(PREV57,5),U,5)
+35 NEW REASON
SET REASON=RESULT_" on "_WHEN
+36 DO ADJUST^ABSPOSBX(PCNDFN,AMTOLD,REASON)
+37 ; mark transaction as having been posted to A/R.
NEW FDA,MSG
+38 SET FDA(9002313.57,IEN57_",",2)=PCNDFN
+39 SET FDA(9002313.57,IEN57_",",.15)=PCNDFN
R88 DO FILE^DIE(,"FDA","MSG")
+1 ; /IHS/OIT/RAM ; 12 JUN 17 ; AND LOG IT IF AN ERROR OCCURS.
IF $DATA(MSG)
DO LOG^ABSPOSL2("R88^ABSPOSBW",.MSG)
+2 IF $DATA(MSG)
Begin DoDot:1
+3 DO LOGARRAY^ABSPOSL("FDA")
+4 DO LOGARRAY^ABSPOSL("MSG")
End DoDot:1
IF $$IMPOSS^ABSPOSUE("FM","TRI","FILE^DIE failed",.MSG,"REVERSAL",$TEXT(+0))
GOTO R88
+5 QUIT
+6 ;
+7 ;
DELAY1() ; how many seconds to wait before posting
QUIT 30*60
DELAY2() ;EP -
+1 ; how many seconds quiet time before it's safe to post
QUIT $$DELAY1/2
+2 ; (that is, if any additional charges in the past xxx time,
+3 ; reschedule the posting for later)
LOG(X) DO LOG^ABSPOSL(X)
QUIT