Spaces:
Running
Running
Update pbs_data.py
Browse files- pbs_data.py +15 -5
pbs_data.py
CHANGED
@@ -210,6 +210,8 @@ class PBSPublicDataAPIClient:
|
|
210 |
schedules[0] # fallback to the most recent schedule if no match
|
211 |
)
|
212 |
latest_schedule = current_schedule['schedule_code']
|
|
|
|
|
213 |
|
214 |
print(f"Selected schedule: {latest_schedule} (Effective: {current_schedule['effective_date']})")
|
215 |
|
@@ -338,6 +340,9 @@ class PBSPublicDataAPIClient:
|
|
338 |
pbs_code = item['pbs_code']
|
339 |
if pbs_code not in data:
|
340 |
data[pbs_code] = {
|
|
|
|
|
|
|
341 |
"name": item['drug_name'],
|
342 |
"brands": [], # Change this to a list
|
343 |
"formulation": classify_formulation(item['li_form']),
|
@@ -414,7 +419,10 @@ class PBSPublicDataAPIClient:
|
|
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()}
|
@@ -446,7 +454,7 @@ class PBSPublicDataAPIClient:
|
|
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),
|
@@ -464,7 +472,7 @@ class PBSPublicDataAPIClient:
|
|
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 = ?),
|
@@ -472,10 +480,12 @@ class PBSPublicDataAPIClient:
|
|
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
|
|
|
210 |
schedules[0] # fallback to the most recent schedule if no match
|
211 |
)
|
212 |
latest_schedule = current_schedule['schedule_code']
|
213 |
+
schedule_year = current_schedule['effective_year']
|
214 |
+
schedule_month = current_schedule['effective_month']
|
215 |
|
216 |
print(f"Selected schedule: {latest_schedule} (Effective: {current_schedule['effective_date']})")
|
217 |
|
|
|
340 |
pbs_code = item['pbs_code']
|
341 |
if pbs_code not in data:
|
342 |
data[pbs_code] = {
|
343 |
+
"schedule_code": latest_schedule,
|
344 |
+
"schedule_year": schedule_year,
|
345 |
+
"schedule_month": schedule_month,
|
346 |
"name": item['drug_name'],
|
347 |
"brands": [], # Change this to a list
|
348 |
"formulation": classify_formulation(item['li_form']),
|
|
|
419 |
'streamlined_code': restriction['streamlined_code'],
|
420 |
'online_application': restriction['online_application'],
|
421 |
'authority_method': restriction['authority_method'],
|
422 |
+
'hospital_type': item['hospital_type'],
|
423 |
+
'schedule_code': item['schedule_code'],
|
424 |
+
'schedule_year': item['schedule_year'],
|
425 |
+
'schedule_month': item['schedule_month']
|
426 |
})
|
427 |
|
428 |
return {k: sorted(v) if isinstance(v, set) else v for k, v in processed.items()}
|
|
|
454 |
(id INTEGER PRIMARY KEY, pbs_code TEXT, drug_id INTEGER, brand_id INTEGER,
|
455 |
formulation_id INTEGER, indication_id INTEGER, treatment_phase_id INTEGER,
|
456 |
streamlined_code TEXT, online_application BOOLEAN, authority_method TEXT,
|
457 |
+
hospital_type_id INTEGER, schedule_code TEXT, schedule_year INTEGER, schedule_month TEXT,
|
458 |
FOREIGN KEY (drug_id) REFERENCES drugs(id),
|
459 |
FOREIGN KEY (brand_id) REFERENCES brands(id),
|
460 |
FOREIGN KEY (formulation_id) REFERENCES formulations(id),
|
|
|
472 |
cursor.execute('''INSERT INTO combinations
|
473 |
(pbs_code, drug_id, brand_id, formulation_id, indication_id,
|
474 |
treatment_phase_id, streamlined_code, online_application, authority_method,
|
475 |
+
hospital_type_id, schedule_code, schedule_year, schedule_month)
|
476 |
VALUES (?,
|
477 |
(SELECT id FROM drugs WHERE name = ?),
|
478 |
(SELECT id FROM brands WHERE name = ?),
|
|
|
480 |
(SELECT id FROM indications WHERE name = ?),
|
481 |
(SELECT id FROM treatment_phases WHERE name = ?),
|
482 |
?, ?, ?,
|
483 |
+
(SELECT id FROM hospital_types WHERE name = ?),
|
484 |
+
?, ?, ?)''',
|
485 |
(combo['pbs_code'], combo['drug'], combo['brand'], combo['formulation'],
|
486 |
combo['indication'], combo['treatment_phase'], combo['streamlined_code'],
|
487 |
+
combo['online_application'], combo['authority_method'], combo['hospital_type'],
|
488 |
+
combo['schedule_code'], combo['schedule_year'], combo['schedule_month']))
|
489 |
|
490 |
# Add last_updated column and insert timestamp
|
491 |
cursor.execute('''CREATE TABLE IF NOT EXISTS metadata
|