ABSPOSR1 ; IHS/FCS/DRS - silent claim submitter ;
;;1.0;PHARMACY POINT OF SALE;**48**;JUN 21, 2001;Build 38
; This routine monitors ^PSRX indexes. As it detects
; the release of prescriptions and sometimes cancellations, too,
; it silently submits claims and sometimes reversals, too.
; Only one of these may run at a time!
Q
STARTME ;EP - enter here to start the background job (by asking Taskman)
; option ABSP BACKGROUND SCAN START
W !
Q:'$$CHKTYPE(1)
N STATUS S STATUS=$$STATUS
W "The background scanner is now ",$$STATUS,!
I $$RUNNING W "The background scanner job is already running.",!
I STATUS["?" D
. W "But since the status is uncertain, let's stop and restart:",!
. D STOPME
D TASK^ABSPOSR1
W "Taskman will start the background scanner job.",!
Q
STOPME ;EP - enter here to stop the background job
; option ABSP BACKGROUND SCAN STOP
W !
Q:'$$CHKTYPE(1)
W "Stopping the background scanner job..."
D STOPIT(1)
W !
Q
MYSTATUS ;EP - enter here to inquire of background job's status
; option ABSP BACKGROUND SCAN STATUS
W !
Q:'$$CHKTYPE(1)
N X S X=$$STATUS
W "Status of POS background job: ",X,!
N DIC,DA,DR,DIQ
S DIC="^ABSP(9002313.99,",DA=1,DR=$T(+0) D EN^DIQ
Q
LOGFILE ;EP -
D LOGFILE1(.3) Q
LOGFILE1(OFFSET) ;EP - enter here to print background job's log file
; OFFSET = the .3 or .6 or whatever the "+" is for this type
W !,"Print "
I OFFSET=.3 W "background job's"
E I OFFSET=.6 W "back billing"
W " log file",!
I $$CHKTYPE(1) ; just report; don't roadblock with it
N ABSPDATE,PROMPT,DEFAULT
S PROMPT="Print log file for what date? ",DEFAULT=DT
S ABSPDATE=$$DATE^ABSPOSU1(PROMPT,DEFAULT,1,3010101,9999999,"EX")
Q:ABSPDATE<1
N POP D ^%ZIS Q:$G(POP)
N LOGFILE S LOGFILE=ABSPDATE+OFFSET
D PRINTLOG^ABSPOSL(ABSPDATE+OFFSET)
D PRESSANY^ABSPOSU5()
D ^%ZISC
Q
RUNNING() ;
N I,S F I=1:1:10 S S=$$STATUS Q:S="RUNNING" Q:S="STOPPED" H 5
Q S'="STOPPED" ; "REQUESTED STOP" comes back True, like RUNNING
CHKTYPE(ECHO) ; returns True if input type is the background polling job
; returns False if not
N XI S XI=$$GET1^DIQ(9002313.99,"1,",943,"I")
I XI=2 Q 1 ; yes, background scanner.
; not background scanner
I $G(ECHO) D
. W "The input method on this POS system is ",$$GET1^DIQ(9002313.99,"1,",943),!
. W "This program is only for use with the background scanner method.",!
Q 0
TASK ;EP -
N X,%DT,Y S X="N",%DT="ST" D ^%DT
D TASKAT(Y)
Q
TASKAT(ZTDTH) ;
N ZTRTN,ZTIO
S ZTRTN="EN^ABSPOSR1",ZTIO=""
D ^%ZTLOAD
Q
STATUS() ; external call to get the status
; returns "RUNNING" or "STOPPED" or "REQUESTED STOP"
; maybe with a "?"
N X S X=$$GETFIELD(120.03) S:X="" X=2
; make sure the lock status is consistent with the numerical status
N Y S Y=$$LOCK I Y D UNLOCK
I X=0 Q "RUNNING"_$S(Y:"?",1:"")
I X=1 Q "REQUESTED STOP"_$S(Y:"?",1:"")
I X=2 Q "STOPPED"_$S(Y:"",1:"?")
Q "?"
STOPIT(ECHO,NOWAIT) ;EP - external call to request that it stop
; and wait until it is stopped
; May DO or $$; $$ returns value of stop flag (2 = success)
I $$GETFIELD(120.03)=2 Q ; already stopped
D SETFIELD(120.03,1) ; set the "stop requested" flag
I '$G(NOWAIT) D
. F Q:$$GETFIELD(120.03)=2 D H 5
. . I $G(ECHO) W "." W:$X>74 !
. . ; Handle the case where the job was killed:
. . ; Run flag says its running but the lock says it's not
. . ; So force run flag to say "stopped".
. . I $$STATUS="REQUESTED STOP?" D SETFIELD(120.03,2)
Q:$Q $$GETFIELD(120.03) Q
DELAYSTP(N) H N D STOPIT() Q ; J TEST^ABSPOSR1 for your testing
;
; Advice for testing:
; 0. Init ^ABSP(9002313.99,"ABSPOSR1")=a starting T1 time
; Just do this once, ever.
;
; Then for each time you do testing:
; 1. DO NEXT^ABSPOSR1(N) ; N = desired number of transactions
; and it sets T1,T2 so you get N transactions
; 2. D TEST^ABSPOSR1 to actually run the test.
; When done, it will update ^ABSP(9002313.99,"ABSPOSR1")
; to be 1 second past the previous T2 that you used.
; 3. DO ^ABSPOS (which goes to EN^ABSPOS6A) to watch the results.
; 4. D LASTLOG^ABSPOSR1 to examine the .3 log and see what's going on
TEST W !,"Running the test - times ",T1,"-",T2,!
I '$$LOCK W "Can't get LOCK",! Q
D INIT^ABSPOSL(.3,1)
D DEFAULTS
D KTESTLST
D WORKLIST^ABSPOSR3(T1,T2,$$TESTLIST)
D PROCESS^ABSPOSR3($$TESTLIST)
D LASTLOG
D UNLOCK
S $P(^ABSP(9002313.99,"ABSPOSR1"),U)=$$TADD^ABSPOSUD(T2,.000001)
Q
KTESTLST K ^ABSPECP($T(+0)_" TESTING") Q
TESTLIST() Q "^ABSPECP("""_$T(+0)_" TESTING"")"
LASTLOG ; tool for test - find and print most recent log file
N X S X=2990000
F S X=$O(^ABSPECP("LOG",X),-1) Q:'X Q:X#1=.3
I 'X W "No log file found",! Q
D PRINTLOG^ABSPOSL(X)
Q
EN ; EP - via Taskman as initiated by START, above
; main program for background job to stealthily submit claims
; changes to EN should be mimicked in TEST(), above
I '$$LOCK Q
N RESTART
D SETFIELD(120.01,$J),SETFIELD(120.03,0)
D INIT^ABSPOSL(DT+.3,1)
D LOG("Background claim submitter running as job "_$J)
D DEFAULTS
D MONITOR^ABSPOSR3 ; may set RESTART
D LOG("Background claim submitter job "_$J_" completed.")
D RELSLOT^ABSPOSL
D UNLOCK
I $G(RESTART) D TASK
Q
DEFAULTS ;EP -
I '$$GETFIELD(120.02) D SETFIELD(120.02,"NOW","E") ; last time proc'd
I '$$GETFIELD(120.04) D SETFIELD(120.04,30) ; default interval 30 sec
; 30 secs is the minimum! you have to allow time for ABSPOSRX
; to get background jobs started, to create .59 entries, etc.
I '$$GETFIELD(120.05) D SETFIELD(120.05,30) ; reach back more sec
; but you miss something if they enter it now with a release time
; of an hour ago, or yesterday
I $$GETFIELD(120.06)="" D SETFIELD(120.06,"AL") ; index for new claims
I $$GETFIELD(120.07)="" D SETFIELD(120.07,"AJ") ; index for canceled
Q
SETFIELD(FIELD,VALUE,FLAGS) ;EP -
N FDA,IENS,MSG,FN S IENS="1,",FN=9002313.99
S FDA(FN,IENS,FIELD)=VALUE
SF1 D FILE^DIE($G(FLAGS),"FDA","MSG")
I $D(MSG) D LOG^ABSPOSL2("SF1^ABSPOSR1",.MSG) ; /IHS/OIT/RAM ; 12 JUN 17 ; AND LOG IT IF AN ERROR OCCURS.
Q:'$D(MSG) ; success
D ZWRITE^ABSPOS("FLAGS","FDA","MSG","FIELD","VALUE")
G SF1:$$IMPOSS^ABSPOSUE("FM","TRI","FILE^DIE failed",,"SETFIELD",$T(+0))
Q
GETFIELD(FIELD) ;EP -
Q $P($G(^ABSP(9002313.99,1,"ABSPOSR1")),U,FIELD-120*100)
LOCK() L +^ABSP(9002313.99,"ABSPOSR1"):0 Q $T
UNLOCK L -^ABSP(9002313.99,"ABSPOSR1") Q
LOG(X) D LOG^ABSPOSL(X) Q
ABSPOSR1 ; IHS/FCS/DRS - silent claim submitter ;
+1 ;;1.0;PHARMACY POINT OF SALE;**48**;JUN 21, 2001;Build 38
+2 ; This routine monitors ^PSRX indexes. As it detects
+3 ; the release of prescriptions and sometimes cancellations, too,
+4 ; it silently submits claims and sometimes reversals, too.
+5 ; Only one of these may run at a time!
+6 QUIT
STARTME ;EP - enter here to start the background job (by asking Taskman)
+1 ; option ABSP BACKGROUND SCAN START
+2 WRITE !
+3 IF '$$CHKTYPE(1)
QUIT
+4 NEW STATUS
SET STATUS=$$STATUS
+5 WRITE "The background scanner is now ",$$STATUS,!
+6 IF $$RUNNING
WRITE "The background scanner job is already running.",!
+7 IF STATUS["?"
Begin DoDot:1
+8 WRITE "But since the status is uncertain, let's stop and restart:",!
+9 DO STOPME
End DoDot:1
+10 DO TASK^ABSPOSR1
+11 WRITE "Taskman will start the background scanner job.",!
+12 QUIT
STOPME ;EP - enter here to stop the background job
+1 ; option ABSP BACKGROUND SCAN STOP
+2 WRITE !
+3 IF '$$CHKTYPE(1)
QUIT
+4 WRITE "Stopping the background scanner job..."
+5 DO STOPIT(1)
+6 WRITE !
+7 QUIT
MYSTATUS ;EP - enter here to inquire of background job's status
+1 ; option ABSP BACKGROUND SCAN STATUS
+2 WRITE !
+3 IF '$$CHKTYPE(1)
QUIT
+4 NEW X
SET X=$$STATUS
+5 WRITE "Status of POS background job: ",X,!
+6 NEW DIC,DA,DR,DIQ
+7 SET DIC="^ABSP(9002313.99,"
SET DA=1
SET DR=$TEXT(+0)
DO EN^DIQ
+8 QUIT
LOGFILE ;EP -
+1 DO LOGFILE1(.3)
QUIT
LOGFILE1(OFFSET) ;EP - enter here to print background job's log file
+1 ; OFFSET = the .3 or .6 or whatever the "+" is for this type
+2 WRITE !,"Print "
+3 IF OFFSET=.3
WRITE "background job's"
+4 IF '$TEST
IF OFFSET=.6
WRITE "back billing"
+5 WRITE " log file",!
+6 ; just report; don't roadblock with it
IF $$CHKTYPE(1)
+7 NEW ABSPDATE,PROMPT,DEFAULT
+8 SET PROMPT="Print log file for what date? "
SET DEFAULT=DT
+9 SET ABSPDATE=$$DATE^ABSPOSU1(PROMPT,DEFAULT,1,3010101,9999999,"EX")
+10 IF ABSPDATE<1
QUIT
+11 NEW POP
DO ^%ZIS
IF $GET(POP)
QUIT
+12 NEW LOGFILE
SET LOGFILE=ABSPDATE+OFFSET
+13 DO PRINTLOG^ABSPOSL(ABSPDATE+OFFSET)
+14 DO PRESSANY^ABSPOSU5()
+15 DO ^%ZISC
+16 QUIT
RUNNING() ;
+1 NEW I,S
FOR I=1:1:10
SET S=$$STATUS
IF S="RUNNING"
QUIT
IF S="STOPPED"
QUIT
HANG 5
+2 ; "REQUESTED STOP" comes back True, like RUNNING
QUIT S'="STOPPED"
CHKTYPE(ECHO) ; returns True if input type is the background polling job
+1 ; returns False if not
+2 NEW XI
SET XI=$$GET1^DIQ(9002313.99,"1,",943,"I")
+3 ; yes, background scanner.
IF XI=2
QUIT 1
+4 ; not background scanner
+5 IF $GET(ECHO)
Begin DoDot:1
+6 WRITE "The input method on this POS system is ",$$GET1^DIQ(9002313.99,"1,",943),!
+7 WRITE "This program is only for use with the background scanner method.",!
End DoDot:1
+8 QUIT 0
TASK ;EP -
+1 NEW X,%DT,Y
SET X="N"
SET %DT="ST"
DO ^%DT
+2 DO TASKAT(Y)
+3 QUIT
TASKAT(ZTDTH) ;
+1 NEW ZTRTN,ZTIO
+2 SET ZTRTN="EN^ABSPOSR1"
SET ZTIO=""
+3 DO ^%ZTLOAD
+4 QUIT
STATUS() ; external call to get the status
+1 ; returns "RUNNING" or "STOPPED" or "REQUESTED STOP"
+2 ; maybe with a "?"
+3 NEW X
SET X=$$GETFIELD(120.03)
IF X=""
SET X=2
+4 ; make sure the lock status is consistent with the numerical status
+5 NEW Y
SET Y=$$LOCK
IF Y
DO UNLOCK
+6 IF X=0
QUIT "RUNNING"_$SELECT(Y:"?",1:"")
+7 IF X=1
QUIT "REQUESTED STOP"_$SELECT(Y:"?",1:"")
+8 IF X=2
QUIT "STOPPED"_$SELECT(Y:"",1:"?")
+9 QUIT "?"
STOPIT(ECHO,NOWAIT) ;EP - external call to request that it stop
+1 ; and wait until it is stopped
+2 ; May DO or $$; $$ returns value of stop flag (2 = success)
+3 ; already stopped
IF $$GETFIELD(120.03)=2
QUIT
+4 ; set the "stop requested" flag
DO SETFIELD(120.03,1)
+5 IF '$GET(NOWAIT)
Begin DoDot:1
+6 FOR
IF $$GETFIELD(120.03)=2
QUIT
Begin DoDot:2
+7 IF $GET(ECHO)
WRITE "."
IF $X>74
WRITE !
+8 ; Handle the case where the job was killed:
+9 ; Run flag says its running but the lock says it's not
+10 ; So force run flag to say "stopped".
+11 IF $$STATUS="REQUESTED STOP?"
DO SETFIELD(120.03,2)
End DoDot:2
HANG 5
End DoDot:1
+12 IF $QUIT
QUIT $$GETFIELD(120.03)
QUIT
DELAYSTP(N) ; J TEST^ABSPOSR1 for your testing
HANG N
DO STOPIT()
QUIT
+1 ;
+2 ; Advice for testing:
+3 ; 0. Init ^ABSP(9002313.99,"ABSPOSR1")=a starting T1 time
+4 ; Just do this once, ever.
+5 ;
+6 ; Then for each time you do testing:
+7 ; 1. DO NEXT^ABSPOSR1(N) ; N = desired number of transactions
+8 ; and it sets T1,T2 so you get N transactions
+9 ; 2. D TEST^ABSPOSR1 to actually run the test.
+10 ; When done, it will update ^ABSP(9002313.99,"ABSPOSR1")
+11 ; to be 1 second past the previous T2 that you used.
+12 ; 3. DO ^ABSPOS (which goes to EN^ABSPOS6A) to watch the results.
+13 ; 4. D LASTLOG^ABSPOSR1 to examine the .3 log and see what's going on
TEST WRITE !,"Running the test - times ",T1,"-",T2,!
+1 IF '$$LOCK
WRITE "Can't get LOCK",!
QUIT
+2 DO INIT^ABSPOSL(.3,1)
+3 DO DEFAULTS
+4 DO KTESTLST
+5 DO WORKLIST^ABSPOSR3(T1,T2,$$TESTLIST)
+6 DO PROCESS^ABSPOSR3($$TESTLIST)
+7 DO LASTLOG
+8 DO UNLOCK
+9 SET $PIECE(^ABSP(9002313.99,"ABSPOSR1"),U)=$$TADD^ABSPOSUD(T2,.000001)
+10 QUIT
KTESTLST KILL ^ABSPECP($TEXT(+0)_" TESTING")
QUIT
TESTLIST() QUIT "^ABSPECP("""_$TEXT(+0)_" TESTING"")"
LASTLOG ; tool for test - find and print most recent log file
+1 NEW X
SET X=2990000
+2 FOR
SET X=$ORDER(^ABSPECP("LOG",X),-1)
IF 'X
QUIT
IF X#1=.3
QUIT
+3 IF 'X
WRITE "No log file found",!
QUIT
+4 DO PRINTLOG^ABSPOSL(X)
+5 QUIT
EN ; EP - via Taskman as initiated by START, above
+1 ; main program for background job to stealthily submit claims
+2 ; changes to EN should be mimicked in TEST(), above
+3 IF '$$LOCK
QUIT
+4 NEW RESTART
+5 DO SETFIELD(120.01,$JOB)
DO SETFIELD(120.03,0)
+6 DO INIT^ABSPOSL(DT+.3,1)
+7 DO LOG("Background claim submitter running as job "_$JOB)
+8 DO DEFAULTS
+9 ; may set RESTART
DO MONITOR^ABSPOSR3
+10 DO LOG("Background claim submitter job "_$JOB_" completed.")
+11 DO RELSLOT^ABSPOSL
+12 DO UNLOCK
+13 IF $GET(RESTART)
DO TASK
+14 QUIT
DEFAULTS ;EP -
+1 ; last time proc'd
IF '$$GETFIELD(120.02)
DO SETFIELD(120.02,"NOW","E")
+2 ; default interval 30 sec
IF '$$GETFIELD(120.04)
DO SETFIELD(120.04,30)
+3 ; 30 secs is the minimum! you have to allow time for ABSPOSRX
+4 ; to get background jobs started, to create .59 entries, etc.
+5 ; reach back more sec
IF '$$GETFIELD(120.05)
DO SETFIELD(120.05,30)
+6 ; but you miss something if they enter it now with a release time
+7 ; of an hour ago, or yesterday
+8 ; index for new claims
IF $$GETFIELD(120.06)=""
DO SETFIELD(120.06,"AL")
+9 ; index for canceled
IF $$GETFIELD(120.07)=""
DO SETFIELD(120.07,"AJ")
+10 QUIT
SETFIELD(FIELD,VALUE,FLAGS) ;EP -
+1 NEW FDA,IENS,MSG,FN
SET IENS="1,"
SET FN=9002313.99
+2 SET FDA(FN,IENS,FIELD)=VALUE
SF1 DO FILE^DIE($GET(FLAGS),"FDA","MSG")
+1 ; /IHS/OIT/RAM ; 12 JUN 17 ; AND LOG IT IF AN ERROR OCCURS.
IF $DATA(MSG)
DO LOG^ABSPOSL2("SF1^ABSPOSR1",.MSG)
+2 ; success
IF '$DATA(MSG)
QUIT
+3 DO ZWRITE^ABSPOS("FLAGS","FDA","MSG","FIELD","VALUE")
+4 IF $$IMPOSS^ABSPOSUE("FM","TRI","FILE^DIE failed",,"SETFIELD",$TEXT(+0))
GOTO SF1
+5 QUIT
GETFIELD(FIELD) ;EP -
+1 QUIT $PIECE($GET(^ABSP(9002313.99,1,"ABSPOSR1")),U,FIELD-120*100)
LOCK() LOCK +^ABSP(9002313.99,"ABSPOSR1"):0
QUIT $TEST
UNLOCK LOCK -^ABSP(9002313.99,"ABSPOSR1")
QUIT
LOG(X) DO LOG^ABSPOSL(X)
QUIT