Copyright © infotec016 . Powered by Blogger.

Monday, December 9, 2019

Compiler Design - Definitions


Lexical analysis
Lexical analyzer reads the source program character by character and returns the tokens of the source program. The tokens represent pattern of characters which have the same meaning such as identifiers, operators, numbers and etc.

Syntax analysis
Syntax analyzer re-combine the tokens and create a graphical representation of the syntactic structure (syntax tree). In addition to that, it rejects the invalid string by reporting the syntax error.
In syntax tree the terminals are at the leave nodes and the inner nodes are non-terminals

Context-free grammar
Context-free grammar is a set of rules for putting strings together and so correspondent to a language.

Parse tree
Parse tree is a ordered rooted tree that graphically represents the semantic of a string derived from a context free grammar.

Top-Down approach
It starts from the start symbol(root) and goes down to leaves using production rules.

Bottom-Up approach
It starts from the leave and proceeds upwards to the root which is  a starting symbol.

Left most derivation
A left most derivation is obtained by applying the production to the left most variable or left most non terminal in each step.

Right most derivation
A right most derivation is obtained by applying the production to the right most variable or right most non terminal in each step.

Ambiguous grammar
A grammar is said to be ambiguous if any string generated by it has more than one parse tree or derivation tree or syntax tree or left most derivation or right most derivation.

Unambiguous grammar
A grammar is said to be unambiguous if a string generated by it has exactly one parse tree or derivation tree or syntax tree or left most derivation or right most derivation.

Left recursion
A production of a grammar is said to have left recursion if the left most variable or non-terminal of the right hand side is same as the variable or non-terminal of the left hand side.

Right recursion
A production of a grammar is said to have right recursion if the right most variable or non-terminal of the right hand side is same as the non-terminal or variable of left hand side.

Associativity
If an operand has operators on both side, then the side on which the operator takes the operand is associativity of that operator.

Precedence
Precedence determines which part operator is performed first in an expression with more than one operators with different precedence level.

Left factorization
In left factorizing, it is not clear that which of the two alternative production to use expand a non-terminal that is A -> ab/ac.

Thursday, December 5, 2019

BST - Binary Search Tree


For any node x,
    the keys in left sub tree of x are at most x.key and
    the keys in right sub tree of x are at least x.key.



Here the fisrt is BST but in the second 11 should not be in the left side of 10.

Binary Search Tree Property
   Let x be a node in BST.
   Let y be a node in left sub tree of x and
   Let z be a node in the right sub tree of y then
   y.key <= x.key and z.key > = x,key
Binary search average case-> O(lg n)
                       worst case -> O(n)
                       best case -> O(1)

Inorder tree walk
left --- root --- right

INORDER-TREE-WALK(x)
if(≠  NIL)
       INORDER-TREE-WALK(x.left)
       print x.key
       INORDER-TREE-WALK(x.right)


Preorder tree walk
root --- left --- right

PREORDER-TREE-WALK(x)
if(≠  NIL)
       print x.key
       PREORDER-TREE-WALK(x.left)
       PREORDER-TREE-WALK(x.right)


Postorder tree walk
left --- right --- root

POSTORDER-TREE-WALK(x)
if(≠  NILL)
       POSTORDER-TREE-WALK(x.left)
       POSTORDER-TREE-WALK(x.right)
       print x.key




INORDER TRAVERSAL
P, H, A, K, C, T, Q, M, R

PREORDER TRAVERSAL
C, H, P, K, A, M, T, Q,  R

POSTORDER TRAVERSAL
P,A, K, H, Q, T, R, M, C

If x is root of an n-node subtree, then the call INORDER-TREE-WALK(x) takes time O(n)

Searching

x- current node , k- search key
TREE-SEARCH(x, k)
if ( x == NIL or k == x.key)
       return x
if( k < x.key)
       return TREE-SEARCH(x.left, k)
else
       return TREE-SEARCH(x.right, k)

ITERATIVE TREE-SEARCH(x, k)
while( x  NIL or k  x.key)
         if( k < x.key)
                x = x.left
          else
                 x = x.right           return x

The running time of tree-search is O(h),  where h is height of tree.

Minimum


TREE-MINIMUM(x)
while(x.left  NIL)
      x = x.left
return x

Maximum
     
TREE-MAXIMUM(x)
while(x.right  NIL)
      x  =  x.right
return x

The running time of minimum and maximum is O(h),  where h is height of tree.



Successor

TREE-SUCCESSOR(x)
if(x.right  NIL)
      return TREE-MINIMUM(x.right)
y = x.p
while( y    NIL and x == y.right)
       x = y
       y = y.p
return y

Maximum
   
TREE-PREDECESSOR(x)
if(x.left    NIL)
       return TREE-PREDECESSOR(x.left)
y = x.p
while( y    NIL and x == y.left)
        x = y
        y = y.p
return y

Simply, Inorder successor of the node x is the smallest value node of its right subtree and the inorder predecessor of the node x is the largest value of its right subtree.






INORDER SUCCESSOR OF C -> T

INORDER PREDECESSOR OF C -> K

Insertion

The new element will be inserted by considering left and right subtree values. 
T- binary tree, z-new node


TREE-INSERT(T, z)
y = NIL
x = T.root
while( x  NIL)
       y = x
       if( z.key < x.key)
              x = x.left
        else
              x = x.right
z.p = y
if( y == NIL)
    T.root = z
else if( z.key < y.key)
     y.left = z
else
     y.right = z

Deletion

Deleting a node z from a binary search tree T has 3 cases:
If z has no children, then simply remove it by replacing with NIL
If z has only one child, then remove the z by replacing the child node of z with the z.
If z has two children then find the successor(y) and replace it with z. Original right and left subtrees of z becomes y's new subtrees.



TRANSPLANT(T, u, v)
if (u.p == NIL)
     T.root = v
else if (u == u.p.left)
      p.p.left = c
else if (u == u.p.right)
      u.p.right == v
if (v  NIL)
      v.p = u.p


TREE-DELETE(T, z)
if (z.left == NIL)
       TRANSPLANT(T, z, z.right)
else if(z.right == NIL)
       TRANSPLANT(T, z, z.left)
else
       y = TREE-MINIMUM(z.right)
       if (y.p  z)
             TRANSPLANT(T, y, y.right)
              y.right = z.right
              y.right.p = y
       TRANSPLANT(T, z, y)
        y.left = z.left
        y.left.p = y

Randomly build binary search tree

Wednesday, November 27, 2019

Machine - learning methods


Classification learning

classification learning is supervised.(Predicting a discrete class)
label is provided with actual outcome.


Association learning

detecting association between features.
it can be applied if no class is specified and any kind of structure is considered as "interesting".

Clustering

Finding group of items that are similar.
It is unsupervised


Numeric prediction

Variant of classification learning where class is numeric

Saturday, November 23, 2019

Wednesday, November 13, 2019

NLP- Natural Language Processing


Natural Language Processing is the technology used to aid computers to understand the human’s natural language.

Different level of analysis for natural language

Prosody: Deals with rhythm and intuition of the language
Phonology: Examined the sound that are combined to from language
Morphology: Concern with the components that make up words 
Syntax: Studies the rules for combining words into legal phrases and sentences
Semantics: Consider the meaning of words
Pragmatics: Study of the ways in which the language is used and its effects on the listener
World knowledge: Include the knowledge of the physical world, interaction and intention in communication

Specification and Parsing using Context-Free Grammar


Phrase structure plays an essential role in semantic interpretation by defining intermediate stages in a derivation at which semantic processing may take place.

Parsing algorithm has 2 types:
 Top-down Parser:
     It begins with a top-level Sentence symbol and expand the tree whose leaves match the target sentence.
 Bottom-up Parser:
     It begins with the word symbols (terminal) attempt to find a series of reductions that leads to the Sentence Symbol.

Sample grammar rules

Sentence <-> noun_phrase verb_phrase
noun_phrase <-> noun
noun_phrase <-> article noun
verb_phrase <-> verb
verb_phrase <-> verb noun_phrase
prep_phrase <-> preposition noun_phrase
noun_phrase <-> noun_phrase prep_phrase
verb_phrase <-> verb prep_phrase
article <-> a/ the
noun <-> cat/ Mango
verb <-> eat/ like
preposition <-> on

Tuesday, November 12, 2019

Red Black Tree


Rules


  • Self-balancing Binary Search Tree
  • The node color can be either red or black (It is possible to have all black nodes but impossible to have all red nodes)
  • The root node must be black
  • There is no two red adjacent nodes (It will not have a parent and a child node in red color)
  • NULL node is always black
  • Every path from root to NULL node should have the same number of black nodes


Insertion


  • If tree is empty, create a root node with black color
  • If tree node is not empty, create a new child node as leaf node with red color
  • If parent of new node is black then do nothing 
  • If parent of new node is red then check the color of parent's sibling of new node (uncle of new node)
    •      If the sibling node is black or NULL then do suitable rotation and re-color 
    •      If the sibling node is red then re-color and check grand parent of new node
      •         If grand parent is root then do nothing
      •         else change the color of grand parent node and recheck 

Deletion


Sunday, November 10, 2019

Saturday, November 9, 2019

Git Commands


To find git version
>> git --version

Initialize a new repository and push
>> git init <repo_name>

Create your files to upload  to the repository created in your machine

To see the status.. It will show the modified files in the directory
>> git status

To add the file
>> git add <file_name>

To commit
>> git commit -m "leave your commit message here"

To see the branch
>> git branch

Add the upstream
>> git remote add upstream <repo_url>

Fetch the changes from upstream to your local repository
>> git fetch upstream master

To push
>> git push

To clone a existing repository in your local machine
>>git clone <repo_url>

To remove a file
>> git rm <file_name>









Tuesday, July 23, 2019

Friday, July 19, 2019

Raster graphics and Vector graphics


Raster Graphics                                                                       Vector graphics

This is composed of pixels                                              This is composed of paths

No File records                                                                 Maintain a record of start and end, number 
                                                                                          of lines , number of straight and curve lines
                                                                                          and colours used

Quality is lost when size changes                                     Quality is not change when size changes

Use less memory space                                                     Use more memory space

Not suitable for high quality creations                             Suitable for high quality creations     

Friday, April 5, 2019

Maven Repository


Maven repository is a directory that contained packaged JAR files. 
Maven searches for dependencies in the repositories.
It searches for dependencies first in the local repository which is located in the local system created by maven when you run any maven command.
The directory is named as .m2 by default.
Second, It searches for maven central repository which is located in the web created by the apache maven community itself
Third, It searches for remote repository which is located on the web. We need to define remote repository in pom file.

Tuesday, February 26, 2019

HL7 - Intro


HL-7 is an international standard used to exchange medical records between healthcare systems. It is introduced by Health level 7 international which is an non profit organization.

Health Level Seven refers to the seventh level(Application Layer) of OSI Model(Open System Interconnection). It specifies communication contents and exchange formats on the 7th layer on OSI.

Application layer addresses the definition of data to be exchanged, the timing of the interchange and communication of certain errors to the application.

Application layer function supports security check, availability check, exchange mechanism negotiation and data exchanging structuring.

Monday, February 25, 2019

HL-7 Version 2 Message Structure


Message

Message is the smallest transferable unit in hl7 and is composed of segments. It begins with the message header Segment(MSH) and is identified by the message type and the initiating event (trigger event).


Segments 

Segments are a way of grouping of items in a logical way. Segments are clearly identified by three letters located at the beginning(Segment Identifier) and are separated by segment separators.
Here, all segments beginning with Z are reserved for locally defined messages.


Fields

The information are contained in the fields of the segments. These fields are in variable length and are separated by field separators.
For each field. a data type is defined.
Field contents can be required or optional and individual fields can be repeated.
Multi component fields are used for further sub division of a field and facilitate the transmission of logically related contents.


Abstract Message Syntax



Hl7 Messages are structured using Abstract Message Syntax to enable straight forward exchange. This describes the frequency of occurrence (cardinality) and definition (required/optional/repeatable) of control and data segments in a message.
Required segments are identified by the segment identifiers, optional segments enclosed in [], repeatable in {}.


Encoding Rules

HL7 provides a specification for the presentation of data. The separating are as follows:

Every message begins with the information about the message itself.
|   => Field Separator
^ => Component Separator
~ = Repetition Separator
\  => Escape Character
& => Subcomponent Separator 


Message Segments 

MSH => Message header
PID => patient identity
PV1 => patient visit information
NK1 => patient’s Next of Kin
EVN => event type
OBX => observation/result
AL1  => Allergy information 
DG1 => Diagnosis information 
DRG => Diagnosis related group 
PR1 => procedures
ROL => Role
IN1 => Insurance
ACC => Accident information
ROL => Role
PDA => Patient death and autopsy


Message Types

ADT => Admission Transfer Discharge
ORM => Order (Pharmacy/ Treatment)
ORU => Observation Result
BAR => (Add/ Change) Billing Account
ACK=> General Acknowledgement
DFT => Detailed Financial Transaction
MDM  => Medical Document Management 
MFN => Master Files Notification
RAS => Pharmacy/ Treatment Administration
RDE => Pharmacy/ Treatment Encoded Order
RGV => Pharmacy/ Treatment Give

Message Structure




Sunday, February 24, 2019

Handling HAPI Test Panel


What is HAPI Test Panel


HAPI Test Panel is a full featured HL7 message editor, used to send and receive HL7 messages.

Install TestPanel

  • Download hapi-testpanel-2.0.1-linux.tar.bz2 from here
  • Extract the download to your perfect location
  • In Ubuntu, run the testpanel.sh file which is at the Home of the Hapi Test Panel extraction
  • In Windows, run the testpanel Application which is at the Home of the Hapi Test Panel extraction

Sending HL7 messages using Testpanel





Creating Sample HL7 Message


  • Go to Test menu and click Populate TestPanel with sample message and connections
  • You can send the message by clicking the send button 






Sending HL7 messages

  • You can click the plus button which is in the Sending Connections panel in the left menu
  • You can give your appropriate Port number, encoding schemes and etc under the Setting menu 
  • You can see the activities through the selected port under the Activity



Receiving HL7 messages

  • You can click the plus button which is in the Receiving Connections panel in the left menu
  • You can give your appropriate Port number, encoding schemes and etc under the Setting menu 
  • You can see the activities through the selected port under the Activity




Creating different type of HL7 messages

  • Go to File which is in the main menu and click the New Message 
  • Select the appropriate message version and message type


Saturday, February 23, 2019

Hl7 Simple Java Client


HL7 Sender Java Code


package hl7sender;
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.app.Connection;
import ca.uhn.hl7v2.app.Initiator;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.Parser;

public class hl7sender {

   public static void main(String[] args) {

final int PORT_NUMBER = 9014;
// In HAPI, almost all things revolve around a context object.
HapiContext context = new DefaultHapiContext();

      try {
        String adtMessage = "MSH|^~\\&|NES|NINTENDO|TESTSYSTEM|TESTFACILITY|" + "20010101000000||ADT^A01|Q123456789T123456789X123456|P|2.3\r" + "EVN|A01|20010101000000|||^KOOPA^BOWSER\r" + "PID|1||123456789|0123456789^AA^^JP|BROS^MARIO||19850101000000|" + "M|||123 FAKE STREET^MARIO \\T\\ LUIGI BROS PLACE^TOADSTOOL" + "KINGDOM^NES^A1B2C3^JP^HOME^^1234|1234|(555)555-0123^HOME^JP:" + "1234567|||S|MSH|12345678|||||||0|||||N\r" + "NK1|1|PEACH^PRINCESS|SO|ANOTHER CASTLE^^TOADSTOOL KINGDOM" + "^NES^^JP|(123)555-1234|(123)555-2345|NOK\r" + "NK1|2|TOADSTOOL^PRINCESS|SO|YET ANOTHER CASTLE^^TOADSTOOL" + "KINGDOM^NES^^JP|(123)555-3456|(123)555-4567|EMC\r" + "PV1|1|O|ABCD^EFGH||||123456^DINO^YOSHI^^^^^^MSRM^CURRENT" + "^^^NEIGHBOURHOOD DR NBR|^DOG^DUCKHUNT^^^^^^^CURRENT||CRD||" + "|||||123456^DINO^YOSHI^^^^^^MSRM^CURRENT^^^NEIGHBOURHOOD DR" + " NBR|AO|0123456789|1|||||||||||||||||||MSH||A|||20010101000000\r" + "IN1|1|PAR^PARENT||||LUIGI\r";

// create a new MLLP client over the specified port.
Connection connection = context.newClient("localhost", PORT_NUMBER, false);

// The initiator which will be used to transmit our message.
Initiator initiator = connection.getInitiator();

// send the created HL7 message over the connection established
Parser parser = context.getPipeParser();

System.out.println("Sending message:" + "\n" + adtMessage);
Message response = initiator.sendAndReceive(parser.parse(adtMessage));

// display the message response received from the remote party
String responseString = parser.encode(response);
System.out.println("Received response:\n" + responseString.replaceAll("\r", "\n"));
        }
        catch (Exception e) {
           e.printStackTrace();
        }
   }
}


HL7 Receiver Java Code

This main class is used to


package hl7receiver;

import ca.uhn.hl7v2.DefaultHapiContext;

import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.app.HL7Service;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.PipeParser;

public class hl7receiver {

    public static void main(String args[]) {

        final int PORT_NUMBER = 9014;
        //In HAPI,almost all things revolve around a context object
        HapiContext context = new DefaultHapiContext();
        try {
            Parser parser = new PipeParser();
            HL7Service ourHl7Server =                   context.newServer(PORT_NUMBER, false);
            // You can set up routing rules for your HL7 listener by extending the AppRoutingData class
            ourHl7Server.registerApplication(new     RegisterEventRouter(), new ourSimpleApplication());
            ourHl7Server.setShutdownTimeout(10000);
            ourHl7Server.startAndWait();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


Simple Application class that is used to receive the message and create and send the acknowledgement

package hl7receiver;

import ca.uhn.hl7v2.HL7Exception;

import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.protocol.ReceivingApplication;
import ca.uhn.hl7v2.protocol.ReceivingApplicationException;

import java.io.IOException;
import java.util.Map;

public class ourSimpleApplication implements ReceivingApplication {

    PipeParser pipeParser = new PipeParser();

    public Message processMessage(Message message, Map map) throws
 ReceivingApplicationException, HL7Exception {

        System.out.println("Received Message\n" + pipeParser.encode(message));
        Message response = null;
        try {
            response = message.generateACK();
            System.out.println("Sent Response\n" + pipeParser.encode(response));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return response;
    }

    public boolean canProcess(Message message) {

        return true;
    }
}



Event Router class that is used to rout the message to the appropriate versions and types.


package hl7receiver;

import ca.uhn.hl7v2.protocol.ApplicationRouter;


public class RegisterEventRouter implements ApplicationRouter.AppRoutingData {

    public String getMessageType() {

        return "*";
    }

    public String getTriggerEvent() {

        return "*";
    }

    public String getProcessingId() {

        return "*";
    }

    public String getVersion() {

        return "*";
    }

}

Friday, February 22, 2019

Hl7 Java Client with Tls


HL7 Sender Java Code


package hl7senderwithTls;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.app.Connection;
import ca.uhn.hl7v2.app.Initiator;
import ca.uhn.hl7v2.hoh.sockets.CustomCertificateTlsSocketFactory;
import ca.uhn.hl7v2.hoh.util.HapiSocketTlsFactoryWrapper;
import ca.uhn.hl7v2.hoh.util.KeystoreUtils;
import ca.uhn.hl7v2.llp.LLPException;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.Parser;

import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

public class hl7senderwithTls {

    public static void main(String[] args) throws HL7Exception, 
     LLPException, IOException {

        final int PORT_NUMBER = 9014;
        final String tlsKeystoreFilepath = "src/main/resources/keystore.jks";
        final String tlsKeystorePassphrase = "changeit";
        final String tlsKeystoreType = "JKS";

        // InHAPI almost all things revolve around a context object
        HapiContext context = new DefaultHapiContext();

        String adtMessage = "MSH|^~\\&|NES|NINTENDO|TESTSYSTEM|TESTFACILITY" + 
                "|20010101000000||ADT^A01|Q123456789T123456789X123456|P|2.3\r" +
                "EVN|A01|20010101000000|||^KOOPA^BOWSER\r";
        try {
            //To validate the keystore
            KeyStore keyStore = KeystoreUtils.loadKeystore(tlsKeystoreFilepath, 
             tlsKeystorePassphrase);
            KeyStore.getInstance(tlsKeystoreType);
            KeystoreUtils.validateKeystoreForTlsSending(keyStore);
            CustomCertificateTlsSocketFactory tlsFac = new 
             CustomCertificateTlsSocketFactory(tlsKeystoreType,
                    tlsKeystoreFilepath, tlsKeystorePassphrase);
            context.setSocketFactory(new HapiSocketTlsFactoryWrapper(tlsFac));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        }
        // create a new MLLP client over the specified port
        Connection connection = context.newClient("localhost", PORT_NUMBER, true);

        // The initiator which will be used to transmit our message
        Initiator initiator = connection.getInitiator();

        // send the created HL7 message over the connection established
        Parser parser = context.getPipeParser();
        System.out.println("Sending message:" + "\n" + adtMessage);
        Message response = initiator.sendAndReceive(parser.parse(adtMessage));

        // display the message response received from the remote party
        String responseString = parser.encode(response);
        System.out.println("Received response:\n" + responseString.replaceAll("\r", "\n"));

    }
}

HL7 Receiver Java Code

This main class is used to


package hl7receiverwithTls;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.app.HL7Service;
import ca.uhn.hl7v2.hoh.sockets.CustomCertificateTlsSocketFactory;
import ca.uhn.hl7v2.hoh.util.HapiSocketTlsFactoryWrapper;
import ca.uhn.hl7v2.hoh.util.KeystoreUtils;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.PipeParser;

import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

public class hl7receiverwithTls {
    public static void main(String[] args) throws InterruptedException {

        final int PORT_NUMBER = 9014;
        final String tlsKeystoreFilepath = "src/main/resources/keystore.jks";
        final String tlsKeystorePassphrase = "changeit";
        final String tlsKeystoreType = "JKS";
        // In HAPI, almost all things revolve around a context object
        HapiContext context = new DefaultHapiContext();
        try {
            //To validate the keystore
            KeyStore keyStore = KeystoreUtils.loadKeystore(tlsKeystoreFilepath, tlsKeystorePassphrase);
            KeyStore.getInstance(tlsKeystoreType);
            KeystoreUtils.validateKeystoreForTlsSending(keyStore);
            CustomCertificateTlsSocketFactory tlsFac = new CustomCertificateTlsSocketFactory(tlsKeystoreType,
                    tlsKeystoreFilepath, tlsKeystorePassphrase);
            context.setSocketFactory(new HapiSocketTlsFactoryWrapper(tlsFac));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        }
            Parser parser = new PipeParser();
            HL7Service ourHl7Server = context.newServer(PORT_NUMBER, true);
            // You can set up routing rules for your HL7 listener by extending the AppRoutingData class
            ourHl7Server.registerApplication(new RegisterEventRouter(), new ourSimpleApplication());
            ourHl7Server.setShutdownTimeout(10000);
            ourHl7Server.startAndWait(); 
    }
}


Simple Application class that is used to receive the message and create and send the acknowledgement

package hl7receiverwithTls;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.protocol.ReceivingApplication;
import ca.uhn.hl7v2.protocol.ReceivingApplicationException;

import java.io.IOException;
import java.util.Map;

public class ourSimpleApplication implements ReceivingApplication {

    PipeParser pipeParser = new PipeParser();

    public Message processMessage(Message message, Map map) throws ReceivingApplicationException, HL7Exception {

        System.out.println("Received Message\n" + pipeParser.encode(message));
        Message response = null;
        try {
            response = message.generateACK();
            System.out.println("Sent Response\n" + pipeParser.encode(response));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return response;
    }

    public boolean canProcess(Message message) {

        return true;
    }
}


Event Router class that is used to rout the message to the appropriate versions and types.


package hl7receiverwithTls;

import ca.uhn.hl7v2.protocol.ApplicationRouter;

public class RegisterEventRouter implements ApplicationRouter.AppRoutingData {

    public String getMessageType() {

        return "*";
    }

    public String getTriggerEvent() {

        return "*";
    }

    public String getProcessingId() {

        return "*";
    }

    public String getVersion() {

        return "*";
    }

}