From dd90715400a587cde1c5f73e43b04f6357f5e392 Mon Sep 17 00:00:00 2001 From: Will King Date: Fri, 22 Sep 2023 13:53:13 -0700 Subject: [PATCH] got uspdc displaying --- .../FormulariesMatching/__init__.py | 7 +- .../formularies_matching.py | 47 ----------- .../FormulariesMatching/matching.py | 70 ++++++++++++++++ .../FormulariesMatching/static/styles.css | 5 ++ .../templates/.formulary_index.html.swp | Bin 12288 -> 0 bytes .../FormulariesMatching/templates/base.html | 16 ++-- .../templates/formulary_index.html | 10 +-- .../templates/trial_formularies.html | 76 ++++++++++++++++++ .../FormulariesMatching/uspdc_db.py | 47 +++++++++++ .../FormulariesMatching/uspmmg_db.py | 35 ++++++++ .../FormulariesMatching/vaform_db.py | 35 ++++++++ 11 files changed, 285 insertions(+), 63 deletions(-) delete mode 100644 FormulariesMatching/FormulariesMatching/formularies_matching.py create mode 100644 FormulariesMatching/FormulariesMatching/matching.py create mode 100644 FormulariesMatching/FormulariesMatching/static/styles.css delete mode 100644 FormulariesMatching/FormulariesMatching/templates/.formulary_index.html.swp create mode 100644 FormulariesMatching/FormulariesMatching/templates/trial_formularies.html create mode 100644 FormulariesMatching/FormulariesMatching/uspdc_db.py create mode 100644 FormulariesMatching/FormulariesMatching/uspmmg_db.py create mode 100644 FormulariesMatching/FormulariesMatching/vaform_db.py diff --git a/FormulariesMatching/FormulariesMatching/__init__.py b/FormulariesMatching/FormulariesMatching/__init__.py index 53f2575..57530ee 100644 --- a/FormulariesMatching/FormulariesMatching/__init__.py +++ b/FormulariesMatching/FormulariesMatching/__init__.py @@ -40,11 +40,8 @@ def create_app(test_config=None): - from . import db_interface - #db_interface.check_connection(app) - - from . import formularies_matching - app.register_blueprint(formularies_matching.bp) + from . import matching + app.register_blueprint(matching.bp) return app diff --git a/FormulariesMatching/FormulariesMatching/formularies_matching.py b/FormulariesMatching/FormulariesMatching/formularies_matching.py deleted file mode 100644 index 8c9d3fe..0000000 --- a/FormulariesMatching/FormulariesMatching/formularies_matching.py +++ /dev/null @@ -1,47 +0,0 @@ -import functools -from flask import (Blueprint, flash, g, redirect, render_template, request, session, url_for) -from datetime import datetime - -from FormulariesMatching.db_interface import ( - get_db, - get_connection_details, - get_trial_summary, - ) - - - -#setup blueprint -bp = Blueprint("formularies validation", __name__, url_prefix='/link/formularies') - -@bp.route("/", methods=['GET']) -def get_remaining(): - #get db connection - #db_conn = get_db() - - #get required data - connection_valid = get_connection_details() - - #return html - return connection_valid - - -@bp.route("/", methods=['GET',"POST"]) -def match_trial_to_formulary_groups(nct_id): - #get db connection - db_conn = get_db() - - if request.method == "GET": - pass - #get list of potential matches for each of the formularies - #get trial summary - summary = get_trial_summary(db_conn,nct_id) - - #render template - return summary - - elif request.method == "POST": - pass - #build array of data to insert - - else: - pass diff --git a/FormulariesMatching/FormulariesMatching/matching.py b/FormulariesMatching/FormulariesMatching/matching.py new file mode 100644 index 0000000..4326301 --- /dev/null +++ b/FormulariesMatching/FormulariesMatching/matching.py @@ -0,0 +1,70 @@ +import functools +from flask import (Blueprint, flash, g, redirect, render_template, request, session, url_for) +from datetime import datetime + +from FormulariesMatching.db_interface import ( + get_db, + get_connection_details, + get_trial_summary, + ) +import FormulariesMatching.uspdc_db as uspdc +import FormulariesMatching.uspmmg_db as uspmmg +import FormulariesMatching.vaform_db as vaform + +FORMULARIES = { + "USP DC":uspdc, +# "USP MMG":uspmmg, +# "VA Formulary":vaform, + } + + +#setup blueprint +bp = Blueprint("formularies", __name__, url_prefix='/link/formularies') + +@bp.route("/", methods=['GET']) +def get_remaining_trials(): + #get db connection + #db_conn = get_db() + + #get required data + connection_valid = get_connection_details() + + #return html + return connection_valid + + +@bp.route("/", methods=['GET',"POST"]) +def match_trial_to_formulary_groups(nct_id): + #get db connection + db_conn = get_db() + + if request.method == "GET": + + #get list of potential matches for each of the formularies + potential_matches = {} + class_lists = {} + + for formulary in FORMULARIES: + potential_matches[formulary] = FORMULARIES[formulary].get_groups_per_nctid(db_conn,nct_id) + class_lists[formulary] = FORMULARIES[formulary].get_all_formulary_groups(db_conn) + + #get trial summary + summary = get_trial_summary(db_conn,nct_id) + + #render template +# return [potential_matches,class_lists,summary] + return render_template('trial_formularies.html', + nct_id=nct_id, + potential_matches=potential_matches, + class_lists=class_lists, + summary=summary, + ) + + elif request.method == "POST": + pass + #build array of data to insert + + else: + raise Exception("HTTP method <{}> not implemented".format(request.method)) + + diff --git a/FormulariesMatching/FormulariesMatching/static/styles.css b/FormulariesMatching/FormulariesMatching/static/styles.css new file mode 100644 index 0000000..58ca343 --- /dev/null +++ b/FormulariesMatching/FormulariesMatching/static/styles.css @@ -0,0 +1,5 @@ +.table { + width: 100%; + border-collapse: collapse; + border: 1px solid; +} diff --git a/FormulariesMatching/FormulariesMatching/templates/.formulary_index.html.swp b/FormulariesMatching/FormulariesMatching/templates/.formulary_index.html.swp deleted file mode 100644 index 4543b2541a4d98bacf577af7ac2246c1ce92b200..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2Pixdb7>B2V2-;TBvp81DwrHE(_M({P(o#^YUfP06iL=RUGjujtlG(bYu7c2u z7cb&PJP6+W3f??<^$U3N&!-T7GubV)l)8c_mN)QhHZyNB@B3utuUt2dVTwdpFu zafY!M--hM0kLTG-!`MTmwQc^@VdJKfDDiUGBAJv(;8w=5O=H> zTkD;N_MLl|bRq*}fDDiUGC&5%02v?yWPl8i0Wv@a{zC&IW-L9$*v(-ikN^MszyH6U zX6y_21a`nCXafNrfCVrQu7k_q1o$z^*n996yaLa`Q?La(;10MA7C{w^g5%)B2xITS z8_)q7gkTk{fC*3m7r;sI9l3r6ufYy@1X>^h_rP6X>sbJFkO4A42FL&zAOmE843Ggb z@P`d-k8_#2kGQV0XoHV;8S_0O>RJY@?7#+H+l)L(6lUz3D#?aZ$b%^IoRHiqDRxvjIhAzHxg{P4TRXpb|?cI~Oe=J}=2J$hY zO~PhSK3=7~oi^>pVi|{86~<*|l3>}5Zg(LU$T6|^mo+dynJIeHjw!U*WEiv&j-rqCdYufu9j97Csy&N!+B9?B^xh2@a=yAa-bx}ySJ-%X7 F`3ZQOgYW + + + + {% block title %}{% endblock %} - ClinicalTrialsProject - + + -
-
+ {% block header %}{% endblock %} -
{% block content %}{% endblock %} -
+ + diff --git a/FormulariesMatching/FormulariesMatching/templates/formulary_index.html b/FormulariesMatching/FormulariesMatching/templates/formulary_index.html index a141319..459d4bb 100644 --- a/FormulariesMatching/FormulariesMatching/templates/formulary_index.html +++ b/FormulariesMatching/FormulariesMatching/templates/formulary_index.html @@ -1,16 +1,16 @@ {% extends 'base.html' %} {% block header %} -

{% block title %} ICD-10 to Trial Conditions Validation {% endblock %}

+

{% block title %} Linking Trials to Formularies{% endblock %}

{% endblock %} {% block content %} -

Trials to Validate

+

Unlinked Trials

-{% for trial in list_to_validate %} +{% for trial in unlinked_trials %}
Trials
{{ trial [0] }} @@ -19,7 +19,7 @@ {% endfor %}
-

Trials that have been Validated

+

Linked Trials

@@ -33,7 +33,7 @@ {% endfor %}
Trials Links
-

Trials that don't have a good match

+

Flagged for later Trials

diff --git a/FormulariesMatching/FormulariesMatching/templates/trial_formularies.html b/FormulariesMatching/FormulariesMatching/templates/trial_formularies.html new file mode 100644 index 0000000..a14158b --- /dev/null +++ b/FormulariesMatching/FormulariesMatching/templates/trial_formularies.html @@ -0,0 +1,76 @@ +{% extends 'base.html' %} + +{% block header %} +

+ {% block title %} + Match Trial {{nct_id}} to Formularies + {% endblock %} +

+{% endblock %} + +{% block content %} + +Based on the drugs associated with a trial, +the following are the formulary group suggestions. + + +{% for formulary in potential_matches %} +
+

+{{ formulary }} +

+ +

+{% for formulary in potential_matches %} + +

Trial Links
+ + + + + + {% for row in potential_matches[formulary] %} + + + + + + + {% endfor %} + +
CategoryClassSelect
{{ row[1] }} {{ row[2] }} +
+

+

+If you've determined it belongs to another class + +{% endfor %} + +{% endfor %} + +

+

+ +

+ + + +{% endblock %} diff --git a/FormulariesMatching/FormulariesMatching/uspdc_db.py b/FormulariesMatching/FormulariesMatching/uspdc_db.py new file mode 100644 index 0000000..60b9688 --- /dev/null +++ b/FormulariesMatching/FormulariesMatching/uspdc_db.py @@ -0,0 +1,47 @@ +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_dc 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".trial_to_uspdc_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 diff --git a/FormulariesMatching/FormulariesMatching/uspmmg_db.py b/FormulariesMatching/FormulariesMatching/uspmmg_db.py new file mode 100644 index 0000000..fc9e5e3 --- /dev/null +++ b/FormulariesMatching/FormulariesMatching/uspmmg_db.py @@ -0,0 +1,35 @@ +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_dc 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): + ''' + Get the list of formulary groups associated with + the drugs found in a trial identified by NCTID + ''' + pass + + +def store_trial_to_formulary_group_matches(): + pass diff --git a/FormulariesMatching/FormulariesMatching/vaform_db.py b/FormulariesMatching/FormulariesMatching/vaform_db.py new file mode 100644 index 0000000..fc9e5e3 --- /dev/null +++ b/FormulariesMatching/FormulariesMatching/vaform_db.py @@ -0,0 +1,35 @@ +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_dc 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): + ''' + Get the list of formulary groups associated with + the drugs found in a trial identified by NCTID + ''' + pass + + +def store_trial_to_formulary_group_matches(): + pass