Skip to content
Merged

Mcq #203

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 37 additions & 22 deletions cohd/cohd.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,44 @@ def api_cohd():
return redirect("https://cohd.smart-api.info/", code=302)


@app.route('/api/metadata/datasets')
def api_metadata_datasets():
return query_cohd_mysql.query_db_datasets()


@app.route('/api/metadata/domainCounts')
def api_metadata_domainCounts():
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
return query_cohd_mysql.query_db_domain_counts(dataset_id)


@app.route('/api/metadata/domainPairCounts')
def api_metadata_domainPairCounts():
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
return query_cohd_mysql.query_db_domain_pair_counts(dataset_id)


@app.route('/api/metadata/patientCount')
def api_metadata_patientCount():
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
return query_cohd_mysql.query_db_patient_count(dataset_id)


@app.route('/api/omop/findConceptIDs')
@app.route('/api/v1/omop/findConceptIDs')
def api_omop_reference():
return api_call('omop', 'findConceptIDs')
query = request.args.get('q')
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
domain_id = request.args.get('domain')
min_count = request.args.get('min_count')
return query_cohd_mysql.query_db_find_concept_ids(dataset_id, query, domain_id, min_count)


@app.route('/api/omop/concepts')
@app.route('/api/v1/omop/concepts')
def api_omop_concepts():
return api_call('omop', 'concepts')
query = request.args.get('q')
return query_cohd_mysql.query_db_concepts(query)


@app.route('/api/omop/conceptAncestors')
Expand Down Expand Up @@ -95,25 +123,6 @@ def api_omop_xrefFromOMOP():
return api_call('omop', 'xrefFromOMOP')


@app.route('/api/metadata/datasets')
def api_metadata_datasets():
return api_call('metadata', 'datasets')


@app.route('/api/metadata/domainCounts')
def api_metadata_domainCounts():
return api_call('metadata', 'domainCounts')


@app.route('/api/metadata/domainPairCounts')
def api_metadata_domainPairCounts():
return api_call('metadata', 'domainPairCounts')


@app.route('/api/metadata/patientCount')
def api_metadata_patientCount():
return api_call('metadata', 'patientCount')


@app.route('/api/frequencies/singleConceptFreq')
@app.route('/api/v1/frequencies/singleConceptFreq')
Expand Down Expand Up @@ -160,6 +169,11 @@ def api_association_relativeFrequency():
return api_call('association', 'relativeFrequency')


@app.route('/api/association/mcq')
def api_association_mcq():
return api_call('association', 'mcq')


@app.route('/api/temporal/conceptAgeCounts')
def api_temporal_conceptAgeCounts():
return api_call('temporal', 'conceptAgeCounts')
Expand Down Expand Up @@ -306,7 +320,8 @@ def api_call(service=None, meta=None, query=None, version=None):
elif service == 'association':
if meta == 'chiSquare' or \
meta == 'obsExpRatio' or \
meta == 'relativeFrequency':
meta == 'relativeFrequency' or \
meta == 'mcq':
result = query_cohd_mysql.query_db(service, meta, request.args)
else:
result = 'meta not recognized', 400
Expand Down
25 changes: 24 additions & 1 deletion cohd/cohd_trapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TrapiStatusCode(Enum):
UNSUPPORTED_ATTR_CONSTRAINT = 'UnsupportedAttributeConstraint'
UNSUPPORTED_QUAL_CONSTRAINT = 'UnsupportedQualifierConstraint'
UNSUPPORTED_SET_INTERPRETATION = 'UnsupportedSetInterpretation'
MISSING_MEMBER_IDS = 'MissingMemberIDs'


class CohdTrapi(ABC):
Expand Down Expand Up @@ -210,6 +211,28 @@ def criteria_confidence(cohd_result, confidence, threshold=CohdTrapi.default_ln_
return True


def criteria_mcq_score(cohd_result, threshold=CohdTrapi.default_ln_ratio_ci_thresohld):
""" Checks the confidence interval of the result for significance using alpha. Only applies to observed-expected
frequency ratio. Returns True for all other types of results.

Parameters
----------
cohd_result
confidence
threshold

Returns
-------
True if significant
"""
if 'ln_ratio_score' in cohd_result:
# obsExpFreq
return abs(cohd_result['ln_ratio_score']) >= threshold
else:
# Missing the score to filter on
return False


mappings_domain_ontology = {
'_DEFAULT': ['ICD9CM', 'RxNorm', 'UMLS', 'DOID', 'MONDO']
}
Expand Down Expand Up @@ -318,7 +341,7 @@ def sort_cohd_results(cohd_results, sort_field='ln_ratio_ci', ascending=False):
if cohd_results is None or len(cohd_results) == 0:
return cohd_results

if sort_field in ['p-value', 'ln_ratio', 'relative_frequency']:
if sort_field in ['p-value', 'ln_ratio', 'relative_frequency', 'ln_ratio_score']:
sort_values = [x[sort_field] for x in cohd_results]
elif sort_field == 'ln_ratio_ci':
sort_values = [score_cohd_result(x) for x in cohd_results]
Expand Down
Loading