Beispiel #1
0
        public static void handleDatabaseTableCaller(SqlConnection connection,
                                                     SqlCommand command,
                                                     SqlTransaction transaction,
                                                     HL7Message hl7Message,
                                                     DatabaseTable databaseTable,
                                                     string hl7Input,
                                                     HL7Broker.Model.Socket socket,
                                                     out int identity)
        {
            // set to negative one
            identity = -1;

            switch (databaseTable.id)
            {
            case APP_MESSAGE_HEADER_INSTANCE:
                identity = MessageHeaderInstanceDAO.insertIntoMessageHeaderInstance(
                    connection,
                    command,
                    transaction);
                break;

            case APP_MESSAGE:
                identity = MessageDAO.insertIntoMessage(
                    connection,
                    command,
                    transaction);

                // get the type of log we are suppose to log
                MessageLogDAO.MessageLogType logType
                    = handleAcknowledgement(hl7Message, hl7Input, identity, socket);

                // pass it to the message log so we can log it
                handleMessageLog(hl7Message, hl7Input, identity, logType);

                // update the app broker stats
                handleUpdateBrokerStats(identity, socket);
                break;

            default:
                break;
            }
        }
Beispiel #2
0
        public static void handleMessageLog(HL7Message hl7Message,
                                            string hl7Input,
                                            int messageIdentity,
                                            MessageLogDAO.MessageLogType logType)
        {
            try
            {
                // build MessageLog Entry
                MessageLog messageLogEntry = new MessageLog()
                {
                    id = NEG_ONE,
                    messageLogTypeId = (int)logType,
                    messageId        = messageIdentity,
                    createdDttm      = DateTime.Now
                };

                // insert into the MessageLog
                messageLogEntry = MessageLogDAO.insertIntoMessageLog(messageLogEntry);
            }
            catch (Exception e)
            {
                ErrorLogger.LogError(e, "handleMessageLog()", messageIdentity.ToString());
            }
        }
Beispiel #3
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);
        }