Пример #1
0
        public static List <Configuration> GetMessagePosition(MessageGroupInstance messageGroupInstance)
        {
            List <Configuration>    configurations = new List <Configuration>();
            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.Text;
                command.CommandText = das.SERVICE_VIEW_GET_MESSAGE_POSITION;
                command.Parameters.AddWithValue(ConfigurationDAO.AT_MESSAGE_GROUP_INSTANCE_ID,
                                                messageGroupInstance.id);
                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            configurations.Add(new Configuration(reader,
                                                                 Configuration.View.GetMessagePosition));
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "getMessagePosition(MessageGroupInstance messageGroupInstance)", messageGroupInstance.id.ToString());
                }
            }
            return(configurations);
        }
Пример #2
0
        private static string getHL7ValueSEL(HL7Message message,
                                             List <MessageGroupInstance> messageGroupInstances,
                                             List <MessageGroup> messageGroups,
                                             WebservicePropertySet wsProperty
                                             )
        {
            // get the ms groups
            List <MessageGroup> msGroups
                = ConfigurationUtility.GetIncomingWebserviceMessageGroup(wsProperty, messageGroups);

            // get segment string type
            MessageGroupInstance messageGroupInstance
                = messageGroupInstances.Find(i => i.id == msGroups[ZERO].messageGroupInstanceId);

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

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

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

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

            return(hl7Value);
        }
        private static List <MessageGroupInstance> getSingleMessageGroupInstance(MessageGroupInstance messageGroupInstance)
        {
            List <MessageGroupInstance> messageGroupInstances = new List <MessageGroupInstance>();
            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.Text;
                command.CommandText = das.GET_SINGLE_MESSAGE_GROUP_INSTANCE;
                command.Parameters.AddWithValue(MessageGroupInstanceDAO.AT_ID, messageGroupInstance.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            messageGroupInstances.Add(new MessageGroupInstance(reader));
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "getSingleMessageGroupInstance(MessageGroupInstance MessageGroupInstance)", messageGroupInstance.id.ToString());
                }
            }

            return(messageGroupInstances);
        }
        private static bool deleteMessageGroupInstance(MessageGroupInstance messageGroupInstance)
        {
            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.Text;
                command.CommandText = das.DELETE_MESSAGE_GROUP_INSTANCE;
                command.Parameters.AddWithValue(MessageGroupInstanceDAO.AT_ID, messageGroupInstance.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            messageGroupInstance.id = DAOUtility.GetData <int>(reader, MessageGroupInstanceDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "DeleteMessageGroupInstance()", messageGroupInstance.id.ToString());
                }
            }
            return(true);
        }
        private static MessageGroupInstance postUpdateMessageGroupInstance(MessageGroupInstance messageGroupInstance)
        {
            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_INSTANCE;
                command.Parameters.AddWithValue(MessageGroupInstanceDAO.AT_MESSAGE_TYPE_ID, messageGroupInstance.messageTypeId);
                command.Parameters.AddWithValue(MessageGroupInstanceDAO.AT_SEGMENT_TYPE_ID, messageGroupInstance.segmentTypeId);
                command.Parameters.AddWithValue(MessageGroupInstanceDAO.AT_DESCRIPTION, messageGroupInstance.description);
                command.Parameters.AddWithValue(MessageGroupInstanceDAO.AT_ID, messageGroupInstance.id);

                try
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            messageGroupInstance.id = DAOUtility.GetData <int>(reader, MessageGroupInstanceDAO.ID);
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError(e, "postUpdateMessageGroupInstance()", messageGroupInstance.id.ToString());
                }
            }
            return(messageGroupInstance);
        }
Пример #6
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();
                }
            }
        }
Пример #7
0
        public static void Begin(MessageGroupInstance messageGroupInstance)
        {
            int beforeCount = 0;
            int afterCount  = 0;

            // MessageGroupInstance API
            List <MessageGroupInstance> messageGroupInstances;

            // Get existing
            beforeCount = MessageGroupInstanceDAO.Get().Count;

            // Insert and Updating: if ID is included, it will update
            messageGroupInstance = MessageGroupInstanceDAO.PostUpdate(messageGroupInstance);

            // Reading: Use GetMessageGroupInstances() to retrieve a list of obj
            messageGroupInstances = MessageGroupInstanceDAO.Get();

            // get master item count
            afterCount = messageGroupInstances.Count;

            // write
            MessageGroupInstanceTest.Write(messageGroupInstances, "INSERT", beforeCount, afterCount, true);
            Console.Read();

            // make a soft update to some property (Optional)
            // messageGroupInstance.<property> = 1;

            // re-assign the before count
            beforeCount = afterCount;

            // Insert and Updating: if ID is included, it will update
            messageGroupInstance = MessageGroupInstanceDAO.PostUpdate(messageGroupInstance);

            // Reading: Use GetMessageGroupInstances() to retrieve a list of obj
            messageGroupInstances = MessageGroupInstanceDAO.Get();

            // Get existing
            afterCount = MessageGroupInstanceDAO.Get().Count;

            // write
            MessageGroupInstanceTest.Write(messageGroupInstances, "UPDATE", beforeCount, afterCount);
            Console.Read();

            // Reading: Use GetMessageGroupInstances() to retrieve a list of obj w/ 1 item
            messageGroupInstances = MessageGroupInstanceDAO.Get(messageGroupInstance);

            // get count
            afterCount = messageGroupInstances.Count;

            // reassign count
            beforeCount = afterCount;

            // write
            MessageGroupInstanceTest.Write(messageGroupInstances, "Single", afterCount, 1);
            Console.Read();

            // Deleting - Send in the obj w/ at minimal the ID populated
            MessageGroupInstanceDAO.Delete(messageGroupInstance);

            // Reading: Use GetMessageGroupInstances() to retrieve a list of obj
            messageGroupInstances = MessageGroupInstanceDAO.Get();

            // get count
            afterCount = messageGroupInstances.Count;

            // write
            MessageGroupInstanceTest.Write(messageGroupInstances, "Removed", beforeCount, afterCount, true);
            Console.Read();
        }
Пример #8
0
        public static void makeNewMessageGroups()
        {
            List <String> lines = new List <string>();

            lines = File.ReadAllLines(@"C:\Users\chrisb\Source\Repos\HL7Broker\HL7BrokerConsoleTest\NewMessageGroupForWebService.txt").ToList();

            lines.ForEach(delegate(String line) {
                // skip comments
                if (line.Contains("##"))
                {
                    return;
                }

                string[] elementSplit = line.Split('|');

                // gives the first part
                string[] tempMessageGroupInstance = elementSplit[0].Split(',');

                Console.WriteLine("Inserting Message Group Instance");
                MessageGroupInstance messageGroupInstance
                    = MessageGroupInstanceDAO.PostUpdate(new MessageGroupInstance()
                {
                    messageTypeId = Convert.ToInt32(tempMessageGroupInstance[0]),
                    segmentTypeId = Convert.ToInt32(tempMessageGroupInstance[1]),
                    description   = tempMessageGroupInstance[2]
                });

                if (messageGroupInstance.id != -1 || messageGroupInstance.id != 0)
                {
                    List <String> tempMessageGroup = elementSplit[1].Split(',').ToList();

                    tempMessageGroup.ForEach(delegate(String tempElement) {
                        Console.WriteLine("Inserting Message Group");

                        string[] tempInnerElement = tempElement.Split('^');

                        MessageGroupDAO.PostUpdate(new MessageGroup()
                        {
                            messageGroupInstanceId = messageGroupInstance.id,
                            messagePartId          = Convert.ToInt32(tempInnerElement[0]),
                            position = Convert.ToInt32(tempInnerElement[1])
                        });
                    });

                    Console.WriteLine("Inserting Message Group Property or Column Set");

                    // gives the first part
                    string[] tempColumnSet = elementSplit[2].Split(',');

                    /*
                     * ColumnSet columnSet = new ColumnSet()
                     * {
                     *  databaseTableId = Convert.ToInt32(tempColumnSet[0]),
                     *  name = tempColumnSet[1],
                     *  messageGroupInstanceId = messageGroupInstance.id,
                     *  isPrimaryKey = Convert.ToBoolean(tempColumnSet[2]),
                     *  columnDataType = tempColumnSet[3]
                     * };
                     *
                     * ColumnSetDAO.PostUpdate(columnSet);
                     */

                    WebservicePropertySet webservicePropertySet = new WebservicePropertySet()
                    {
                        webserviceObjectId = Convert.ToInt32(tempColumnSet[0]),
                        name = tempColumnSet[1],
                        messageGroupInstanceId = messageGroupInstance.id,
                        columnDataType         = tempColumnSet[2]
                    };

                    WebservicePropertySetDAO.PostUpdate(webservicePropertySet);
                }
            });
            Console.Read();
        }
 public static bool Delete(MessageGroupInstance messageGroupInstance)
 {
     return(deleteMessageGroupInstance(messageGroupInstance));
 }
 public static MessageGroupInstance PostUpdate(MessageGroupInstance messageGroupInstance)
 {
     return(postUpdateMessageGroupInstance(messageGroupInstance));
 }
 public static List <MessageGroupInstance> Get(MessageGroupInstance messageGroupInstance)
 {
     return(getSingleMessageGroupInstance(messageGroupInstance));
 }