Spaces:
Running
Running
Upload 3 files
Browse files- main.py +53 -30
- pbs_data.py +25 -7
- rheumatology_biologics_data.db +0 -0
main.py
CHANGED
@@ -102,19 +102,21 @@ def load_data():
|
|
102 |
'brands': [],
|
103 |
'formulations': [],
|
104 |
'indications': [],
|
105 |
-
'treatment_phases': []
|
|
|
106 |
}
|
107 |
|
108 |
# Fetch all data
|
109 |
cursor.execute('''SELECT c.pbs_code, d.name as drug, b.name as brand, f.name as formulation,
|
110 |
i.name as indication, tp.name as treatment_phase, c.streamlined_code,
|
111 |
-
c.online_application, c.authority_method
|
112 |
FROM combinations c
|
113 |
JOIN drugs d ON c.drug_id = d.id
|
114 |
JOIN brands b ON c.brand_id = b.id
|
115 |
JOIN formulations f ON c.formulation_id = f.id
|
116 |
JOIN indications i ON c.indication_id = i.id
|
117 |
-
JOIN treatment_phases tp ON c.treatment_phase_id = tp.id
|
|
|
118 |
|
119 |
data = cursor.fetchall()
|
120 |
|
@@ -133,6 +135,9 @@ def load_data():
|
|
133 |
|
134 |
cursor.execute('SELECT name FROM treatment_phases')
|
135 |
treatment_phases = [row[0] for row in cursor.fetchall()]
|
|
|
|
|
|
|
136 |
|
137 |
conn.close()
|
138 |
|
@@ -142,25 +147,27 @@ def load_data():
|
|
142 |
'brands': brands,
|
143 |
'formulations': formulations,
|
144 |
'indications': indications,
|
145 |
-
'treatment_phases': treatment_phases
|
|
|
146 |
}
|
147 |
|
148 |
biologics_data = load_data()
|
149 |
|
150 |
app, rt = fast_app()
|
151 |
|
152 |
-
def search_biologics(drug, brand, formulation, indication, treatment_phase):
|
153 |
field_indices = {
|
154 |
'drug': 1,
|
155 |
'brand': 2,
|
156 |
'formulation': 3,
|
157 |
'indication': 4,
|
158 |
-
'treatment_phase': 5
|
|
|
159 |
}
|
160 |
|
161 |
results = [combo for combo in biologics_data['combinations'] if all(
|
162 |
not value or combo[field_indices[key]] == value
|
163 |
-
for key, value in {'drug': drug, 'brand': brand, 'formulation': formulation, 'indication': indication, 'treatment_phase': treatment_phase}.items()
|
164 |
)]
|
165 |
|
166 |
if not results:
|
@@ -178,19 +185,21 @@ def search_biologics(drug, brand, formulation, indication, treatment_phase):
|
|
178 |
<p><strong>Streamlined Code:</strong> {item[6] or 'N/A'}</p>
|
179 |
<p><strong>Authority Method:</strong> {item[8]}</p>
|
180 |
<p><strong>Online Application:</strong> {'Yes' if item[7] else 'No'}</p>
|
|
|
181 |
</div>
|
182 |
<hr>
|
183 |
"""
|
184 |
|
185 |
return output
|
186 |
|
187 |
-
def update_options(drug, brand, formulation, indication, treatment_phase):
|
188 |
selected = {
|
189 |
'drug': drug,
|
190 |
'brand': brand,
|
191 |
'formulation': formulation,
|
192 |
'indication': indication,
|
193 |
-
'treatment_phase': treatment_phase
|
|
|
194 |
}
|
195 |
|
196 |
field_indices = {
|
@@ -198,7 +207,8 @@ def update_options(drug, brand, formulation, indication, treatment_phase):
|
|
198 |
'brand': 2,
|
199 |
'formulation': 3,
|
200 |
'indication': 4,
|
201 |
-
'treatment_phase': 5
|
|
|
202 |
}
|
203 |
|
204 |
filtered = [combo for combo in biologics_data['combinations'] if all(
|
@@ -211,7 +221,8 @@ def update_options(drug, brand, formulation, indication, treatment_phase):
|
|
211 |
'brands': sorted(set(combo[2] for combo in filtered)),
|
212 |
'formulations': sorted(set(combo[3] for combo in filtered)),
|
213 |
'indications': sorted(set(combo[4] for combo in filtered)),
|
214 |
-
'treatment_phases': sorted(set(combo[5] for combo in filtered))
|
|
|
215 |
}
|
216 |
|
217 |
return options
|
@@ -224,23 +235,27 @@ def get():
|
|
224 |
Form(
|
225 |
Div(
|
226 |
Label("Drug:"),
|
227 |
-
Select(Option("All", value=""), *[Option(drug, value=drug) for drug in biologics_data['drugs']], name="drug", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
228 |
),
|
229 |
Div(
|
230 |
Label("Brand:"),
|
231 |
-
Select(Option("All", value=""), *[Option(brand, value=brand) for brand in biologics_data['brands']], name="brand", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
232 |
),
|
233 |
Div(
|
234 |
Label("Formulation:"),
|
235 |
-
Select(Option("All", value=""), *[Option(formulation, value=formulation) for formulation in biologics_data['formulations']], name="formulation", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
236 |
),
|
237 |
Div(
|
238 |
Label("Indication:"),
|
239 |
-
Select(Option("All", value=""), *[Option(indication, value=indication) for indication in biologics_data['indications']], name="indication", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
240 |
),
|
241 |
Div(
|
242 |
Label("Treatment Phase:"),
|
243 |
-
Select(Option("All", value=""), *[Option(phase, value=phase) for phase in biologics_data['treatment_phases']], name="treatment_phase", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
|
|
|
|
|
|
|
|
244 |
),
|
245 |
Div(
|
246 |
Button("Search", type="submit"),
|
@@ -260,23 +275,27 @@ def get():
|
|
260 |
Form(
|
261 |
Div(
|
262 |
Label("Drug:"),
|
263 |
-
Select(Option("All", value=""), *[Option(drug, value=drug) for drug in biologics_data['drugs']], name="drug", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
264 |
),
|
265 |
Div(
|
266 |
Label("Brand:"),
|
267 |
-
Select(Option("All", value=""), *[Option(brand, value=brand) for brand in biologics_data['brands']], name="brand", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
268 |
),
|
269 |
Div(
|
270 |
Label("Formulation:"),
|
271 |
-
Select(Option("All", value=""), *[Option(formulation, value=formulation) for formulation in biologics_data['formulations']], name="formulation", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
272 |
),
|
273 |
Div(
|
274 |
Label("Indication:"),
|
275 |
-
Select(Option("All", value=""), *[Option(indication, value=indication) for indication in biologics_data['indications']], name="indication", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
276 |
),
|
277 |
Div(
|
278 |
Label("Treatment Phase:"),
|
279 |
-
Select(Option("All", value=""), *[Option(phase, value=phase) for phase in biologics_data['treatment_phases']], name="treatment_phase", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
|
|
|
|
|
|
|
|
280 |
),
|
281 |
Div(
|
282 |
Button("Search", type="submit"),
|
@@ -289,30 +308,34 @@ def get():
|
|
289 |
)
|
290 |
|
291 |
@rt('/update_options')
|
292 |
-
def get(drug: str = '', brand: str = '', formulation: str = '', indication: str = '', treatment_phase: str = ''):
|
293 |
-
options = update_options(drug, brand, formulation, indication, treatment_phase)
|
294 |
return Div(
|
295 |
custom_css,
|
296 |
Form(
|
297 |
Div(
|
298 |
Label("Drug:"),
|
299 |
-
Select(Option("All", value=""), *[Option(d, value=d, selected=(d == drug)) for d in options['drugs']], name="drug", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
300 |
),
|
301 |
Div(
|
302 |
Label("Brand:"),
|
303 |
-
Select(Option("All", value=""), *[Option(b, value=b, selected=(b == brand)) for b in options['brands']], name="brand", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
304 |
),
|
305 |
Div(
|
306 |
Label("Formulation:"),
|
307 |
-
Select(Option("All", value=""), *[Option(f, value=f, selected=(f == formulation)) for f in options['formulations']], name="formulation", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
308 |
),
|
309 |
Div(
|
310 |
Label("Indication:"),
|
311 |
-
Select(Option("All", value=""), *[Option(i, value=i, selected=(i == indication)) for i in options['indications']], name="indication", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
312 |
),
|
313 |
Div(
|
314 |
Label("Treatment Phase:"),
|
315 |
-
Select(Option("All", value=""), *[Option(p, value=p, selected=(p == treatment_phase)) for p in options['treatment_phases']], name="treatment_phase", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase']")
|
|
|
|
|
|
|
|
|
316 |
),
|
317 |
Div(
|
318 |
Button("Search", type="submit"),
|
@@ -325,8 +348,8 @@ def get(drug: str = '', brand: str = '', formulation: str = '', indication: str
|
|
325 |
)
|
326 |
|
327 |
@rt('/search')
|
328 |
-
def post(drug: str = '', brand: str = '', formulation: str = '', indication: str = '', treatment_phase: str = ''):
|
329 |
-
results = search_biologics(drug, brand, formulation, indication, treatment_phase)
|
330 |
return results
|
331 |
|
332 |
|
|
|
102 |
'brands': [],
|
103 |
'formulations': [],
|
104 |
'indications': [],
|
105 |
+
'treatment_phases': [],
|
106 |
+
'hospital_types': []
|
107 |
}
|
108 |
|
109 |
# Fetch all data
|
110 |
cursor.execute('''SELECT c.pbs_code, d.name as drug, b.name as brand, f.name as formulation,
|
111 |
i.name as indication, tp.name as treatment_phase, c.streamlined_code,
|
112 |
+
c.online_application, c.authority_method, ht.name as hospital_type
|
113 |
FROM combinations c
|
114 |
JOIN drugs d ON c.drug_id = d.id
|
115 |
JOIN brands b ON c.brand_id = b.id
|
116 |
JOIN formulations f ON c.formulation_id = f.id
|
117 |
JOIN indications i ON c.indication_id = i.id
|
118 |
+
JOIN treatment_phases tp ON c.treatment_phase_id = tp.id
|
119 |
+
JOIN hospital_types ht ON c.hospital_type_id = ht.id''')
|
120 |
|
121 |
data = cursor.fetchall()
|
122 |
|
|
|
135 |
|
136 |
cursor.execute('SELECT name FROM treatment_phases')
|
137 |
treatment_phases = [row[0] for row in cursor.fetchall()]
|
138 |
+
|
139 |
+
cursor.execute('SELECT name FROM hospital_types')
|
140 |
+
hospital_types = [row[0] for row in cursor.fetchall()]
|
141 |
|
142 |
conn.close()
|
143 |
|
|
|
147 |
'brands': brands,
|
148 |
'formulations': formulations,
|
149 |
'indications': indications,
|
150 |
+
'treatment_phases': treatment_phases,
|
151 |
+
'hospital_types': hospital_types
|
152 |
}
|
153 |
|
154 |
biologics_data = load_data()
|
155 |
|
156 |
app, rt = fast_app()
|
157 |
|
158 |
+
def search_biologics(drug, brand, formulation, indication, treatment_phase, hospital_type):
|
159 |
field_indices = {
|
160 |
'drug': 1,
|
161 |
'brand': 2,
|
162 |
'formulation': 3,
|
163 |
'indication': 4,
|
164 |
+
'treatment_phase': 5,
|
165 |
+
'hospital_type': 9
|
166 |
}
|
167 |
|
168 |
results = [combo for combo in biologics_data['combinations'] if all(
|
169 |
not value or combo[field_indices[key]] == value
|
170 |
+
for key, value in {'drug': drug, 'brand': brand, 'formulation': formulation, 'indication': indication, 'treatment_phase': treatment_phase, 'hospital_type': hospital_type}.items()
|
171 |
)]
|
172 |
|
173 |
if not results:
|
|
|
185 |
<p><strong>Streamlined Code:</strong> {item[6] or 'N/A'}</p>
|
186 |
<p><strong>Authority Method:</strong> {item[8]}</p>
|
187 |
<p><strong>Online Application:</strong> {'Yes' if item[7] else 'No'}</p>
|
188 |
+
<p><strong>Hospital Type:</strong> {item[9]}</p>
|
189 |
</div>
|
190 |
<hr>
|
191 |
"""
|
192 |
|
193 |
return output
|
194 |
|
195 |
+
def update_options(drug, brand, formulation, indication, treatment_phase, hospital_type):
|
196 |
selected = {
|
197 |
'drug': drug,
|
198 |
'brand': brand,
|
199 |
'formulation': formulation,
|
200 |
'indication': indication,
|
201 |
+
'treatment_phase': treatment_phase,
|
202 |
+
'hospital_type': hospital_type
|
203 |
}
|
204 |
|
205 |
field_indices = {
|
|
|
207 |
'brand': 2,
|
208 |
'formulation': 3,
|
209 |
'indication': 4,
|
210 |
+
'treatment_phase': 5,
|
211 |
+
'hospital_type': 9
|
212 |
}
|
213 |
|
214 |
filtered = [combo for combo in biologics_data['combinations'] if all(
|
|
|
221 |
'brands': sorted(set(combo[2] for combo in filtered)),
|
222 |
'formulations': sorted(set(combo[3] for combo in filtered)),
|
223 |
'indications': sorted(set(combo[4] for combo in filtered)),
|
224 |
+
'treatment_phases': sorted(set(combo[5] for combo in filtered)),
|
225 |
+
'hospital_types': sorted(set(combo[9] for combo in filtered))
|
226 |
}
|
227 |
|
228 |
return options
|
|
|
235 |
Form(
|
236 |
Div(
|
237 |
Label("Drug:"),
|
238 |
+
Select(Option("All", value=""), *[Option(drug, value=drug) for drug in biologics_data['drugs']], name="drug", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
239 |
),
|
240 |
Div(
|
241 |
Label("Brand:"),
|
242 |
+
Select(Option("All", value=""), *[Option(brand, value=brand) for brand in biologics_data['brands']], name="brand", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
243 |
),
|
244 |
Div(
|
245 |
Label("Formulation:"),
|
246 |
+
Select(Option("All", value=""), *[Option(formulation, value=formulation) for formulation in biologics_data['formulations']], name="formulation", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
247 |
),
|
248 |
Div(
|
249 |
Label("Indication:"),
|
250 |
+
Select(Option("All", value=""), *[Option(indication, value=indication) for indication in biologics_data['indications']], name="indication", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
251 |
),
|
252 |
Div(
|
253 |
Label("Treatment Phase:"),
|
254 |
+
Select(Option("All", value=""), *[Option(phase, value=phase) for phase in biologics_data['treatment_phases']], name="treatment_phase", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
255 |
+
),
|
256 |
+
Div(
|
257 |
+
Label("Hospital Type:"),
|
258 |
+
Select(Option("All", value=""), *[Option(ht, value=ht) for ht in biologics_data['hospital_types']], name="hospital_type", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
259 |
),
|
260 |
Div(
|
261 |
Button("Search", type="submit"),
|
|
|
275 |
Form(
|
276 |
Div(
|
277 |
Label("Drug:"),
|
278 |
+
Select(Option("All", value=""), *[Option(drug, value=drug) for drug in biologics_data['drugs']], name="drug", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
279 |
),
|
280 |
Div(
|
281 |
Label("Brand:"),
|
282 |
+
Select(Option("All", value=""), *[Option(brand, value=brand) for brand in biologics_data['brands']], name="brand", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
283 |
),
|
284 |
Div(
|
285 |
Label("Formulation:"),
|
286 |
+
Select(Option("All", value=""), *[Option(formulation, value=formulation) for formulation in biologics_data['formulations']], name="formulation", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
287 |
),
|
288 |
Div(
|
289 |
Label("Indication:"),
|
290 |
+
Select(Option("All", value=""), *[Option(indication, value=indication) for indication in biologics_data['indications']], name="indication", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
291 |
),
|
292 |
Div(
|
293 |
Label("Treatment Phase:"),
|
294 |
+
Select(Option("All", value=""), *[Option(phase, value=phase) for phase in biologics_data['treatment_phases']], name="treatment_phase", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
295 |
+
),
|
296 |
+
Div(
|
297 |
+
Label("Hospital Type:"),
|
298 |
+
Select(Option("All", value=""), *[Option(ht, value=ht) for ht in biologics_data['hospital_types']], name="hospital_type", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
299 |
),
|
300 |
Div(
|
301 |
Button("Search", type="submit"),
|
|
|
308 |
)
|
309 |
|
310 |
@rt('/update_options')
|
311 |
+
def get(drug: str = '', brand: str = '', formulation: str = '', indication: str = '', treatment_phase: str = '', hospital_type: str = ''):
|
312 |
+
options = update_options(drug, brand, formulation, indication, treatment_phase, hospital_type)
|
313 |
return Div(
|
314 |
custom_css,
|
315 |
Form(
|
316 |
Div(
|
317 |
Label("Drug:"),
|
318 |
+
Select(Option("All", value=""), *[Option(d, value=d, selected=(d == drug)) for d in options['drugs']], name="drug", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
319 |
),
|
320 |
Div(
|
321 |
Label("Brand:"),
|
322 |
+
Select(Option("All", value=""), *[Option(b, value=b, selected=(b == brand)) for b in options['brands']], name="brand", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
323 |
),
|
324 |
Div(
|
325 |
Label("Formulation:"),
|
326 |
+
Select(Option("All", value=""), *[Option(f, value=f, selected=(f == formulation)) for f in options['formulations']], name="formulation", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
327 |
),
|
328 |
Div(
|
329 |
Label("Indication:"),
|
330 |
+
Select(Option("All", value=""), *[Option(i, value=i, selected=(i == indication)) for i in options['indications']], name="indication", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
331 |
),
|
332 |
Div(
|
333 |
Label("Treatment Phase:"),
|
334 |
+
Select(Option("All", value=""), *[Option(p, value=p, selected=(p == treatment_phase)) for p in options['treatment_phases']], name="treatment_phase", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
335 |
+
),
|
336 |
+
Div(
|
337 |
+
Label("Hospital Type:"),
|
338 |
+
Select(Option("All", value=""), *[Option(ht, value=ht, selected=(ht == hospital_type)) for ht in options['hospital_types']], name="hospital_type", hx_get="/update_options", hx_target="#options", hx_trigger="change", hx_include="[name='drug'],[name='brand'],[name='formulation'],[name='indication'],[name='treatment_phase'],[name='hospital_type']")
|
339 |
),
|
340 |
Div(
|
341 |
Button("Search", type="submit"),
|
|
|
348 |
)
|
349 |
|
350 |
@rt('/search')
|
351 |
+
def post(drug: str = '', brand: str = '', formulation: str = '', indication: str = '', treatment_phase: str = '', hospital_type: str = ''):
|
352 |
+
results = search_biologics(drug, brand, formulation, indication, treatment_phase, hospital_type)
|
353 |
return results
|
354 |
|
355 |
|
pbs_data.py
CHANGED
@@ -197,7 +197,7 @@ class PBSPublicDataAPIClient:
|
|
197 |
rheumatic_diseases = [
|
198 |
"rheumatoid arthritis", "psoriatic arthritis", "ankylosing spondylitis",
|
199 |
"non-radiographic axial spondyloarthritis", "giant cell arteritis",
|
200 |
-
"juvenile idiopathic arthritis"
|
201 |
]
|
202 |
|
203 |
data = {}
|
@@ -325,6 +325,14 @@ class PBSPublicDataAPIClient:
|
|
325 |
else:
|
326 |
return 'unknown' # For cases that don't match any category
|
327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
for item in items:
|
329 |
if any(biologic.lower() in item['drug_name'].lower() for biologic in biologics):
|
330 |
pbs_code = item['pbs_code']
|
@@ -338,6 +346,7 @@ class PBSPublicDataAPIClient:
|
|
338 |
"manner_of_administration": item['manner_of_administration'],
|
339 |
"maximum_quantity": item['maximum_quantity_units'],
|
340 |
"number_of_repeats": item['number_of_repeats'],
|
|
|
341 |
"restrictions": []
|
342 |
}
|
343 |
# Append the brand name if it's not already in the list
|
@@ -380,6 +389,7 @@ class PBSPublicDataAPIClient:
|
|
380 |
'formulations': set(),
|
381 |
'indications': set(),
|
382 |
'treatment_phases': set(),
|
|
|
383 |
'combinations': []
|
384 |
}
|
385 |
|
@@ -387,6 +397,7 @@ class PBSPublicDataAPIClient:
|
|
387 |
processed['drugs'].add(item['name'])
|
388 |
processed['brands'].update(item['brands']) # Update this line
|
389 |
processed['formulations'].add(item['li_form'])
|
|
|
390 |
|
391 |
for restriction in item['restrictions']:
|
392 |
processed['indications'].add(restriction['indications'])
|
@@ -402,7 +413,8 @@ class PBSPublicDataAPIClient:
|
|
402 |
'treatment_phase': restriction['treatment_phase'],
|
403 |
'streamlined_code': restriction['streamlined_code'],
|
404 |
'online_application': restriction['online_application'],
|
405 |
-
'authority_method': restriction['authority_method']
|
|
|
406 |
})
|
407 |
|
408 |
return {k: sorted(v) if isinstance(v, set) else v for k, v in processed.items()}
|
@@ -428,18 +440,22 @@ class PBSPublicDataAPIClient:
|
|
428 |
(id INTEGER PRIMARY KEY, name TEXT UNIQUE)''')
|
429 |
cursor.execute('''CREATE TABLE IF NOT EXISTS treatment_phases
|
430 |
(id INTEGER PRIMARY KEY, name TEXT UNIQUE)''')
|
|
|
|
|
431 |
cursor.execute('''CREATE TABLE IF NOT EXISTS combinations
|
432 |
(id INTEGER PRIMARY KEY, pbs_code TEXT, drug_id INTEGER, brand_id INTEGER,
|
433 |
formulation_id INTEGER, indication_id INTEGER, treatment_phase_id INTEGER,
|
434 |
streamlined_code TEXT, online_application BOOLEAN, authority_method TEXT,
|
|
|
435 |
FOREIGN KEY (drug_id) REFERENCES drugs(id),
|
436 |
FOREIGN KEY (brand_id) REFERENCES brands(id),
|
437 |
FOREIGN KEY (formulation_id) REFERENCES formulations(id),
|
438 |
FOREIGN KEY (indication_id) REFERENCES indications(id),
|
439 |
-
FOREIGN KEY (treatment_phase_id) REFERENCES treatment_phases(id)
|
|
|
440 |
|
441 |
# Insert data
|
442 |
-
for table in ['drugs', 'brands', 'formulations', 'indications', 'treatment_phases']:
|
443 |
cursor.executemany(f"INSERT OR IGNORE INTO {table} (name) VALUES (?)",
|
444 |
[(item,) for item in processed_data[table]])
|
445 |
|
@@ -447,17 +463,19 @@ class PBSPublicDataAPIClient:
|
|
447 |
for combo in processed_data['combinations']:
|
448 |
cursor.execute('''INSERT INTO combinations
|
449 |
(pbs_code, drug_id, brand_id, formulation_id, indication_id,
|
450 |
-
treatment_phase_id, streamlined_code, online_application, authority_method
|
|
|
451 |
VALUES (?,
|
452 |
(SELECT id FROM drugs WHERE name = ?),
|
453 |
(SELECT id FROM brands WHERE name = ?),
|
454 |
(SELECT id FROM formulations WHERE name = ?),
|
455 |
(SELECT id FROM indications WHERE name = ?),
|
456 |
(SELECT id FROM treatment_phases WHERE name = ?),
|
457 |
-
?, ?,
|
|
|
458 |
(combo['pbs_code'], combo['drug'], combo['brand'], combo['formulation'],
|
459 |
combo['indication'], combo['treatment_phase'], combo['streamlined_code'],
|
460 |
-
combo['online_application'], combo['authority_method']))
|
461 |
|
462 |
# Add last_updated column and insert timestamp
|
463 |
cursor.execute('''CREATE TABLE IF NOT EXISTS metadata
|
|
|
197 |
rheumatic_diseases = [
|
198 |
"rheumatoid arthritis", "psoriatic arthritis", "ankylosing spondylitis",
|
199 |
"non-radiographic axial spondyloarthritis", "giant cell arteritis",
|
200 |
+
"juvenile idiopathic arthritis", "systemic lupus erythematosus"
|
201 |
]
|
202 |
|
203 |
data = {}
|
|
|
325 |
else:
|
326 |
return 'unknown' # For cases that don't match any category
|
327 |
|
328 |
+
def classify_hospital_type(program_code):
|
329 |
+
if program_code == 'HS':
|
330 |
+
return 'Private'
|
331 |
+
elif program_code == 'HB':
|
332 |
+
return 'Public'
|
333 |
+
else:
|
334 |
+
return 'Any'
|
335 |
+
|
336 |
for item in items:
|
337 |
if any(biologic.lower() in item['drug_name'].lower() for biologic in biologics):
|
338 |
pbs_code = item['pbs_code']
|
|
|
346 |
"manner_of_administration": item['manner_of_administration'],
|
347 |
"maximum_quantity": item['maximum_quantity_units'],
|
348 |
"number_of_repeats": item['number_of_repeats'],
|
349 |
+
"hospital_type": classify_hospital_type(item['program_code']),
|
350 |
"restrictions": []
|
351 |
}
|
352 |
# Append the brand name if it's not already in the list
|
|
|
389 |
'formulations': set(),
|
390 |
'indications': set(),
|
391 |
'treatment_phases': set(),
|
392 |
+
'hospital_types': set(),
|
393 |
'combinations': []
|
394 |
}
|
395 |
|
|
|
397 |
processed['drugs'].add(item['name'])
|
398 |
processed['brands'].update(item['brands']) # Update this line
|
399 |
processed['formulations'].add(item['li_form'])
|
400 |
+
processed['hospital_types'].add(item['hospital_type'])
|
401 |
|
402 |
for restriction in item['restrictions']:
|
403 |
processed['indications'].add(restriction['indications'])
|
|
|
413 |
'treatment_phase': restriction['treatment_phase'],
|
414 |
'streamlined_code': restriction['streamlined_code'],
|
415 |
'online_application': restriction['online_application'],
|
416 |
+
'authority_method': restriction['authority_method'],
|
417 |
+
'hospital_type': item['hospital_type']
|
418 |
})
|
419 |
|
420 |
return {k: sorted(v) if isinstance(v, set) else v for k, v in processed.items()}
|
|
|
440 |
(id INTEGER PRIMARY KEY, name TEXT UNIQUE)''')
|
441 |
cursor.execute('''CREATE TABLE IF NOT EXISTS treatment_phases
|
442 |
(id INTEGER PRIMARY KEY, name TEXT UNIQUE)''')
|
443 |
+
cursor.execute('''CREATE TABLE IF NOT EXISTS hospital_types
|
444 |
+
(id INTEGER PRIMARY KEY, name TEXT UNIQUE)''')
|
445 |
cursor.execute('''CREATE TABLE IF NOT EXISTS combinations
|
446 |
(id INTEGER PRIMARY KEY, pbs_code TEXT, drug_id INTEGER, brand_id INTEGER,
|
447 |
formulation_id INTEGER, indication_id INTEGER, treatment_phase_id INTEGER,
|
448 |
streamlined_code TEXT, online_application BOOLEAN, authority_method TEXT,
|
449 |
+
hospital_type_id INTEGER,
|
450 |
FOREIGN KEY (drug_id) REFERENCES drugs(id),
|
451 |
FOREIGN KEY (brand_id) REFERENCES brands(id),
|
452 |
FOREIGN KEY (formulation_id) REFERENCES formulations(id),
|
453 |
FOREIGN KEY (indication_id) REFERENCES indications(id),
|
454 |
+
FOREIGN KEY (treatment_phase_id) REFERENCES treatment_phases(id),
|
455 |
+
FOREIGN KEY (hospital_type_id) REFERENCES hospital_types(id))''')
|
456 |
|
457 |
# Insert data
|
458 |
+
for table in ['drugs', 'brands', 'formulations', 'indications', 'treatment_phases', 'hospital_types']:
|
459 |
cursor.executemany(f"INSERT OR IGNORE INTO {table} (name) VALUES (?)",
|
460 |
[(item,) for item in processed_data[table]])
|
461 |
|
|
|
463 |
for combo in processed_data['combinations']:
|
464 |
cursor.execute('''INSERT INTO combinations
|
465 |
(pbs_code, drug_id, brand_id, formulation_id, indication_id,
|
466 |
+
treatment_phase_id, streamlined_code, online_application, authority_method,
|
467 |
+
hospital_type_id)
|
468 |
VALUES (?,
|
469 |
(SELECT id FROM drugs WHERE name = ?),
|
470 |
(SELECT id FROM brands WHERE name = ?),
|
471 |
(SELECT id FROM formulations WHERE name = ?),
|
472 |
(SELECT id FROM indications WHERE name = ?),
|
473 |
(SELECT id FROM treatment_phases WHERE name = ?),
|
474 |
+
?, ?, ?,
|
475 |
+
(SELECT id FROM hospital_types WHERE name = ?))''',
|
476 |
(combo['pbs_code'], combo['drug'], combo['brand'], combo['formulation'],
|
477 |
combo['indication'], combo['treatment_phase'], combo['streamlined_code'],
|
478 |
+
combo['online_application'], combo['authority_method'], combo['hospital_type']))
|
479 |
|
480 |
# Add last_updated column and insert timestamp
|
481 |
cursor.execute('''CREATE TABLE IF NOT EXISTS metadata
|
rheumatology_biologics_data.db
CHANGED
Binary files a/rheumatology_biologics_data.db and b/rheumatology_biologics_data.db differ
|
|