Пример #1
0
def newPatient():
    data = request.data
    data = data.decode('utf8').replace("'", '"')
    data = json.loads(data)
    print(data)
    success = False

    # Create a patient and find our whether it is successful or not
    success = PatientService.createPatient(hcnumber=data['hcnumber'],
                                           fname=data['fname'],
                                           lname=data['lname'],
                                           birthday=data['birthday'],
                                           gender=data['gender'],
                                           phone=data['phone'],
                                           email=data['email'],
                                           address=data['address'],
                                           password=data['password'],
                                           lastAnnual=data['lastAnnual'])
    if success:
        message = "Patient has been created"
    else:
        message = "Patient already exists"

    response = json.dumps({"success": success, "message": message})
    return response
Пример #2
0
def userFind():

    # convert request data to dictionary
    data = toDict(request.data)

    success = False
    message = ""
    status = ""  # OK, DENIED, WARNING
    response = {}

    # check if user exists

    # check if health card number exists
    success = PatientService.patientExists(data['hcnumber'])

    # if health card number exists & authenticated, then get the patient
    if success:
        message = "Patient found."
        status = "OK"
        response = json.dumps({
            'success': success,
            'status': status,
            'message': message
        })
    # else the user is not authenticated, request is denied
    else:
        message = "Patient not found."
        status = "DENIED"

    response = json.dumps({
        'success': success,
        'status': status,
        'message': message
    })
    return response
Пример #3
0
def updateAppointmentForDoctor():
    data = request.data
    data = data.decode('utf8').replace("'", '"')
    data = json.loads(data)
    print(data)
    success = False
    message = ""

    if AppointmentService.getAppointment(data['id']) is not None:
        message, success = AppointmentService.updateAppointment(
            clinic_id=data['clinic_id'],
            appointment_id=data['id'],
            doctor_permit_number=data['permit_number'],
            length=data['length'],
            new_time=data['time'],
            new_date=data['date'])
    if data['length'] is '60':
        bookableAnnual = PatientService.canBookAnnual(data['hcnumber'])
        response = json.dumps({
            "success": success,
            "message": message,
            "bookableAnnual": bookableAnnual
        })
    else:
        response = json.dumps({"success": success, "message": message})
    return response
Пример #4
0
def userAuthenticate():

    # convert request data to dictionary
    data = toDict(request.data)

    success = False
    message = ""
    status = ""  # OK, DENIED, WARNING
    response = {}
    user = {}

    # logging in

    # check if health card number exists
    success = PatientService.patientExists(data['hcnumber'])
    # Verify User
    success = PatientService.authenticate(data['hcnumber'], data['password'])

    # if health card number exists & authenticated, then get the patient
    if success:
        user = PatientService.getPatient(data['hcnumber'])
        # convert datetimes to strings
        user['birthday'] = user['birthday'].strftime("%Y-%m-%d")
        if user['lastAnnual'] is not None:
            user['lastAnnual'] = user['lastAnnual'].strftime("%Y-%m-%d")
        message = "Patient authenticated."
        status = "OK"
        response = json.dumps({
            'success': success,
            'status': status,
            'message': message,
            'user': user
        })
    # else the user is not authenticated, request is denied
    else:
        message = "User not authenticated."
        status = "DENIED"

    response = json.dumps({
        'success': success,
        'status': status,
        'message': message,
        'user': user
    })
    return response
Пример #5
0
def newAppointment():
    data = request.data
    data = data.decode('utf8').replace("'", '"')
    data = json.loads(data)
    print(data)
    success = False
    bookableAnnual = None
    message = ""

    patient_hcnumber = data['hcnumber']
    time = data['time']
    date = data['date']
    length = data['length']
    clinic_id = data['clinic_id']

    # to avoid potential double bookings
    patient_is_already_booked = AppointmentService.is_patient_already_booked(
        patient_hcnumber=patient_hcnumber,
        time=time,
        length=length,
        clinic_id=clinic_id,
        date=date)

    if (length is '60'):
        bookableAnnual = PatientService.canBookAnnual(patient_hcnumber)

    if not patient_is_already_booked:
        success = AppointmentService.bookAppointment(
            patient_hcnumber=patient_hcnumber,
            clinic_id=clinic_id,
            length=length,
            time=time,
            date=date)
    if success:
        message = "Appointment has been created"
    else:
        message = "Appointment already exists or there are no doctors/rooms available, or annual cannot be booked."

    response = json.dumps({
        "success": success,
        "message": message,
        "bookableAnnual": bookableAnnual,
        "patientIsAlreadyBooked": patient_is_already_booked
    })
    return response
Пример #6
0
def updateAppointment():
    data = request.data
    data = data.decode('utf8').replace("'", '"')
    data = json.loads(data)
    print(data)
    success = False

    if data['length'] is '60':
        bookableAnnual = PatientService.canBookAnnual(data['hcnumber'])

    if AppointmentService.getAppointment(data['id']) is not None:
        success = AppointmentService.updateAppointment(
            clinic_id=data['clinic_id'],
            appointment_id=data['id'],
            length=data['length'],
            new_time=data['time'],
            new_date=data['date'])
    if success:
        message = 'Appointment has been updated.'
        appointment = AppointmentService.getAppointment(data['id'])
    else:
        message = 'Appointment has not been updated.'

    if data['length'] is '60':
        response = json.dumps({
            "success": success,
            "message": message,
            "appointment": appointment,
            "bookableAnnual": bookableAnnual
        })
    else:
        response = json.dumps({
            "success": success,
            "message": message,
            "appointment": appointment
        })
    return response
Пример #7
0
def newAppointmentByDoctor():
    message = ""
    success = False
    status_code = 400
    data = toDict(request.data)
    doctor_permit_number = data['permit_number']
    patient_health_card_number = data['hcnumber']
    clinic_id = data['clinic_id']
    date = data['date']
    time = data['time']
    appointment_type = data['appointment_type']
    patientExists = True
    room_is_available = True
    bookable = True
    if appointment_type == 'Annual':
        length = 60
    else:
        length = 20

    # preliminary checks
    if not DoctorService.doctorExists(doctor_permit_number):
        message = "Doctor " + doctor_permit_number + " doesn't exist."
        success = False
        status_code = 404
        response = json.dumps({"success": success, "message": message})
        return response, status_code
    if not PatientService.patientExists(patient_health_card_number):
        message = "Patient " + doctor_permit_number + " doesn't exist."
        patientExists = False
        success = False
        status_code = 404
        response = json.dumps({
            "success": success,
            "message": message,
            "patientExists": patientExists,
            "room_is_available": room_is_available
        })
        return response, status_code

    # finding out if the doctor is available
    if appointment_type == 'Annual':
        doctor_is_available = DoctorScheduleService.isDoctorAvailableForAnnual(
            permit_number=doctor_permit_number, date=date, time=time)
    else:
        doctor_is_available = DoctorScheduleService.isDoctorAvailable(
            permit_number=doctor_permit_number, date=date, time=time)
    # finding out if a room is avail
    if appointment_type == 'Annual':
        room_is_available = RoomScheduleService.findRoomForAnnual(
            clinic_id, date, time)
    else:
        room_is_available = RoomScheduleService.findRoomAtTime(
            clinic_id, date, time)

    # to avoid potential double bookings
    patient_is_already_booked = AppointmentService.is_patient_already_booked(
        patient_hcnumber=patient_health_card_number,
        time=time,
        length=length,
        clinic_id=clinic_id,
        date=date)

    # check if annual, if so, check if bookable
    if appointment_type == 'Annual':
        bookable = PatientService.canBookAnnual(patient_health_card_number)

    # booking attempt
    if doctor_is_available and room_is_available and not patient_is_already_booked and bookable:
        AppointmentService.bookAppointmentWithASpecificDoctor(
            patient_hcnumber=patient_health_card_number,
            doctor_permit_number=doctor_permit_number,
            length=length,
            time=time,
            date=date,
            clinic_id=clinic_id)
        message = "Appointment has been booked successfully"
        success = True
        status_code = 200
        response = json.dumps({
            "success":
            success,
            "message":
            message,
            "patientExists":
            patientExists,
            "room_is_available":
            room_is_available,
            "patientIsAlreadyBooked":
            patient_is_already_booked
        })
        return response, status_code
    else:
        message = "Cannot book."
        success = False
        status_code = 200
        response = json.dumps({
            "success": success,
            "message": message,
            "patientExists": patientExists,
            "room_is_available": room_is_available,
            "doctor_is_available": doctor_is_available,
            "patientIsAlreadyBooked": patient_is_already_booked,
            "bookable": bookable
        })
        return response, status_code