Esempio n. 1
0
        public static void handleAckForService(HL7Message hl7Message, Message message, string ackResponseMessage)
        {
            // get the message control id to build the ack
            string messageControlId = HL7MessageUtility.getValueByPosition(hl7Message,
                                                                           SegmentType.MSH,
                                                                           MESSAGE_HEADER_CONTROL_ID);
            // get the message date stamp
            string messageDateStamp = HL7MessageUtility.getValueByPosition(hl7Message,
                                                                           SegmentType.MSH,
                                                                           MESSAGE_DATE_STAMP_POSITION);

            // get the correct ack response
            bool isRejected = ShieldsExpressLinkUtility.handleCheckApplicationRejected(ackResponseMessage);

            // if the ack message is rejected, apply act type
            AcknowledgementDAO.AcknowledgementType ackMessageEnum
                = (isRejected) ? AcknowledgementDAO.AcknowledgementType.AR:
                  AcknowledgementDAO.AcknowledgementType.AA;

            // get ack response
            string strAckResponse = HL7MessageUtility.getAck(ackMessageEnum.ToString(),
                                                             messageControlId,
                                                             messageDateStamp,
                                                             MESSAGE_HEADER_APPLICATION_NAME,
                                                             MESSAGE_HEADER_FACILITY_NAME,
                                                             ackResponseMessage);

            // build ack response
            Acknowledgement ackResponse = new Acknowledgement()
            {
                acknowledgementTypeId = (int)ackMessageEnum,
                messageId             = message.id,
                raw         = strAckResponse,
                createdDttm = DateTime.Now
            };

            // insert into ack
            AcknowledgementDAO.insertIntoAcknowledgement(ackResponse);
        }
Esempio n. 2
0
        public static MessageLogDAO.MessageLogType handleAcknowledgement(HL7Message hl7Message,
                                                                         string hl7Input,
                                                                         int messageIdentity,
                                                                         HL7Broker.Model.Socket socket)
        {
            string ackResponseMessage = BLANK;

            AcknowledgementDAO.AcknowledgementType ackType
                = AcknowledgementDAO.AcknowledgementType.UNKNOWN;

            MessageLogDAO.MessageLogType logType
                = MessageLogDAO.MessageLogType.UNKNOWN;

            if (messageIdentity == NEG_ONE)
            {
                // swap it to 9999 so we don't insert a neg value
                messageIdentity    = ERROR_CODE_NINE;
                ackType            = AcknowledgementDAO.AcknowledgementType.AE;
                ackResponseMessage = ERROR_MESSAGE_FROM_BROKER;
            }
            else if (messageIdentity == ZERO)
            {
                ackType            = AcknowledgementDAO.AcknowledgementType.AR;
                ackResponseMessage = ERROR_MESSAGE_REJECTED;
            }
            else
            {
                ackType            = AcknowledgementDAO.AcknowledgementType.AA;
                ackResponseMessage = MESSAGE_NO_ERROR;
            }

            // get the message control id to build the ack
            string messageControlId = HL7MessageUtility.getValueByPosition(hl7Message,
                                                                           SegmentType.MSH,
                                                                           MESSAGE_HEADER_CONTROL_ID);

            string messageDateStamp = HL7MessageUtility.getValueByPosition(hl7Message,
                                                                           SegmentType.MSH,
                                                                           MESSAGE_DATE_STAMP_POSITION);
            // get ack response
            string strAckResponse = HL7MessageUtility.getAck(ackType.ToString(),
                                                             messageControlId,
                                                             messageDateStamp,
                                                             MESSAGE_HEADER_APPLICATION_NAME,
                                                             MESSAGE_HEADER_FACILITY_NAME,
                                                             ackResponseMessage);

            try
            {
                // build ack response
                Acknowledgement ackResponse = new Acknowledgement()
                {
                    id = NEG_ONE,
                    acknowledgementTypeId = (int)ackType,
                    messageId             = messageIdentity,
                    raw         = strAckResponse,
                    createdDttm = DateTime.Now
                };

                // insert into the acknowledgement
                ackResponse = AcknowledgementDAO.insertIntoAcknowledgement(ackResponse);

                logType = (ackResponse.id != NEG_ONE) ? MessageLogDAO.MessageLogType.ORIGINAL
                                                      : MessageLogDAO.MessageLogType.ERRORED;


                // get the network stream to send the ack back
                NetworkStream stream = socket.getNetworkStream();

                // pad the hl7 msesage for transfer
                strAckResponse = HL7MessageUtility.padHL7MessageForTransfer(strAckResponse);

                stream.Write(Encoding.UTF8.GetBytes(strAckResponse), 0, strAckResponse.Length);
            }
            catch (Exception e)
            {
                ErrorLogger.LogError(e, "handleAcknowledgement()", messageControlId);
            }

            // send the ack message

            // return the type of log we are submitting
            return(logType);
        }
Esempio n. 3
0
        private void run()
        {
            // create bye buffer the size of the input
            Byte[] buffer = new Byte[MAX_MESSAGE_SIZE];

            // set connected here
            TcpClient tcpClient = this.tcpListener.AcceptTcpClient();

            if (tcpClient.Connected)
            {
                if (this.broker.interfaceStatusId != BrokerDAO.CONNECTED)
                {
                    // update interface broker status to connected since we are connected
                    this.broker.interfaceStatusId = BrokerDAO.CONNECTED;

                    // set worklist to waiting
                    BrokerDAO.UpdateAppBrokerProperty(this.broker, BrokerDAO.Property.Status);
                }
            }
            else
            {
                startWaiting();
            }

            // get the data
            String data = null;

            // get the network stream
            this.networkStream = tcpClient.GetStream();

            // define stream byte index
            int byteIndex = 0;

            try
            {
                // define stream byte index
                // Loop to receive all the data sent by the client.
                while ((byteIndex = this.networkStream.Read(buffer, 0, buffer.Length)) != 0)
                {
                    // Translate data bytes to a ASCII string.
                    data = System.Text.Encoding.UTF8.GetString(buffer, 0, byteIndex);

                    // if for some reason we can't process the message, we'll reject it (hopefully)
                    try
                    {
                        // pass it over to inbound delegate delegate
                        this.incomingHandler(data.ToString(), this.incomingCommunication, this);
                    }
                    catch (Exception e)
                    {
                        // this means we had trouble parsing the message when it came in.
                        string ackRejected = HL7MessageUtility.getAck(AcknowledgementDAO.AcknowledgementType.AR.ToString(),
                                                                      ERROR_CONTROL_ID,
                                                                      DateTime.Now.ToString(),
                                                                      MESSAGE_HEADER_APPLICATION_NAME,
                                                                      MESSAGE_HEADER_FACILITY_NAME,
                                                                      ERROR_MESSAGE_REJECTED);

                        // build ack response
                        AcknowledgementDAO.insertIntoAcknowledgement(new Acknowledgement()
                        {
                            id = NEG_ONE,
                            acknowledgementTypeId = (int)AcknowledgementDAO.AcknowledgementType.AE,
                            messageId             = 0,
                            raw         = ERROR_MESSAGE_REJECTED,
                            createdDttm = DateTime.Now
                        });

                        // pad the hl7 msesage for transfer
                        ackRejected = HL7MessageUtility.padHL7MessageForTransfer(ackRejected);

                        // write back
                        this.networkStream.Write(Encoding.UTF8.GetBytes(ackRejected), 0, ackRejected.Length);

                        // move on, don't stop
                        continue;
                    }

                    // pass it over to the outbound delegate
                    this.outgoingdHandler(data.ToString(), this.outgoingCommunication, this);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex, "run()");
            }
            finally
            {
                // Shutdown and end connection
                tcpClient.Close();
                // if the user is disconnected - set to waiting
                startWaiting();
            }
            // Shutdown and end connection
            tcpClient.Close();
        }