INHUSEN6 ;KN,DGH; 11 Nov 1999 16:52 ;Main X12 processing logic
;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
;COPYRIGHT 1991-2000 SAIC
;CHCS ; INT_460; GEN 1;26-SEP-1996
;COPYRIGHT 1998 SAIC
;
;
Q
X12IN(ING,INDEST,INDSTR,INSEND,INERR,INXDST,INMSG,INLHSCH,INSTAT,INNOACK) ;X12
; DESCRIPTION:
; This is the primary entry function to process all incoming
; transmissions. The main functions for this entry are:
; 1. Verify all needed headers are present (see VERIF^
; INHUSEN7) and determine type of incoming transmission.
; 2. Based on types of incoming transmission.
; - Incoming transmission is an Interchange Ack (TA1 or FA)
; Evaluate the result, store the Ack, and update the
; original transmission status.
; - Incoming transmission is response to query.
; (The Transaction Set may contain a Response (271) or
; an Unsolicited message) - Determine destination and file
; into Output Controller for further processing. If
; Interchange Ack (TA1 or 997) is required, create and send.
; Parameters:
; Input:
; ING = (REQ) Variable array/global containing lines from transmission
; INDEST = Array of valid destinations in format INDEST(type) = .01
; field of Transaction Type. This is not required if
; processing incoming ACKS.
; INDSTR = (REQ) Receiver dest. pointer -- $P(^INTHPC(INBPN,0),U,7)
; INXDST = (OPT) EXecutable code to identify the destination for
; msgs which won't be uniquely identified. The
; executable must return the ien in the variable INDSTP.
; INLHSCH = (OPT) Set to 1 if the incoming msg should not be
; placed on the output controller queue, ^INLHSCH. If
; not specified, this routine will determine the
; conditions under which a msg is queued.
;
; Output:
; INSEND = (OPT) Variable which will contain the UIF entry(ies)
; of msg which needs to be sent by tranceiver back to
; other system. This may be a functional ack (PBR)
; INERR = (OPT) Variable to return error msg. (PBR)
; INMSG = (OPT) Variable to return UIF of inbound transaction (PBR)
; INSTAT = (OPT) If incoming is an ack, this variable contains the
; the status of the original message. (PBR)
; Note: transmitter retry logic is based on HL7 values of
; CA, CR, CE, so the X12 status values of A,E,R are
; transformed into their HL7 equivalents in this function.
;
; Return:
; 0 = Success
; 1 = Non-fatal error ( no resend required )
; 2 = Fatal error
;
N INDELIM,INLINK,INSUBDEL,INTA
;First verify and evaluate the X12 transmission, quit if fatal error
D:$G(INDEBUG) LOG^INHVCRA1("Entering X12 INHUSEN verification",9)
S INVL=$$VERIF^INHUSEN7(ING,.INTYP,.INTA,.ORIGID,.INLINK,.INSTAT,.INERR)
;Convert X12 status to HL7 equivalent for transmitter logic
I $L($G(INSTAT)) S INSTAT=$S(INSTAT="A":"CA",INSTAT="R":"CR",1:"CA")
I INVL=2 Q INVL
D:$G(INDEBUG) LOG^INHVCRA1("Verification completed: INVL="_INVL_" INTYP="_INTYP,5)
S MESSID=ORIGID
;--- Communication acknowledgment processing --
;If incoming is a commit-type ack, FA or TA1, store it, update
;the original message, and quit
I ",FA,TA1,"[(","_INTYP_",") D Q INVL
. ;Use generic destination (required to STORE). Don't queue.
. S INDST="INCOMING ACK",INDSTP=$O(^INRHD("B",INDST,"")),INLHSCH=1
. D STORE,CACKLOG^INHUSEN8(INMSG,INLINK,INSTAT)
;--All other messages must have a "real" destination to allow STOREage.
D Q:INVL=2 INVL
.;Tranceiver must specify INXDST, execute it.
.I '$L($G(INXDST)) D ERRADD^INHUSEN3(.INERR,"No destination determination code specified for recevier") S INVL=2 Q
.D:$G(INDEBUG) LOG^INHVCRA1("Executing Destination Determination Code"_INXDST,9)
.X INXDST
.I '$D(INDSTP) S INVL=2,MSG(1)="Message "_ORIGID_" has no destination" D ERRADD^INHUSEN3(.INERR,.MSG) Q
.;pointer needed for most functions, NAME needed for NEW^INHD.
.S:'$D(INDST) INDST=$P(^INRHD(INDSTP,0),U)
.;Store msg
.D STORE
;--If incoming is a response, update query. INLINK should have value.
;If VERIF did not set INLINK, assume this is an unsolicited message
;not a response to a query so there's no original message to update.
I $L($G(INMSG)),$G(INLINK) D UPDATE^INHUSEN8(INMSG,INLINK)
;
;---If incoming message requires FA or TA1 to be returned
ACK ;Process Interchange Ack and quit back to transceiver routine.
D:$G(INDEBUG) LOG^INHVCRA1("Creating commit ack",5)
D
.;INNOACK parameter over-rides all others.
.I $G(INNOACK) Q
.;Interface Destination File may have over-ride value.
.S:$L($P(^INRHD(INDSTR,0),U,11)) CND=$P(^INRHD(INDSTR,0),U,11)
;Stop Transaction Type Audit
D:$D(XUAUDIT) TTSTP^XUSAUD("",$G(INMSG))
;Create Interchange Ack
S CERR=$$TACK^INHUSEN8(INDSTR,.INTA,ORIGID,.INSEND)
Q $S($G(CERR)>INVL:CERR,1:INVL)
;
STORE ;Store incoming xmission in the Universal Interface file
;Use same STORE as for HL7.
;INMSH variable used for selective routing of inbound HL7 messages
;based on sending/receiving facility. If needed for X12 different
;variables need to be passed to STORE and selective routing
;logic needs to be changed.
S INMSH=""
D STORE^INHUSEN4
Q
;
;
;
INHUSEN6 ;KN,DGH; 11 Nov 1999 16:52 ;Main X12 processing logic
+1 ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
+2 ;COPYRIGHT 1991-2000 SAIC
+3 ;CHCS ; INT_460; GEN 1;26-SEP-1996
+4 ;COPYRIGHT 1998 SAIC
+5 ;
+6 ;
+7 QUIT
X12IN(ING,INDEST,INDSTR,INSEND,INERR,INXDST,INMSG,INLHSCH,INSTAT,INNOACK) ;X12
+1 ; DESCRIPTION:
+2 ; This is the primary entry function to process all incoming
+3 ; transmissions. The main functions for this entry are:
+4 ; 1. Verify all needed headers are present (see VERIF^
+5 ; INHUSEN7) and determine type of incoming transmission.
+6 ; 2. Based on types of incoming transmission.
+7 ; - Incoming transmission is an Interchange Ack (TA1 or FA)
+8 ; Evaluate the result, store the Ack, and update the
+9 ; original transmission status.
+10 ; - Incoming transmission is response to query.
+11 ; (The Transaction Set may contain a Response (271) or
+12 ; an Unsolicited message) - Determine destination and file
+13 ; into Output Controller for further processing. If
+14 ; Interchange Ack (TA1 or 997) is required, create and send.
+15 ; Parameters:
+16 ; Input:
+17 ; ING = (REQ) Variable array/global containing lines from transmission
+18 ; INDEST = Array of valid destinations in format INDEST(type) = .01
+19 ; field of Transaction Type. This is not required if
+20 ; processing incoming ACKS.
+21 ; INDSTR = (REQ) Receiver dest. pointer -- $P(^INTHPC(INBPN,0),U,7)
+22 ; INXDST = (OPT) EXecutable code to identify the destination for
+23 ; msgs which won't be uniquely identified. The
+24 ; executable must return the ien in the variable INDSTP.
+25 ; INLHSCH = (OPT) Set to 1 if the incoming msg should not be
+26 ; placed on the output controller queue, ^INLHSCH. If
+27 ; not specified, this routine will determine the
+28 ; conditions under which a msg is queued.
+29 ;
+30 ; Output:
+31 ; INSEND = (OPT) Variable which will contain the UIF entry(ies)
+32 ; of msg which needs to be sent by tranceiver back to
+33 ; other system. This may be a functional ack (PBR)
+34 ; INERR = (OPT) Variable to return error msg. (PBR)
+35 ; INMSG = (OPT) Variable to return UIF of inbound transaction (PBR)
+36 ; INSTAT = (OPT) If incoming is an ack, this variable contains the
+37 ; the status of the original message. (PBR)
+38 ; Note: transmitter retry logic is based on HL7 values of
+39 ; CA, CR, CE, so the X12 status values of A,E,R are
+40 ; transformed into their HL7 equivalents in this function.
+41 ;
+42 ; Return:
+43 ; 0 = Success
+44 ; 1 = Non-fatal error ( no resend required )
+45 ; 2 = Fatal error
+46 ;
+47 NEW INDELIM,INLINK,INSUBDEL,INTA
+48 ;First verify and evaluate the X12 transmission, quit if fatal error
+49 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Entering X12 INHUSEN verification",9)
+50 SET INVL=$$VERIF^INHUSEN7(ING,.INTYP,.INTA,.ORIGID,.INLINK,.INSTAT,.INERR)
+51 ;Convert X12 status to HL7 equivalent for transmitter logic
+52 IF $LENGTH($GET(INSTAT))
SET INSTAT=$SELECT(INSTAT="A":"CA",INSTAT="R":"CR",1:"CA")
+53 IF INVL=2
QUIT INVL
+54 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Verification completed: INVL="_INVL_" INTYP="_INTYP,5)
+55 SET MESSID=ORIGID
+56 ;--- Communication acknowledgment processing --
+57 ;If incoming is a commit-type ack, FA or TA1, store it, update
+58 ;the original message, and quit
+59 IF ",FA,TA1,"[(","_INTYP_",")
Begin DoDot:1
+60 ;Use generic destination (required to STORE). Don't queue.
+61 SET INDST="INCOMING ACK"
SET INDSTP=$ORDER(^INRHD("B",INDST,""))
SET INLHSCH=1
+62 DO STORE
DO CACKLOG^INHUSEN8(INMSG,INLINK,INSTAT)
End DoDot:1
QUIT INVL
+63 ;--All other messages must have a "real" destination to allow STOREage.
+64 Begin DoDot:1
+65 ;Tranceiver must specify INXDST, execute it.
+66 IF '$LENGTH($GET(INXDST))
DO ERRADD^INHUSEN3(.INERR,"No destination determination code specified for recevier")
SET INVL=2
QUIT
+67 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Executing Destination Determination Code"_INXDST,9)
+68 XECUTE INXDST
+69 IF '$DATA(INDSTP)
SET INVL=2
SET MSG(1)="Message "_ORIGID_" has no destination"
DO ERRADD^INHUSEN3(.INERR,.MSG)
QUIT
+70 ;pointer needed for most functions, NAME needed for NEW^INHD.
+71 IF '$DATA(INDST)
SET INDST=$PIECE(^INRHD(INDSTP,0),U)
+72 ;Store msg
+73 DO STORE
End DoDot:1
IF INVL=2
QUIT INVL
+74 ;--If incoming is a response, update query. INLINK should have value.
+75 ;If VERIF did not set INLINK, assume this is an unsolicited message
+76 ;not a response to a query so there's no original message to update.
+77 IF $LENGTH($GET(INMSG))
IF $GET(INLINK)
DO UPDATE^INHUSEN8(INMSG,INLINK)
+78 ;
+79 ;---If incoming message requires FA or TA1 to be returned
ACK ;Process Interchange Ack and quit back to transceiver routine.
+1 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Creating commit ack",5)
+2 Begin DoDot:1
+3 ;INNOACK parameter over-rides all others.
+4 IF $GET(INNOACK)
QUIT
+5 ;Interface Destination File may have over-ride value.
+6 IF $LENGTH($PIECE(^INRHD(INDSTR,0),U,11))
SET CND=$PIECE(^INRHD(INDSTR,0),U,11)
End DoDot:1
+7 ;Stop Transaction Type Audit
+8 IF $DATA(XUAUDIT)
DO TTSTP^XUSAUD("",$GET(INMSG))
+9 ;Create Interchange Ack
+10 SET CERR=$$TACK^INHUSEN8(INDSTR,.INTA,ORIGID,.INSEND)
+11 QUIT $SELECT($GET(CERR)>INVL:CERR,1:INVL)
+12 ;
STORE ;Store incoming xmission in the Universal Interface file
+1 ;Use same STORE as for HL7.
+2 ;INMSH variable used for selective routing of inbound HL7 messages
+3 ;based on sending/receiving facility. If needed for X12 different
+4 ;variables need to be passed to STORE and selective routing
+5 ;logic needs to be changed.
+6 SET INMSH=""
+7 DO STORE^INHUSEN4
+8 QUIT
+9 ;
+10 ;
+11 ;