You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.2 KiB
Python
63 lines
1.2 KiB
Python
import psycopg as psyco
|
|
from datetime import datetime
|
|
|
|
from flask import current_app, g
|
|
|
|
|
|
|
|
|
|
def get_all_formulary_groups(db_conn):
|
|
'''
|
|
Get the list of active formulary groups
|
|
TODO: IMplement for the given formulary
|
|
'''
|
|
sql = '''\
|
|
select distinct "USP Category", "USP Class"
|
|
from "Formularies".usp_mmg ud
|
|
order by "USP Category", "USP Class"
|
|
;
|
|
'''
|
|
#query
|
|
with db_conn.cursor() as curse:
|
|
curse.execute(sql)
|
|
return curse.fetchall()
|
|
|
|
|
|
|
|
|
|
def get_groups_per_nctid(db_conn, nct_id):
|
|
'''
|
|
Get the list of formulary groups associated with
|
|
the drugs found in a trial identified by NCTID
|
|
'''
|
|
pass
|
|
sql = '''\
|
|
select * from "Formularies".uspmmg_trial_to_category_class ttucc
|
|
where nct_id = %(nctid)s
|
|
;
|
|
'''
|
|
|
|
#query
|
|
with db_conn.cursor() as curse:
|
|
curse.execute(sql, {"nctid":nct_id})
|
|
return curse.fetchall()
|
|
|
|
|
|
|
|
def insert_match(db_conn, nct_id, category,uspclass,status):
|
|
sql = '''\
|
|
INSERT INTO "Formularies".uspmmg_matching
|
|
VALUES
|
|
(
|
|
%(nct_id)s
|
|
,%(category)s
|
|
,%(uspclass)s
|
|
,%(status)s
|
|
,NOW()
|
|
)
|
|
;
|
|
'''
|
|
with db_conn.cursor() as curse:
|
|
curse.execute(sql, {"nct_id":nct_id, "category":category, "uspclass":uspclass, "status":status} )
|
|
db_conn.commit()
|