-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.py
143 lines (137 loc) · 4.58 KB
/
queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
questionBanksIDandName = "SELECT name, id FROM question_banks WHERE state = 'active' ORDER BY id asc"
noSubjects = """With internal_medicine as (
WITH all_internal_medicine_question_subjects as (
SELECT questions_subjects.question_id, questions_subjects.subject_id, subjects.name
FROM questions_subjects
JOIN
question_banks_subjects ON question_banks_subjects.subject_id = questions_subjects.subject_id AND question_banks_subjects.question_bank_id = %(qbank_id)s
JOIN
subjects on subjects.id = questions_subjects.subject_id
)
SELECT
questions.id as id, string_agg(all_internal_medicine_question_subjects.name, ', ') as all_subjects
FROM
questions
JOIN
question_banks_questions qbqs ON qbqs.question_id = questions.id AND qbqs.question_bank_id = %(qbank_id)s
LEFT OUTER JOIN
all_internal_medicine_question_subjects ON all_internal_medicine_question_subjects.question_id = questions.id
WHERE
questions.state = 'active'
GROUP BY
questions.id
ORDER BY questions.id ASC),
internal_medicine_no_vc_or_ie as (SELECT
distinct explanations.question_id as id,
string_agg(subjects.name, ', ') as Subject_name
FROM
explanations
JOIN
question_banks_questions qbq on explanations.question_id = qbq.question_id
JOIN
question_banks qb on qb.id = qbq.question_bank_id
JOIN
questions on questions.id = qbq.question_id
JOIN
questions_subjects on questions_subjects.question_id = questions.id
JOIN
subjects on subjects.id = questions_subjects.subject_id
WHERE
questions.state = 'active'
and qb.id = %(qbank_id)s
GROUP BY
explanations.question_id
ORDER BY
explanations.question_id asc)
select
count(id)
FROM
internal_medicine
WHERE
all_subjects is null"""
questionsWithMultipleSubjects = """ WITH all_internal_medicine_question_subjects as (
SELECT questions_subjects.question_id, questions_subjects.subject_id, subjects.name
FROM questions_subjects
JOIN
question_banks_subjects ON question_banks_subjects.subject_id = questions_subjects.subject_id AND question_banks_subjects.question_bank_id = %(qbank_id)s
JOIN
subjects on subjects.id = questions_subjects.subject_id
), question_bank_question_subjects as (
SELECT
questions.id as id,
string_agg(all_internal_medicine_question_subjects.name, ', ') as all_subjects
FROM
questions
JOIN
question_banks_questions qbqs ON qbqs.question_id = questions.id AND qbqs.question_bank_id = %(qbank_id)s
LEFT OUTER JOIN
all_internal_medicine_question_subjects ON all_internal_medicine_question_subjects.question_id = questions.id
WHERE
questions.state = 'active'
GROUP BY
questions.id
ORDER BY questions.id ASC)
SELECT
count(question_bank_question_subjects.id)
from question_bank_question_subjects
WHERE
question_bank_question_subjects.all_subjects ilike '%%,%%' """
noVitalConcept = '''select
distinct explanations.question_id as qid,
string_agg(question_banks.name, ',') as bank_names
from
explanations
join questions on questions.id = explanations.question_id
join question_banks_questions qbq on questions.id = qbq.question_id
join question_banks on qbq.question_bank_id = question_banks.id
where
NOT explanations.name ilike '%%vital concept%%'
AND questions.state = 'active'
group by
qid
order by
qid asc'''
noIncorrectAnswer = '''select
distinct explanations.question_id as qid,
string_agg(question_banks.name, ',') as bank_names
from
explanations
join questions on questions.id = explanations.question_id
join question_banks_questions qbq on questions.id = qbq.question_id
join question_banks on qbq.question_bank_id = question_banks.id
where
NOT explanations.name ilike '%%incorrect answer%%'
AND questions.state = 'active'
group by
qid
order by
qid asc'''
noRefernceLink = '''
select
distinct questions.id as qid,
string_agg(question_banks.name, ',') as bank_names
from
questions
join question_banks_questions qbq on questions.id = qbq.question_id
join question_banks on qbq.question_bank_id = question_banks.id
where
NOT questions.reference ilike '%href%'
AND questions.state = 'active'
group by
qid
order by
qid asc
'''
allQuestionsQuestionBanks = '''
select
distinct questions.id as qid,
string_agg(question_banks.name, ',') as bank_names
from
questions
join question_banks_questions qbq on questions.id = qbq.question_id
join question_banks on qbq.question_bank_id = question_banks.id
group by
qid
order by
qid asc
'''