current version of formulary linker

main^2
Will King 3 years ago
parent 692559ee5a
commit d4527b6b7c

@ -43,6 +43,7 @@ def check_connection(app):
def get_trial_summary(db_conn,nct_id):
sql_summary ="""
/*get brief and detailed descriptions*/
select
s.nct_id,
brief_title ,
@ -64,22 +65,39 @@ where c.nct_id = %s
;
"""
sql_keywords="""
/*get keywords*/
select nct_id ,downcase_name
from ctgov.keywords k
where k.nct_id = %s
;
"""
sql_indications='''
select downcase_mesh_term
from ctgov.browse_interventions bi
where bi.nct_id = %s and mesh_type = 'mesh-list'
'''
with db_conn.cursor() as curse:
curse.execute(sql_summary,[nct_id])
summary = curse.fetchall()
curse.execute(sql_keywords,[nct_id])
keywords = curse.fetchall()
keywords = [ x[1] for x in curse.fetchall()]
curse.execute(sql_conditions,[nct_id])
conditions = curse.fetchall()
conditions = [ x[2] for x in curse.fetchall()]
curse.execute(sql_indications,[nct_id])
indications = [ x[0] for x in curse.fetchall()]
return {"summary":summary, "keywords":keywords, "conditions":conditions}
return {
"summary":summary,
"keywords":keywords,
"conditions":conditions,
"indications":indications
}
def get_trials_unmatched_to_formularies(db_conn):
@ -106,20 +124,40 @@ where nct_id not in (
select nct_id from "Formularies".uspdc_most_recent_matched_status umrms
where status is not null
)
; '''
uspmmg_sql = ''' Null; '''
and nct_id in (select distinct nct_id from public.formatted_data_mat fd )
;
'''
uspmmg_sql = '''\
/*
Get the trials that have not been proceesed.
First: get most recent matched status
Second: only include those who have non-null status
Third: check list of trials against this and remove any of them.
This leaves unmatched trials.
*/
select distinct(nct_id)
from "DiseaseBurden".trial_to_icd10 tti
where nct_id not in (
select nct_id from "Formularies".uspmmg_most_recent_matched_status umrms
where status is not null
)
and nct_id in (select distinct nct_id from public.formatted_data_mat fd )
;
'''
vaform_sql = ''' Null; '''
#query each formulary, adding data to dict
formulary_list = dict()
with db_conn.cursor as curse:
with db_conn.cursor() as curse:
# uspdc
curse.execute(uspdc_sql)
formulary_list["uspdc"] = curse.fetchall()
# uspmm
curse.execute(uspmmg_sql)
formulary_list["uspmmg"] = curse.fetchall()
# vaform
return formulary_list

@ -12,9 +12,11 @@ import FormulariesMatching.uspdc_db as uspdc
import FormulariesMatching.uspmmg_db as uspmmg
import FormulariesMatching.vaform_db as vaform
import re
FORMULARIES = {
"USP DC":uspdc,
# "USP MMG":uspmmg,
"USP MMG":uspmmg,
# "VA Formulary":vaform,
}
@ -28,10 +30,14 @@ def get_remaining_trials():
db_conn = get_db()
#get list of trials
connection_valid = get_trials_unmatched_to_formularies(db_conn)
unmatched_trials = get_trials_unmatched_to_formularies(db_conn)
unmatched_trials_list = list(set([ x[0] for y in unmatched_trials for x in unmatched_trials[y]] ))
#return html
return connection_valid
# return {"formularies":unmatched_trials,"nctids":nctid_list}
return render_template('formulary_index.html',
unmatched_trials=unmatched_trials_list,
)
@bp.route("/<nct_id>", methods=['GET',"POST"])
@ -62,8 +68,36 @@ def match_trial_to_formulary_groups(nct_id):
)
elif request.method == "POST":
pass
#build array of data to insert
#For each Formulary
translation={"('":None,"')":None}
for key in request.form.keys():
match key.split("|"):
case ["select_box", formulary]:
#parse data
result = request.form["select_box|{}".format(formulary)]
if result == 'difficult':
FORMULARIES[formulary].insert_match(db_conn,nct_id,None,None,'difficult')
else:
category,uspclass = [re.sub("['\(\)]","",x).strip() for x in result.split("', '")]
FORMULARIES[formulary].insert_match(db_conn,nct_id,category,uspclass,'accepted')
case ["check_box", data]:
formulary_trial,category,uspclass = [re.sub("['\(\)]","",x).strip() for x in data.split("', '")]
formulary,_ = formulary_trial.split(",")
#Insert data
FORMULARIES[formulary].insert_match(db_conn,nct_id,category,uspclass,'accepted')
case _:
return 400
return redirect(url_for("formularies.get_remaining_trials"))
else:
raise Exception("HTTP method <{}> not implemented".format(request.method))

@ -8,16 +8,14 @@
<h2>Unlinked Trials</h2>
<table>
<th>Trials</th>
{% for trial in unlinked_trials %}
<tr><td>
<a href="{{ url_for('.validate_trial', nct_id=trial[0] ) }}">
{{ trial [0] }}
</a>
</td></tr>
{% endfor %}
</table>
<ul>
{% for trial in unmatched_trials %}
<li> <a href="{{ url_for('formularies.match_trial_to_formulary_groups', nct_id=trial ) }}">
{{ trial }}
</a>
</li>
{% endfor %}
</ul>
<h2>Linked Trials</h2>

@ -10,18 +10,75 @@
{% block content %}
Based on the drugs associated with a trial,
the following are the formulary group suggestions.
<div class=trial_summary>
<h3> Trial Summary </h3>
<table>
<tr>
<th>Short Title</th>
<td>{{ summary['summary'][0][1] }}</td>
</tr>
<tr>
<th>Complete Title</th>
<td>{{ summary['summary'][0][2] }}</td>
</tr>
<tr>
<th>Summary</th>
<td>{{ summary['summary'][0][3] }}</td>
</tr>
<tr>
<th>Summary 2</th>
<td>{{ summary['summary'][0][4] }}</td>
</tr>
<tr>
<th>Indicated Drugs</th>
<td>
<ul>
{% for drug in summary['indications'] %}
<li>
<a
href="https://www.drugs.com/search.php?searchterm={{drug}}"
target="_blank"
>
{{drug}}
</a>
</li>
{% endfor %}
</ul>
</td>
</tr>
<tr>
<th>Conditions</th>
<td>
<ul>
{% for condition in summary['conditions'] %}
<li>
<a
href="https://www.mayoclinic.org/search/search-results?q={{condition}}"
target="_blank"
>
{{condition}}
</a>
</li>
{% endfor %}
</ul>
</td>
</tr>
<tr>
<th>keywords</th>
<td>{{ summary['keywords'] }}</td>
</tr>
</table>
</div>
<form>
<form method="post">
<h2>Matching Classes</h2>
{% for formulary in potential_matches %}
<div class=formulary_matches>
<h2>
<h3>
{{ formulary }}
</h2>
</h3>
<p>
{% for formulary in potential_matches %}
<table>
<tr>
@ -34,9 +91,9 @@ the following are the formulary group suggestions.
<td> {{ row[1] }} </td>
<td> {{ row[2] }} </td>
<td> <input
type="checkbox"
type="checkbox"
id="{{ formulary,row }}"
name={{ formulary,row }}
name="check_box|{{ formulary,row }}"
value="selected">
</td>
<!-- add checkbox here -->
@ -47,22 +104,21 @@ the following are the formulary group suggestions.
</p>
<p>
If you've determined it belongs to another class
<select name="{{ formulary }}-select_box" id="{{ formularay }}-select_box">
<select name="select_box|{{ formulary }}" id="{{ formularay }}-select_box">
<option disabled selected value> -- select an option -- </option>
<option value="difficult">
Difficult to choose
</option>
{% for option in class_lists[formulary] %}
<option value={{ (option[0],option[1]) }}>
Category:{{ option[0] }} Class:{{ option[1] }}
<option value="{{ (option[0],option[1]) }}">
Cat:{{ option[0] }} Class:{{ option[1] }}
<!-- FIX this is really hard to read -->
<!-- FIX try to add opgroups? -->
</option>
{% endfor %}
</select>
{% endfor %}
{% endfor %}

@ -32,7 +32,7 @@ def get_groups_per_nctid(db_conn, nct_id):
'''
pass
sql = '''\
select * from "Formularies".trial_to_uspdc_category_class ttucc
select * from "Formularies".uspdc_trial_to_category_class ttucc
where nct_id = %(nctid)s
;
'''
@ -43,5 +43,19 @@ where nct_id = %(nctid)s
return curse.fetchall()
def store_trial_to_formulary_group_matches():
pass
def insert_match(db_conn, nct_id, category,uspclass,status):
sql = '''\
INSERT INTO "Formularies".uspdc_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()

@ -13,23 +13,50 @@ def get_all_formulary_groups(db_conn):
'''
sql = '''\
select distinct "USP Category", "USP Class"
from "Formularies".usp_dc ud
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_formulary_groups_per_NCTID(db_conn, nct_id):
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 store_trial_to_formulary_group_matches():
pass
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()

@ -1 +1,2 @@
waitress-serve --port=5000 --call 'Icd10ConditionsMatching:create_app'
waitress-serve --port=5000 --call 'FormulariesMatching:create_app'
#flask --app FormulariesMatching run --debug

Loading…
Cancel
Save