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

ABSPOSBX.m

Go to the documentation of this file.
  1. ABSPOSBX ; IHS/FCS/DRS - Billing - FSI/ILC A/R v1,2;
  1. ;;1.0;PHARMACY POINT OF SALE;**48**;JUN 21, 2001;Build 38
  1. Q
  1. ENABLED() Q 1
  1. EN ; Taskman routine begins here
  1. ; with KEY15=visit/insurer/time sched for
  1. ; Does posting for just this one visit and insurer
  1. ;
  1. ; ^ABSPTL("AR",KEY15,IEN57)="" is defined for one or more IEN57's
  1. ; These are all charges.
  1. ; None are reversals - the reversals were dealt with in ABSPOSBW.
  1. ; But some of these charges may already have reversals outstanding!
  1. ;
  1. N PCNDFN
  1. ;
  1. ; Same interlock as other billing
  1. ; Unlock happens implicitly when Taskman job stops
  1. ;
  1. I '$$LOCK^ABSPOSBD D RESCHED(5*60) Q ; 5 minutes later
  1. D INIT^ABSPOSL(DT+.2,1) ; same log file
  1. ;
  1. ; If posting is turned off, then reschedule this to run much later.
  1. ;
  1. I '$$ENABLED D RESCHED(3*60*60) Q ; 3 hours later
  1. ;
  1. ; Gather all the IEN57's with the same visit/insurer as KEY15 has
  1. ; Put them into CHGLIST(IEN57)=""
  1. ; But for those which were reversed, put them into REVLIST(IEN57)
  1. ;
  1. N CHGLIST,REVLIST D
  1. . N X S X=$P(KEY15,"/",1,2)
  1. . F S X=$O(^ABSPTL("AR",X)) Q:$P(X,"/",1,2)'=$P(KEY15,"/",1,2) D
  1. . . N IEN57 S IEN57=0
  1. . . F S IEN57=$O(^ABSPTL("AR",X,IEN57)) Q:'IEN57 D
  1. . . . S @$$LIST57@(IEN57)=""
  1. ;
  1. ; If charges for the visit/insurer are still coming in,
  1. ; then reschedule this to run later.
  1. ; (DT test is to facilitate testing on the date shown)
  1. ;
  1. I DT>3010327,'$$SETTLED D Q
  1. . D RESCHED($$DELAY2^ABSPOSBW)
  1. . D LOG(KEY15_" still busy; billing rescheduled for later")
  1. ;
  1. ; Post everything in CHGLIST(IEN57)=""
  1. ; except those which have been reversed
  1. ;
  1. I $D(CHGLIST) D
  1. . S PCNDFN=$$CHGLIST^ABSPOSBM ; 03/26/2001
  1. ;
  1. ; If any of these charges had been posted before,
  1. ; adjust off the old charges. (Should not happen any more, since
  1. ; we enforce a reverse-first-then-resubmit policy, even for paper.)
  1. ;
  1. D REBILLED
  1. ;
  1. ; Clear the KEY15 values (thus removing these charges
  1. ; from the ^ABSPTL("AR",key15,ien57) index)
  1. ; and Mark each of these as having been posted to ILC A/R.
  1. ;
  1. D
  1. . I '$G(PCNDFN) N PCNDFN S PCNDFN="not posted"
  1. . N FDA,MSG
  1. . S IEN57=0 F S IEN57=$O(CHGLIST(IEN57)) Q:'IEN57 D
  1. . . S FDA(9002313.57,IEN57_",",2)=PCNDFN
  1. . . S FDA(9002313.57,IEN57_",",.15)=PCNDFN
  1. . S IEN57=0 F S IEN57=$O(REVLIST(IEN57)) Q:'IEN57 D
  1. . . S FDA(9002313.57,IEN57_",",.15)=PCNDFN
  1. . . D LOG^ABSPOSL("Transaction "_IEN57_" was already reversed; we did not post it.")
  1. F . I $D(FDA) D FILE^DIE("","FDA","MSG")
  1. . I $D(MSG) D LOG^ABSPOSL2("F^ABSPOSBX",.MSG) ; /IHS/OIT/RAM ; 12 JUN 17 ; AND LOG IT IF AN ERROR OCCURS.
  1. . I $D(MSG) D G F:$$IMPOSS^ABSPOSUE("FM","TRI","FILE^DIE failed",.MSG,,$T(+0))
  1. . . D LOG^ABSPOSL("Failed - trying to store in fields .15 and 2")
  1. . . D LOGARRAY^ABSPOSL("FDA")
  1. . . D LOGARRAY^ABSPOSL("MSG")
  1. ;
  1. ;
  1. D DONE^ABSPOSL ; done with log file
  1. D UNLOCK^ABSPOSBD ; release billing interlock
  1. Q
  1. LIST57() ; given IEN57 ; return "CHGLIST" or "REVLIST"
  1. ; "CHGLIST" - this is a charge which should be posted to a/r
  1. ; "REVLIST" - this charge was subsequently reversed; do not post it
  1. N X S X=$P(^ABSPTL(IEN57,0),U) ; RXIRXR
  1. I '$O(^ABSPTL("B",X,IEN57)) Q "CHGLIST" ; no subsequent transactions
  1. N NXT57 S NXT57=$O(^ABSPTL("B",X,IEN57))
  1. S X=$$GET1^DIQ(9002313.57,NXT57_",","RESULT WITH REVERSAL")
  1. I X="E REVERSAL ACCEPTED" Q "REVLIST"
  1. E I X="PAPER REVERSAL" Q "REVLIST"
  1. E Q "CHGLIST"
  1. REBILLED ; if anything in CHGLIST() was previously posted to A/R,
  1. ; write off the old charges and make comments on both old and new bills
  1. S IEN57=0 F S IEN57=$O(CHGLIST(IEN57)) Q:'IEN57 D
  1. . N OLD57,OLDPCNI,OLDPCNE,OLDAMT ; internal, external id's of the old bill
  1. . S OLD57=$$PREVIOUS^ABSPOS57(IEN57) Q:'OLD57
  1. . S OLDPCNI=$P(^ABSPTL(OLD57,0),U,3) Q:'OLDPCNI
  1. . S OLDAMT=$P(^ABSPTL(OLD57,5),U,5)
  1. . S OLDPCNE=$P(^ABSBITMS(9002302,OLDPCNI,0),U)
  1. . ; comment on old bill to say "rebilled"
  1. . N NEWPCNI,NEWPCNE
  1. . N DRUG S DRUG=$$DRGNAME^ABSPOS57
  1. . S NEWPCNI=PCNDFN,NEWPCNE=$P(^ABSBITMS(9002302,NEWPCNI,0),U)
  1. . D ADJUST(OLDPCNI,OLDAMT,"Rebilled "_DRUG_" on "_NEWPCNE)
  1. . D COMMENT^ABSPOSBF(NEWPCNI,"Rebilling of "_DRUG_" from "_OLDPCNE)
  1. Q
  1. ADJUST(PCNDFN,AMTOLD,REASON) ; EP - used by reversals handling in ABSPOSBW
  1. N BATCH S BATCH=$$ADJBATCH
  1. ; Do we need to release this batch?
  1. I $$NEEDREL D:BATCH'=0 ; batch old enough to need to be released
  1. . ;No, don't actually release the batch here.
  1. . ;Let someone do it from the A/R Menu.
  1. . S BATCH=0 ; force a new one to be created
  1. ; Do we need a new batch?
  1. AB I 'BATCH D
  1. . S BATCH=$$NEWBATCH^ABSPOSP(0)
  1. . D LOG^ABSPOSL("Opened new adjustments batch "_BATCH)
  1. . D SET235(5,BATCH)
  1. I 'BATCH G AB:$$IMPOSS^ABSPOSUE("P,DB,FM,L","TRI","Failed to obtain a new batch",,"ADJUST",$T(+0))
  1. D ADJUST^ABSPOSP(PCNDFN,BATCH,AMTOLD,REASON)
  1. D LOG^ABSPOSL("Adjustment recorded in payments batch "_BATCH)
  1. D SET235(6,DT) ; record the date we last used this batch
  1. Q
  1. NEEDREL() Q:'BATCH 0 ; no batch on record
  1. I $P(^ABSBPMNT(BATCH,0),U,5)'="A" Q 0 ; prev. batch no longer active
  1. N X1,X2,X,%Y S X1=DT,X2=$$BLASTDT D ^%DTC
  1. Q X>$$BLIFE ; 1 if it's older than that, 0 if not older
  1. ADJBATCH() N B S B=$P($$GET235,U,5) Q:'B B ; batch # of last adjustments batch
  1. Q $S($P($G(^ABSBPMNT(B,0)),U,5)="A":B,1:"") ; but only if Active batch
  1. BLASTDT() Q $P($$GET235,U,6) ; date we last made an entry in it
  1. BLIFE() Q $P($$GET235,U,7) ; how many days a batch is good for
  1. GET235() Q $G(^ABSP(9002313.99,1,"BILLING - NEW"))
  1. SET235(PIECE,VALUE) S $P(^ABSP(9002313.99,1,"BILLING - NEW"),U,PIECE)=VALUE Q
  1. SETTLED() ; has the flow of new charges for this KEY15 settled?
  1. ; yes, if all of them are at least $$DELAY2^ABSPOSBW seconds old
  1. N RET S RET=1 ; assume yes
  1. N IEN57 S IEN57=0
  1. F S IEN57=$O(^ABSPTL("AR",KEY15,IEN57)) Q:'IEN57 D Q:'RET
  1. . N T1 S T1=$P(^ABSPTL(IEN57,0),U,8) ; LAST UPDATE
  1. . N DIF S DIF=$$TIMEDIFI^ABSPOSUD(T1,$$NOW^ABSPOS) ; how old?
  1. . I DIF<$$DELAY2^ABSPOSBW S RET=0
  1. Q RET
  1. RESCHED(DELTA) ;
  1. N ZTDTH,ZTIO,ZTSAVE,ZTRTN
  1. S ZTDTH=$$TADDNOWS^ABSPOSUD(DELTA)
  1. S ZTIO="",ZTSAVE("KEY15")=""
  1. S ZTRTN="EN^ABSPOSBX"
  1. D ^%ZTLOAD
  1. Q
  1. LOG(X) D LOG^ABSPOSL(X) Q
  1. LOGCLAIM(X) D LOG59^ABSPOS57(X) Q