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

HLOAPI3.m

Go to the documentation of this file.
  1. HLOAPI3 ;ALB/CJM-HL7 - Developer API's for sending application acks ;09/13/2006
  1. ;;1.6;HEALTH LEVEL SEVEN;**126,133**;Oct 13, 1995;Build 13
  1. ;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. BATCHACK(HLMSTATE,PARMS,ACK,ERROR) ;Starts a batch message that is the response to a batch message. Individual acks are placed in the batch by calling $$ADDACK.
  1. ;$$SENDACK^HLOAPI2 must be called when the batch of acks is complete. The return destination is determined automatically from the original message.
  1. ;
  1. ;Input:
  1. ; HLMSTATE (pass by reference, required) the array obtained by calling $$STARTMSG^HLOPRS when parsing the original message
  1. ; PARMS (optional, pass by reference) These subscripts may be defined:
  1. ; "ACCEPT ACK RESPONSE")=<tag^routine> to call when the commit ack is received (optional)
  1. ; "ACCEPT ACK TYPE") = <AL,NE> (optional, defaults to AL)
  1. ; "COUNTRY") - a 3 character country code from the HL7 standard table (optional)
  1. ; "ENCODING CHARACTERS" - the 4 HL7 encoding characters (optional,defaults to "^~\&"
  1. ; "FAILURE RESPONSE" (optional) the <tag>^<routine> that the sending application routine should execute if the transmission of the message fails, i.e., the message can not be sent or a requested commit ack is not received.
  1. ; "FIELD SEPARATOR" - the field separator (optional, defaults to "|")
  1. ; "QUEUE" (optional) An application can name a private queue (a string under 20 characters, namespaced). The default is the name of the queue of the original message
  1. ; "SECURITY" - security information to include in the header segment, SEQ 8 (optional)
  1. ; "VERSION" - the HL7 Version ID (optional, defaults to 2.4)
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure
  1. ; PARMS - left undefined upon completion
  1. ; ACK (pass by reference, required) the batch acknowledgment message being built.
  1. ; ERROR (pass by reference) error message
  1. N I,TOLINK,SUCCESS
  1. S SUCCESS=0
  1. ;
  1. D
  1. .N PORT
  1. .I '$G(HLMSTATE("IEN")) S ERROR="ORIGINAL MESSAGE TO ACKNOWLEDGMENT IS NOT IDENTIFIED" Q
  1. .;if the return link can not be determined, the HL Logical Link file has a problem
  1. .S TOLINK=$$ACKLINK^HLOAPI2(.HLMSTATE)
  1. .I TOLINK="" S ERROR="TRANSMISSION LINK FOR APPLICATION ACK CANNOT BE DETERMINED" Q
  1. .S PORT=$P(HLMSTATE("HDR","SENDING FACILITY",2),":",2)
  1. .I 'PORT S PORT=$$PORT2^HLOTLNK(TOLINK)
  1. .;
  1. .I $$NEWBATCH^HLOAPI(.PARMS,.ACK) ;can't fail!
  1. .S ACK("STATUS","QUEUE")=$G(PARMS("QUEUE"),$G(HLMSTATE("STATUS","QUEUE")))
  1. .S ACK("STATUS","PORT")=PORT
  1. .S ACK("HDR","SECURITY")=$G(PARMS("SECURITY"))
  1. .S ACK("HDR","SENDING APPLICATION")=$G(HLMSTATE("HDR","RECEIVING APPLICATION"))
  1. .S ACK("HDR","RECEIVING APPLICATION")=$G(HLMSTATE("HDR","SENDING APPLICATION"))
  1. .F I=1:1:3 S ACK("HDR","RECEIVING FACILITY",I)=$G(HLMSTATE("HDR","SENDING FACILITY",I))
  1. .S ACK("HDR","APP ACK TYPE")="NE"
  1. .S ACK("HDR","ACCEPT ACK TYPE")=$G(PARMS("ACCEPT ACK TYPE"),"AL")
  1. .S ACK("ACK TO")=$G(HLMSTATE("HDR","BATCH CONTROL ID"))
  1. .S ACK("ACK TO","IEN")=HLMSTATE("IEN")
  1. .S ACK("ACK TO","BODY")=$G(HLMSTATE("BODY"))
  1. .S ACK("STATUS","LINK NAME")=TOLINK
  1. .S ACK("LINE COUNT")=0
  1. .S SUCCESS=1
  1. K PARMS
  1. Q SUCCESS
  1. ;
  1. ADDACK(ACK,PARMS,ERROR) ;This API adds an application acknowledgment to a batch
  1. ;of acknowledgments that was started by calling $$BATCHACK.
  1. ;The Default behavior is to return a general application ack.
  1. ;The application may optionally specify the message
  1. ;type and event and/or call $$ADDSEG^HLOAPI to add segments.
  1. ;A generic MSA segment (components 1-3) will be added automatically
  1. ;if the application doesn't call $$ADDSEG^HLOAPI to add an MSA segment
  1. ;as the FIRST segment following the MSH segment.
  1. ;$$SENDACK^HLOAPI2 must be called when the batch is complete.
  1. ;
  1. ;Input:
  1. ; ACK (pass by reference,required) the batch of acks that is being built
  1. ; PARMS (pass by reference) These subscripts may be defined:
  1. ; "ACK CODE" (required) MSA1[ {AA,AE,AR}
  1. ; "ERROR MESSAGE" (optional) MSA3, should be used only if AE or AR
  1. ; "EVENT" - 3 character event type (optional, defaults to the event code of the original message)
  1. ; "MESSAGE CONTROL ID" (required) this is the message control id of the original individual message within the batch which is being acknowledged
  1. ; "MESSAGE STRUCTURE" (optional)
  1. ; "MESSAGE TYPE" (optional, defaults to ACK)
  1. ; "SECURITY" (optional) security information to include in the header segment SEQ 8
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure
  1. ; ACK (pass by reference, required) The batch, updated with another ack
  1. ; PARMS - left undefined when this function returns
  1. ; ERROR (pass by reference) error msg
  1. ;
  1. N SUB,SUCCESS
  1. S SUCCESS=0
  1. D
  1. .I $G(PARMS("ACK CODE"))'="AA",$G(PARMS("ACK CODE"))'="AE",$G(PARMS("ACK CODE"))'="AR" S ERROR="INVALID ACK CODE" Q
  1. .;
  1. .I $G(PARMS("MESSAGE CONTROL ID"))="" S ERROR="MESSAGE CONTROL ID MUST EXIST TO RETURN AN APPLICATION ACK" Q
  1. .S SUB=""
  1. .F S SUB=$O(^HLB("AE",PARMS("MESSAGE CONTROL ID"),SUB)) Q:SUB="" I $P(SUB,"^")=ACK("ACK TO","IEN"),$P(SUB,"^",2) S PARMS("ACK TO","IEN")=SUB Q
  1. .S PARMS("MESSAGE TYPE")=$G(PARMS("MESSAGE TYPE"),"ACK")
  1. .S:PARMS("MESSAGE TYPE")="ACK" PARMS("MESSAGE STRUCTURE")="ACK"
  1. .S PARMS("EVENT")=$G(PARMS("EVENT"))
  1. .I PARMS("EVENT")="",ACK("ACK TO","BODY"),$P(SUB,"^",2) S PARMS("EVENT")=$P($G(^HLA(ACK("ACK TO","BODY"),2,$P(SUB,"^",2),0)),"^",3)
  1. .S PARMS("ACK TO")=PARMS("MESSAGE CONTROL ID")
  1. .S PARMS("ACK TO","STATUS")=$S(PARMS("ACK CODE")="AA":"SU",1:"AE")
  1. .Q:'$$ADDMSG^HLOAPI(.ACK,.PARMS,.ERROR)
  1. .S ACK("MSA")="MSA|"_PARMS("ACK CODE")_"|"_PARMS("MESSAGE CONTROL ID")_"|"_$G(PARMS("ERROR MESSAGE"))
  1. .S SUCCESS=1
  1. K PARMS
  1. Q SUCCESS
  1. ;
  1. RESEND(MSGIEN,ERROR) ;
  1. ;Description: This message will re-transmit an out-going message. It
  1. ;does this by making a copy of the message, reusing all the original
  1. ;parameters. Then the message is placed on the same out-going queue.
  1. ;
  1. ;Input:
  1. ; MSGIEN - the ien (file #778) of the message that is to be sent
  1. ;Output:
  1. ; Function returns the ien of the message in file 778 on success, 0 on failure
  1. ; ERROR (pass by reference, optional) - on failure, will contain an error message
  1. ;
  1. N MSG,SUB,HDR
  1. I '$$STARTMSG^HLOPRS(.MSG,MSGIEN) S ERROR="MESSAGE NOT FOUND" Q 0
  1. I MSG("DIRECTION")'="OUT" S ERROR="MESSAGE IS NOT OUTGOING" Q 0
  1. I MSG("STATUS","LINK NAME")="" S ERROR="LINK NOT DEFINED" Q 0
  1. F SUB="ID","IEN","DT/TM","ACK BY","STATUS" S MSG(SUB)=""
  1. F SUB="PURGE" K MSG("STATUS",SUB)
  1. D GETSYS^HLOAPI(.MSG)
  1. I $$SAVEMSG^HLOF778(.MSG) D OUTQUE^HLOQUE(MSG("STATUS","LINK NAME"),$G(MSG("STATUS","PORT")),MSG("STATUS","QUEUE"),MSG("IEN")) Q +MSG("IEN")
  1. Q 0
  1. ;
  1. SETPURGE(MSGIEN,TIME) ;
  1. ;Resets the purge date/time.
  1. ;Input:
  1. ; MSGIEN (required) ien of the message, file #778
  1. ; TIME (optional) dt/time to set the purge time to, defaults to NOW
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure
  1. N NODE,OLDTIME,HLDIR
  1. Q:'$G(MSGIEN) 0
  1. S NODE=$G(^HLB(MSGIEN,0))
  1. Q:NODE="" 0
  1. S OLDTIME=$P(NODE,"^",9)
  1. S:'$G(TIME) TIME=$$NOW^XLFDT
  1. S HLDIR=$S($E($P(NODE,"^",4))="I":"IN",1:"OUT")
  1. K:OLDTIME ^HLB("AD",HLDIR,OLDTIME,MSGIEN)
  1. S $P(^HLB(MSGIEN,0),"^",9)=TIME
  1. S ^HLB("AD",HLDIR,TIME,MSGIEN)=""
  1. Q 1
  1. ;
  1. REPROC(MSGIEN,ERROR) ;
  1. ;Description: This message will re-process an incoming message by placing it on the appropriate incoming queue. If successful the message is set to be purged.
  1. ;
  1. ;Input:
  1. ; MSGIEN - the ien (file #778) of the message that is to be processed
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure
  1. ; ERROR (pass by reference, optional) - on failure, will contain an error message
  1. ;
  1. N MSG,HDR,ACTION,QUEUE,FROM
  1. ;
  1. I '$$STARTMSG^HLOPRS(.MSG,MSGIEN) S ERROR="MESSAGE NOT FOUND" Q 0
  1. I MSG("DIRECTION")'="IN" S ERROR="MESSAGE IS NOT INCOMING" Q 0
  1. M HDR=MSG("HDR")
  1. I '$$ACTION^HLOAPP(.HDR,.ACTION,.QUEUE),$G(MSG("ACK TO"))="" S ERROR="RECEIVING APPLICATION NOT DEFINED"
  1. ;If this message references an earlier message, get the action specified by the original message
  1. I $G(MSG("ACK TO"))]"" D
  1. .N NODE,IEN
  1. .S IEN=$O(^HLB("B",$P(MSG("ACK TO"),"-"),0))
  1. .S:IEN NODE=$G(^HLB(IEN,0))
  1. .I ($P(NODE,"^",11)]"") S ACTION=$P(NODE,"^",10,11),QUEUE=$S($P(NODE,"^",6)]"":$P(NODE,"^",6),1:"DEFAULT")
  1. I ACTION="" S ERROR="ORIGINAL MESSAGE NOT FOUND" Q 0
  1. S FROM=$S(MSG("HDR","SENDING FACILITY",2)]"":MSG("HDR","SENDING FACILITY",2),1:MSG("HDR","SENDING FACILITY",1))
  1. D INQUE^HLOQUE(FROM,QUEUE,MSGIEN,ACTION,1)
  1. Q 1
  1. ;
  1. PROCNOW(MSGIEN,PURGE,ERROR) ;
  1. ;Description: This message will re-process an incoming message immediately.
  1. ;
  1. ;Input:
  1. ; MSGIEN - the ien (file #778) of the message that is to be processed
  1. ;Output:
  1. ; Function returns 1 on success, 0 on failure
  1. ; PURGE (optional) a date/time to purge the message
  1. ; ERROR (pass by reference, optional) - on failure, will contain an error message
  1. ;
  1. N MSG,HDR,ACTION,MCODE,HLMSGIEN
  1. ;
  1. S ERROR=""
  1. I '$$STARTMSG^HLOPRS(.MSG,MSGIEN) S ERROR="MESSAGE NOT FOUND" Q 0
  1. I MSG("DIRECTION")'="IN" S ERROR="MESSAGE IS NOT INCOMING" Q 0
  1. M HDR=MSG("HDR")
  1. I '$$ACTION^HLOAPP(.HDR,.ACTION),'$G(MSG("ACK TO IEN")) S ERROR="RECEIVING APPLICATION NOT DEFINED" Q 0
  1. ;If this msg is an ack to an earlier message, get the action specified by the original message
  1. I $G(ACTION)="",$G(MSG("ACK TO IEN")) S ACTION=$P($G(^HLB(+MSG("ACK TO IEN"),0)),"^",10,11) I $P(ACTION,"^",2)="" S ERROR="ORIGINAL MESSAGE NOT FOUND" Q 0
  1. D:$G(PURGE)
  1. .K:MSG("STATUS","PURGE") ^HLB("AD","IN",MSG("STATUS","PURGE"),MSGIEN)
  1. .S $P(^HLB(MSGIEN,0),"^",9)=PURGE
  1. .S ^HLB("AD","IN",PURGE,MSGIEN)=""
  1. .I $G(MSG("ACK TO IEN")),$D(^HLB(MSG("ACK TO IEN"),0)) K ^HLB("AD","OUT",MSG("STATUS","PURGE"),MSG("ACK TO IEN")) S $P(^HLB(MSG("ACK TO IEN"),0),"^",9)=PURGE,^HLB("AD","OUT",PURGE,MSG("ACK TO IEN"))=""
  1. S HLMSGIEN=MSGIEN
  1. S $P(^HLB(MSGIEN,0),"^",19)=1
  1. S MCODE="D "_ACTION
  1. X MCODE
  1. Q 1