Example #1
0
def get_for_date_and_specialty(name, agenda_date, specialty):
    try:
        calendar = Calendar.objects.get(name=name)
        therapists = Therapist.objects(Q(specialties__contains=specialty))
        print(therapists)
        agendas = Agenda.objects(
            Q(calendar=calendar,
              appointment=None,
              date=agenda_date.replace('-', '/'),
              therapist__in=therapists))
        print(agendas)
        agendas = [
            ag for ag in agendas if Agenda.objects(
                calendar=calendar,
                date=ag.date,
                time=ag.time,
                appointment__exists=True).count() < int(calendar.room_size)
        ]

        agendas_json = json.dumps([t.to_dict() for t in agendas],
                                  default=default)
        return Response(agendas_json, mimetype='application/json', status=200)
    except Exception as ex:
        print(ex)
        abort(500)
Example #2
0
def get_next_dates(name):
    try:
        calendar = Calendar.objects.get(name=name)
        agendas = Agenda.objects(calendar=calendar, appointment=None)
        print(agendas)
        tz = pytz.timezone('America/Sao_Paulo')
        now = datetime.now(tz)
        today = now.date()
        current_hour = f'{str(now.hour).zfill(2)}:00'
        agendas = [
            ag.date for ag in agendas if Agenda.objects(
                calendar=calendar,
                date=ag.date,
                time=ag.time,
                appointment__exists=True).count() < int(calendar.room_size) and
            (datetime.strptime(ag.date, '%d/%m/%Y').date() > today) or (
                datetime.strptime(ag.date, '%d/%m/%Y').date() == today
                and ag.time > current_hour)
        ]
        all_dates_list = [
            datetime.strptime(ag, '%d/%m/%Y').date() for ag in list(agendas)
        ]

        all_dates_list.sort()
        dates_list = [dt for dt in list(dict.fromkeys(all_dates_list))]

        next_dates_sorted = dates_list[:30]

        dates_json = json.dumps(next_dates_sorted, default=default)
        return Response(dates_json, mimetype='application/json', status=200)
    except Exception as ex:
        print(ex)
        abort(500)
Example #3
0
def get_for_date(name, agenda_date):
    try:
        calendar = Calendar.objects.get(name=name)
        agendas = Agenda.objects(calendar=calendar,
                                 date=agenda_date.replace('-', '/'),
                                 appointment=None)
        print(agendas)
        tz = pytz.timezone('America/Sao_Paulo')
        now = datetime.now(tz)
        today = now.date()
        current_hour = f'{str(now.hour).zfill(2)}:00'
        agendas = [
            ag for ag in agendas if Agenda.objects(
                calendar=calendar,
                date=ag.date,
                time=ag.time,
                appointment__exists=True).count() < int(calendar.room_size) and
            (datetime.strptime(ag.date, '%d/%m/%Y').date() > today) or (
                datetime.strptime(ag.date, '%d/%m/%Y').date() == today
                and ag.time > current_hour)
        ]

        agendas_json = json.dumps([t.to_dict() for t in agendas],
                                  default=default)
        return Response(agendas_json, mimetype='application/json', status=200)
    except Exception as ex:
        print(ex)
        abort(500)
Example #4
0
def upload(name, therapist_email, month, year):
    # check if the post request has the file part
    if 'file' not in request.files:
        return 'Please upload a file', 400
    file = request.files['file']
    if file.filename == '':
        return 'Please upload a file... this is empty', 400

    print('processing upload...')

    calendar = Calendar.objects.get(name=name)
    therapist = Therapist.objects.get(email=therapist_email)
    agenda_list = Agenda.objects(calendar=calendar,
                                 therapist=therapist,
                                 date__contains=f'{month}/{year}',
                                 appointment=None)
    print(agenda_list)
    print(f'removing agenda entries {len(agenda_list)}')
    for agenda in agenda_list:
        agenda.delete()

    agendas = process_agenda(file, calendar, therapist, month, year)
    agenda_list_booked = Agenda.objects(calendar=calendar,
                                        therapist=therapist,
                                        date__contains=f'{month}/{year}',
                                        appointment__exists=True)
    print('all booked agendas')
    print(agenda_list_booked)
    agendas_to_persist = list(
        filter(
            lambda a: len(
                list(
                    filter(
                        lambda b: b.calendar.name == a.calendar.name and b.
                        therapist.name == a.therapist.name and b.date == a.date
                        and b.time == a.time, agenda_list_booked))) == 0,
            agendas))

    print(f'persisting agendas : {list(agendas_to_persist)}')
    for agenda in agendas_to_persist:
        print(f'saving agenda {agenda.date} {agenda.time}')
        agenda.save()

    return 'processamento efetuado com sucesso!', 200
Example #5
0
def get_all(name):
    try:
        calendar = Calendar.objects.get(name=name)
        agendas = Agenda.objects(calendar=calendar)
        print(agendas)
        agendas_json = json.dumps([t.to_dict() for t in agendas],
                                  default=default)
        return Response(agendas_json, mimetype='application/json', status=200)
    except Exception as ex:
        print(ex)
        abort(500)
def process_agenda_mock(calendar, therapist):
    created_agendas = []
    with open('calendar_upload/template-agenda-aset.csv') as f:
        reader = csv.DictReader(f, delimiter=';', quoting=csv.QUOTE_NONE)
        for row in reader:
            for k in row:
                if row[k] is not None and row[k] != '':
                    print(f'Day: {k} -> Hour: {row[k]}')
                    agenda = Agenda()
                    agenda.date = f'{k}/05/2020'
                    agenda.time = f'{row[k]}'
                    agenda.calendar = calendar
                    agenda.therapist = therapist
                    created_agendas.append(agenda)

    return created_agendas
Example #7
0
def create(name):
    try:
        agenda_json = request.json
        agenda = Agenda(**agenda_json)
        calendar = Calendar.objects().get(name=name)
        agenda.calendar = calendar
        therapist = Therapist\
            .objects\
            .get(email=agenda_json['therapist']['email'])
        agenda.therapist = therapist
        agenda.save()

        return Response(status=201)
    except Exception as ex:
        print(ex)
        abort(500)
Example #8
0
def alive():
    customer = Customer()
    customer.email = '*****@*****.**'
    customer.name = 'emilio murta resende'
    therapist = Therapist()
    therapist.email = '*****@*****.**'
    therapist.name = 'Simone L. Tavares'
    agenda = Agenda()
    agenda.date = '21/04/2020'
    agenda.time = '23:00'
    agenda.therapist = therapist

    appointment = Appointment()
    appointment.customer = customer
    appointment.specialty = 'Especialidade teste'

    agenda.appointment = appointment

    send_mail_sendgrid('agendamento atendimento aset', agenda)
    return 'e-mail enviado com suscesso'
def process_agenda(file, calendar, therapist, month, year):
    print('processing agenda...')
    file.save(os.path.join(dirname(__file__), file.filename))
    file_path = os.path.join(dirname(__file__), file.filename)
    print(f'file created: {file_path}')
    created_agendas = []
    with open(file_path) as f:
        reader = csv.DictReader(f, delimiter=';', quoting=csv.QUOTE_NONE)
        print('csv readed... starting to create agenda entries')
        rows = list(reader)
        print(f'number of rows: {len(rows)}')
        for row in rows:
            print(f'processing row {row}')
            for k in row:
                if row[k] is not None and row[k] != '':
                    print(f'Day: {k} -> Hour: {row[k]}')
                    agenda = Agenda()
                    agenda.date = f'{k}/{month}/{year}'
                    agenda.time = f'{row[k]}'
                    agenda.calendar = calendar
                    agenda.therapist = therapist
                    created_agendas.append(agenda)

    return created_agendas