Properties and methods¶
Properties¶
All the properties are valid for the duration of a Servoy session, meaning that you usually set them once for a particular server.
You can override them on a call by call basis though. Just make sure the values are set before calling the sendAndRetrieve() method.
server¶
A String: it is a mandatory property, meaning that until set, you will not be able to use the sendAndRetrieve() method.
You can use a name (domain name or network name) or an IP.
No default for this property.
port¶
An Integer: also mandatory property, until it is set you will not be able to use the sendAndRetrieve() method.
No default for this property
startPattern¶
A String: the pattern used by the protocol to start a message. This is added before the String received as parameter to the sendAndRetrieve() method when sending a message to the server.
Default value = \t - as defined by default for HL7 communications.
endingPattern¶
A String: the pattern used by the protocol to end a message. This is added after the String received as parameter to the sendAndRetrieve() method when sending a message to the server.
This is also the pattern which is waited for by the plugin to decide whether a message received is finished, close the communication and return the response.
Default value = char [13,28,13] or String.formChar( 13, 28, 13 ) - as defined by default for HL7 communications.
timeout¶
An Integer: the number of milliseconds to wait for a server to respond before spilling an I/O Exception
Default: 10000 - as defined by default for HL7 communications.
retries¶
An Integer: the number of attempts made by the plugin to send and retrieve a message.
Default: 3
Methods¶
sendAndRetrieve¶
You use this method to send a message to a server, and retrieve his response.
You can use it either synchronously, with this signature:
String sendAndRetrieve( String message )
or asynchronously, with this signature:
void sendAndRetrieve( String message, Function callback )
Syncrhonously, the method will be a blocking call, meaning the client will be blocked until a response is retrieved from the server (and sent back to the calling Servoy client), or an Exception happened during the process (and after a certain number of retry attempts). Typically you will use it like this:
var answer = plugins.hl7.sendAndRetrieve(hl7Message);
Asyncrhonously, the method will not block the client. The call will return immediately (without any response), but will call a callback Function when the response is retrieved from the server. Typically, you will use it like this:
function sendMessage( hl7Message ) { try { plugins.hl7.sendAndRetrieve( hl7Message, hl7Callback ); } catch (e) { application.output( e ); } } function hl7Callback( msg, exception ) { if ( msg ) { // do something with the message here } else { // treat the exception (log, display the error, etc.) // the exception has 2 methods available: application.output( exception.getMessage() ); application.output( exception.getStackTrace() ); } }
getVersion¶
A convenience method to get the exact version used by the client, returns the plugin version as a String.
application.output( 'HL7 Plugin v.' + plugins.hl7.getVersion() );