Пример #1
0
def create_appointment():
    if not request.form:
        abort(400)
    try:
        params = request.form
        professional = Professional.find_by_id(params['professional_id'])
        appointments = Appointment.find_by_professional(professional)
        start_date = dateparser.parse(params['start_date'])
        end_date = dateparser.parse(params['end_date'])
        for appointment in appointments:
            schedule_start_date = dateparser.parse(appointment.start_date)
            schedule_end_date = dateparser.parse(appointment.end_date)
            if not (start_date <= schedule_start_date
                    and end_date <= schedule_start_date
                    or start_date >= schedule_end_date
                    and end_date >= schedule_end_date):
                abort(404)

        appointment = Appointment(
            professional=professional,
            patient=Patient.find_by_id(params['patient_id']),
            start_date=params['start_date'],
            end_date=params['end_date'],
        )

        appointment.save()
    except:
        abort(500)
    return jsonify(appointment.to_dict())
Пример #2
0
def create_appointment():
    """Creates an appointment
    :return: a success message
    """
    details = json.loads(request.data)

    appointment = Appointment(consultation_type=details["consultation_type"],
                              resolution=details["resolution"],
                              status=details["status"],
                              slot_id=details["slot_id"],
                              venue=details["venue"],
                              patient_id=details["patient_id"],
                              doctor_id=details["doctor_id"])

    appointment.save()
    return make_response(
        jsonify({"message": "appointment created_successfully"}), 201)
Пример #3
0
def create():
    online_user = get_jwt_identity()
    user = User.get_or_none(User.id == online_user['id'])

    if "admin" not in user.role:
        return jsonify({
            "message": "401 Unauthorized (Only admin is allowed)",
            "status": "fail"
        })

    params = request.json
    doctor_ic = params.get("doctor_ic")
    patient_ic = params.get("patient_ic")
    start_datetime = params.get("start_datetime")
    end_datetime = params.get("end_datetime")

    doctor = User.get_or_none(User.ic_number == doctor_ic)
    patient = User.get_or_none(User.ic_number == patient_ic)
    if doctor and patient:
        new_appointment = Appointment(doctor_id=doctor.id,
                                      patient_id=patient.id,
                                      start_datetime=start_datetime,
                                      end_datetime=end_datetime)
        if new_appointment.save():
            response = {
                "message": "Successfully created an appointment",
                "status ": "success",
                "doctor_name": new_appointment.doctor.name,
                "doctor_ic": new_appointment.doctor.ic_number,
                "patient_name": new_appointment.patient.name,
                "patient_ic": new_appointment.patient.ic_number,
                "start_datetime": new_appointment.start_datetime,
                "end_datetime": new_appointment.end_datetime
            }
        else:
            response = new_appointment.error()
        return jsonify(response)
    else:
        return jsonify({
            "message": "Can't find doctor or patient",
            "status ": "fail",
        })