diff --git a/FormulariesMatching/FormulariesMatching/db_interface.py b/FormulariesMatching/FormulariesMatching/db_interface.py index 93f5fe9..19c60de 100644 --- a/FormulariesMatching/FormulariesMatching/db_interface.py +++ b/FormulariesMatching/FormulariesMatching/db_interface.py @@ -81,3 +81,45 @@ where k.nct_id = %s return {"summary":summary, "keywords":keywords, "conditions":conditions} + +def get_trials_unmatched_to_formularies(db_conn): + """ + Get the NCT_IDs of trials not yet matchec to formularies + + For each formulary + get list + add to dsp + """ + + #setup sql for each formulary + uspdc_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".uspdc_most_recent_matched_status umrms + where status is not null + ) +; ''' + uspmmg_sql = ''' Null; ''' + vaform_sql = ''' Null; ''' + + #query each formulary, adding data to dict + formulary_list = dict() + + with db_conn.cursor as curse: + + # uspdc + curse.execute(uspdc_sql) + formulary_list["uspdc"] = curse.fetchall() + + # uspmm + # vaform + + return formulary_list diff --git a/FormulariesMatching/FormulariesMatching/matching.py b/FormulariesMatching/FormulariesMatching/matching.py index 4326301..b5df1ff 100644 --- a/FormulariesMatching/FormulariesMatching/matching.py +++ b/FormulariesMatching/FormulariesMatching/matching.py @@ -6,6 +6,7 @@ from FormulariesMatching.db_interface import ( get_db, get_connection_details, get_trial_summary, + get_trials_unmatched_to_formularies, ) import FormulariesMatching.uspdc_db as uspdc import FormulariesMatching.uspmmg_db as uspmmg @@ -24,10 +25,10 @@ bp = Blueprint("formularies", __name__, url_prefix='/link/formularies') @bp.route("/", methods=['GET']) def get_remaining_trials(): #get db connection - #db_conn = get_db() + db_conn = get_db() - #get required data - connection_valid = get_connection_details() + #get list of trials + connection_valid = get_trials_unmatched_to_formularies(db_conn) #return html return connection_valid