def create_visits(output=True): '''Create fake visits and front desk events, depending on Participants and Programs. Visits are created using now(), i.e. today''' participants = Participant.objects.all() programs = Program.objects.all() for _ in range(DEFAULT_NUMBER_VISITS): v = Visit() v.participant = random.choice(participants) #v.created_at = pytz.utc.localize(fake.date_time()) v.created_at = timezone.now() v.program = random.choice(programs) v.notes = fake.sentence(nb_words=10, variable_nb_words=True, ext_word_list=None) v.full_clean() v.save() #Create FrontDeskEvents to correspond to the Visit, which always begins with ARRIVED arrived(v) if output: print("Created visit: {} {}, {}, {}, {}". format(v.participant.first_name, v.participant.last_name, v.created_at, v.program.name, v.notes))
def add_checklist(request, pk): pet = get_object_or_404(Pet, pk=pk) if request.method == 'POST': form = ChecklistForm2(request.POST) sitterform = UserForm(request.POST, user=request.user) if form.is_valid() and sitterform.is_valid(): start_date = form.cleaned_data.get('start_date') end_date = form.cleaned_data.get('end_date') sitter = sitterform.cleaned_data.get('sitter') task1 = request.POST['task1'] task2 = request.POST['task2'] task3 = request.POST['task3'] task4 = request.POST['task4'] task5 = request.POST['task5'] task6 = request.POST['task6'] task7 = request.POST['task7'] task8 = request.POST['task8'] task9 = request.POST['task9'] task10 = request.POST['task10'] print (start_date) print (end_date) delta = end_date - start_date print(delta.days) existing_visit = Visit.objects.filter(sitter_id=sitter).filter(due_date_on=start_date) num_of_days = delta.days if delta.days == 0: if existing_visit: visitpk = existing_visit[0] Checklist.objects existing_checklist = Checklist.objects.filter(visit=visitpk).filter(pet_id=pet) if existing_checklist: checklist = existing_checklist[0] else: checklist = Checklist(visit=visitpk, pet_id=pet) checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=checklist) new_task10.save() print("EXISTING VISIT WITH DATE AND USER") else: new_visit = Visit(sitter_id=sitter, due_date_on=start_date) new_visit.save() visit_id = new_visit.pk new_checklist = Checklist(visit=new_visit, pet_id=pet) new_checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=new_checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=new_checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=new_checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=new_checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=new_checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=new_checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=new_checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=new_checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=new_checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=new_checklist) new_task10.save() print("A NEW VISIT WITH DATE AND USER") else: for day in range(num_of_days+1): print("MORE THAN ONE DAY!") current_date = start_date + datetime.timedelta(days=day) print(current_date) existing_visit = Visit.objects.filter(sitter_id=sitter).filter(due_date_on=current_date) if existing_visit: print("EXISTING VISIT") visitpk = existing_visit[0] print(visitpk) Checklist.objects existing_checklist = Checklist.objects.filter(visit=visitpk).filter(pet_id=pet) if existing_checklist: checklist = existing_checklist[0] else: checklist = Checklist(visit=visitpk, pet_id=pet) checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=checklist) new_task10.save() print("SAME DAY") else: new_visit = Visit(sitter_id=sitter, due_date_on=current_date) new_visit.save() visit_id = new_visit.pk new_checklist = Checklist(visit=new_visit, pet_id=pet) new_checklist.save() if task1: new_task1 = Task(description=task1, checklist_id=new_checklist) new_task1.save() if task2: new_task2 = Task(description=task2, checklist_id=new_checklist) new_task2.save() if task3: new_task3 = Task(description=task3, checklist_id=new_checklist) new_task3.save() if task4: new_task4 = Task(description=task4, checklist_id=new_checklist) new_task4.save() if task5: new_task5 = Task(description=task5, checklist_id=new_checklist) new_task5.save() if task6: new_task6 = Task(description=task6, checklist_id=new_checklist) new_task6.save() if task7: new_task7 = Task(description=task7, checklist_id=new_checklist) new_task7.save() if task8: new_task8 = Task(description=task8, checklist_id=new_checklist) new_task8.save() if task9: new_task9 = Task(description=task9, checklist_id=new_checklist) new_task9.save() if task10: new_task10 = Task(description=task10, checklist_id=new_checklist) new_task10.save() print("DIFFERENT DAYS") return redirect('home') else: form = ChecklistForm2() sitterform = UserForm(user=request.user) return render(request, 'add_checklist.html', {'form': form, 'pet' : pet, 'sitterform': sitterform})
def create_visits(output=True, uds=True, medication=True): """Create fake visits and front desk events, depending on Participants and Programs. Visits are created using now(), i.e. today""" participants = Participant.objects.all() p_s_maps = ProgramServiceMap.objects.all() for _ in range(DEFAULT_NUMBER_VISITS): v = Visit() v.participant = random.choice(participants) # v.created_at = pytz.utc.localize(fake.date_time()) v.created_at = timezone.now() v.program_service_map = random.choice(p_s_maps) v.urgency = random.choice(list(UrgencyLevel)).name v.notes = fake.sentence(nb_words=10, variable_nb_words=True, ext_word_list=None) v.full_clean() v.save() # Create FrontDeskEvents to correspond to the Visit, which always begins with ARRIVED arrived(v) if uds: create_uds_results(v) if medication: create_medication(v) if output: print( "Created visit: {} {}, {}, {}, {}".format( v.participant.first_name, v.participant.last_name, v.created_at, v.program.name, v.notes, ) )
def create_visits(output=True, uds=True, medication=True): """Create fake visits and front desk events, depending on Participants and Programs. Visits are created using now(), i.e. today""" participants = Participant.objects.all() services = Service.objects.all().select_related() sep_program_id = Program.objects.get(name="SEP").pk for _ in range(DEFAULT_NUMBER_VISITS): v = Visit() v.participant = random.choice(participants) # v.created_at = pytz.utc.localize(fake.date_time()) v.created_at = timezone.now() service = random.choice(services) v.service = service v.program = service.program v.urgency = random.choice(list(UrgencyLevel)).name v.notes = fake.sentence(nb_words=10, variable_nb_words=True, ext_word_list=None) v.full_clean() v.save() if v.program.pk == sep_program_id: # sep program does not have a queue. TODO: update program model to have isqueueable boolean or similar continue # Create FrontDeskEvents to correspond to the Visit, which always begins with ARRIVED arrived(v) if uds: create_uds_results(v) if medication: create_medication(v) if output: print( "Created visit: {} {}, {}, {}, {}".format( v.participant.first_name, v.participant.last_name, v.created_at, v.program.name, v.notes, ) )