Tonic commited on
Commit
36e302c
·
unverified ·
1 Parent(s): b45c9bd

try for one click fix callback manager

Browse files
Files changed (2) hide show
  1. app.py +26 -4
  2. templates/oneclick.html +5 -1
app.py CHANGED
@@ -144,18 +144,40 @@ def file_analysis():
144
  return render_template('analysis.html', result=result, file_type=file_type)
145
  return render_template('analysis.html')
146
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  @app.route('/oneclick', methods=['GET', 'POST'])
148
  def one_click():
 
 
149
  if request.method == 'POST':
150
  patient_id = request.form.get('patient_id', '')
151
  first_name = request.form.get('first_name', '')
152
  last_name = request.form.get('last_name', '')
153
- pdf_path, status = generate_discharge_paper_one_click(CALLBACK_MANAGER.api, patient_id, first_name, last_name)
154
- if pdf_path:
 
 
 
 
 
 
 
155
  return send_file(pdf_path, as_attachment=True, download_name="discharge_summary.pdf")
156
- return render_template('oneclick.html', status=status)
 
157
  return render_template('oneclick.html')
158
 
159
  if __name__ == '__main__':
160
- port = int(os.getenv("PORT", 7860)) # Default to 5000, override with PORT env var
161
  app.run(debug=False, host='0.0.0.0', port=port)
 
144
  return render_template('analysis.html', result=result, file_type=file_type)
145
  return render_template('analysis.html')
146
 
147
+ # Configuration from environment variables
148
+ CLIENT_ID = os.getenv("MELDRX_CLIENT_ID")
149
+ CLIENT_SECRET = None
150
+ WORKSPACE_ID = os.getenv("WORKSPACE_URL")
151
+
152
+ # # Initialize MeldRx API
153
+ # meldrx_api = MeldRxAPI(
154
+ # client_id=CLIENT_ID,
155
+ # client_secret=CLIENT_SECRET,
156
+ # workspace_id=WORKSPACE_ID,
157
+ # redirect_uri=REDIRECT_URI
158
+ # )
159
  @app.route('/oneclick', methods=['GET', 'POST'])
160
  def one_click():
161
+ if not CALLBACK_MANAGER.access_token:
162
+ return redirect(url_for('auth'))
163
  if request.method == 'POST':
164
  patient_id = request.form.get('patient_id', '')
165
  first_name = request.form.get('first_name', '')
166
  last_name = request.form.get('last_name', '')
167
+ action = request.form.get('action', '')
168
+
169
+ pdf_path, status, display_summary = generate_discharge_paper_one_click(
170
+ CALLBACK_MANAGER, patient_id, first_name, last_name
171
+ )
172
+
173
+ if action == "display" and display_summary:
174
+ return render_template('oneclick.html', status=status, summary=display_summary)
175
+ elif action == "generate_pdf" and pdf_path:
176
  return send_file(pdf_path, as_attachment=True, download_name="discharge_summary.pdf")
177
+ return render_template('oneclick.html', status=status, summary=display_summary)
178
+
179
  return render_template('oneclick.html')
180
 
181
  if __name__ == '__main__':
182
+ port = int(os.getenv("PORT", 7860))
183
  app.run(debug=False, host='0.0.0.0', port=port)
templates/oneclick.html CHANGED
@@ -5,9 +5,13 @@
5
  <input type="text" name="patient_id" placeholder="Patient ID (Optional)">
6
  <input type="text" name="first_name" placeholder="First Name (Optional)">
7
  <input type="text" name="last_name" placeholder="Last Name (Optional)"><br>
8
- <input type="submit" value="Generate with AI" class="cyberpunk-button">
 
9
  </form>
10
  {% if status %}
11
  <div>{{ status }}</div>
12
  {% endif %}
 
 
 
13
  {% endblock %}
 
5
  <input type="text" name="patient_id" placeholder="Patient ID (Optional)">
6
  <input type="text" name="first_name" placeholder="First Name (Optional)">
7
  <input type="text" name="last_name" placeholder="Last Name (Optional)"><br>
8
+ <input type="submit" name="action" value="Display Summary" class="cyberpunk-button">
9
+ <input type="submit" name="action" value="Generate PDF" class="cyberpunk-button">
10
  </form>
11
  {% if status %}
12
  <div>{{ status }}</div>
13
  {% endif %}
14
+ {% if summary %}
15
+ <div>{{ summary | safe }}</div>
16
+ {% endif %}
17
  {% endblock %}