Skip to content

Commit b2f87ef

Browse files
authored
Merge pull request #203 from WengLab-InformaticsResearch/mcq
Mcq
2 parents 0b03f8e + 91b3cc5 commit b2f87ef

File tree

6 files changed

+937
-359
lines changed

6 files changed

+937
-359
lines changed

cohd/cohd.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,44 @@ def api_cohd():
4848
return redirect("https://cohd.smart-api.info/", code=302)
4949

5050

51+
@app.route('/api/metadata/datasets')
52+
def api_metadata_datasets():
53+
return query_cohd_mysql.query_db_datasets()
54+
55+
56+
@app.route('/api/metadata/domainCounts')
57+
def api_metadata_domainCounts():
58+
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
59+
return query_cohd_mysql.query_db_domain_counts(dataset_id)
60+
61+
62+
@app.route('/api/metadata/domainPairCounts')
63+
def api_metadata_domainPairCounts():
64+
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
65+
return query_cohd_mysql.query_db_domain_pair_counts(dataset_id)
66+
67+
68+
@app.route('/api/metadata/patientCount')
69+
def api_metadata_patientCount():
70+
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
71+
return query_cohd_mysql.query_db_patient_count(dataset_id)
72+
73+
5174
@app.route('/api/omop/findConceptIDs')
5275
@app.route('/api/v1/omop/findConceptIDs')
5376
def api_omop_reference():
54-
return api_call('omop', 'findConceptIDs')
77+
query = request.args.get('q')
78+
dataset_id = query_cohd_mysql.get_arg_dataset_id(request.args)
79+
domain_id = request.args.get('domain')
80+
min_count = request.args.get('min_count')
81+
return query_cohd_mysql.query_db_find_concept_ids(dataset_id, query, domain_id, min_count)
5582

5683

5784
@app.route('/api/omop/concepts')
5885
@app.route('/api/v1/omop/concepts')
5986
def api_omop_concepts():
60-
return api_call('omop', 'concepts')
87+
query = request.args.get('q')
88+
return query_cohd_mysql.query_db_concepts(query)
6189

6290

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

97125

98-
@app.route('/api/metadata/datasets')
99-
def api_metadata_datasets():
100-
return api_call('metadata', 'datasets')
101-
102-
103-
@app.route('/api/metadata/domainCounts')
104-
def api_metadata_domainCounts():
105-
return api_call('metadata', 'domainCounts')
106-
107-
108-
@app.route('/api/metadata/domainPairCounts')
109-
def api_metadata_domainPairCounts():
110-
return api_call('metadata', 'domainPairCounts')
111-
112-
113-
@app.route('/api/metadata/patientCount')
114-
def api_metadata_patientCount():
115-
return api_call('metadata', 'patientCount')
116-
117126

118127
@app.route('/api/frequencies/singleConceptFreq')
119128
@app.route('/api/v1/frequencies/singleConceptFreq')
@@ -160,6 +169,11 @@ def api_association_relativeFrequency():
160169
return api_call('association', 'relativeFrequency')
161170

162171

172+
@app.route('/api/association/mcq')
173+
def api_association_mcq():
174+
return api_call('association', 'mcq')
175+
176+
163177
@app.route('/api/temporal/conceptAgeCounts')
164178
def api_temporal_conceptAgeCounts():
165179
return api_call('temporal', 'conceptAgeCounts')
@@ -306,7 +320,8 @@ def api_call(service=None, meta=None, query=None, version=None):
306320
elif service == 'association':
307321
if meta == 'chiSquare' or \
308322
meta == 'obsExpRatio' or \
309-
meta == 'relativeFrequency':
323+
meta == 'relativeFrequency' or \
324+
meta == 'mcq':
310325
result = query_cohd_mysql.query_db(service, meta, request.args)
311326
else:
312327
result = 'meta not recognized', 400

cohd/cohd_trapi.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class TrapiStatusCode(Enum):
2727
UNSUPPORTED_ATTR_CONSTRAINT = 'UnsupportedAttributeConstraint'
2828
UNSUPPORTED_QUAL_CONSTRAINT = 'UnsupportedQualifierConstraint'
2929
UNSUPPORTED_SET_INTERPRETATION = 'UnsupportedSetInterpretation'
30+
MISSING_MEMBER_IDS = 'MissingMemberIDs'
3031

3132

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

212213

214+
def criteria_mcq_score(cohd_result, threshold=CohdTrapi.default_ln_ratio_ci_thresohld):
215+
""" Checks the confidence interval of the result for significance using alpha. Only applies to observed-expected
216+
frequency ratio. Returns True for all other types of results.
217+
218+
Parameters
219+
----------
220+
cohd_result
221+
confidence
222+
threshold
223+
224+
Returns
225+
-------
226+
True if significant
227+
"""
228+
if 'ln_ratio_score' in cohd_result:
229+
# obsExpFreq
230+
return abs(cohd_result['ln_ratio_score']) >= threshold
231+
else:
232+
# Missing the score to filter on
233+
return False
234+
235+
213236
mappings_domain_ontology = {
214237
'_DEFAULT': ['ICD9CM', 'RxNorm', 'UMLS', 'DOID', 'MONDO']
215238
}
@@ -318,7 +341,7 @@ def sort_cohd_results(cohd_results, sort_field='ln_ratio_ci', ascending=False):
318341
if cohd_results is None or len(cohd_results) == 0:
319342
return cohd_results
320343

321-
if sort_field in ['p-value', 'ln_ratio', 'relative_frequency']:
344+
if sort_field in ['p-value', 'ln_ratio', 'relative_frequency', 'ln_ratio_score']:
322345
sort_values = [x[sort_field] for x in cohd_results]
323346
elif sort_field == 'ln_ratio_ci':
324347
sort_values = [score_cohd_result(x) for x in cohd_results]

0 commit comments

Comments
 (0)