Ejemplo n.º 1
0
 def get_instrument_info(self):
     logger.info('Getting message instrument info...')
     instrument_info = namedtuple('Instrument', 'id model sn sw_version')
     model = self.msg.oul_r22_specimen[0].oul_r22_order[
         0].oul_r22_obxtcdsidnte_suppgrp[0].obx.obx_18.ei_1.value
     sn = self.msg.msh.msh_3.msh_3_2.value
     sw = self.msg.msh.msh_3.msh_3_1.value
     pattern = '.*(\d\.\d\.\d\.\d{4})$'
     match = re.search(pattern, sw)
     sw_version = match.group(1)
     with CursorFromPool() as cur:
         cur.execute(
             """
         SELECT id, model, sn, sw_version FROM instruments
         WHERE model = %s AND sn = %s AND sw_version = %s;
         """, (model, sn, sw_version))
         result = cur.fetchone()
     if result is None:
         with CursorFromPool() as cur:
             cur.execute(
                 """
             INSERT INTO instruments (model, sn, sw_version)
             VALUES (%s, %s, %s)
             RETURNING id, model, sn, sw_version;
             """, (model, sn, sw_version))
             update_result = cur.fetchone()
         self.instrument_info = instrument_info(*update_result)
     else:
         self.instrument_info = instrument_info(*result)
         logger.debug('Message instrument_info: {}'.format(
             self.instrument_info))
Ejemplo n.º 2
0
 def get_assay_info(self):
     """
     Parses assay from HL7 message and queries assays table for relevant information.
     :return: namedtuple of assay information (id, instrument_id, lis_code, name)
     """
     logger.debug('Getting sample assay info...')
     assay = namedtuple('Assay', 'id instrument_id lis_code assay_name')
     lis_code = self.msg.oul_r22_specimen[0].oul_r22_order[
         0].obr.obr_4.obr_4_1.value
     with CursorFromPool() as cur:
         cur.execute(
             """
         SELECT * FROM assays WHERE instrument_id = %s AND lis_code =%s;
         """, (self.instrument_info.id, lis_code))
         result = cur.fetchone()
     if result is None:
         with CursorFromPool() as cur:
             cur.execute(
                 """
             INSERT INTO assays (instrument_id, lis_code, assay_name)
             VALUES (%s, %s, %s)
             RETURNING id, instrument_id, lis_code, assay_name;
             """, (self.instrument_info.id, lis_code, 'temp'))
             update_result = cur.fetchone()
         return assay(*update_result)
     return assay(*result)
Ejemplo n.º 3
0
    def load_from_db(cls, customer):
        with CursorFromPool() as cursor:
            cursor.execute('select * from reservation where name = %s', (customer,))
            customer_data = cursor.fetchone()

        if customer_data:
            return cls(customer_data[0], customer_data[1], customer_data[2], customer_data[3])
Ejemplo n.º 4
0
def availability(room):

    with CursorFromPool() as cursor:

        if room == "Presidential" or room == "Suite":
            cursor.execute('select count(*) from reservation where room = %s', (room,))
            for row in cursor:
                if row[0] >= 2:
                    print("NO more rooms available")
                else:
                    print("Welcome!")

        elif room == "Double":
            cursor.execute('select count(*) from reservation where room = %s', (room,))
            for row in cursor:
                if row[0] >= 5:
                    print("NO more rooms available")
                else:
                    print("Welcome!")

        elif room == "Standard":
            cursor.execute('select count(*) from reservation where room = %s', (room,))
            for row in cursor:
                if row[0] >= 5:
                    print("NO more rooms available")
                else:
                    print("Welcome!")
Ejemplo n.º 5
0
def fetch_results():
    global results
    global runid
    runid = request.args.get('run')
    logger.info('Fetching results for run {}...'.format(runid))
    with CursorFromPool() as cur:
        cur.execute("SELECT * FROM results_file(%s)", (str(runid),))
        results = [result for result in cur.fetchall()]
    logger.info('Run {} results fetched'.format(runid))
    return render_template('index.html', run_list=runs, results=results, runid=runid)
Ejemplo n.º 6
0
 def load_from_db_by_screen_name(cls, screen_name):
     with CursorFromPool() as cursor:
         cursor.execute('SELECT * from users WHERE screen_name=%s',
                        (screen_name, ))
         user_data = cursor.fetchone()
         if user_data is not None:
             return cls(screen_name=user_data[1],
                        oauth_token=user_data[2],
                        oauth_token_secret=user_data[3],
                        id=user_data[0])
         else:
             return None
Ejemplo n.º 7
0
 def save_run_info(self):
     logger.info('Getting message run info...')
     run_info = namedtuple('Run', 'id instrument_id msg_ts msg_guid')
     msg_ts = datetime.strptime(self.msg.msh.msh_7.value, '%Y%m%d%H%M%S%z')
     msg_guid = self.msg.msh.msh_10.value
     with CursorFromPool() as cur:
         cur.execute(
             """
         INSERT INTO runs (instrument_id, msg_ts, msg_guid)
         VALUES (%s, %s, %s)
         RETURNING id, instrument_id, msg_ts, msg_guid;
         """, (self.instrument_info.id, msg_ts, msg_guid))
         result = cur.fetchone()
     self.run_info = run_info(*result)
Ejemplo n.º 8
0
 def save_results(self):
     """
     Inserts results into database
     """
     with CursorFromPool() as cur:
         for i, result in enumerate(self._parse_results(), start=1):
             logger.info(
                 'Inserting run {} - sample {} into results table...'.
                 format(result.run_id, i))
             cur.execute(
                 """
                 INSERT INTO results (run_id, assay_id, sample_role, sample_type, sample_id, result, units,
                   result_status, username, flags, cntrl_cts, comments, dwp_id, mwp_id, mwp_position, start_ts,
                   end_ts)
                 VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
                 """, result)
Ejemplo n.º 9
0
def update(customer):
    with CursorFromPool() as cursor:
        cursor.execute('delete from reservation where name = %s cascade', (customer,))
Ejemplo n.º 10
0
def check(customer):
    with CursorFromPool() as cursor:
        cursor.execute('select * from net where name = %s', (customer,))
Ejemplo n.º 11
0
 def insert_to_db(self):
     with CursorFromPool() as cursor:
         cursor.execute('insert into reservation values(%s, %s, %s, %s)',
                        (self.customer, self.room, self.check_in, self.check_out))
Ejemplo n.º 12
0
def index():
    global runs
    with CursorFromPool() as cur:
        cur.execute("SELECT * FROM runs;")
        runs = [run for run in cur.fetchall()]
    return render_template('index.html', run_list=runs, results=None, runid=None)
Ejemplo n.º 13
0
 def save_to_db(self):
     with CursorFromPool() as cursor:
         cursor.execute(
             'INSERT INTO users (screen_name, oauth_token, oauth_token_secret) '
             'VALUES (%s,%s,%s)',
             (self.screen_name, self.oauth_token, self.oauth_token_secret))