コード例 #1
0
def get_dist(state):
    cities = City.find_by_state(state)
    city_array = []
    for city in cities:
        city_obj = {'id': city.uuid, 'name': city.name}
        city_array.append(city_obj)
    return jsonify({'cities': city_array})
コード例 #2
0
def search_blood_donor():
    form = FindBloodDonorForm()
    form.city.choices = [(city.id, city.name) for city in City.find_by_state('Kerala')]
    if form.is_submitted():
        city = City.get_by_id(form.city.data)
        state_name = form.state.data
        bld_grp = form.bld_grp.data
        city_name = city.name
        donors = User.find_blood_donor(location=city_name, blood_type=bld_grp)
        len_of_donors = len(donors)
        if current_user in donors:
            print('found ', current_user.username, ' in donors list. removing it!')
            len_of_donors = len_of_donors - 1
        if len_of_donors > 0:
            return render_template('donor_search_result.html', data=donors, current_user=current_user, bld_grp=bld_grp,
                                   auth=is_auth())
        flash(message="No donors found!!")
        render_template("search_blood_donor.html", current_user=current_user, form=form, auth=is_auth())
    return render_template("search_blood_donor.html", current_user=current_user, form=form, auth=is_auth())
コード例 #3
0
def update_profile():
    user = User.find_by_username(username=current_user.username)
    city = City.get_id_by_name(_name=current_user.city)
    form = ProfileUpdateForm(city=city.uuid, bld_grp=user.bld_grp, sex=user.sex, pan=user.pan,
                             organ_donation=bool(user.organ_donation),
                             bld_donation=bool(user.bld_donation))
    form.city.choices = [(city.uuid, city.name) for city in City.find_by_state('Kerala')]

    role = Role.find_by_id(current_user.role)
    print('user role is ', role.name)
    print(form.validate_on_submit())
    print(form.errors)
    if 'pan' in form.errors:
        flash("PAN is a mandatory field \n PAN will always be a of 10 characters length")
        return render_template("update_profile.html", form=form, role=role.name)
    print('log')
    if form.validate_on_submit():
        user.uname = form.uname.data
        user.mail = form.mail.data
        user.dob = form.dob.data
        user.age = get_age(form.dob.data)
        user.pan = form.pan.data
        user.name = form.name.data
        user.sex = form.sex.data
        user.bld_grp = form.bld_grp.data
        user.addr = form.addr.data
        user.state = form.state.data
        curr_city = City.get_by_id(form.city.data)
        user.city = curr_city.name
        user.po_num = form.pincode.data
        user.mobile = form.mobile.data
        user.aadhar = form.aadhar.data
        # user_role = form.role.data
        user.organ_donation = bool(strtobool(form.organ_donation.data))
        user.bld_donation = bool(strtobool(form.bld_donation.data))
        # role = Role.find_by_id(user_role)
        user.role = role.uuid
        user.save_to_db()
        print('user_id=', user.uuid, 'selected_role_id=', role.uuid, 'selected_role_name=', role.name)
        print('user_id=', user.uuid, 'role_id_db=', user.role, )
        return redirect(url_for("view_profile"))
    return render_template("update_profile.html", form=form, role=role.name, auth=is_auth())
コード例 #4
0
def getCities(state):
    from models import City
    out = City.find_by_state('Kerala')
    return out
コード例 #5
0
def search_hospital():
    form = SearchHospitalForm()
    if form.state != "None":
        form.city.choices = [(city.uuid, city.name) for city in City.find_by_state(form.city.data)]
    if form.is_submitted():
        if form.city != "None" or form.state != "None":
            city = City.get_by_id(form.city.data)
            state_name = city.name
            spec = form.spec.data
            scheme_id = form.scheme.data
            if spec != "None" and state_name != "" and not state_name.isspace():
                hosps = Hospital.find_by_spec_and_state(_spec=spec, _state=state_name)
                print("scheme id is ", scheme_id)
                if scheme_id != '0':
                    filtered = []
                    scheme = Scheme.find_by_scheme_id(scheme_id)
                    print(scheme.name)
                    print(scheme.partner_hospitals)
                    for a_hosp in hosps:
                        if a_hosp in scheme.partner_hospitals.all():
                            filtered.append(a_hosp)
                    print(filtered)
                    if len(filtered) <= 0:
                        flash("No Hospitals found, why don't you try without the Scheme filter!!")
                        return render_template("search_hospital.html", current_user=current_user, form=form)
                    return render_template('searchResult.html', data=filtered, current_user=current_user,
                                           auth=is_auth(),
                                           searchterm=state_name)
                print("results form spec for ", decodeSpecialties(spec)[0])
                if len(hosps.all()) > 0:
                    return render_template('searchResult.html', data=hosps, current_user=current_user, auth=is_auth(),
                                           searchterm=state_name)
                else:
                    print('no hospitals with ', spec)
                    flash("No Hospitals found, why don't you try without the Speciality filter!!")
                    return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth())
            elif state_name != '' and not state_name.isspace():
                hosp = Hospital.find_by_state(state_name)
                if len(hosp.all()) > 0:
                    print("scheme id is ", scheme_id)
                    if scheme_id != '0':
                        scheme = Scheme.find_by_scheme_id(scheme_id)
                        print(scheme.name)
                        filtered = []
                        for a_hosp in hosp:
                            if a_hosp in scheme.partner_hospitals.all():
                                filtered.append(a_hosp)
                        if len(filtered) <= 0:
                            flash("No Hospitals found, why don't you try without the Scheme filter!!")
                            return render_template("search_hospital.html", current_user=current_user, form=form,
                                                   auth=is_auth())
                        return render_template('searchResult.html', data=filtered, current_user=current_user,
                                               auth=is_auth(),
                                               searchterm=state_name)
                    return render_template('searchResult.html', data=hosp, current_user=current_user,
                                           searchterm=state_name, auth=is_auth())
                else:
                    flash('No Hospitals found!!')
                    return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth())
            else:
                flash("Enter a valid query")
                return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth())
        flash("State and City are Mandatory Fields")
        return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth())
    return render_template("search_hospital.html", current_user=current_user, form=form, auth=is_auth())