private static ApplicationSetting postUpdateApplicationSetting(ApplicationSetting applicationSetting)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_APPLICATION_SETTING;
                command.Parameters.AddWithValue(ApplicationSettingDAO.AT_APPLICATION_ID, applicationSetting.applicationId);
                command.Parameters.AddWithValue(ApplicationSettingDAO.AT_COMMUNICATION_ID, applicationSetting.communicationId);
                command.Parameters.AddWithValue(ApplicationSettingDAO.AT_DISABLED, applicationSetting.disabled);
                command.Parameters.AddWithValue(ApplicationSettingDAO.AT_AUTOSTART, applicationSetting.autoStart);
                command.Parameters.AddWithValue(ApplicationSettingDAO.AT_ID, applicationSetting.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            applicationSetting.id = DAOUtility.GetData <int>(reader, ApplicationSettingDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateApplicationSetting()", applicationSetting.id.ToString());
                }
            }
            return(applicationSetting);
        }
Exemplo n.º 2
0
        private static Communication postUpdateCommunication(Communication communication)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_COMMUNICATION;
                command.Parameters.AddWithValue(CommunicationDAO.AT_DIRECTION_TYPE_ID, communication.directionTypeId);
                command.Parameters.AddWithValue(CommunicationDAO.AT_COMMUNICATION_TYPE_ID, communication.communicationTypeId);
                command.Parameters.AddWithValue(CommunicationDAO.AT_APPLICATION_ID, communication.applicationId);
                command.Parameters.AddWithValue(CommunicationDAO.AT_ID, communication.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            communication.id = DAOUtility.GetData <int>(reader, CommunicationDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateCommunication()", communication.id.ToString());
                }
            }
            return(communication);
        }
Exemplo n.º 3
0
        private static MessageGroup postUpdateMessageGroup(MessageGroup messageGroup)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_MESSAGE_GROUP;
                command.Parameters.AddWithValue(MessageGroupDAO.AT_MESSAGE_GROUP_INSTANCE_ID, messageGroup.messageGroupInstanceId);
                command.Parameters.AddWithValue(MessageGroupDAO.AT_MESSAGE_PART_ID, messageGroup.messagePartId);
                command.Parameters.AddWithValue(MessageGroupDAO.AT_POSITION, messageGroup.position);
                command.Parameters.AddWithValue(MessageGroupDAO.AT_ID, messageGroup.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            messageGroup.id = DAOUtility.GetData <int>(reader, MessageGroupDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateMessageGroup()", messageGroup.id.ToString());
                }
            }
            return(messageGroup);
        }
Exemplo n.º 4
0
        private static Credential postUpdateCredential(Credential credential)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_CREDENTIAL;
                command.Parameters.AddWithValue(CredentialDAO.AT_CREDENTIAL_TYPE_ID, credential.credentialTypeId);
                command.Parameters.AddWithValue(CredentialDAO.AT_USERNAME, credential.username);
                command.Parameters.AddWithValue(CredentialDAO.AT_PASSWORD, credential.password);
                command.Parameters.AddWithValue(CredentialDAO.AT_ID, credential.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            credential.id = DAOUtility.GetData <int>(reader, CredentialDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateCredential()", credential.id.ToString());
                }
            }
            return(credential);
        }
Exemplo n.º 5
0
        public static List <MessageBucket> GetUnprocessedMessageHeaderInstancesByApplication(Application application)
        {
            List <MessageBucket>    brokerMessages = new List <MessageBucket>();
            SysDataAccessCredential dac            = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            // set process flag
            bool isProcessed = false;

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();
                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = das.SERVICE_VIEW_GET_MESSAGE_HEADER_INSTANCES;
                command.Parameters.AddWithValue(MessageBucketDAO.AT_MHI_SENDING_APPLICATION, application.name);
                command.Parameters.AddWithValue(MessageBucketDAO.AT_MHI_PROCESSED, isProcessed);
                try
                {
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            brokerMessages.Add(new MessageBucket(reader,
                                                                 MessageBucket.View.GetMessageHeaderInstances));
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "GetUnprocessedMessageHeaderInstancesByApplication(Application application)", application.id.ToString());
                }
            }
            return(brokerMessages);
        }
Exemplo n.º 6
0
        private static DatabaseTableRelation postUpdateDatabaseTableRelation(DatabaseTableRelation databaseTableRelation)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_DATABASE_TABLE_RELATION;
                command.Parameters.AddWithValue(DatabaseTableRelationDAO.SOURCE_DATABASE_TABLE_ID, databaseTableRelation.sourceDatabaseTableId);
                command.Parameters.AddWithValue(DatabaseTableRelationDAO.TARGET_DATABASE_TABLE_ID, databaseTableRelation.targetDatabaseTableId);
                command.Parameters.AddWithValue(DatabaseTableRelationDAO.REQUIRES_IDENTITY, databaseTableRelation.requiresIdentity);
                command.Parameters.AddWithValue(DatabaseTableRelationDAO.AT_ID, databaseTableRelation.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            databaseTableRelation.id = DAOUtility.GetData <int>(reader, DatabaseTableDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateDatabaseTableRelation()", databaseTableRelation.id.ToString());
                }
            }
            return(databaseTableRelation);
        }
        private static MessageHeaderInstance updateMessageHeaderInstanceToProcessed(MessageHeaderInstance messageHeaderInstance,
                                                                                    Message message,
                                                                                    bool isReprocess = false)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.UPDATE_MESSAGE_HEADER_INSTANCE_PROCESS;
                command.Parameters.AddWithValue(MessageHeaderInstanceDAO.AT_ID, messageHeaderInstance.id);
                command.Parameters.AddWithValue(MessageHeaderInstanceDAO.AT_MESSAGE_ID, message.id);
                command.Parameters.AddWithValue(MessageHeaderInstanceDAO.AT_ISREPROCESS, isReprocess);
                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            messageHeaderInstance.id = DAOUtility.GetData <int>(reader, MessageHeaderInstanceDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "updateMessageHeaderInstanceToProcessed()", messageHeaderInstance.id.ToString());
                }
            }
            return(messageHeaderInstance);
        }
Exemplo n.º 8
0
        private static Application postUpdateApplication(Application application)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_APPLICATION;
                command.Parameters.AddWithValue(ApplicationDAO.AT_NAME, application.name);
                command.Parameters.AddWithValue(ApplicationDAO.AT_DESCRIPTION, application.description);
                command.Parameters.AddWithValue(ApplicationDAO.AT_ID, application.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            application.id = DAOUtility.GetData <int>(reader, ApplicationDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateApplication()", application.name);
                }
            }
            return(application);
        }
Exemplo n.º 9
0
        private static MessagePart postUpdateMessagePart(MessagePart messagePart)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_MESSAGE_PART;
                command.Parameters.AddWithValue(MessagePartDAO.AT_NAME, messagePart.name);
                command.Parameters.AddWithValue(MessagePartDAO.AT_DELIMITER, messagePart.delimiter);
                command.Parameters.AddWithValue(MessagePartDAO.AT_ID, messagePart.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            messagePart.id = DAOUtility.GetData <int>(reader, MessagePartDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateMessagePart()", messagePart.id.ToString());
                }
            }
            return(messagePart);
        }
Exemplo n.º 10
0
        private static void updateProcessIdentity(Broker broker)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            try
            {
                using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
                {
                    SqlCommand command = new SqlCommand();
                    conn.Open();
                    command.Connection  = conn;
                    command.CommandText = das.UPDATE_PROCESS_IDENTITY;
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.AddWithValue(BrokerDAO.AT_PROCESS_ID, broker.processId);
                    command.Parameters.AddWithValue(BrokerDAO.AT_ID, broker.id);
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex, "BrokerDAO.updateProcessIdentity(Broker broker", broker.id.ToString());
            }
        }
Exemplo n.º 11
0
        private static DatabaseTable postUpdateDatabaseTable(DatabaseTable databaseTable)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_DATABASE_TABLE;
                command.Parameters.AddWithValue(DatabaseTableDAO.AT_DATABASE_INSTANCE_ID, databaseTable.databaseInstanceId);
                command.Parameters.AddWithValue(DatabaseTableDAO.AT_NAME, databaseTable.name);
                command.Parameters.AddWithValue(DatabaseTableDAO.AT_ID, databaseTable.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            databaseTable.id = DAOUtility.GetData <int>(reader, DatabaseTableDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateDatabaseTable()", databaseTable.id.ToString());
                }
            }
            return(databaseTable);
        }
Exemplo n.º 12
0
        private static WebserviceObject postUpdateWebserviceObject(WebserviceObject webserviceObject)
        {
            SysDataAccessCredential dac = DAOUtility.GetSysCredentials();
            DataAccess das = new DataAccess();

            using (SqlConnection conn = new SqlConnection(DAOUtility.GetConnectionString(dac)))
            {
                conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = conn;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = das.PUT_WEBSERVICE_OBJECT;
                command.Parameters.AddWithValue(WebserviceObjectDAO.WEBSERVICE_INSTANCE_ID, webserviceObject.webserviceInstanceId);
                command.Parameters.AddWithValue(WebserviceObjectDAO.AT_NAME, webserviceObject.name);
                command.Parameters.AddWithValue(WebserviceObjectDAO.AT_ID, webserviceObject.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            webserviceObject.id = DAOUtility.GetData <int>(reader, WebserviceObjectDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateWebserviceObject()", webserviceObject.id.ToString());
                }
            }
            return(webserviceObject);
        }
Exemplo n.º 13
0
        public static void handleOutgoingHL7MessageToBrokerV1(string hl7Input,
                                                              Communication databaseCommunication,
                                                              HL7Broker.Model.Socket socket)
        {
            Dictionary <int, int> databaseTableRelationDictionary
                = new Dictionary <int, int>();

            // get all database table relations
            List <DatabaseTableRelation> relations = DatabaseTableRelationDAO.Get();

            // this identity is used for multiple inserts
            int identityNo = -1;

            // text
            string baseCommandText = BLANK;
            string tableName       = BLANK;
            // these will help build the custom query
            List <string> columns      = new List <string>();
            List <string> columnValues = new List <string>();

            // get message
            HL7Message hl7Message = socket.getHL7Message();

            // get configurations for the database comminucation
            List <Configuration> configurations
                = ConfigurationDAO.GetDatabaseConfiguration(databaseCommunication);

            // get the credential
            Credential credential = configurations[ZERO_ELEMENT].credential;

            // get the database instance
            DatabaseInstance databaseInstance = configurations[ZERO_ELEMENT].databaseInstance;

            // build the connection string
            string connectionString = DAOUtility.GetConnectionString(credential,
                                                                     databaseInstance, true);


            // build database query to insert data into tables based on configuration
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    // get a list of databses tables
                    List <Configuration> configDatabaseTables
                        = ConfigurationDAO.GetDatabaseTables(databaseInstance);

                    // pick up all the tables for the config
                    configDatabaseTables.ForEach(delegate(Configuration tableConfig)
                    {
                        // empty the db value
                        string dbValue = BLANK;
                        // reset variables
                        baseCommandText = BLANK;
                        // empty the stores
                        columns.Clear();
                        columnValues.Clear();

                        SqlCommand command = new SqlCommand();

                        // set the database table
                        DatabaseTable table = tableConfig.databaseTable;

                        // init database table relation
                        DatabaseTableRelation databaseTableRelation = tableConfig.databaseTableRelation;

                        // based on the table instance id , get the column set
                        List <Configuration> configDatabaseColumns
                            = ConfigurationDAO.GetDatabaseColumns(table);

                        // set the table name
                        tableName = table.name;

                        // for each column, get the column name
                        configDatabaseColumns.ForEach(delegate(Configuration configColumn)
                        {
                            // set the column
                            ColumnSet column = configColumn.columnSet;

                            // get the data type to use
                            SqlDbType sqlDbType = DAOUtility.GetSqlDataType(column.columnDataType);

                            // if it's 0, there must be some special condition here, such as a primary key or handling a specific data type
                            if (column.messageGroupInstanceId == ZERO &&
                                column.columnDataType == INTEGER_TYPE)
                            {
                                // if the source table does have a relationship, then we need to get it
                                if (relations.Count(x => x.sourceDatabaseTableId == table.id) > ZERO)
                                {
                                    if (column.isPrimaryKey)
                                    {
                                        // do something here
                                        int keyValue = -1;

                                        // get the target table based on the source table
                                        int targetTableId = relations.Find(r => r.sourceDatabaseTableId ==
                                                                           table.id).targetDatabaseTableId;

                                        // get the identity
                                        databaseTableRelationDictionary.TryGetValue(targetTableId, out keyValue);

                                        // set the keyvalue to the db value
                                        dbValue = keyValue.ToString();
                                    }
                                    else
                                    {
                                        // Throw Error - there is an issue if the column value is of interger type but no
                                        // key is assoicated it it.
                                    }
                                }
                            }
                            // if this isn't bound to a column and it's of type text - then it should ALWAYS be an HL7 Message
                            else if (column.messageGroupInstanceId == ZERO &&
                                     column.columnDataType == TEXT_TYPE)
                            {
                                // apply hl7 message
                                dbValue = hl7Input;
                            }
                            // database column is of current date type, so we set the value to the current date time
                            else if (column.messageGroupInstanceId == ZERO &&
                                     column.columnDataType == DATE_TYPE)
                            {
                                // set the value to the current date time
                                dbValue = DateTime.Now.ToString();
                            }
                            // search for it by hl7 position
                            else
                            {
                                // init a message group instance
                                MessageGroupInstance messageGroupInstance = new MessageGroupInstance()
                                {
                                    id = column.messageGroupInstanceId
                                };

                                // reset the message group instance
                                configColumn.messageGroupInstance = messageGroupInstance;

                                // get the message position for this specific column
                                List <Configuration> configMessagePoisition
                                    = ConfigurationDAO.GetMessagePosition(configColumn.messageGroupInstance);

                                // get the coordinates for the message item
                                string messageCoordinates = HL7MessageUtility.getItemCoordinates(configMessagePoisition);

                                // get segment string type
                                string columnSegment = configMessagePoisition[ZERO_ELEMENT].segmentType.name;

                                // get the value for the database inside of the value position
                                string hl7Value = HL7MessageUtility.getValueByPosition(
                                    hl7Message,
                                    HL7MessageUtility.getSegmentType(columnSegment),
                                    messageCoordinates);

                                // generate the value
                                dbValue = (!String.IsNullOrEmpty(hl7Value) ? hl7Value : DBNull.Value.ToString());
                            }

                            // initialize for each new table
                            baseCommandText
                                = DAOUtility.GetBaseQuery(DAOUtility.SERVICE_QUERY_TYPE.INSERT);

                            // add to columns statement
                            columns.Add(column.name);

                            // add to values statement
                            columnValues.Add(AT_SIGN + column.name);

                            // set the command string
                            command.Parameters.Add(AT_SIGN + column.name, sqlDbType);

                            // set the values
                            command.Parameters[AT_SIGN + column.name].Value = dbValue;
                        });

                        // open the connection
                        connection.Open();

                        // grab command text
                        command.CommandText = DAOUtility.GetStatement(DAOUtility.SERVICE_QUERY_TYPE.INSERT,
                                                                      baseCommandText,
                                                                      tableName,
                                                                      columns,
                                                                      columnValues);

                        // make new transaction to allow roll back
                        SqlTransaction transaction = connection.BeginTransaction();

                        // initialize the connection
                        command.Connection = connection;

                        // initialize the transaction
                        command.Transaction = transaction;

                        // handle the database insert for message header instance
                        handleDatabaseTableCaller(connection,
                                                  command,
                                                  transaction,
                                                  hl7Message,
                                                  table,
                                                  hl7Input,
                                                  socket,
                                                  out identityNo);

                        // if the "database table has dependencies" - store the relation id w/ the table id
                        if (databaseTableRelation.id != ZERO)
                        {
                            // or in better terms - has a dependency that this ide requires
                            if (databaseTableRelation.requiresIdentity)
                            {
                                // add to the dictionary if it does require depdents
                                databaseTableRelationDictionary.Add(table.id, identityNo);
                            }
                            else
                            {
                                // reset if it doesn't need it
                                identityNo = NEG_ONE;
                            }
                        }
                    });
                }
                catch (SqlException sqlex)
                {
                    ErrorLogger.LogError(sqlex, "handleOutgoingHL7MessageToBroker()", hl7Input);
                    connection.Close();
                }
            }
        }