cmcmaster commited on
Commit
4731312
1 Parent(s): 0a709a0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +176 -39
main.py CHANGED
@@ -7,6 +7,82 @@ from pbs_data import PBSPublicDataAPIClient
7
  import os
8
  from fasthtml_hf import setup_hf_backup # Add this line
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  # Database file
11
  DB_FILE = 'rheumatology_biologics_data.db'
12
 
@@ -17,7 +93,7 @@ def load_data():
17
  try:
18
  conn = sqlite3.connect(DB_FILE)
19
  cursor = conn.cursor()
20
- # ... (rest of the function)
21
  except sqlite3.Error as e:
22
  print(f"An error occurred: {e}")
23
  return {
@@ -93,14 +169,16 @@ def search_biologics(drug, brand, formulation, indication, treatment_phase):
93
  output = ""
94
  for item in results:
95
  output += f"""
96
- <h2>{item[1]} ({item[2]})</h2>
97
- <p>PBS Code: <a href="https://www.pbs.gov.au/medicine/item/{item[0]}" target="_blank">{item[0]}</a></p>
98
- <p>Formulation: {item[3]}</p>
99
- <p>Indication: {item[4]}</p>
100
- <p>Treatment Phase: {item[5]}</p>
101
- <p>Streamlined Code: {item[6] or 'N/A'}</p>
102
- <p>Authority Method: {item[8]}</p>
103
- <p>Online Application: {'Yes' if item[7] else 'No'}</p>
 
 
104
  <hr>
105
  """
106
 
@@ -140,15 +218,34 @@ def update_options(drug, brand, formulation, indication, treatment_phase):
140
 
141
  @rt('/')
142
  def get():
143
- return Titled("Biologics Prescriber Helper",
 
 
144
  Form(
145
- Select(Option("All", value=""), *[Option(drug, value=drug) for drug in biologics_data['drugs']], label="Drug", 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']"),
146
- Select(Option("All", value=""), *[Option(brand, value=brand) for brand in biologics_data['brands']], label="Brand", 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']"),
147
- Select(Option("All", value=""), *[Option(formulation, value=formulation) for formulation in biologics_data['formulations']], label="Formulation", 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']"),
148
- Select(Option("All", value=""), *[Option(indication, value=indication) for indication in biologics_data['indications']], label="Indication", 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']"),
149
- Select(Option("All", value=""), *[Option(phase, value=phase) for phase in biologics_data['treatment_phases']], label="Treatment Phase", 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']"),
150
- Button("Search", type="submit"),
151
- Button("Reset", hx_get="/reset", hx_target="#options"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  hx_post="/search",
153
  hx_target="#results",
154
  id="options"
@@ -158,33 +255,73 @@ def get():
158
 
159
  @rt('/reset')
160
  def get():
161
- return Form(
162
- Select(Option("All", value=""), *[Option(drug, value=drug) for drug in biologics_data['drugs']], label="Drug", 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']"),
163
- Select(Option("All", value=""), *[Option(brand, value=brand) for brand in biologics_data['brands']], label="Brand", 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']"),
164
- Select(Option("All", value=""), *[Option(formulation, value=formulation) for formulation in biologics_data['formulations']], label="Formulation", 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']"),
165
- Select(Option("All", value=""), *[Option(indication, value=indication) for indication in biologics_data['indications']], label="Indication", 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']"),
166
- Select(Option("All", value=""), *[Option(phase, value=phase) for phase in biologics_data['treatment_phases']], label="Treatment Phase", 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']"),
167
- Button("Search", type="submit"),
168
- Button("Reset", hx_get="/reset", hx_target="#options"),
169
- hx_post="/search",
170
- hx_target="#results",
171
- id="options"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  )
173
 
174
  @rt('/update_options')
175
  def get(drug: str = '', brand: str = '', formulation: str = '', indication: str = '', treatment_phase: str = ''):
176
  options = update_options(drug, brand, formulation, indication, treatment_phase)
177
- return Form(
178
- Select(Option("All", value=""), *[Option(d, value=d, selected=(d == drug)) for d in options['drugs']], label="Drug", 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']"),
179
- Select(Option("All", value=""), *[Option(b, value=b, selected=(b == brand)) for b in options['brands']], label="Brand", 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']"),
180
- Select(Option("All", value=""), *[Option(f, value=f, selected=(f == formulation)) for f in options['formulations']], label="Formulation", 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']"),
181
- Select(Option("All", value=""), *[Option(i, value=i, selected=(i == indication)) for i in options['indications']], label="Indication", 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']"),
182
- Select(Option("All", value=""), *[Option(p, value=p, selected=(p == treatment_phase)) for p in options['treatment_phases']], label="Treatment Phase", 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']"),
183
- Button("Search", type="submit"),
184
- Button("Reset", hx_get="/reset", hx_target="#options"),
185
- hx_post="/search",
186
- hx_target="#results",
187
- id="options"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  )
189
 
190
  @rt('/search')
 
7
  import os
8
  from fasthtml_hf import setup_hf_backup # Add this line
9
 
10
+ custom_css = Style("""
11
+ body {
12
+ font-family: Arial, sans-serif;
13
+ line-height: 1.6;
14
+ color: #333;
15
+ max-width: 800px;
16
+ margin: 0 auto;
17
+ padding: 20px;
18
+ background-color: #f0f0f0;
19
+ }
20
+ h1 {
21
+ color: #2c3e50;
22
+ text-align: center;
23
+ margin-bottom: 30px;
24
+ }
25
+ form {
26
+ background-color: #ffffff;
27
+ padding: 20px;
28
+ border-radius: 8px;
29
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
30
+ }
31
+ label {
32
+ display: block;
33
+ margin-bottom: 5px;
34
+ font-weight: bold;
35
+ color: #2c3e50;
36
+ }
37
+ select, button {
38
+ width: 100%;
39
+ padding: 10px;
40
+ margin-bottom: 15px;
41
+ border: 1px solid #ddd;
42
+ border-radius: 4px;
43
+ background-color: #fff;
44
+ color: #333;
45
+ }
46
+ button {
47
+ background-color: #3498db;
48
+ color: white;
49
+ font-weight: bold;
50
+ cursor: pointer;
51
+ transition: background-color 0.3s;
52
+ }
53
+ button:hover {
54
+ background-color: #2980b9;
55
+ }
56
+ #results {
57
+ margin-top: 30px;
58
+ background-color: #ffffff;
59
+ padding: 20px;
60
+ border-radius: 8px;
61
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
62
+ }
63
+ #results h2 {
64
+ color: #2c3e50;
65
+ border-bottom: 2px solid #3498db;
66
+ padding-bottom: 10px;
67
+ }
68
+ #results p {
69
+ margin-bottom: 10px;
70
+ color: #333;
71
+ }
72
+ #results hr {
73
+ border: none;
74
+ border-top: 1px solid #eee;
75
+ margin: 20px 0;
76
+ }
77
+ a {
78
+ color: #3498db;
79
+ text-decoration: none;
80
+ }
81
+ a:hover {
82
+ text-decoration: underline;
83
+ }
84
+ """)
85
+
86
  # Database file
87
  DB_FILE = 'rheumatology_biologics_data.db'
88
 
 
93
  try:
94
  conn = sqlite3.connect(DB_FILE)
95
  cursor = conn.cursor()
96
+
97
  except sqlite3.Error as e:
98
  print(f"An error occurred: {e}")
99
  return {
 
169
  output = ""
170
  for item in results:
171
  output += f"""
172
+ <div class="result-item">
173
+ <h2>{item[1]} ({item[2]})</h2>
174
+ <p><strong>PBS Code:</strong> <a href="https://www.pbs.gov.au/medicine/item/{item[0]}" target="_blank">{item[0]}</a></p>
175
+ <p><strong>Formulation:</strong> {item[3]}</p>
176
+ <p><strong>Indication:</strong> {item[4]}</p>
177
+ <p><strong>Treatment Phase:</strong> {item[5]}</p>
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
 
 
218
 
219
  @rt('/')
220
  def get():
221
+ return Div(
222
+ custom_css,
223
+ H1("Biologics Prescriber Helper"),
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"),
247
+ Button("Reset", hx_get="/reset", hx_target="#options")
248
+ ),
249
  hx_post="/search",
250
  hx_target="#results",
251
  id="options"
 
255
 
256
  @rt('/reset')
257
  def get():
258
+ return Div(
259
+ custom_css,
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"),
283
+ Button("Reset", hx_get="/reset", hx_target="#options")
284
+ ),
285
+ hx_post="/search",
286
+ hx_target="#results",
287
+ id="options"
288
+ )
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"),
319
+ Button("Reset", hx_get="/reset", hx_target="#options")
320
+ ),
321
+ hx_post="/search",
322
+ hx_target="#results",
323
+ id="options"
324
+ )
325
  )
326
 
327
  @rt('/search')