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

ABSPOSRB.m

Go to the documentation of this file.
  1. ABSPOSRB ; IHS/FCS/DRS - background from ABSPOSRX ;
  1. ;;1.0;PHARMACY POINT OF SALE;**31,32,40,41**;JUN 21, 2001;Build 38
  1. Q
  1. BACKGR ;
  1. ;I '$$LOCKNOW^ABSPOSRX("BACKGROUND") Q
  1. ;IHS/OIT/PIERAN/RAN Patch 40 10/13/2010 checking locks is not a good way to verify something isn't running! Added next two lines
  1. I $P(+$G(^ABSP(9002313.99,1,"ABSPOSRX")),"^") Q ; it is running; dont start another
  1. S ^ABSP(9002313.99,1,"ABSPOSRX")=1_U_$H ;Note that it is running so no other processes try to run it till we're done
  1. N BACKSLOT S BACKSLOT=DT+.4
  1. D INIT^ABSPOSL(BACKSLOT,1,-1)
  1. N LIST,TYPE,RXI,RXR S LIST="ABSPOSRX"
  1. I '$$LOCK^ABSPOSRX("BACKGROUND") D G FAIL
  1. . D LOG^ABSPOSL("Failed to $$LOCK^ABSPOSRX(""BACKGROUND"")")
  1. F TYPE="CLAIM","UNCLAIM" D
  1. . S RXI="" F S RXI=$O(^ABSPECP(LIST,TYPE,RXI)) Q:RXI="" D
  1. . . S RXR="" F S RXR=$O(^ABSPECP(LIST,TYPE,RXI,RXR)) Q:RXR="" D
  1. . . . N X S X=$$STATUS(RXI,RXR)
  1. . . . I $P(X,U)="IN PROGRESS" D Q
  1. . . . . D LOG^ABSPOSL(RXI_","_RXR_" in progress; wait")
  1. . . . N TIME,MOREDATA
  1. . . . S TIME=^ABSPECP(LIST,TYPE,RXI,RXR) ; time requested
  1. . . . I '$$LOCK^ABSPOSRX("SUBMIT") D Q
  1. . . . . D LOG^ABSPOSL("Failed to $$LOCK^ABSPOSRX(""SUBMIT"") for RXI="_RXI_",RXR="_RXR)
  1. . . . I $D(^ABSPECP(LIST,TYPE,RXI,RXR,"MOREDATA")) M MOREDATA=^("MOREDATA")
  1. . . . E S MOREDATA=0
  1. . . . K ^ABSPECP(LIST,TYPE,RXI,RXR)
  1. . . . D BACKGR1(TYPE,RXI,RXR,TIME,.MOREDATA)
  1. . . . D UNLOCK^ABSPOSRX("SUBMIT")
  1. . . . ;IHS/OIT/PIERAN/RAN Patch 40 10/15/2010 This hang is completely unnecessary and is the reason it stays locked so long
  1. . . . ;D HANG
  1. FAIL D RELSLOT^ABSPOSL
  1. D UNLOCK^ABSPOSRX("BACKGROUND")
  1. ;IHS/OIT/PIERAN/RAN Patch 40 10/20/2010 checking locks is not a good way to verify something isn't running! Added next line
  1. S ^ABSP(9002313.99,1,"ABSPOSRX")=0_U_$H ;Note that it is no longer running so other processes can access
  1. Q
  1. STARTTIM(RXI,RXR) Q $P($G(^ABSPT($$IEN59(RXI,RXR),0)),U,11)
  1. BACKGLOG(X) ;
  1. N MSG S MSG=RXI_","_RXR_" "_$S(TYPE="CLAIM":"",1:TYPE)_" "_X
  1. D LOG2SLOT^ABSPOSL(MSG,BACKSLOT)
  1. Q
  1. BACKGR1(TYPE,RXI,RXR,TIME,MOREDATA) ;
  1. ; Resolve multiple requests
  1. N SKIP S SKIP=0 ; skip if you already got desired result
  1. N SKIPREAS
  1. N RESULT S RESULT=$$STATUS(RXI,RXR),RESULT=$P(RESULT,U)
  1. N STARTTIM S STARTTIM=$$STARTTIM(RXI,RXR)
  1. I TYPE="CLAIM" D
  1. . I $$RXDEL^ABSPOS(RXI,RXR) D Q
  1. . . S SKIP=1,SKIPREAS="is marked as DELETED or CANCELLED"
  1. . ; If it's never been through POS before, good.
  1. . I RESULT="" Q
  1. . ; There's already a complete transaction for this RXI,RXR
  1. . ; (We screened out "IN PROGRESS" earlier)
  1. . ; The program to poll indexes would have set DO NOT RESUBMIT.
  1. . ; Calls from pharm pkg to POS have '$D(MOREDATA("DO NOT RESUBMIT"))
  1. . I $D(MOREDATA("DO NOT RESUBMIT")) D
  1. . . S SKIP=1
  1. . . S SKIPREAS="MOREDATA(""DO NOT RESUBMIT"") is set"
  1. . E I TIME<STARTTIM D ; our request was made before trans. began
  1. . . ; submit claim but only if the prev result was successful reversal
  1. . . I RESULT="PAPER REVERSAL" Q
  1. . . I RESULT="E REVERSAL ACCEPTED" Q
  1. . . S SKIP=1
  1. . . S SKIPREAS="prev result "_RESULT_"; claim started "_STARTTIM_"<"_TIME_" submitted"
  1. . E D ; our request was made after it began
  1. . . ; So we will make a reversal if necessary,
  1. . . ; and then the claim will be resubmitted.
  1. . . ;IHS/OIT/CASSEVERN/RAN - 02/07/2011 - Patch 41 - Add "E CAPTURED" to types to be reversed.
  1. . . ;I RESULT="PAPER"!(RESULT="E PAYABLE") D
  1. . . I RESULT="PAPER"!(RESULT="E PAYABLE")!(RESULT="E CAPTURED") D
  1. . . . S MOREDATA("REVERSE THEN RESUBMIT")=1
  1. E I TYPE="UNCLAIM" D
  1. . ; It must have gone through POS with a payable result
  1. . ;IHS/OIT/CASSEVERN/RAN - 02/07/2011 - Patch 41 - Add "E CAPTURED" to types to be reversed.
  1. . ;I RESULT="PAPER"!(RESULT="E PAYABLE") Q
  1. . I RESULT="PAPER"!(RESULT="E PAYABLE")!(RESULT="E CAPTURED") Q
  1. . S SKIP=1
  1. . S SKIPREAS="cannot reverse - previous result was "_RESULT
  1. E D IMPOSS^ABSPOSUE("P","TI","bad arg TYPE="_TYPE,,"BACKGR1",$T(+0))
  1. I SKIP D Q
  1. . D BACKGLOG("SKIP:"_SKIPREAS)
  1. I TYPE="UNCLAIM"!$G(MOREDATA("REVERSE THEN RESUBMIT")) G BACKGRUN
  1. N ABSBRXI,ABSBRXR,ABSBNDC
  1. S (ABSBRXI,ABSBRXI(1))=RXI,(ABSBRXR,ABSBRXR(1))=RXR
  1. S ABSBNDC(1)=$$DEFNDC^ABSPOSIV
  1. ;
  1. ; Caller should have MOREDATA("ORIGIN") set.
  1. ; except if CLAIM^ABSPOSRX() was called by RPMS pharmacy,
  1. ; in which case MOREDATA("ORIGIN") is undefined - give it a "1" here.
  1. I '$D(MOREDATA("ORIGIN")) S MOREDATA("ORIGIN")=1
  1. D FILING^ABSPOSIV(0,MOREDATA("ORIGIN"))
  1. D BACKGLOG("initiated")
  1. Q
  1. BACKGRUN ; reverse RXI,RXR ; (reached by a GOTO from a few lines above)
  1. N IEN59 S IEN59=$$IEN59(RXI,RXR)
  1. N M S M="reversal initiated"
  1. I $G(MOREDATA("REVERSE THEN RESUBMIT")) D
  1. . ; set flag to say "After reversal is done, resubmit the claim."
  1. . S $P(^ABSPT(IEN59,1),U,12)=1
  1. . S M=M_" and after that, claim will be resubmitted"
  1. ;IHS/OIT/SCR 04/17/09 patch 31 - save MOREDATA("RXREASON") if it exists
  1. S $P(^ABSPT(IEN59,4),U,4)=$G(MOREDATA("RXREASON"))
  1. D REVERS59^ABSPOS6D(IEN59,1)
  1. D BACKGLOG(M)
  1. Q
  1. LASTLOG ; tool for test - find and print most recent log file
  1. N X S X=999999999999
  1. F S X=$O(^ABSPECP("LOG",X),-1) Q:'X Q:X#1=.4
  1. I 'X W "No log file found",! Q
  1. D PRINTLOG^ABSPOSL(X)
  1. Q
  1. HANG ; how long to hang before submitting the next claim?
  1. ; usually not at all (0 secs)
  1. ; but if there are an extraordinary # of claims in processing,
  1. ; then wait up a bit before letting anything else through
  1. ;
  1. ; FUTURE: Have to make this smarter - make it aware of how many
  1. ; claims have been requested in, say, the past 1 minute as well.
  1. ; This would be to keep the backbilling from flooding taskman
  1. ; with excessive ABSPOSQ1 and ABSPOSQ2 jobs which have nothing to
  1. ; do. That way, the ABSPOSQ3 jobs would activate more quickly.
  1. ;
  1. ; I $H<some date H $R(10) ; put in this line if doing massive backbill
  1. I $R(50) Q ; for efficiency - check only once every 50 claims
  1. N LOCK,MYDEST
  1. HANGA ;
  1. K MYDEST S LOCK=0 D FETSTAT^ABSPOS2("MYDEST")
  1. N T,S S T=0 F S=0:10:90 S T=T+$G(MYDEST(S))
  1. I T<20 Q ; not too many; that's fine
  1. H 30 ; wait 30 secs and try again until things have settled down
  1. G HANGA
  1. IEN59(RXI,RXR) Q $$IEN59^ABSPOSRX(RXI,RXR)
  1. STATUS(RXI,RXR) Q $$STATUS^ABSPOSRX(RXI,RXR)