View Javadoc

1   /*
2    * Created on 16-Apr-2004
3    */
4   package ca.uhn.hl7v2.protocol;
5   
6   import ca.uhn.hl7v2.HL7Exception;
7   import ca.uhn.hl7v2.parser.Parser;
8   
9   /**
10   * Routes messages to the appropriate application.  
11   * 
12   * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
13   */
14  public interface ApplicationRouter {
15  	/**
16  	 * {@link Transportable#getMetadata() Metadata} key: 
17  	 * Charset (MSH-18)
18  	 */
19  	String METADATA_KEY_MESSAGE_CHARSET = "MSH-18";
20  
21  	/**
22  	 * {@link Transportable#getMetadata() Metadata} key: 
23  	 * Message control ID (MSH-10)
24  	 */
25      String METADATA_KEY_MESSAGE_CONTROL_ID = MetadataKeys.IN_MESSAGE_CONTROL_ID;
26  	
27      /**
28  	 * {@link Transportable#getMetadata() Metadata} key: 
29  	 * Provides the IP of the sending system for a given message
30  	 */
31  	String METADATA_KEY_SENDING_IP = MetadataKeys.IN_SENDING_IP;
32  
33      
34      /** 
35       * Attempts to route the given message to the associated <code>Application</code>  
36       * and obtain a response.  
37       * 
38       * @param theMessage the message to route 
39       * @return the response message (this may be null, for example if the given 
40       *      message doesn't require an application ACK)
41       */
42      public Transportable processMessage(Transportable theMessage) throws HL7Exception;
43      
44      /**
45       * @param theRoutingData message fields used in determining the appropriate destination  
46       * @return true if there is a destination application for messages with the given
47       *      characteristics  
48       */
49      public boolean hasActiveBinding(AppRoutingData theRoutingData);  
50          
51      /**
52       * <p>Associates the given application with the given message parameters, so that messages
53       * with matching parameters will be sent there.  Only one application can be registered 
54       * for a given set of parameters: repeated registration for a particular combination 
55       * over-writes the previous one.</p>  
56       * 
57       * <p>Because of wildcards, there may be multiple registrations that match a given message.  
58       * In this case, the first registered wins.</p>  
59       * 
60       * @param theRoutingData message fields used in determining the appropriate destination  
61       * @param theApplication the application to which messages with these parameters should be 
62       *      sent 
63       */
64      public void bindApplication(AppRoutingData theRoutingData, ReceivingApplication theApplication);
65      
66      /**
67       * Temporarily deactivates the binding on the given field data, if present.  
68       * @param theRoutingData the fields that define a set of messages that are bound to 
69       *      some <code>Application</code>  
70       */
71      public void disableBinding(AppRoutingData theRoutingData);
72      
73      /**
74       * Undoes <code>disableBinding(AppRoutingData theRoutingData)</code>.    
75       * @param theRoutingData the fields that define a set of messages that are bound to 
76       *      some <code>Application</code>  
77       */
78      public void enableBinding(AppRoutingData theRoutingData);
79      
80      /**
81       * @return the <code>Parser</code> that is used to parse inbound messages
82       * and encode outbound ones.  It may be of interest to set certain parameters 
83       * of this parser.     
84       */
85      public Parser getParser();
86      
87      /**
88       * Sets an exception handler which will be invoked in the event of a
89       * failure during parsing, processing, or encoding of an
90       * incoming message or its response.
91       */
92      void setExceptionHandler(ReceivingApplicationExceptionHandler exceptionHandler);
93      
94      /**
95       * <p>Encapsulates the message fields used for routing of messages from the 
96       * HL7 protocol to the appropriate <code>Application</code>. </p>   
97       * 
98       * <p>The wildcard "*" in any member indicates all values of the associated parameter.  For 
99       * example the conbination "ADT", "*", "*", "*" means all ADT messages.  Each value can also
100      * be a regular expression that is matched against the corresponding field.  </p>
101      * 
102      * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
103      */
104     public static interface AppRoutingData {
105 
106         /**
107          * @return MSH-9-1
108          */        
109         public String getMessageType(); 
110         
111         /**
112          * @return MSH-9-2
113          */        
114         public String getTriggerEvent();
115         
116         /**
117          * @return MSH-11-1
118          */        
119         public String getProcessingId();
120         
121         /**
122          * @return MSH-12
123          */                
124         public String getVersion();
125     }
126 
127 }