Exemplo n.º 1
0
def bookAppointment(patient_hcnumber, length, time, date, clinic_id):
    if int(length) == CHECKUP_LENGTH:  # checkup
        available_doctor = DoctorScheduleService.findDoctorAtTime(
            date, time, clinic_id=clinic_id)
        available_room = RoomScheduleService.findRoomAtTime(
            time=time, date=date, clinic_id=clinic_id)
        if available_doctor is None or available_room is None:
            return False
        return bookRegular(patient_hcnumber=patient_hcnumber,
                           doctor_permit_number=available_doctor,
                           room_number=available_room,
                           length=length,
                           time=time,
                           date=date,
                           clinic_id=clinic_id)
    elif int(length) == ANNUAL_LENGTH:  # annual
        if not canBookAnnual(patient_hcnumber):
            return False
        available_doctor = DoctorScheduleService.findDoctorForAnnual(
            date, time)
        available_room = RoomScheduleService.findRoomForAnnual(
            clinic_id, date, time)
        if (available_doctor is None) | (available_room is None):
            return False
        return bookAnnual(patient_hcnumber=patient_hcnumber,
                          doctor_permit_number=available_doctor,
                          room_number=available_room,
                          length=length,
                          time=time,
                          date=date,
                          clinic_id=clinic_id)
    else:
        return False
Exemplo n.º 2
0
def cancelAppointment(id):
    appointment = getAppointment(id)
    if appointment is None:
        return False
    else:
        doctor = appointment['doctor_permit_number']
        room = appointment['room']
        date = appointment['date']
        time = appointment['time']
        clinic_id = appointment['clinic_id']
        if appointment['length'] == CHECKUP_LENGTH:
            DoctorScheduleService.makeTimeSlotAvailable(doctor, date, time)
            RoomScheduleService.makeTimeSlotAvailable(room, clinic_id, date,
                                                      time)
            AppointmentTDG.delete(appointment['id'])
            return True
        elif appointment['length'] == ANNUAL_LENGTH:
            DoctorScheduleService.makeTimeSlotAvailableAnnual(
                doctor, date, time)
            RoomScheduleService.makeTimeSlotAvailableAnnual(
                room, clinic_id, date, time)
            updateAnnual(appointment['patient_hcnumber'], None)
            AppointmentTDG.delete(appointment['id'])
            return True
        else:
            return False
Exemplo n.º 3
0
def bookRegular(patient_hcnumber, doctor_permit_number, room_number, clinic_id,
                length, time, date):
    DoctorScheduleService.makeTimeSlotUnavailable(doctor_permit_number, date,
                                                  time)
    RoomScheduleService.makeTimeSlotUnavailable(roomNumber=room_number,
                                                date=date,
                                                time=time,
                                                clinic_id=clinic_id)
    createAppointment(room=room_number,
                      doctor_permit_number=doctor_permit_number,
                      patient_hcnumber=patient_hcnumber,
                      length=length,
                      time=time,
                      date=date,
                      clinic_id=clinic_id)
    return True
Exemplo n.º 4
0
def crossCheckDoctorAndRoomList(date, doctorPermitNumberList, roomList,
                                clinic_id):
    available_time_slots = [False] * 36
    # preferential filtering by doctors, since they are the ones to most likely have fewer availabilities
    for permit_number in doctorPermitNumberList:
        doctor_time_slots = DoctorScheduleService.getTimeSlotsByDateDoctorAndClinic(
            permit_number=permit_number, date=date, clinic_id=clinic_id)
        if doctor_time_slots is None:
            continue
        else:
            doctor_time_slots = doctor_time_slots.toString().split(',')
        # for all available rooms
        # concatenate existing availabilities with the cross availabilities of each room and the doc schedule
        for roomNumber in roomList:
            room_slots = RoomScheduleService.getTimeSlotsByDateAndRoom(
                date=date, roomNumber=roomNumber,
                clinic_id=clinic_id).toString().split(',')
            common_time_slots = BooleanArrayOperations.getCommonTimeslots(
                doctor_time_slots, room_slots)
            available_time_slots = BooleanArrayOperations.concatenateBooleanLists(
                available_time_slots, common_time_slots)
    return available_time_slots
Exemplo n.º 5
0
def findAppointments():
    data = request.data
    data = data.decode('utf8').replace("'", '"')
    data = json.loads(data)
    date = data['date']
    clinic_id = data['clinic_id']
    message = ""
    success = False
    if (date is None):
        message = 'Enter a date to find the appointments for'
        return message, 404

    availableDoctorPermitNumbers = DoctorScheduleService.getAllAvailableDoctorPermitsByDate(
        date)
    availableRoomNumbers = RoomService.getAllRoomNumbersByClinic(
        clinic_id=clinic_id)
    if (availableDoctorPermitNumbers is None):
        message = "Unfortunately there are no doctors available for this date at the moment. Please try later."
        return message, 200
    if (availableRoomNumbers is None):
        message = "Unfortunately there are no rooms available for this date at the moment. Please try later."
        return message, 200
    listOfAvailableAppointments = AppointmentService.crossCheckDoctorAndRoomList(
        date=date,
        doctorPermitNumberList=availableDoctorPermitNumbers,
        roomList=availableRoomNumbers,
        clinic_id=clinic_id)
    if listOfAvailableAppointments is None:
        return 204
    else:
        success = True
        response = json.dumps({
            "success": success,
            "listOfAvailableAppointments": listOfAvailableAppointments,
            "date": date,
            "message": message
        })
        return response, 200
Exemplo n.º 6
0
def getDoctorAvailability():
    # convert request data to dictionary
    data = request.args

    success = False
    message = ""
    status = ""  # OK, DENIED, WARNING
    response = {}
    user = {}
    returned_values = {'timeslot': '', 'clinics': ''}

    # check if permit number exists
    success = DoctorService.doctorExists(data['permit_number']) and \
       NurseService.verifyHash(data['access_ID'], data['password_hash'])

    # if permit number exists, get the doctor's timeslots
    if success:
        returned_values = DoctorScheduleService.getAvailability(
            data['permit_number'], data['date'])
        # convert datetimes to strings
        message = "schedule found."
        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 or does not exist."
        status = "DENIED"

    response = json.dumps({'success': success, 'status': status, 'message': message,\
     'schedule': returned_values['timeslot'], 'clinics': returned_values['clinics']})
    return response
Exemplo n.º 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