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

ABSPOSU.m

Go to the documentation of this file.
  1. ABSPOSU ; IHS/FCS/DRS - utilities ;
  1. ;;1.0;PHARMACY POINT OF SALE;;JUN 21, 2001
  1. Q
  1. ; some common utilities called a lot.
  1. ;
  1. ; SETSTAT - set status field for ^ABSPT(ABSBRXI,
  1. ;
  1. SETSTAT(STATUS) ;EP - from many places
  1. ; set ^ABSPT( status for ABSBRXI
  1. ;
  1. ; Timing problem: if response got processed before the SETCSTAT
  1. ; was sent for "waiting to process response", don't reset it now.
  1. I STATUS=80,$P(^ABSPT(ABSBRXI,0),U,2)>80 Q
  1. ;
  1. ; Perhaps other such detection would be a good idea here.
  1. ;
  1. ; LOCK the file - something is very wrong if you can't get the lock
  1. F L +^ABSPT:300 Q:$T Q:'$$IMPOSS^ABSPOSUE("L","RTI","LOCK +^ABSPT",,"SETSTAT",$T(+0))
  1. N DIE,DA,DR,X S DIE=9002313.59,DA=ABSBRXI,DR="1///"_STATUS_";7///NOW"
  1. I STATUS=0 S DR=DR_";15///NOW" ; START TIME, too.
  1. ;I STATUS=0 W "Before: ",$G(^ABSPT(ABSBRXI,0)),!
  1. D ^DIE
  1. ;I STATUS=0 W "After: ",$G(^ABSPT(ABSBRXI,0)),!
  1. ; Extra: make sure it's not in any index with any other status.
  1. ; We got one such corrupted index once and got infinite loop
  1. ; in a background job - it was a terrifying day.
  1. ; This consumes machine time but saves huge queue corruption headache.
  1. N X S X="" F S X=$O(^ABSPT("AD",X)) Q:X="" D
  1. .I X'=STATUS K ^ABSPT("AD",X,ABSBRXI)
  1. I STATUS=99 D STATUS99
  1. L -^ABSPT
  1. Q
  1. STATUS99 ; special activity when a claim reaches status 99
  1. ; Transaction log in .57 (but not if it's a canceled transaction!)
  1. I $P($G(^ABSPT(ABSBRXI,3)),U,2) D
  1. . ; canceled - shouldn't we restore old .57 into this .59?
  1. . D LOG^ABSPOSL($T(+0)_" - Cancellation succeeded.")
  1. E D
  1. . N ABSP57 S ABSP57=$$NEW57(ABSBRXI)
  1. . D TRANSACT^ABSPOSBC(ABSP57) ; hand it to posting
  1. . D RECEIPT(ABSP57) ; automatic receipt printing
  1. ; Possible reverse-then-resubmit
  1. I $P(^ABSPT(ABSBRXI,1),U,12)=1 D
  1. . N OLDSLOT,SLOT S OLDSLOT=$$GETSLOT^ABSPOSL
  1. . S SLOT=ABSBRXI D SETSLOT^ABSPOSL(SLOT)
  1. . D LOG^ABSPOSL($T(+0)_" Reverse then Resubmit attempt:")
  1. . ; reverse, then resubmit
  1. . N X S X=$$CATEG^ABSPOSUC(ABSBRXI)
  1. . ; it must be a successful reversal
  1. . I X'="E REVERSAL ACCEPTED",X'="PAPER REVERSAL" D
  1. . . D LOG^ABSPOSL($T(+0)_" Cannot - reversal failed - "_X)
  1. . E D
  1. . . S $P(^ABSPT(ABSBRXI,1),U,12)=0 ; clear the flag
  1. . . D LOG^ABSPOSL($T(+0)_" Now resubmit")
  1. . . D RESUB1^ABSPOS6D(ABSBRXI) ; resubmit it
  1. . . D TASK^ABSPOSIZ ; and start background processing
  1. . D RELSLOT^ABSPOSL
  1. . I OLDSLOT D SETSLOT^ABSPOSL(OLDSLOT)
  1. ; And at random times, winnow the log files
  1. I $R(10000)=0 D
  1. . N ZTRTN,ZTIO,ZTSAVE,ZTDTH
  1. . ; I $R(10)=0 winnow everything? INCOMPLETE - future
  1. . S ZTRTN="SILENT^ABSPOSK(1)"
  1. . S ZTIO="",ZTDTH=$$TADD^ABSPOSUD(DT,1)_".0222" ; tomorrow early a.m.
  1. . D ^%ZTLOAD
  1. Q
  1. ;
  1. NEW57(RXI) ;EP - copy this ^ABSPT(RXI) into ^ABSPTL(N)
  1. F L +^ABSPTL:300 Q:$T Q:'$$IMPOSS^ABSPOSUE("L","RTI","LOCK ^ABSPTL",,"NEW57",$T(+0))
  1. NEW57A N N S N=$P(^ABSPTL(0),U,3)+1
  1. N C S C=$P(^ABSPTL(0),U,4)+1
  1. S $P(^ABSPTL(0),U,3,4)=N_U_C
  1. I $D(^ABSPTL(N)) G NEW57A ; should never happen
  1. L -^ABSPTL
  1. M ^ABSPTL(N)=^ABSPT(RXI)
  1. ;
  1. ; Indexing - First, fileman indexing
  1. D
  1. . N DIK,DA S DIK="^ABSPTL(",DA=N N N D IX1^DIK
  1. ;
  1. ; The NON-FILEMAN index on RXI,RXR
  1. D
  1. . N INDEX,A,B,TYPE S TYPE=$E(RXI,$L(RXI))
  1. . I TYPE=1!(TYPE=2) D
  1. . . S A=$P(^ABSPTL(N,1),U,11)
  1. . . S B=$P(^ABSPTL(N,1),U)
  1. . . S INDEX=$S(TYPE=1:"RXIRXR",TYPE=2:"POSTAGE")
  1. . E I TYPE=3 D
  1. . . S A=$P(^ABSPTL(N,0),U,7)
  1. . . S B=$P(^ABSPTL(N,1),U,3) ; VCPT
  1. . . S B=$P(^ABSVCPT(9002301,B,0),U) ; CPT IEN
  1. . . S INDEX="OTHERS"
  1. . E D IMPOSS^ABSPOSUE("DB,P","TI","Bad TYPE="_TYPE,"in RXI="_RXI,"NEW57",$T(+0))
  1. . S ^ABSPTL("NON-FILEMAN",INDEX,A,B,N)=""
  1. Q N
  1. ; $$PREV57(point to 57) returns pointer to previous transaction
  1. ; for the same RXI,RXR - returns "" if no such
  1. PREV57(N57) ; EP -
  1. N RXI,RXR S RXI=$P(^ABSPTL(N57,1),U,11)
  1. S RXR=$P(^ABSPTL(N57,1),U)
  1. I RXI=""!(RXR="") Q ""
  1. Q $O(^ABSPTL("NON-FILEMAN","RXIRXR",RXI,RXR,N57),-1)
  1. ;
  1. ; SETCSTAT - set the status for every prescription associated with
  1. ; this claim
  1. ;
  1. SETCSTAT(CLAIM,STATUS) ;EP - ABSPOSAM
  1. N ABSBRXI
  1. I $$ISREVERS(CLAIM) D Q ; different for reversals
  1. .S ABSBRXI=$$RXI4REV(CLAIM) I ABSBRXI D SETSTAT(STATUS)
  1. S ABSBRXI=""
  1. F S ABSBRXI=$O(^ABSPT("AE",CLAIM,ABSBRXI)) Q:ABSBRXI="" D
  1. .D SETSTAT(STATUS)
  1. Q
  1. ISREVERS(CLAIM) ;EP - ABSPOSP2
  1. ; is this a reversal claim? $$ returns 1 or 0
  1. Q $P($G(^ABSPC(CLAIM,100)),"^",3)=11
  1. RXI4REV(REVCLAIM) ; given IEN of reversal claim $$this to get RXI
  1. ; The reversal claim must be associated with exactly one RXI.
  1. N RET,MBN ; MBN=Must Be Null
  1. S RET=$O(^ABSPT("AER",REVCLAIM,0)),MBN=$O(^(RET))
  1. ; Uncomment the next line when doing certification tests! (ABSPOSC*)
  1. ;Q RET
  1. I 'RET D IMPOSS^ABSPOSUE("DB,P","TI","REVCLAIM="_REVCLAIM_" and ""AER"" index",,"RXI4REV",$T(+0)) ; may not apply to certification testing!! SEE ABOVE.
  1. I MBN'="" D IMPOSS^ABSPOSUE("DB,P","TI","REVCLAIM="_REVCLAIM_" points back to multiple .59 entries",,"RXI4REV",$T(+0))
  1. Q RET
  1. ;
  1. ; SETCOMMS - for each prescription associated with this claim,
  1. ; point back to the log of the comms session wherein xmit/rcv happened
  1. ;
  1. SETCOMMS(CLAIM,POINTER) ;EP - ABSPOSAM
  1. N ABSBRXI S ABSBRXI=""
  1. F S ABSBRXI=$O(^ABSPT("AE",CLAIM,ABSBRXI)) Q:ABSBRXI="" D
  1. .S $P(^ABSPT(ABSBRXI,0),"^",12)=POINTER
  1. Q
  1. ;
  1. ; SETRESU - Set Result into ^ABSPT(ABSBRXI,2)
  1. ;
  1. ; NOTE !!! NOTE !!! NOTE !!! ABSBRXI must be set (not RXI) !!!
  1. ;
  1. SETRESU(RESULT,TEXT) ;EP - from many places
  1. S $P(^ABSPT(ABSBRXI,2),U)=RESULT
  1. I $G(TEXT)]"" D
  1. .N X,Y S X=^ABSPT(ABSBRXI,2)
  1. .S Y=$P(X,U),X=$P(X,U,2,$L(X,U))
  1. .I X="" S X=$E(TEXT,1,255-$L(Y)-1)
  1. .E S X=$E(TEXT_X,1,255-$L(Y)-1)
  1. .S ^ABSPT(ABSBRXI,2)=Y_U_X
  1. I RESULT=0 Q ; look at the associated RESPONSE in ^ABSPR(
  1. ;
  1. ; For other RESULT codes, put a textual explanation in
  1. Q
  1. ;
  1. ; SETCRESU - set the result code for every prescription assoc'd with
  1. ; this claim
  1. SETCRESU(CLAIM,RESULT,TEXT) ;
  1. N ABSBRXI S ABSBRXI=""
  1. F S ABSBRXI=$O(^ABSPT("AE",CLAIM,ABSBRXI)) Q:ABSBRXI="" D
  1. .D SETRESU(RESULT,$G(TEXT))
  1. Q
  1. ;
  1. ; STATI(X) gives a text version of what status code X means.
  1. ;
  1. STATI(X) ;EP - from many places ; perhaps should be a Fileman file
  1. I X=99 Q "Done"
  1. I X=50 Q "Waiting for transmit"
  1. I X=30 Q "Waiting for packet build"
  1. I X=0 Q "Waiting to start"
  1. I X=10 Q "Gathering claim info"
  1. I X=40 Q "Packet being built"
  1. I X=60 Q "Transmitting"
  1. I X=70 Q "Receiving response"
  1. I X=80 Q "Waiting to process response"
  1. I X=90 Q "Processing response"
  1. I X=51 Q "Wait for retry (comms error)"
  1. I X=31 Q "Wait for retry (insurer asleep)"
  1. I X=19 Q "Special grouping"
  1. ; When you add new X=, account for these in FETSTAT^ABSPOS2
  1. Q "?"_X_"?"
  1. ;
  1. ; RESULTI(X) gives a text version of what result code X means
  1. ;
  1. RESULTI(X) ;
  1. I X=0 Q "See detail in ABSP RESPONSES file" ; say more
  1. Q "Result code "_X ; a catch-all default
  1. ;
  1. RECEIPT(IEN57) ; This is where the receipt would go - taskman it to print in
  1. ; background, somewhere, somehow
  1. Q:'$$DORECEI
  1. ; Lookup printer for this pharmacy.
  1. ; If none, lookup printer for this system, in general.
  1. ; Also customizable: routine for each pharmacy, each system.
  1. ; Otherwise, a default-default routine for general receipt.
  1. ;
  1. ;S ZTIO=$P($G(^%ZIS(1,X,0)),U) Q:ZTIO=""
  1. ;S X="N",%DT="ST" D ^%DT S ZTDTH=Y
  1. ;S ZTRTN=""
  1. ;S ZTSAVE("ClaimIEN")=""
  1. ;D ^%ZTLOAD Q
  1. Q
  1. DORECEI() ; Should we print a receipt?
  1. ; Site-specific conditions needed.
  1. ; example: electronic claims only;
  1. ; only claims with co-pay;
  1. ; etc.
  1. Q 0