7 Replies Latest reply on Feb 12, 2010 4:41 AM by ENorthby

    HL7 Interface

      I work for a hospital and we have lots of HL7 interfaces. I decided to try and create one to CF using a Socket gateway for a project.
      The Datagate Interface Engine (DIE) seems to talk to my gateway ok, as I am receiving the message, but I am not able to get the DIE to accept my ACKnowledgement that I received the messsage, thus the DIE keeps resending me the same message.
      I removed the socket default response "CRLF > " from the java socket code and recompiled so I can respond with exactly the characters I want. Still no ACK. I tried sending just CHR(06), also tried sending an HL7 message back with the |MSH|^~\&|.... it does not respond.
      I was wondering if anyone else has been successful and if so, what did you do??
      My specs are: CF7.0.1 Enterprise on Win 2003 server. Interface engine is on an AIX box running Datagate.
        • 1. Re: HL7 Interface
          Hi Dan,

          Just wondered whether you'd got anywhere with this. I've been trying to do the same thing, i.e. use socket gateway to receive HL7 messages. One of the issues I ran into is that each segement in the HL7 message is delimited by a carriage return. This results in each segment being received as a separate message, and not necessarily in the same order as in the original HL7 message. I'm able to work around that in this particualr case because I know the order they should be in and am able to rebuld original message. Now like you I'm stuck trying to send a succesful ack message.

          If i understand things correctly the ack message must use the MLLP protocol, i.e. the message must start with chr(11)and end with chr(13) chr(28) . Maybe the socket gateway is unable to return the entire message when it contains carriage returns??

          • 2. Re: HL7 Interface
            Dmadzia Level 1
            This is what I had to do to get this working (yes it works now).
            First I modified the Socket java code. I removed the "CR >" from the code and recompiled the class (not an easy job to get it to compile with all the right stuff).
            I don't think this was necessary, but I did it anyway.

            The CR's in the message are bad as it breaks up the message and it is very difficult for the CFC to "remember" the previous segments since each CR really is another call to the function. So, I had my interface guy change the interface to send CHR(30) which is RS instead of CHR(13) so I get one long record with the standard CHR(28) and CHR(13) at the end. I do a find and if I find a CHR(28) I reply with a return value of CHR(11)&"MSH|^~\&|CFADT|CFADT|DATAGATE|STC|||ACK|"&serialnum&"|P|2.2||"&chr(30)&"MSA|AA|" &serialnum&"||1|"&chr(13)&chr(28)&chr(13)

            Note I pull the serial number out of the message and send it back.
            I also found a usefull function on CFLIB.org called ListGetAtIncNulls(list,position,delimiter) that helps me pull the correct data from the message. The CF listgetat function will not count any list items that are empty (null). This of course throws off where to find data in an HL7 message.

            I think that is all I did. If you want a copy of my test CFC, I will be happy to send it to you. Hope this helps.
            • 3. Re: HL7 Interface
              bobk1 Level 1

              Thanks for the response. That helped me see what I was doing wrong (didn't realize that the MSA part was a separate segment). I got around the carriage return issue by concatenating the various segments in their expected order. Trouble is they arrive asynchronously and not necessarily in the correct order. Your solution sounds better - have to talk to the interface team;-)

              I managed the empty list items by replacing them with a special value:

              theMsg=replace(replace(theMsg,'||', '|@@|','all'),'||', '|@@|','all');

              then substituting '' back when accessing the element:


              But ListGetAtIncNulls looks promising, I'll check that out.


              • 4. Re: HL7 Interface

                Dan, Your knowledge on this matter seems a bit beyond mine. I know this is an old post, but do you have an example of your code? I am attempting a HL7 to CF8 interface (socket gateway), and I'm having the same issue with the acknowledgement response. I'm getting the messages, but i get tons of them because the E*Gate engine never receives a response telling it to stop attempting. Any help would be greatly appreciated.

                • 5. Re: HL7 Interface
                  ENorthby Level 1

                  Bob, I am new to the HL7/CF integration world, and I noticed this posting that looks to be addressing exactly what I'm trying to achieve. Do you have any working examples that you feel comfortable sharing? I know it's been over 3 years since you addressed these issues on the Adobe forum, but any help would be greatly appreciated.


                  Thank you



                  • 6. Re: HL7 Interface
                    Scott_thornton Level 1



                    We re-wrote an hl7 interface to use a .net app instead of CF, as doing so in CF proved unreliable. Check out the software from Symphonia to add some great .dll's to your .net app for message processing.


                    We use the .net app to save the message into a table, acknowledge the message etc. Once its in the database it just text in a big string...


                    BUT, poking around I found some old code from many many many years ago when it was attempted within CF ( not my code, or know who to attribute):


                    it may provide some inspiration. this code took the message and other code saved the string into the database...


                    but stil I would recommned against doing it in cf


                    function createsocket(port) {
                    // Create a server socket, and start listening.

                    // get a socket object
                    getsocket = CreateObject("java", "java.net.ServerSocket");
                    // wait for external connection
                    socket = getsocket.accept();
                    //  If socket pre-exists from a previous program failure, attempt to connect to it, rather than create it.
                    // This code does not actually seem to connect, but does result in the socket dying within about 15 seconds
                    // so that the next invocation of this program can run cleanly.
                    // A restart of the CF application service will also kill any leftover sockets.
                    catch (any excpt) {
                        socket = CreateObject("java", "java.net.Socket");

                    // get an InputStreamReader object
                    inputsr = CreateObject("java", "java.io.InputStreamReader");
                    // call the InputStreamReader constructor

                    // get a BufferedReader object
                    input = CreateObject("java", "java.io.BufferedReader");
                    // call the BufferedReader constructor

                    // get a PrintWriter object
                    printWriter = CreateObject("java", "java.io.PrintWriter");
                    // call the PrintWriter constructor
                    printWriter.init(socket.getOutputStream(), true);

                    return 'OK';

                    function getMsg() {
                    // Read a complete HL7 message from the socket.

                    f_hl7_msg = input.readLine();
                    while (input.ready())
                       f_hl7_msg = f_hl7_msg & Chr(13) & Chr(10) & input.readLine();
                    return f_hl7_msg;

                    function sendAck(msg_id, src, resp) {

                    // Construct and Send the ACK
                    thistime = DateFormat(Now(),'yyyymmdd') & TimeFormat(Now(),'HHmmss');
                    msg_seg = 'MSH|^~\&|'   &
                        src     & '|' &
                                '|' &
                        resp     & '|' &
                                '|' &
                        thistime    & '|' &
                                '|' &
                        'ACK'     & '|' &
                        msg_id  & '|' &
                       'P'     & '|' &
                       '2.3.1'    & '||||';

                    msa_seg   = 'MSA'    & '|' &
                        'AA'     & '|' &
                        msg_id    & '|' &
                        'Message Processed Successfully';
                    hl7_ack  =  CHR(11) &
                         msg_seg & CHR(13) &
                         msa_seg & CHR(13) &
                         CHR(28) & CHR(13);


                    function closePort() {


                    • 7. Re: HL7 Interface
                      ENorthby Level 1

                      Scott, thank you for taking the time to look into this. I was able to accomplish exactly what I was trying to do by working with someone who new a bit more Java than I did. What we did was duplicate the demo event gateway listener in Coldfusion's default instance copied it, renamed it and modified it to deal with HL7 messages. We also created a cfg file to allow us to select the HL7 message that we were interested in picking up as they were sent  across a specified port. We did this all with CF8 and a retrofitted Java component. We may actually decide to sell this one, because I believe there is a need out there for HL7/CF plug-in-play functionality.


                      Again thank you for taking the time to respond to my inquiry. These types of forums keep us all in business!