def add_patient(patient_id): from forms import PatientForm if patient_id: id = int(patient_id.replace('P00', '').replace( 'P0', '').replace('P', '')) patient = Patient.query.get(id) else: patient = Patient() form = PatientForm(obj=patient) if form.validate_on_submit(): if 'photo' not in request.files: flash('No file part') return redirect(request.url) file = request.files['photo'] # if user does not select file, browser also # submit an empty part without filename if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = uuid.uuid4().hex+'.' + \ secure_filename(file.filename).split('.')[-1].lower() form.photo.data.save(os.path.join( app.config['UPLOAD_FOLDER'], 'patients', filename)) form.populate_obj(patient) patient.photo = filename patient.gender = Gender(form.gender.data) db.session.add(patient) db.session.commit() url = url_for('patient_profile', patient_id=repr(patient)) flash( 'Patient saved with ID: {}, <a href="{}">view patient profile</a>'.format(repr(patient), url)) return redirect(url_for('add_patient')) return render_template('add-patient.html', form=form)
def patient(): form = PatientForm() req = request.form if form.validate_on_submit(): session["Patient"] = req.get("Patient") session["age"] = req.get("age") session["Schuljahre"] = req.get("Schuljahre") session["gender"] = req.get("gender") return redirect(url_for('messwerte')) return render_template('patient.html', title='Patientendaten Extern', form=form)
def patient_create(): patient_form_create = PatientForm() if patient_form_create.validate_on_submit(): form_data = patient_form_create.data id = patient_form_create.patient_id.data qry = db.patient_insert_sql(form_data) db.insert(qry) flash('New patient record created', 'success') return redirect(f'/patient_created/{id}.html') return render_template('patient_create.html', template_form=patient_form_create)
def setup(): pform = PatientForm() error = None if pform.validate_on_submit(): #user input name = pform.name.data dob = pform.dob.data street = pform.street_address.data city = pform.city.data state = pform.state.data country = pform.country.data telephone = pform.telephone.data patient = models.add_patient(name, dob, street, city, state, country, telephone) error = 'A patient with that patient id already exists' return redirect('/patient') return render_template('setup.html', error = error, form = pform)
def editPatientData(id): # Initialize form from forms.py form = PatientForm() # if form is sent back (POST) to the server if form.validate_on_submit(): # capture data from form form_data = form.data # build SQL query in update table qry = db.patient_update_sql(form_data) # update table with new data try: db.insert(qry) except: flash('Not able to update patient record', 'warning') return render_template(f'edit-patient-data.html', template_form=form, id=id) # redirect user to patient updated page return redirect(f'/patient_updated/{id}.html') # get values for this row from the database sql = f"SELECT * FROM patient WHERE patient_id = '{id}'" res = db.query(sql) # populate values to the form form.patient_id.data = res[0][0] form.name.data = res[0][1] form.address_street.data = res[0][2] form.address_city.data = res[0][3] form.address_state.data = res[0][4] form.address_zip.data = res[0][5] form.phone.data = res[0][6] form.admitted.data = res[0][7] form.discharged.data = res[0][8] form.county_id.data = res[0][9] form.health_info.data = res[0][10] form.age.data = res[0][11] form.race.data = res[0][12] form.gender.data = res[0][13] return render_template('edit-patient-data.html', template_form=form, id=id)
def edit_patient(patient_id): pform = PatientForm() #return redirect('/login') error = None patient_details = models.get_patient(patient_id) if pform.validate_on_submit(): #user input name = pform.name.data dob = pform.dob.data street = pform.street_address.data city = pform.city.data state = pform.state.data country = pform.country.data telephone = pform.telephone.data models.update_patient(patient_id, name, dob, street, city, state, country, telephone) return redirect('/patient') return render_template('edit_patient.html', id=patient_id, form = pform, existing=patient_details)
def form(): form = PatientForm() print("form generated") if form.validate_on_submit(): print("form submitted and succeeded") feature = Features(age=int(escape(form.age.data)), apoe4=int(escape(form.apoe4.data)), mmse=escape(form.mmse.data), adas11=escape(form.adas11.data), adas13=escape(form.adas13.data), ICV=escape(form.ICV.data), Ventricles=escape(form.Ventricles.data), Entorhinal=escape(form.Entorhinal.data), CEREBRUM=escape(form.CEREBRUM.data), HIPPO=escape(form.HIPPO.data), CSF=escape(form.CSF.data), RAVLT_immediate=escape(form.RAVLT_immediate.data), ABETA=escape(form.ABETA.data), FAQTOTAL=escape(form.FAQTOTAL.data), PTGENDER=escape(form.PTGENDER.data), PTMARRY=escape(form.PTMARRY.data), PTEDUCAT=escape(form.PTEDUCAT.data), PTRACCAT=escape(form.PTRACCAT.data)) mrn = escape(form.medicalRecordNum.data) # here we need to take the raw form values for imaging data and turn them into ratios in respect to ICV # print("feature 2: ", featureList[2]) db.session.add(feature) db.session.commit() to_predict_list = [ int(escape(form.age.data)), int(escape(form.apoe4.data)), int(escape(form.mmse.data)), int(escape(form.adas11.data)), int(escape(form.adas13.data)), int(escape(form.ICV.data)), float(escape(form.Ventricles.data)), float(escape(form.Entorhinal.data)), float(escape(form.CEREBRUM.data)), float(escape(form.HIPPO.data)), float(escape(form.CSF.data)), int(escape(form.RAVLT_immediate.data)), int(escape(form.ABETA.data)), int(escape(form.FAQTOTAL.data)), int(escape(form.PTGENDER.data)), int(escape(form.PTMARRY.data)), int(escape(form.PTEDUCAT.data)), int(escape(form.PTRACCAT.data)) ] print(to_predict_list) sample = np.array(to_predict_list) result = ModelClassification(to_predict_list) proba = LIME(to_predict_list, sample) print("Patient Data Submitted!") flash('Patient data has been submitted!', 'success') return redirect(url_for('result', result=result, mrn=mrn, proba=proba)) return render_template('form.html', title='Form', form=form)