def create_patients(): form = PatientsForm() # The user pressed the "Submit" button if 'submit' in request.form: if form.validate_on_submit(): new_request = { k: v.capitalize() for k, v in request.form.items() if k not in ['csrf_token', 'submit', 'cancel', 'ct_scan', 'picture'] } patient = Patient(**new_request, doctor=current_user) if form.picture.data: patient.picture = save_picture_patients(form.picture.data) db.session.add(patient) db.session.commit() flash('Your patient has been added!', 'success') return redirect( url_for('patients_blueprint.patients_profile', patient_id=patient.id)) # The user pressed the "Cancel" button if 'cancel' in request.form: return redirect(url_for('home_blueprint.index')) picture_file = url_for('static', filename='patients_pics/default.png') return render_template('edit_info.html', title='Create', heading='Create', form=form, picture_file=picture_file)
def edit_info(patient_id): patient = Patient.query.get_or_404(patient_id) form = PatientsForm() # The user pressed the "Cancel" button if form.cancel.data: return redirect( url_for('patients_blueprint.patients_profile', patient_id=patient.id)) # The user pressed the "Submit" button if form.submit.data: if form.validate_on_submit(): if form.picture.data: patient.picture = save_picture_patients(form.picture.data) if form.blood_drawn_date.data: patient.blood_drawn_date = datetime.strptime( form.blood_drawn_date.data, '%Y-%m-%d').strftime('%b %d, %Y') for field in form: if field.name not in [ 'csrf_token', 'submit', 'cancel', 'ct_scan', 'picture', 'blood_drawn_date' ]: setattr(patient, field.name, field.data) db.session.commit() flash('Your patient info has been updated!', 'success') return redirect( url_for('patients_blueprint.patients_profile', patient_id=patient.id)) elif request.method == 'GET': for field in form: if field.name not in [ 'csrf_token', 'submit', 'cancel', 'ct_scan', 'picture', 'blood_drawn_date' ]: field.data = getattr(patient, field.name) elif field.name == 'blood_drawn_date': if field.data: field.data = datetime.strptime( patient.blood_drawn_date, '%b %d, %Y').strftime('%Y-%m-%d') if patient.picture == '': picture_file = url_for('static', filename='patients_pics/default.png') else: picture_file = url_for('static', filename='patients_pics/' + patient.picture) return render_template('edit_info.html', title='Edit', heading='Edit', form=form, picture_file=picture_file, health_info_dict=health_info_dict)
def pdf_template(patient_id, upload_id): form = PatientsForm() upload = Upload.query.filter_by(id=upload_id).first() upload_list = upload.patient.upload.order_by( Upload.date_uploaded.desc()).all() if len(upload_list) > 1: upload_index = upload_list.index(upload) + 1 previous_upload_list = upload_list[upload_index:] else: previous_upload_list = [] ct_scan = upload.ct_scan patient = upload.patient specs_list = list( itertools.chain(*[ health_info_dict['biopsy_test'], health_info_dict['genetic_test'] ])) specs_dict = dict( zip(specs_list, [getattr(patient, spec) for spec in specs_list])) if ct_scan.binary_prediction == 0: result_text = 'NOT having lung cancer' treatment = 'No treatment required' medicine = 'No medicine required' elif ct_scan.binary_prediction == 1: result = additional_specs(ct_scan.diameter, specs_dict) result_text = f"stage {result['stage']}, {result['cell_type']}, grade {result['grade']}, {result['invasive_type']}" treatment = result['treatment'] medicine = result['medicine'] else: result_text = f'{round(ct_scan.binary_prediction*100, 2)}% chance of having lung cancer' treatment = 'No treatment required' medicine = 'No medicine required' # if not upload.result_text: # upload.result_text = result_text # db.session.commit() rendered = render_template('pdf_template.html', form=form, upload=upload, ct_scan=ct_scan, result_text=result_text, treatment=treatment, medicine=medicine, result_percent=ct_scan.binary_prediction, previous_upload_list=previous_upload_list, health_info_dict=health_info_dict) return render_pdf(HTML(string=rendered))
def patients_profile(patient_id): patient = Patient.query.get_or_404(patient_id) if patient.picture == '': picture_file = url_for('static', filename='patients_pics/default.png') else: picture_file = url_for('static', filename='patients_pics/' + patient.picture) return render_template('patients_profile.html', title='Profile', patient=patient, form=PatientsForm(), picture_file=picture_file)
def patients_profile(patient_id): patient = Patient.query.get_or_404(patient_id) if patient.picture == '': picture_file = url_for('static', filename='patients_pics/default.png') else: picture_file = url_for('static', filename='patients_pics/' + patient.picture) upload_list = patient.upload.order_by(Upload.date_uploaded.desc()).all() return render_template('patients_profile.html', title='Profile', patient=patient, form=PatientsForm(), picture_file=picture_file, upload_list=upload_list, health_info_dict=health_info_dict)
def test(patient_id): patient = Patient.query.get_or_404(patient_id) form = PatientsForm() # The user pressed the "Cancel" button if form.cancel.data: return redirect( url_for('patients_blueprint.patients_profile', patient_id=patient.id)) # The user pressed the "Submit" button if form.submit.data: for field in [ 'ardenocarcinoma', 'squamous_cell_carcinoma', 'large_cell_carcinoma', 'atypia', 'angiolymphatic', 'lymph_node', 'metastasis', 'egfr', 'alk', 'ros1', 'kras', 'braf', 'mek', 'ret', 'met' ]: field_data = getattr(form, field).data setattr(patient, field, field_data) db.session.commit() flash('Your patient info has been updated!', 'success') return redirect( url_for('patients_blueprint.patients_profile', patient_id=patient.id, _anchor='tab_content2')) elif request.method == 'GET': for field in [ 'ardenocarcinoma', 'squamous_cell_carcinoma', 'large_cell_carcinoma', 'atypia', 'angiolymphatic', 'lymph_node', 'metastasis', 'egfr', 'alk', 'ros1', 'kras', 'braf', 'mek', 'ret', 'met' ]: field_data = getattr(form, field) field_data.data = getattr(patient, field) return render_template('test.html', title='Test', heading='Test', form=form)
def upload_ct_scan(): form = PatientsForm() return render_template('upload_ct_scan.html', title='Upload CT Scan', form=form)