- ABSPOSAM ; IHS/FCS/DRS - JWS ; [ 06/10/2002 7:19 AM ]
- ;;1.0;PHARMACY POINT OF SALE;**2**;JUN 21, 2001;Build 38
- ;
- ; ABSPOSAM is the main program for send/receive communications
- ; with the Envoy or NDC switches. Or certain insurance company
- ; systems, such as the PCS test system.
- ;
- ; Sets up these variables:
- ; ABSPECT2 = count of successful xmit/recv transactions
- ; (without regard to rejected claims, merely that the
- ; xmit/recv sequence completed with apparent success)
- ;
- ; Subroutines are in ABSPOSAN, ABSPOSAO, ABSPOSAP, ABSPOSAQ
- ;
- ; Future: List of claims to be sent is handled by an index in
- ; file 9002313.02; list of responses to be processed is handled by
- ; an index in file 9002313.03. Make sure Fileman Database Server
- ; calls really do handle the locking you need.
- ;
- ; IHS/SD/lwj 06/10/02 change made to the S12 subroutine - checking
- ; of the value in IO changed from a numeric assumption to an
- ; alpha/numeric check. This was done as a result of the Cache changes.
- ; For Cache, the device is now an alpha/numeric value as opposed to the
- ; numerice value (56) used in MSM.
- ;
- ;
- Q
- SEND(DIALOUT) ;EP - from ABSPOSQ3
- S ABSPECT2=0
- ;
- N CLAIMNXT,I,RESPLRC,RESPMSG
- N HMSG,LRCOK,SENDMSG,SENDMSGP,GETMSG,CLAIMIEN,LRC,RET
- N TRANSBEG,TRANSEND,TRANSTIM ; transaction begin,end,time
- N SEG S SEG=245 ; length of string segments storing long string in gbl
- ;
- N ACK,ENQ,EOT,ETX,NAK,STX,ETB
- S ACK=$C(6),ENQ=$C(5),EOT=$C(4),ETX=$C(3)
- S NAK=$C(21),STX=$C(2),ETB=$C(23)
- ;
- S12 ;
- ;IHS/SD/lwj 06/10/02 nxt line remarkd out- following line added
- ; this change was done as a result of the Cache changes - IO will no
- ; longer just be a number (56) - for Cache, it will be a "|TCP|"
- ; coupled with the port number
- ;
- ;N IO S IO=$$IO^ABSPOSA(DIALOUT) I 'IO G S12:$$IMPOSS^ABSPOSUE("DB","TRI","IO field missing in DIALOUT="_DIALOUT,,"S12",$T(+0))
- N IO S IO=$$IO^ABSPOSA(DIALOUT) I IO="" G S12:$$IMPOSS^ABSPOSUE("DB","TRI","IO field missing in DIALOUT="_DIALOUT,,"S12",$T(+0))
- ; IHS/SD/lwj 06/10/02 - end of Cache changes
- ;
- N T1LINE S T1LINE=$$T1DIRECT^ABSPOSA(DIALOUT)
- ;
- I $$SHUTDOWN Q 0
- I '$$GETNEXT^ABSPOSAP Q 0
- ; Dial the phone and connect to Envoy
- S RET=$$CONNECT^ABSPOSAQ(DIALOUT)
- I RET D PUTBACK^ABSPOSAP Q RET ; error? put back claim before quitting
- ;
- START ;Main message loop ; we have SENDMSG and SENDMSGP and CLAIMIEN
- ; If anything goes wrong, be sure to DO PUTBACK before quitting!
- ;
- D CLAIMBEG ; write to our own log file - beginning for this claim
- D SETCOMMS^ABSPOSU(CLAIMIEN,$$GETPLACE^ABSPOSL) ; mark start in .59
- ;
- LOOP0 ; Wait for host to send ENQ
- ;
- I 'T1LINE D I RET Q RET
- . S RET=$$INITIATE^ABSPOSAO I RET D ; wait for host to send ENQ
- . . D PUTBACK^ABSPOSAP,CLAIMEND ; and if you didn't get it...
- ;
- ;Send message to host: STX, message, ETX, LRC
- ;
- D SETCSTAT^ABSPOSU(CLAIMIEN,60) ; set prescrs' status = "Transmitting"
- LOOP1A D LOG("2 - Sending message #"_CLAIMIEN)
- ; NDC and test mode, "HN." instead of "HN*" ? Ancient code.
- ; I don't know if it makes a shred of difference
- I $E(SENDMSG,1,3)="HN." D
- . D LOG("2 - Sending message in TEST mode")
- S TRANSBEG=$P($H,",",2) ; beginning time (for timing transaction)
- D SENDREQ^ABSPOSAS(DIALOUT,.SENDMSG)
- D ; stats - figure out which piece the transaction code increments
- .N % S %=$P($G(^ABSPC(CLAIMIEN,100)),U,3)
- .S %=$S(%>0&(%<5):%,%=11:5,1:19)
- .D ADDSTAT^ABSPOSUD("C",2,1,"C",3,$L(SENDMSG)+3,"C",%,1)
- ;
- ;Wait for response from host
- ; Envoy sends an ACK at this point.
- ; Apparently NDC does not? Or maybe NDC sends ACK then STX
- ; Also: make the timeout 60 seconds. "The Envoy host typically allows
- ; an end processor up to 55 seconds to respond."
- ;
- LOOP1B I T1LINE S HMSG="ACK" G LOOP1C
- D LOG("2 - Waiting for ACK or NAK")
- S HMSG=$$WAITCHAR(ACK_NAK_STX_ENQ,60)
- I HMSG="ACK" D
- . ; we got what we expected; do nothing else here
- E I HMSG="STX" D
- . D LOG("2 - Missing ACK but got STX; must be start of response?")
- E I HMSG="NAK" D G LOOP1A
- . D LOG("2 - Host sent NAK - we will resend")
- E I HMSG="ENQ" D G LOOP1A ; Envoy 4.1, p. 12
- . D LOG("2 - Host sent another ENQ - we will resend")
- E D Q RET
- . D LOG("2 - But received "_HMSG_" instead.")
- . D PUTBACK^ABSPOSAP,CLAIMEND ; put message back for later transmission
- . I HMSG'="+++" D HANGUP
- . S RET=$S(HMSG="+++":31101,HMSG="":31102,1:31103)
- ;
- ; The response message is preceded by STX
- ; If we just got an ACK, then wait for the STX
- ;
- LOOP1C I HMSG="ACK" D
- . I T1LINE S HMSG="STX" Q
- . S HMSG=$$WAITCHAR(STX,60)
- . D LOG("2 - "_HMSG_" received from host")
- E I HMSG="STX" D
- . ; do nothing; fall through with STX still here
- E D Q 30239
- . D LOG("Internal error at LOOP1C")
- ;
- I HMSG="STX" D
- . ; nothing, got what we expected
- E D Q RET
- . D LOG("2 - Expected STX but got "_HMSG_" instead")
- . D PUTBACK^ABSPOSAP,CLAIMEND
- . S RET=$S(HMSG="+++":30251,HMSG="":30252,1:30253)
- ;I HMSG'="STX" D INCSTAT^ABSPOSUD("CR",$S(HMSG="ENQ":2,HMSG="NAK":3,HMSG="+++":4,HMSG="":5,1:9))
- ;
- ; The host sends us the response message
- ;
- LOOP3 S (GETMSG,LRC)=""
- D SETCSTAT^ABSPOSU(CLAIMIEN,70) ; status = "Receiving response"
- D LOG("3 - Gathering response from host")
- S HMSG=$$GETMSG^ABSPOSAR(DIALOUT,.RESPMSG,.RESPLRC,60)
- ;
- ; HMSG="ETX" or "EOT" or "" (if timed out)
- ;
- I HMSG="ETX" D
- . D LOG("3 - Received "_$L(RESPMSG)_" bytes; LRC "_$A(RESPLRC))
- . D ADDSTAT^ABSPOSUD("C",4,1,"C",5,$L(RESPMSG)+3)
- E D Q RET
- . D INCSTAT^ABSPOSUD("CR2",1,"CR2",$S(HMSG="EOT":2,HMSG="":3,HMSG="+++":4,1:9))
- . D LOG("3 - Error while gathering response: HMSG="_HMSG)
- . D PUTBACK^ABSPOSAP
- . D CLAIMEND
- . I HMSG'="+++" D HANGUP
- . S RET=$S(HMSG="+++":30261,HMSG="":30262,1:30263)
- ;
- ; Test LRC character. If we agree, we send ACK. If not, we NAK.
- ; And if we send ACK, get the next message to send, if any.
- ;
- I T1LINE S LRCOK=1 ; G PASTLRC ; if T1 connection, LRC is n/a
- E I $L(RESPMSG)<9 S LRCOK=0 ; we have seen 1-byte response msg!
- E S LRCOK=$$TESTLRC^ABSPOSAD(RESPMSG,RESPLRC)
- ;
- S CLAIMNXT=0 ; assume no claims to send after this one
- I LRCOK D
- . N CLAIMIEN ; protect CLAIMIEN - $$GETNEXT will reset it
- . I '$$SHUTDOWN S CLAIMNXT=$$GETNEXT^ABSPOSAP ; remember next CLAIMIEN
- . I CLAIMNXT,$P($G(^ABSP(9002313.55,DIALOUT,"PROTOCOL")),U) D
- . . Q:T1LINE
- . . D LOG("6 - Send ETB to host")
- . . D SENDETB^ABSPOSAS(DIALOUT)
- . E D
- . . Q:T1LINE
- . . D LOG("6 - Send ACK to host")
- . . D SENDACK^ABSPOSAS(DIALOUT)
- . S ABSPECT2=ABSPECT2+1 ; count our successes (and blessings)
- . ;
- . ; ABSPOSQ3 will start up processing of responses
- . ; But here, if we have heavy volume, we need to get it going
- . ; right now, every so often.
- . ;
- . I ABSPECT2>10,ABSPECT2#5=0 D TASK^ABSPOSQ3()
- E D
- . D LOG("6 - Send NAK to host because of LRC disagreement")
- . D SENDNAK^ABSPOSAS(DIALOUT)
- ;
- PASTLRC ;
- S TRANSEND=$P($H,",",2) ; timing - when transaction completed
- S TRANSTIM=TRANSEND-TRANSBEG S:TRANSTIM<0 TRANSTIM=TRANSTIM+86400
- ; Statistics: Comms - Transaction Time Comms
- ; Comms - Send ACK Comms - Send NAK
- D ADDSTAT^ABSPOSUD("CT",1,TRANSTIM,"C",7+'LRCOK,1)
- ;
- I 'LRCOK D G LOOP1C
- . S HMSG="ACK" ; fake it out so it drops into the WAITCHAR(STX) code
- ;
- D CLAIMEND
- ;
- ; At this happy point, we have received a response and ACK'ed it.
- ; NOTE!! SENDMSG is the _next_ message to send, not the one just sent!
- ;
- ;File response message in temporary global
- ;
- LR L +^ABSPECX("POS",DIALOUT,"R",CLAIMIEN):300 ; lock the response
- I '$T G LR:$$IMPOSS^ABSPOSUE("L","RIT","LOCK response",,"LR",$T(+0))
- K ^ABSPECX("POS",DIALOUT,"R",CLAIMIEN) ; kill anything that's there
- F I=1:SEG:$L(RESPMSG) D
- .S ^ABSPECX("POS",DIALOUT,"R",CLAIMIEN,I\SEG+1)=$E(RESPMSG,I,I+SEG-1)
- .S ^ABSPECX("POS",DIALOUT,"R",CLAIMIEN,0)=I\SEG+1
- L -^ABSPECX("POS",DIALOUT,"R",CLAIMIEN) ; unlock the response
- D SETCSTAT^ABSPOSU(CLAIMIEN,80) ; Waiting to process response.
- ;
- ; Now we're ready to go again.
- I CLAIMNXT S CLAIMIEN=CLAIMNXT G START
- ;
- ; No more to send.
- ; We expect EOT from Envoy. NDC might send ENQ here?
- I T1LINE Q 0
- S HMSG=$$WAITCHAR(EOT_ENQ,3)
- I HMSG'="+++",HMSG'="ENQ" D
- . D LOG("9 - No more to send; expect EOT, got "_HMSG)
- I HMSG'="+++" D HANGUP
- Q 0
- ; ----- end of main part of routine -----
- ;
- LOG(X) D LOG^ABSPOSL($T(+0)_" - "_X) Q
- ;
- ; READCHAR not used? READCHAR(TIMEOUT) N X U IO R *X:TIMEOUT Q X
- ;
- ; WAITCHAR: Envoy 4.1, page 16
- ; If during one of the wait stages of the transmission, the
- ; pharmacy system should receive unexpected characters, they should
- ; be ignored unless they are transmitted as a part of the response
- ; (beginning with the STX and concluding with the ETX). At that
- ; point, they should be considered a part of a message. The ENVOY
- ; system will react in the same manner after returning a response.
- ; After the issuance of the ENQ, however, if the host receives
- ; unexpected characters without receiving the STX and/or the ETX,
- ; it will issue an EOT.
- ;
- ; In plain English: WAITCHAR^ABSPOSAW ignores unexpected characters.
- ; Except for EOT - it catches that, as well as the watched-for
- ; characters.
- ;
- WAITCHAR(CHARS,TIMEOUT) ;EP -
- N RET S RET=$$WAITCHAR^ABSPOSAW(DIALOUT,CHARS,TIMEOUT)
- I RET="+++" D LOG("WAITCHAR tells us that modem is disconnected.")
- Q RET
- ;
- SHUTDOWN() N RET S RET=$$SHUTDOWN^ABSPOSQ3
- I RET D LOG("The transmit/receive shutdown flag is set.")
- Q RET
- HANGUP D HANGUP^ABSPOSAB(DIALOUT) Q
- ; NOTE!!! Print of log for one claim depends on finding
- ; the exact texts shown below!
- CLAIMBEG D LOG("CLAIM - BEGIN - #"_CLAIMIEN_$$CLAIM01) Q
- CLAIMEND D LOG("CLAIM - END - #"_CLAIMIEN_$$CLAIM01) Q
- CLAIM01() Q " ("_$P(^ABSPC(CLAIMIEN,0),U)_")"
- ABSPOSAM ; IHS/FCS/DRS - JWS ; [ 06/10/2002 7:19 AM ]
- +1 ;;1.0;PHARMACY POINT OF SALE;**2**;JUN 21, 2001;Build 38
- +2 ;
- +3 ; ABSPOSAM is the main program for send/receive communications
- +4 ; with the Envoy or NDC switches. Or certain insurance company
- +5 ; systems, such as the PCS test system.
- +6 ;
- +7 ; Sets up these variables:
- +8 ; ABSPECT2 = count of successful xmit/recv transactions
- +9 ; (without regard to rejected claims, merely that the
- +10 ; xmit/recv sequence completed with apparent success)
- +11 ;
- +12 ; Subroutines are in ABSPOSAN, ABSPOSAO, ABSPOSAP, ABSPOSAQ
- +13 ;
- +14 ; Future: List of claims to be sent is handled by an index in
- +15 ; file 9002313.02; list of responses to be processed is handled by
- +16 ; an index in file 9002313.03. Make sure Fileman Database Server
- +17 ; calls really do handle the locking you need.
- +18 ;
- +19 ; IHS/SD/lwj 06/10/02 change made to the S12 subroutine - checking
- +20 ; of the value in IO changed from a numeric assumption to an
- +21 ; alpha/numeric check. This was done as a result of the Cache changes.
- +22 ; For Cache, the device is now an alpha/numeric value as opposed to the
- +23 ; numerice value (56) used in MSM.
- +24 ;
- +25 ;
- +26 QUIT
- SEND(DIALOUT) ;EP - from ABSPOSQ3
- +1 SET ABSPECT2=0
- +2 ;
- +3 NEW CLAIMNXT,I,RESPLRC,RESPMSG
- +4 NEW HMSG,LRCOK,SENDMSG,SENDMSGP,GETMSG,CLAIMIEN,LRC,RET
- +5 ; transaction begin,end,time
- NEW TRANSBEG,TRANSEND,TRANSTIM
- +6 ; length of string segments storing long string in gbl
- NEW SEG
- SET SEG=245
- +7 ;
- +8 NEW ACK,ENQ,EOT,ETX,NAK,STX,ETB
- +9 SET ACK=$CHAR(6)
- SET ENQ=$CHAR(5)
- SET EOT=$CHAR(4)
- SET ETX=$CHAR(3)
- +10 SET NAK=$CHAR(21)
- SET STX=$CHAR(2)
- SET ETB=$CHAR(23)
- +11 ;
- S12 ;
- +1 ;IHS/SD/lwj 06/10/02 nxt line remarkd out- following line added
- +2 ; this change was done as a result of the Cache changes - IO will no
- +3 ; longer just be a number (56) - for Cache, it will be a "|TCP|"
- +4 ; coupled with the port number
- +5 ;
- +6 ;N IO S IO=$$IO^ABSPOSA(DIALOUT) I 'IO G S12:$$IMPOSS^ABSPOSUE("DB","TRI","IO field missing in DIALOUT="_DIALOUT,,"S12",$T(+0))
- +7 NEW IO
- SET IO=$$IO^ABSPOSA(DIALOUT)
- IF IO=""
- IF $$IMPOSS^ABSPOSUE("DB","TRI","IO field missing in DIALOUT="_DIALOUT,,"S12",$TEXT(+0))
- GOTO S12
- +8 ; IHS/SD/lwj 06/10/02 - end of Cache changes
- +9 ;
- +10 NEW T1LINE
- SET T1LINE=$$T1DIRECT^ABSPOSA(DIALOUT)
- +11 ;
- +12 IF $$SHUTDOWN
- QUIT 0
- +13 IF '$$GETNEXT^ABSPOSAP
- QUIT 0
- +14 ; Dial the phone and connect to Envoy
- +15 SET RET=$$CONNECT^ABSPOSAQ(DIALOUT)
- +16 ; error? put back claim before quitting
- IF RET
- DO PUTBACK^ABSPOSAP
- QUIT RET
- +17 ;
- START ;Main message loop ; we have SENDMSG and SENDMSGP and CLAIMIEN
- +1 ; If anything goes wrong, be sure to DO PUTBACK before quitting!
- +2 ;
- +3 ; write to our own log file - beginning for this claim
- DO CLAIMBEG
- +4 ; mark start in .59
- DO SETCOMMS^ABSPOSU(CLAIMIEN,$$GETPLACE^ABSPOSL)
- +5 ;
- LOOP0 ; Wait for host to send ENQ
- +1 ;
- +2 IF 'T1LINE
- Begin DoDot:1
- +3 ; wait for host to send ENQ
- SET RET=$$INITIATE^ABSPOSAO
- IF RET
- Begin DoDot:2
- +4 ; and if you didn't get it...
- DO PUTBACK^ABSPOSAP
- DO CLAIMEND
- End DoDot:2
- End DoDot:1
- IF RET
- QUIT RET
- +5 ;
- +6 ;Send message to host: STX, message, ETX, LRC
- +7 ;
- +8 ; set prescrs' status = "Transmitting"
- DO SETCSTAT^ABSPOSU(CLAIMIEN,60)
- LOOP1A DO LOG("2 - Sending message #"_CLAIMIEN)
- +1 ; NDC and test mode, "HN." instead of "HN*" ? Ancient code.
- +2 ; I don't know if it makes a shred of difference
- +3 IF $EXTRACT(SENDMSG,1,3)="HN."
- Begin DoDot:1
- +4 DO LOG("2 - Sending message in TEST mode")
- End DoDot:1
- +5 ; beginning time (for timing transaction)
- SET TRANSBEG=$PIECE($HOROLOG,",",2)
- +6 DO SENDREQ^ABSPOSAS(DIALOUT,.SENDMSG)
- +7 ; stats - figure out which piece the transaction code increments
- Begin DoDot:1
- +8 NEW %
- SET %=$PIECE($GET(^ABSPC(CLAIMIEN,100)),U,3)
- +9 SET %=$SELECT(%>0&(%<5):%,%=11:5,1:19)
- +10 DO ADDSTAT^ABSPOSUD("C",2,1,"C",3,$LENGTH(SENDMSG)+3,"C",%,1)
- End DoDot:1
- +11 ;
- +12 ;Wait for response from host
- +13 ; Envoy sends an ACK at this point.
- +14 ; Apparently NDC does not? Or maybe NDC sends ACK then STX
- +15 ; Also: make the timeout 60 seconds. "The Envoy host typically allows
- +16 ; an end processor up to 55 seconds to respond."
- +17 ;
- LOOP1B IF T1LINE
- SET HMSG="ACK"
- GOTO LOOP1C
- +1 DO LOG("2 - Waiting for ACK or NAK")
- +2 SET HMSG=$$WAITCHAR(ACK_NAK_STX_ENQ,60)
- +3 IF HMSG="ACK"
- Begin DoDot:1
- +4 ; we got what we expected; do nothing else here
- End DoDot:1
- +5 IF '$TEST
- IF HMSG="STX"
- Begin DoDot:1
- +6 DO LOG("2 - Missing ACK but got STX; must be start of response?")
- End DoDot:1
- +7 IF '$TEST
- IF HMSG="NAK"
- Begin DoDot:1
- +8 DO LOG("2 - Host sent NAK - we will resend")
- End DoDot:1
- GOTO LOOP1A
- +9 ; Envoy 4.1, p. 12
- IF '$TEST
- IF HMSG="ENQ"
- Begin DoDot:1
- +10 DO LOG("2 - Host sent another ENQ - we will resend")
- End DoDot:1
- GOTO LOOP1A
- +11 IF '$TEST
- Begin DoDot:1
- +12 DO LOG("2 - But received "_HMSG_" instead.")
- +13 ; put message back for later transmission
- DO PUTBACK^ABSPOSAP
- DO CLAIMEND
- +14 IF HMSG'="+++"
- DO HANGUP
- +15 SET RET=$SELECT(HMSG="+++":31101,HMSG="":31102,1:31103)
- End DoDot:1
- QUIT RET
- +16 ;
- +17 ; The response message is preceded by STX
- +18 ; If we just got an ACK, then wait for the STX
- +19 ;
- LOOP1C IF HMSG="ACK"
- Begin DoDot:1
- +1 IF T1LINE
- SET HMSG="STX"
- QUIT
- +2 SET HMSG=$$WAITCHAR(STX,60)
- +3 DO LOG("2 - "_HMSG_" received from host")
- End DoDot:1
- +4 IF '$TEST
- IF HMSG="STX"
- Begin DoDot:1
- +5 ; do nothing; fall through with STX still here
- End DoDot:1
- +6 IF '$TEST
- Begin DoDot:1
- +7 DO LOG("Internal error at LOOP1C")
- End DoDot:1
- QUIT 30239
- +8 ;
- +9 IF HMSG="STX"
- Begin DoDot:1
- +10 ; nothing, got what we expected
- End DoDot:1
- +11 IF '$TEST
- Begin DoDot:1
- +12 DO LOG("2 - Expected STX but got "_HMSG_" instead")
- +13 DO PUTBACK^ABSPOSAP
- DO CLAIMEND
- +14 SET RET=$SELECT(HMSG="+++":30251,HMSG="":30252,1:30253)
- End DoDot:1
- QUIT RET
- +15 ;I HMSG'="STX" D INCSTAT^ABSPOSUD("CR",$S(HMSG="ENQ":2,HMSG="NAK":3,HMSG="+++":4,HMSG="":5,1:9))
- +16 ;
- +17 ; The host sends us the response message
- +18 ;
- LOOP3 SET (GETMSG,LRC)=""
- +1 ; status = "Receiving response"
- DO SETCSTAT^ABSPOSU(CLAIMIEN,70)
- +2 DO LOG("3 - Gathering response from host")
- +3 SET HMSG=$$GETMSG^ABSPOSAR(DIALOUT,.RESPMSG,.RESPLRC,60)
- +4 ;
- +5 ; HMSG="ETX" or "EOT" or "" (if timed out)
- +6 ;
- +7 IF HMSG="ETX"
- Begin DoDot:1
- +8 DO LOG("3 - Received "_$LENGTH(RESPMSG)_" bytes; LRC "_$ASCII(RESPLRC))
- +9 DO ADDSTAT^ABSPOSUD("C",4,1,"C",5,$LENGTH(RESPMSG)+3)
- End DoDot:1
- +10 IF '$TEST
- Begin DoDot:1
- +11 DO INCSTAT^ABSPOSUD("CR2",1,"CR2",$SELECT(HMSG="EOT":2,HMSG="":3,HMSG="+++":4,1:9))
- +12 DO LOG("3 - Error while gathering response: HMSG="_HMSG)
- +13 DO PUTBACK^ABSPOSAP
- +14 DO CLAIMEND
- +15 IF HMSG'="+++"
- DO HANGUP
- +16 SET RET=$SELECT(HMSG="+++":30261,HMSG="":30262,1:30263)
- End DoDot:1
- QUIT RET
- +17 ;
- +18 ; Test LRC character. If we agree, we send ACK. If not, we NAK.
- +19 ; And if we send ACK, get the next message to send, if any.
- +20 ;
- +21 ; G PASTLRC ; if T1 connection, LRC is n/a
- IF T1LINE
- SET LRCOK=1
- +22 ; we have seen 1-byte response msg!
- IF '$TEST
- IF $LENGTH(RESPMSG)<9
- SET LRCOK=0
- +23 IF '$TEST
- SET LRCOK=$$TESTLRC^ABSPOSAD(RESPMSG,RESPLRC)
- +24 ;
- +25 ; assume no claims to send after this one
- SET CLAIMNXT=0
- +26 IF LRCOK
- Begin DoDot:1
- +27 ; protect CLAIMIEN - $$GETNEXT will reset it
- NEW CLAIMIEN
- +28 ; remember next CLAIMIEN
- IF '$$SHUTDOWN
- SET CLAIMNXT=$$GETNEXT^ABSPOSAP
- +29 IF CLAIMNXT
- IF $PIECE($GET(^ABSP(9002313.55,DIALOUT,"PROTOCOL")),U)
- Begin DoDot:2
- +30 IF T1LINE
- QUIT
- +31 DO LOG("6 - Send ETB to host")
- +32 DO SENDETB^ABSPOSAS(DIALOUT)
- End DoDot:2
- +33 IF '$TEST
- Begin DoDot:2
- +34 IF T1LINE
- QUIT
- +35 DO LOG("6 - Send ACK to host")
- +36 DO SENDACK^ABSPOSAS(DIALOUT)
- End DoDot:2
- +37 ; count our successes (and blessings)
- SET ABSPECT2=ABSPECT2+1
- +38 ;
- +39 ; ABSPOSQ3 will start up processing of responses
- +40 ; But here, if we have heavy volume, we need to get it going
- +41 ; right now, every so often.
- +42 ;
- +43 IF ABSPECT2>10
- IF ABSPECT2#5=0
- DO TASK^ABSPOSQ3()
- End DoDot:1
- +44 IF '$TEST
- Begin DoDot:1
- +45 DO LOG("6 - Send NAK to host because of LRC disagreement")
- +46 DO SENDNAK^ABSPOSAS(DIALOUT)
- End DoDot:1
- +47 ;
- PASTLRC ;
- +1 ; timing - when transaction completed
- SET TRANSEND=$PIECE($HOROLOG,",",2)
- +2 SET TRANSTIM=TRANSEND-TRANSBEG
- IF TRANSTIM<0
- SET TRANSTIM=TRANSTIM+86400
- +3 ; Statistics: Comms - Transaction Time Comms
- +4 ; Comms - Send ACK Comms - Send NAK
- +5 DO ADDSTAT^ABSPOSUD("CT",1,TRANSTIM,"C",7+'LRCOK,1)
- +6 ;
- +7 IF 'LRCOK
- Begin DoDot:1
- +8 ; fake it out so it drops into the WAITCHAR(STX) code
- SET HMSG="ACK"
- End DoDot:1
- GOTO LOOP1C
- +9 ;
- +10 DO CLAIMEND
- +11 ;
- +12 ; At this happy point, we have received a response and ACK'ed it.
- +13 ; NOTE!! SENDMSG is the _next_ message to send, not the one just sent!
- +14 ;
- +15 ;File response message in temporary global
- +16 ;
- LR ; lock the response
- LOCK +^ABSPECX("POS",DIALOUT,"R",CLAIMIEN):300
- +1 IF '$TEST
- IF $$IMPOSS^ABSPOSUE("L","RIT","LOCK response",,"LR",$TEXT(+0))
- GOTO LR
- +2 ; kill anything that's there
- KILL ^ABSPECX("POS",DIALOUT,"R",CLAIMIEN)
- +3 FOR I=1:SEG:$LENGTH(RESPMSG)
- Begin DoDot:1
- +4 SET ^ABSPECX("POS",DIALOUT,"R",CLAIMIEN,I\SEG+1)=$EXTRACT(RESPMSG,I,I+SEG-1)
- +5 SET ^ABSPECX("POS",DIALOUT,"R",CLAIMIEN,0)=I\SEG+1
- End DoDot:1
- +6 ; unlock the response
- LOCK -^ABSPECX("POS",DIALOUT,"R",CLAIMIEN)
- +7 ; Waiting to process response.
- DO SETCSTAT^ABSPOSU(CLAIMIEN,80)
- +8 ;
- +9 ; Now we're ready to go again.
- +10 IF CLAIMNXT
- SET CLAIMIEN=CLAIMNXT
- GOTO START
- +11 ;
- +12 ; No more to send.
- +13 ; We expect EOT from Envoy. NDC might send ENQ here?
- +14 IF T1LINE
- QUIT 0
- +15 SET HMSG=$$WAITCHAR(EOT_ENQ,3)
- +16 IF HMSG'="+++"
- IF HMSG'="ENQ"
- Begin DoDot:1
- +17 DO LOG("9 - No more to send; expect EOT, got "_HMSG)
- End DoDot:1
- +18 IF HMSG'="+++"
- DO HANGUP
- +19 QUIT 0
- +20 ; ----- end of main part of routine -----
- +21 ;
- LOG(X) DO LOG^ABSPOSL($TEXT(+0)_" - "_X)
- QUIT
- +1 ;
- +2 ; READCHAR not used? READCHAR(TIMEOUT) N X U IO R *X:TIMEOUT Q X
- +3 ;
- +4 ; WAITCHAR: Envoy 4.1, page 16
- +5 ; If during one of the wait stages of the transmission, the
- +6 ; pharmacy system should receive unexpected characters, they should
- +7 ; be ignored unless they are transmitted as a part of the response
- +8 ; (beginning with the STX and concluding with the ETX). At that
- +9 ; point, they should be considered a part of a message. The ENVOY
- +10 ; system will react in the same manner after returning a response.
- +11 ; After the issuance of the ENQ, however, if the host receives
- +12 ; unexpected characters without receiving the STX and/or the ETX,
- +13 ; it will issue an EOT.
- +14 ;
- +15 ; In plain English: WAITCHAR^ABSPOSAW ignores unexpected characters.
- +16 ; Except for EOT - it catches that, as well as the watched-for
- +17 ; characters.
- +18 ;
- WAITCHAR(CHARS,TIMEOUT) ;EP -
- +1 NEW RET
- SET RET=$$WAITCHAR^ABSPOSAW(DIALOUT,CHARS,TIMEOUT)
- +2 IF RET="+++"
- DO LOG("WAITCHAR tells us that modem is disconnected.")
- +3 QUIT RET
- +4 ;
- SHUTDOWN() NEW RET
- SET RET=$$SHUTDOWN^ABSPOSQ3
- +1 IF RET
- DO LOG("The transmit/receive shutdown flag is set.")
- +2 QUIT RET
- HANGUP DO HANGUP^ABSPOSAB(DIALOUT)
- QUIT
- +1 ; NOTE!!! Print of log for one claim depends on finding
- +2 ; the exact texts shown below!
- CLAIMBEG DO LOG("CLAIM - BEGIN - #"_CLAIMIEN_$$CLAIM01)
- QUIT
- CLAIMEND DO LOG("CLAIM - END - #"_CLAIMIEN_$$CLAIM01)
- QUIT
- CLAIM01() QUIT " ("_$PIECE(^ABSPC(CLAIMIEN,0),U)_")"