Exemplo n.º 1
0
def build_medical_center(medical_center, request):
    medical_center_model = MedicalCenter()
    medical_center_model.balanced = medical_center['balanced']
    medical_center_model.distance = medical_center['distance']
    location = Location()
    location.latitude = medical_center['location']['latitude']
    location.longitude = medical_center['location']['latitude']
    medical_center_model.location = location
    medical_center_model.name = medical_center['name']
    medical_center_model.request = request
    return medical_center_model
Exemplo n.º 2
0
def save_data(data):
    init_db()
    request = Request()
    request.distance_imbalance = data['calculate']
    user_location = Location()
    user_location.latitude = data['user_location']['latitude']
    user_location.longitude = data['user_location']['latitude']
    request.location = user_location
    request.radius = data['radius']
    medical_centers = [
        build_medical_center(medical_center, request)
        for medical_center in data['medical_centers']
    ]
    request.medical_centers = medical_centers
    db_session.add(request)
    db_session.commit()