Exemplo n.º 1
0
def bookAppointmentWithASpecificDoctor(patient_hcnumber, doctor_permit_number,
                                       length, time, date, clinic_id):
    if int(length) == CHECKUP_LENGTH:  # checkup
        available_doctor = doctor_permit_number
        available_room = RoomScheduleService.findRoomAtTime(
            time=time, date=date, clinic_id=clinic_id)
        if 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 = doctor_permit_number
        available_room = RoomScheduleService.findRoomForAnnual(
            clinic_id, date, time)
        if 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 checkAvailability():
	# convert request data to dictionary
	data = toDict(request.data)

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

	# check if room number exists
	success = RoomService.roomExists(data['roomNumber'], data['clinic_id'])

	# if room exists, room availabilities
	if success:
		roomAvail = RoomScheduleService.getTimeSlotsByDateAndRoom(data['roomNumber'], data['clinic_id'], data['date'])
		message = "Room availabilities retrieved."
		status = "OK"
		response = json.dumps({'success': success, 'status': status, 'message': message, 'roomAvail': roomAvailability})
	# else the room doesn't exist and request is denied.
	else:
		message = "Room does not exist."
		status = "DENIED"

	response = json.dumps({'success': success, 'status': status, 'message': message,'roomAvail': roomAvail})
	return response
Exemplo n.º 5
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.º 6
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