Ejemplo n.º 1
0
def addClinic(doctor_id):
	form = ClinicForm(request.form)
	doctor = Doctor.query.get(int(doctor_id))
	doctors = Doctor.query.all()
	if request.method == 'POST':
		if form.validate():
			clinic = Clinic.query.filter_by(clinicName = form.clinicName.data, locality = form.locality.data, city = form.city.data, address = form.address.data).first()
			docclinic = DocClinic(request.form['fees'], request.form['timings'])
			db_session.add(docclinic)
			if clinic:
				docclinicAll = DocClinic.query.filter_by(doctor_id = doctor.id, clinic_id = clinic.id).first()
				if docclinicAll:
					return render_template("home.html", errMsg = "Already added for this doctor", doctors = doctors)
				doctor.docClinics.append(docclinic)
				clinic.docClinics.append(docclinic)
				db_session.commit()
			else:
				clinic = Clinic(clinicName = form.clinicName.data, locality = form.locality.data, city = form.city.data, address = form.address.data, services = form.services.data)
				db_session.add(clinic)
				doctor.docClinics.append(docclinic)
				clinic.docClinics.append(docclinic)
				db_session.commit()
		else:
			flash ('Form Validation unsuccessful. Please enter valid data')
		return render_template("home.html", doctors = doctors)
	else:
		return render_template("addClinic.html", form = form, doctor = doctor)
Ejemplo n.º 2
0
def editClinic(clinic_id):
	try:
		clinic = Clinic.query.get(int(clinic_id))
	except AttributeError:
		doctors = Doctor.query.all()
		return render_template("home.html", doctors = doctors, errMsg = "No Such clinic")
	form = ClinicForm(request.form)
	if request.method == 'POST':
		if form.validate():
			clinic.clinicName = form.clinicName.data
			clinic.locality = form.locality.data
			clinic.city = form.city.data
			clinic.address = form.address.data
			clinic.services = form.services.data
			db_session.commit()
		else:
			flash("Invalid data entered. Please verify and try again.")
		doctors = Doctor.query.all()
		return render_template("home.html", doctors = doctors)
	else:
		return render_template("editClinics.html", form = form, clnc = clinic)