def seed_appointments(): demo1 = Appointment(user_id=User.query.filter(User.username == 'Chun Li').first().id, chef_id=Chef.query.get(1).id, notes="Please get here very early in the morning, we are ready at 8 o'clock", date=datetime.now(), ) demo2 = Appointment(user_id=User.query.filter(User.username == 'Demo User').first().id, chef_id=Chef.query.get(2).id, notes="Sweets required, need more sweets, because I'm so sweet", date=datetime.now(), ) demo3 = Appointment(user_id=User.query.filter(User.username == 'Chun Li').first().id, chef_id=Chef.query.get(1).id, notes="Down payment already sent last night, please make sure you recieved it", date=datetime.now(), ) db.session.add(demo1) db.session.add(demo2) db.session.add(demo3) db.session.commit()
def appointments(): form = AppointmentForm() searchform = AppointmentSearchForm() if searchform.validate_on_submit(): search = searchform.search.data return redirect(url_for('main.search_results')) if form.validate_on_submit(): # Get the data from the form, and add it to the database. new_appt = Appointment() new_appt.appt_title = form.appt_title.data new_appt.appt_date = form.appt_date.data new_appt.appt_start_time = form.appt_start_time.data new_appt.appt_duration = form.appt_duration.data new_appt.appt_location = form.appt_location.data new_appt.appt_customer_name = form.appt_customer_name.data new_appt.appt_notes = form.appt_notes.data new_appt.appt_status = form.appt_status_completed.data print(new_appt.appt_title) db.session.add(new_appt) db.session.commit() flash('your appointment has been created') # Redirect to this handler - but without form submitted - gets a clear form. return redirect(url_for('main.appointments')) appointments = db.session.query(Appointment).all() return render_template("main/appointment.html", appointments=appointments, searchform=searchform, form=form)
def appointmentlist(): form = AppointmentForm() if form.validate_on_submit(): new_appointment = Appointment() new_appointment.appointment_title = form.appointment_title.data new_appointment.appointment_status = form.appointment_status_completed.data new_appointment.appointment_date = form.appointment_date.data new_appointment.start_time = form.start_time.data new_appointment.duration = form.duration.data new_appointment.location = form.location.data new_appointment.customer_name = form.customer_name.data new_appointment.notes = form.notes.data db.session.add(new_appointment) db.session.commit() return redirect(url_for('main.appointmentlist')) appointment_list = db.session.query(Appointment).all() return render_template("main/appointmentlist.html", appointment_list=appointment_list, form=form)
def save(self, *args, **kwargs): cost = kwargs.pop('cost', None) time_slot = kwargs.pop('time_slot', None) address_id = kwargs.pop('address', None) test_ids = kwargs.pop('test_ids', None) _is_new = not self.pk super(TestRequest, self).save(*args, **kwargs) if _is_new: new_appointment = Appointment( address_id=address_id, time_slot=time_slot, test_request=self, ) new_appointment.save() self.appointment = new_appointment self.payment_request = PaymentHandler.create_new_payment_request( cost) self.save() for test in test_ids: Test.objects.create( lab_test=self.appointment.time_slot.lab.get_test(test), test_request=self, )
def test_repr(self): start = datetime.utcnow() end = datetime.utcnow() + timedelta(days=1) appointment = Appointment(title='title', description='description', date_start=start, date_end=end) self.assertEqual(appointment.__repr__(), 'title')
def book(Did): app = Appointment(doctor_id=Did, patient_id=current_user.id) form = AppointmentForm(obj=app) if form.validate_on_submit(): appoint = Appointment(requested_date=form.date.data, doctor_id=form.doctor_id.data, patient_id=form.patient_id.data, status=0) db.session.add(appoint) db.session.commit() flash('Congratulations, your appointment is successfully booked!') return redirect(url_for('home')) return render_template('bookdoctor.html', form=form)
def test_attributes_assignment(self): start = datetime.utcnow() end = datetime.utcnow() + timedelta(days=1) appointment = Appointment(title='title', description='description', date_start=start, date_end=end) appointment.color = 'blue' appointment.is_completed = True self.assertEqual(appointment.title, 'title') self.assertEqual(appointment.description, 'description') self.assertEqual(appointment.date_start, start) self.assertEqual(appointment.date_end, end) self.assertEqual(appointment.color, 'blue') self.assertEqual(appointment.is_completed, True)
def test_create_appointment(): """ Test creating an appointment with a patient and a provider """ # Arrange patient = Patient(first_name="Aly", last_name="Sivji") provider = Provider(first_name="Doctor", last_name="Acula") now = datetime.now() a = Appointment(start=now, end=now, department='foo', patient=patient, provider=provider) # Act db.session.add(a) db.session.commit() # Assert assert len(Appointment.query.all()) == 1 queried_appointment = Appointment.query.one() assert queried_appointment.department == 'foo' assert queried_appointment.patient_id == patient.id assert queried_appointment.provider_id == provider.id db.session.delete(a) db.session.delete(patient) db.session.delete(provider) db.session.commit()
def post_appointment(id): form = AppointmentForm() data = request.get_json() # print("********************************* ", data["notes"]) new_appointment = Appointment(user_id=data["user_id"], chef_id=data["chef_id"], notes=form.data['notes'], date=datetime.datetime.strptime( data["date"], "%a, %d %b %Y %H:%M:%S %Z")) db.session.add(new_appointment) db.session.commit() return new_appointment.to_dict()
def create_appt_process(): """ API access for creating appointments """ try: data = request.get_json() client_id = data['clientId'] appt_date = data['apptDate'] appt_time = data['apptTime'] appt_notes = data['apptNotes'] date_obj = datetime.datetime.strptime(appt_date, '%Y-%m-%d').date() client = Client.query.filter_by(id=client_id).first() appointment = Appointment(client_first=client.first_name, client_last=client.last_name, date=date_obj, time=appt_time, notes=appt_notes, creator=current_user, client=client) interaction = Interaction(client_id=client_id, marketer=str(current_user), date=date_tool.get_current_date(), time=date_tool.get_current_time(), type_of='Appointment Created', about=appt_notes) db.session.add(appointment) db.session.add(interaction) db.session.commit() return jsonify("Appointment successfully created") except Exception as e: return jsonify("Unsuccessful")
def create_appointment(id): """ Handle requests to /appointments route Create & save a new appointment """ form = AppointmentForm() inquiry = Inquiry.query.get_or_404(id) if form.validate_on_submit(): appointment = Appointment(title=form.title.data, description=form.description.data, start=form.start.data, location=form.location.data, client=inquiry.client, inquiry=inquiry, user=current_user) try: db.session.add(appointment) db.session.commit() flash('Successfully created the appointment.') return redirect(url_for('inquiry.read_inquiry', id=id)) except: flash('Error creating the appointment') return render_template('inquiries/appointment-form.html.j2', form=form, title='Create appointment')
def test_get_appointments(self): hospital = Hospital(name='Severance') user = User(first_name='one', last_name='one', email='*****@*****.**', username='******', password='******') start = datetime.utcnow() end = datetime.utcnow() + timedelta(days=1) appointment1 = Appointment(title='title', description='description', date_start=start, date_end=end) appointment2 = Appointment(title='title', description='description', date_start=start, date_end=end) appointment3 = Appointment(title='title', description='description', date_start=start, date_end=end) appointment1.user = user appointment2.user = user user.hospital = hospital db.session.add_all( [hospital, user, appointment1, appointment2, appointment3]) db.session.commit() self.assertTrue(appointment1 in hospital.get_appointments().all()) self.assertTrue(appointment2 in hospital.get_appointments().all()) self.assertFalse(appointment3 in hospital.get_appointments().all())
def todolist(): #form = TaskForm() form = AppointmentForm() if form.validate_on_submit(): # Get the data from the form, and add it to the database. #new_task = Task() new_appointment = Appointment() #new_task.task_desc = form.task_desc.data new_appointment.appointment_date = form.appointment_date.data #new_task.task_status = form.task_status_completed.data new_appointment.appointment_dur = form.appointment_dur.data new_appointment.appointment_loc = form.appointment_loc.data new_appointment.appointment_client = form.appointment_client.data new_appointment.appointment_desc = form.appointment_desc.data #db.session.add(new_task) db.session.add(new_appointment) db.session.commit() # Redirect to this handler - but without form submitted - gets a clear form. return redirect(url_for('main.todolist')) #todo_list = db.session.query(Task).all() todo_list = db.session.query(Appointment).all() return render_template("main/todolist.html", todo_list=todo_list, form=form)
def creat_appointment(id): data = request.get_json() or {} now = datetime.datetime.now() nowdate = now.strftime("%Y-%m-%d") for i in data['date']: if nowdate <= i: appointment = Appointment.query.filter_by(appointment_date=i).first() if appointment: appointment.am_appointment = data['am_appointment'] appointment.pm_appointment = data['pm_appointment'] appointment.cost = data['cost'] else: appointment = Appointment(doctor_id=id, am_appointment=data['am_appointment'], pm_appointment=data['am_appointment'], cost=data['cost']) appointment.appointment_date = i db.session.add(appointment) db.session.commit() return jsonify({'code': 200})
def Schedule(): form = AppointmentForm() if form.validate_on_submit(): new_appointment = Appointment() new_appointment.customer_name = form.customer_name.data new_appointment.appointment_title = form.appointment_title.data new_appointment.appointment_date = form.appointment_date.data new_appointment.appointment_time = form.start_time.data new_appointment.appointment_duration = form.duration_of_appointment.data new_appointment.appointment_location = form.location.data new_appointment.notes = form.notes.data new_appointment.appointment_status = form.appointment_status_completed.data db.session.add(new_appointment) db.session.commit() return redirect(url_for('main.view_schedule')) return render_template('main/schedule_appointment.html', title='Schedule an appointment', form=form)
def appt(): form = Appointment() if form.validate_on_submit(): appts = AppointmentF() appts.appt_title = form.title.data appts.appt_datetime = datetime.datetime.combine( form.date.data, form.time.data) appts.location = form.location.data appts.add_notes = form.notes.data appts.customer_Name = form.name.data appts.customer_email = form.email.data appts.appointment.status = "Created Appointment" db.session.add(appts) db.session.commit() flash('Successfully created the appointment!', category='success') return redirect(url_for('main/viewappt'), appts=appts) return render_template("main/createappt.html", appts=appts, form=form)
def test_id(self): start = datetime.utcnow() end = datetime.utcnow() + timedelta(days=1) appointment = Appointment(title='title', description='description', date_start=start, date_end=end) db.session.add(appointment) db.session.commit() self.assertEqual(appointment.id, 1)
def add_appointment(): form = AppointmentForm() if form.validate_on_submit(): new_appointment = Appointment() new_appointment.title = form.title.data new_appointment.date_time = datetime.datetime.combine( form.start_date.data, form.start_time.data) new_appointment.duration = form.duration.data new_appointment.location = form.location.data new_appointment.customer_name = form.customer_name.data new_appointment.notes = form.notes.data new_appointment.status = form.status.data db.session.add(new_appointment) db.session.commit() flash("Added the appointment") return redirect(url_for('main.add_appointment')) return render_template("main/add_appointment.html", form=form)
def create_appt(): """ User can create appointments. It will log appointments into database, as well as the interaction of 'Appointment'. """ create_form = CreateAppointmentForm() if create_form.validate_on_submit(): date = create_form.year_menu.data + '-' + create_form.month_menu.data + '-' + create_form.day_menu.data date_obj = datetime.datetime.strptime(date, '%Y-%m-%d').date() time = create_form.hour_menu.data + ':' + create_form.minute_menu.data + ' ' + create_form.ampm_menu.data if create_form.client_id1.data == create_form.client_id2.data: client = Client.query.filter_by( id=create_form.client_id1.data).first() if client: appt = Appointment(client_first=client.first_name, client_last=client.last_name, date=date_obj, time=time, notes=create_form.notes.data, creator=current_user, client=client) interaction = Interaction( client_id=create_form.client_id1.data, marketer=str(current_user), date=date_tool.get_current_date(), time=date_tool.get_current_time(), type_of="Appointment", about=create_form.notes.data) db.session.add(appt) db.session.add(interaction) db.session.commit() flash('Appointment added') else: flash('No clients exists under that ID!') else: flash('ID fields must match!') return redirect(url_for('create_appt')) return render_template('create_appt.html', create_form=create_form, pretty_date=pretty_date)
def test_create_invalid_appointment_missing_patient(): """ Test creating an appointment with a provider and no patient """ # Arrange provider = Provider(first_name="Doctor", last_name="Acula") now = datetime.now() a = Appointment(start=now, end=now, department='foo', provider=provider) # Act db.session.add(a) # Assert with pytest.raises(IntegrityError): db.session.commit() db.session.rollback() assert len(Appointment.query.all()) == 0
def test_appointments_relationship(self): start = datetime.utcnow() end = datetime.utcnow() + timedelta(days=1) appointment1 = Appointment(title='title1', description='description1', date_start=start, date_end=end) appointment2 = Appointment(title='title2', description='description2', date_start=start, date_end=end) patient = Patient(first_name='John', last_name='Elliot', email="*****@*****.**") user = User(first_name='John', last_name='Elliot', username='******', email="*****@*****.**", password='******') treatment = Treatment(name='Tylenol') # before connecting self.assertEqual(len(patient.appointments.all()), 0) self.assertEqual(len(user.appointments.all()), 0) self.assertEqual(len(treatment.appointments.all()), 0) # after connecting appointment1 appointment1.patient = patient appointment1.user = user appointment1.treatment = treatment db.session.add_all( [patient, user, treatment, appointment1, appointment2]) db.session.commit() self.assertEqual(len(patient.appointments.all()), 1) self.assertTrue(appointment1 in patient.appointments.all()) self.assertEqual(appointment1.patient_id, patient.id) self.assertFalse(appointment2 in patient.appointments.all()) self.assertNotEqual(appointment2.patient_id, patient.id) self.assertEqual(len(user.appointments.all()), 1) self.assertTrue(appointment1 in user.appointments.all()) self.assertEqual(appointment1.user_id, user.id) self.assertFalse(appointment2 in user.appointments.all()) self.assertNotEqual(appointment2.user_id, user.id) self.assertEqual(len(treatment.appointments.all()), 1) self.assertTrue(appointment1 in treatment.appointments.all()) self.assertEqual(appointment1.treatment_id, treatment.id) self.assertFalse(appointment2 in treatment.appointments.all()) self.assertNotEqual(appointment2.treatment_id, treatment.id)
def appointmentlist(sortby): form = AppointmentForm() if form.validate_on_submit(): # Get the data from the form, and add it to the database. new_appointment = Appointment( appointment_title=form.appointment_title.data, appointment_start_date=form.appointment_start_date.data, appointment_duration=form.appointment_duration.data, appointment_location=form.appointment_location.data, customer_name=form.customer_name.data, customer_notes=form.customer_notes.data) db.session.add(new_appointment) db.session.commit() # Redirect to this handler - but without form submitted - gets a clear form. return redirect(url_for('main.appointmentlist', sortby=sortby)) if sortby == 0: appointment_list = Appointment.query.order_by( Appointment.appointment_title) elif sortby == 1: appointment_list = Appointment.query.order_by( Appointment.appointment_start_date) elif sortby == 2: appointment_list = Appointment.query.order_by( Appointment.appointment_duration) elif sortby == 3: appointment_list = Appointment.query.order_by( Appointment.appointment_location) elif sortby == 4: appointment_list = Appointment.query.order_by( Appointment.customer_name) elif sortby == 5: appointment_list = Appointment.query.order_by( Appointment.customer_notes) else: appointment_list = db.session.query(Appointment).all() return render_template("main/appointmentlist.html", appointment_list=appointment_list, form=form, sortby=sortby)
def index(): if current_user.is_administrator: return redirect( url_for('administrator', username=current_user.username)) form = AppointmentForm(datetime.now().date(), current_user.id) if form.validate_on_submit(): appointment = Appointment( address=current_user.address, date=datetime.strptime(form.date.data, "%Y-%m-%d").date(), time=timeslot[int(form.time.data)], comment=form.comment.data, applicant=current_user, fordog=Dog.query.filter_by(id=form.dog.data, user_id=current_user.id).first(), type=Service.query.filter_by(id=form.service.data).first()) db.session.add(appointment) db.session.commit() flash('Your appointment is already submitted!') return redirect(url_for('user', username=current_user.username)) return render_template('index.html', title='Home', form=form)
def appointment(): form = AppointmentForm() if form.validate_on_submit(): new_appo = Appointment() new_appo.appo_title = form.appo_title.data new_appo.appo_date = form.appo_date.data new_appo.appo_duration = form.appo_duration.data new_appo.appo_location = form.appo_location.data new_appo.appo_customer_name = form.appo_customer_name.data new_appo.appo_notes = form.appo_notes.data db.session.add(new_appo) db.session.commit() return redirect(url_for('appointment.appointment')) appo_list = db.session.query(Appointment).all() return render_template("appointment/appointment.html", appo_list=appo_list, form=form)
def appointment(appointment_id): form = AppointmentForm() if form.validate_on_submit(): # Get the data from the form, and add it to the database. modified_appointment = Appointment( appointment_title=form.appointment_title.data, appointment_start_date=form.appointment_start_date.data, appointment_duration=form.appointment_duration.data, appointment_location=form.appointment_location.data, customer_name=form.customer_name.data, customer_notes=form.customer_notes.data) Appointment.query.filter( Appointment.appointment_id == appointment_id).delete() db.session.commit() db.session.add(modified_appointment) db.session.commit() appointment = Appointment.query.filter( Appointment.appointment_id == appointment_id).one() return render_template("main/appointment.html", appointment=appointment, form=form, appointment_id=appointment_id)
def Update_Schedule(appointment_id): form = AppointmentForm() print(form.validate_on_submit()) if form.validate_on_submit(): new_appointment = Appointment() current_appointment = Appointment.query.filter_by( appointment_id=appointment_id).first_or_404() current_appointment.customer_name = form.customer_name.data current_appointment.appointment_title = form.appointment_title.data current_appointment.appointment_date = form.appointment_date.data current_appointment.appointment_time = form.start_time.data current_appointment.appointment_duration = form.duration_of_appointment.data current_appointment.appointment_location = form.location.data current_appointment.appointment_status = form.appointment_status_completed.data current_appointment.notes = form.notes.data db.session.add(current_appointment) db.session.commit() return redirect(url_for('main.display_schedule')) current_appointment = Appointment.query.filter_by( appointment_id=appointment_id).first_or_404() form.customer_name.data = current_appointment.customer_name form.appointment_title.data = current_appointment.appointment_title form.appointment_date.data = current_appointment.appointment_date form.start_time.data = current_appointment.appointment_time form.duration_of_appointment.data = current_appointment.appointment_duration form.location.data = current_appointment.appointment_location form.appointment_status_completed.data = current_appointment.appointment_status form.notes.data = current_appointment.notes return render_template('main/schedule_appointment.html', title='Schedule an appointment', form=form)
def appointments(request): if request.method == 'GET': return redirect("/all_timeslots/") else: # slots = json.loads(request.POST.get("slots", "")) appointments = Appointment.objects.filter( user_email=request.user.email) if (appointments.count() > 0): return JsonResponse({"result": "Error"}) appointment = Appointment() profRel = ProfessorStudent.objects.filter( student_email=request.user.email)[0] prof = Professor.objects.get(email=profRel.professor_email) profUser = User.objects.get(email=profRel.professor_email) appointment.save_data(request.POST, request.user, profUser, prof) appointment.save() TimeSlot.objects.get(id=request.POST['timeslot_id']).delete() return JsonResponse({'result': 'Ok'})
def process_mapping_encounter(self, json_result, user_id): print("process mapping encounter") try: mapped_girl_object = self.get_form_id_and_extract_json_object( json_result) next_of_kin_number = None voucher_number = "" attended_anc_visit = False bleeding = False fever = False swollenfeet = False blurred_vision = False voucher_number_creation = False nationality = "Ugandan" disabled = False mapping_encounter = MappingEncounter() try: odk_instance_id = mapped_girl_object["meta"][0]["instanceID"][ 0] except Exception as e: print(e) odk_instance_id = "abc123" demographic1 = mapped_girl_object["GirlDemographic"][0] first_name = demographic1["FirstName"][0] last_name = demographic1["LastName"][0] girls_phone_number = demographic1["GirlsPhoneNumber"][0] dob = demographic1["DOB"][0] try: demographic2 = mapped_girl_object["GirlDemographic2"][0] next_of_kin_number = demographic2["NextOfKinNumber"][0] except Exception as e: print(e) try: nationality_group = mapped_girl_object["NationalityGroup"][0] nationality = nationality_group['Nationality'][0] except KeyError or IndexError as e: print(e) girl_location = mapped_girl_object["GirlLocation"][0] # use filter and get first because there are so some duplicate locations parish = Parish.objects.filter(name__icontains=replace_underscore( girl_location["parish"][0])).first() village = Village.objects.filter( Q(name__icontains=replace_underscore( girl_location["village"][0])) & Q(parish=parish)).first() try: disability_group = mapped_girl_object["DisabilityGroup"][0] disabled = disability_group['Disability'][0] == "yes" except KeyError or IndexError as e: print(e) observations3 = mapped_girl_object["Observations3"][0] marital_status = observations3["marital_status"][0] education_level = replace_underscore( observations3["education_level"][0]) last_menstruation_date = observations3["MenstruationDate"][0] try: observations1 = mapped_girl_object["Observations1"][0] bleeding = observations1["bleeding"][0] == "yes" fever = observations1["fever"][0] == "yes" observations2 = mapped_girl_object["Observations2"][0] swollenfeet = observations2["swollenfeet"][0] == "yes" blurred_vision = observations2["blurred_vision"][0] == "yes" except Exception: print(traceback.print_exc()) try: voucher_card_group = mapped_girl_object["VouncherCardGroup"][0] has_voucher_card = voucher_card_group["VoucherCard"][ 0] == "yes" if has_voucher_card: voucher_number = voucher_card_group["VoucherNumber"][0] else: voucher_number_creation = voucher_card_group[ "VoucherNumberCreation"][0] == "yes" except KeyError or IndexError: print(traceback.print_exc()) user = User.objects.get(id=user_id) print(user) # incase the village does not exist use the health worker's village if not village: village = user.village # incase the girl already exists with the same name, # create a new girl and swap the new girl for the old one with updated data old_girl = Girl.objects.filter( Q(first_name__icontains=first_name) & Q(last_name__icontains=last_name)) if old_girl: if len(voucher_number) == 0: voucher_number = old_girl.first().voucher_number edited_girl = Girl( first_name=first_name, last_name=last_name, village=village, phone_number=girls_phone_number, user=user, disabled=disabled, voucher_number=voucher_number, next_of_kin_phone_number=next_of_kin_number, nationality=nationality, education_level=education_level, dob=dob, marital_status=marital_status, last_menstruation_date=last_menstruation_date, odk_instance_id=odk_instance_id) edited_girl.save() girl = edited_girl # swap the old girl for the edited girl old_girl = old_girl.first() old_appointments = old_girl.appointment_set.all() for appointment in old_appointments: appointment.girl = edited_girl appointment.save(update_fields=['girl']) old_referrals = old_girl.referral_set.all() for referral in old_referrals: referral.girl = edited_girl referral.save(update_fields=['girl']) # lastly delete the old girl old_girl.delete() else: voucher_number = voucher_number if user.district.name.lower( ) in MSI_DISTRICTS else "" new_girl = Girl.objects.create( first_name=first_name, last_name=last_name, village=village, phone_number=girls_phone_number, user=user, nationality=nationality, disabled=disabled, next_of_kin_phone_number=next_of_kin_number, education_level=education_level, dob=dob, marital_status=marital_status, last_menstruation_date=last_menstruation_date, voucher_number=voucher_number, odk_instance_id=odk_instance_id) girl = new_girl try: # incase girl who has already had ANC visit is mapped by midwife # save that date and create an anc visit anc_previous_group = mapped_girl_object[ "ANCAppointmentPreviousGroup"][0] attended_anc_visit = anc_previous_group[ "AttendedANCVisit"][0] == "yes" if attended_anc_visit: previous_appointment_date = anc_previous_group[ "ANCDatePrevious"][0] self.auto_generate_appointment( new_girl, user, previous_appointment_date) else: self.auto_generate_appointment(new_girl, user) except Exception: print(traceback.print_exc()) try: anc_group = mapped_girl_object["ANCAppointmentGroup"][0] next_appointment_date = anc_group["ANCDate"][0] appointment = Appointment(girl=new_girl, user=user, date=next_appointment_date) appointment.save() except Exception: print(traceback.print_exc()) observation = Observation(blurred_vision=blurred_vision, bleeding_heavily=bleeding, fever=fever, swollen_feet=swollenfeet) observation.save() mapping_encounter.observation = observation mapping_encounter.attended_anc_visit = attended_anc_visit mapping_encounter.voucher_card = voucher_number if user.district.name.lower( ) != "bundibugyo" else "" mapping_encounter.odk_instance_id = odk_instance_id mapping_encounter.user = user mapping_encounter.girl = girl mapping_encounter.save() self.save_family_planning_methods_in_mapping_encounter( mapped_girl_object, mapping_encounter) # MSI voucher are only provided to MSI districts if user.district.name.lower( ) in MSI_DISTRICTS and user.role == USER_TYPE_CHEW: self.get_and_save_msi_voucher_to_girl(girl) return Response({'result': 'success'}, status.HTTP_200_OK) except Exception: print(traceback.print_exc()) return Response({'result': 'failure'}, status.HTTP_400_BAD_REQUEST)
def process_follow_up_and_delivery_encounter(self, girl_id, json_result, user_id): try: try: follow_up_object = json_result[FOLLOW_UP_FORM_CHEW_NAME] except Exception: print(traceback.print_exc()) try: follow_up_object = json_result[FOLLOW_UP_FORM_MIDWIFE_NAME] except Exception: print(traceback.print_exc()) try: follow_up_object = json_result[DEFAULT_TAG] except KeyError: print(traceback.print_exc()) print(follow_up_object) fever = False swollenfeet = False bleeding = False blurred_vision = False missed_anc_before = False missed_anc_reason = "" action_taken_by_health_person = "appointment" try: # captured in chew follow up observations1 = follow_up_object["observations1"][0] bleeding = observations1["bleeding"][0] == "yes" fever = observations1["fever"][0] == "yes" observations2 = follow_up_object["observations2"][0] swollenfeet = observations2["swollenfeet"][0] == "yes" blurred_vision = observations2["blurred_vision"][0] == "yes" except Exception: print(traceback.print_exc()) try: missed_anc_before_group = follow_up_object[ "missed_anc_before_group"][0] missed_anc_before = missed_anc_before_group[ "missed_anc_before"][0] == "yes" if missed_anc_before: missed_anc_before_group2 = follow_up_object[ "missed_anc_before_group2"][0] missed_anc_reason = replace_underscore( missed_anc_before_group2["missed_anc_reason"][0]) if missed_anc_reason == "Other": missed_anc_reason = replace_underscore( missed_anc_before_group2["missed_anc_reason_other"] [0]) except Exception: print(traceback.print_exc()) try: action_taken_group = follow_up_object[ "action_taken_by_health_person_group"][0] action_taken_by_health_person = action_taken_group[ "action_taken_by_health_person"][0] except Exception: print(traceback.print_exc()) girl = Girl.objects.get(id=girl_id) user = User.objects.get(id=user_id) if action_taken_by_health_person == "appointment": next_appointment = follow_up_object[ "schedule_appointment_group"][0]["schedule_appointment"][0] appointment = Appointment(girl=girl, user=user, date=next_appointment) appointment.save() elif action_taken_by_health_person == "delivery": self.save_delivery(follow_up_object, girl, user) elif action_taken_by_health_person in ["referral", "referred"]: Referral.objects.create(girl=girl, user=user, reason="critical") observation = Observation(blurred_vision=blurred_vision, bleeding_heavily=bleeding, fever=fever, swollen_feet=swollenfeet) observation.save() follow_up = FollowUp( girl=girl, user=user, follow_up_action_taken=action_taken_by_health_person, missed_anc_reason=missed_anc_reason, missed_anc_before=missed_anc_before, observation=observation) follow_up.save() return Response({'result': 'success'}, 200) except Exception: print(traceback.print_exc()) return Response({'result': 'failure'}, 400)
def process_appointment_encounter(self, girl_id, json_result, user_id): try: try: appointment_object = json_result[APPOINTMENT_FORM_MIDWIFE_NAME] except Exception: print(traceback.print_exc()) try: appointment_object = json_result[DEFAULT_TAG] except KeyError: print(traceback.print_exc()) needed_ambulance = False used_ambulance = False missed_anc_reason = "" appointment_method = "" fever = False swollenfeet = False bleeding = False blurred_vision = False try: ambulance_group = appointment_object["ambulance_group"][0] needed_ambulance = ambulance_group["needed_ambulance"][ 0] == "yes" used_ambulance = ambulance_group["used_ambulance"][0] == "yes" except Exception: print(traceback.print_exc()) try: appointment_soon_group = appointment_object[ "appointment_soon_group"][0] appointment_method = replace_underscore( appointment_soon_group["appointment_method"][0]) except Exception: print(traceback.print_exc()) missed_anc_before_group = appointment_object[ "missed_anc_before_group"][0] missed_anc_before = missed_anc_before_group["missed_anc_before"][ 0] == "yes" if missed_anc_before: missed_anc_before_group2 = appointment_object[ "missed_anc_before_group2"][0] missed_anc_reason = missed_anc_before_group2[ "missed_anc_reason"][0] if missed_anc_reason == "Other": missed_anc_reason = missed_anc_before_group2[ "missed_anc_reason_other"][0] action_taken_group = appointment_object["action_taken_group"][0] action_taken = replace_underscore( action_taken_group["action_taken_meeting_girl"][0]) if action_taken == 'other': action_taken = replace_underscore( action_taken_group["action_taken_other"][0]) schedule_appointment_group = appointment_object[ "schedule_appointment_group"][0] next_appointment_date = schedule_appointment_group[ "schedule_appointment"][0] girl = Girl.objects.get(id=girl_id) user = User.objects.get(id=user_id) try: if user.district.name.lower( ) in MSI_DISTRICTS and user.role == USER_TYPE_MIDWIFE: msi_service = appointment_object["voucher_redeem_group"][ 0]["voucher_services"][0] MSIService.objects.create(girl=girl, option=msi_service) except Exception as e: print(e) observation = Observation(blurred_vision=blurred_vision, bleeding_heavily=bleeding, fever=fever, swollen_feet=swollenfeet) observation.save() appointment = Appointment(girl=girl, user=user, date=next_appointment_date) appointment.save() appointment_encounter = AppointmentEncounter( used_ambulance=used_ambulance, needed_ambulance=needed_ambulance, missed_anc_reason=missed_anc_reason, action_taken=action_taken, appointment_method=appointment_method, missed_anc_before=missed_anc_before, appointment=appointment) appointment_encounter.observation = observation appointment_encounter.save() return Response({'result': 'success'}, 200) except Exception: print(traceback.print_exc()) return Response({'result': 'failure'}, 400)
#!flask/bin/python from config import SQLALCHEMY_DATABASE_URI from app.models import Patient, Appointment, PhoneCalls from app import db import os.path db.create_all() # Patient.generate_fake(); # Appointment.generate_fake(); # PhoneCalls.generate_fake(); Patient.add_patient(); Appointment.add_appointment(); PhoneCalls.add_call();