def delete_medicine(request): med_to_delete = request.POST.get('key_to_delete', 0) category_key = str(med_to_delete).split(',')[0] medicine_key = str(med_to_delete).split(',')[1] db.child("Data").child('medicine_list').child(category_key).child( "medicationList").child(medicine_key).remove() return redirect('/medications')
def edit_question(request): question_to_edit = request.POST.get('key_to_edit', 0) if request.method == "POST": answers = {} form = Question(request.POST) if form.is_valid(): title = form.cleaned_data['title'] choice_type = form.cleaned_data['choice_type'] if choice_type != 'OpenQuestion': number_of_answers = int(request.POST.get("edit_number_of_answers", 0)) + 1 for i in range(number_of_answers): answers[str(i)] = request.POST.get(str(i)) if choice_type == 'SingleChoice' or choice_type == 'MultipleChoice': type = 'MultipleChoiceQuestion' else: type = 'OpenQuestion' data = { 'title': title, 'choiceType': choice_type, 'choices': answers, 'type': type } db.child("Data").child('questionnaire_follow_up').child("questionList").child(question_to_edit).update(data) db.child("Data").child('questionnaire_follow_up').child("answeredAt").update( {'time': round(time.time() * 1000)}) return redirect('/questionnaire') # Reload new questionnaire and prevent resubmission
def edit_medicine(request): medicine_form = MedicationForm(med_categories=get_medications_categories(), data=request.POST) med_key_to_update = request.POST.get('key_to_edit', 0) if medicine_form.is_valid(): category = medicine_form.cleaned_data['category'] medication_name = medicine_form.cleaned_data['medication_name'] data = { 'categoryId': category, 'dosage': 0, 'name': medication_name, } med_name = db.child("Data").child('medicine_list').child( category).child("medicationList").order_by_child('name').equal_to( medication_name).get() if not med_name.val(): db.child("Data").child('medicine_list').child(category).child( "medicationList").child(med_key_to_update).update(data) return redirect( '/medications' ) # Reload new questionnaire and prevent resubmission return HttpResponse("Already Exist")
def update_medicine(request): data = request.POST.dict() times = (data.get('hoursArr')).split(',') time_dict = {} idx = 0 for time in times: if time != "00:00" and time != '': hours = time.split(':')[0] minutes = time.split(':')[1] time_dict[idx] = {'hour': int(hours), 'minutes': int(minutes)} idx += 1 data['hoursArr'] = time_dict data['dosage'] = float(data['dosage']) if data['keyToUpdate'] != data['id']: db.child("Patients").child( request.session.get('patient_key')).child('medicine_list').child( data['keyToUpdate']).remove() del data['keyToUpdate'] check = db.child("Patients").child( request.session.get('patient_key')).child('medicine_list').child( data['id']).update(data) if check: db.child("Patients").child(request.session.get('patient_key')).child( 'user_details').child("needToUpdateMedicine").set(False) PushService.send_medicine_notification( request.session.get('patient_token')) return HttpResponse("True") else: return HttpResponse("False")
def register_new_patient(response): if response.method == "POST": django_form = RegisterForm(response.POST) # django User patient_form = PatientRegisterForm(response.POST) # our user if django_form.is_valid() and patient_form.is_valid(): first_name = django_form.cleaned_data["first_name"] last_name = django_form.cleaned_data["last_name"] email = django_form.cleaned_data["email"] password = django_form.cleaned_data["password1"] gender = patient_form.cleaned_data["gender"] country = patient_form.cleaned_data["country"] mobile_phone = patient_form.cleaned_data["mobile_phone"] clinic = patient_form.cleaned_data["clinic"] date_of_birth = str(patient_form.cleaned_data['date_of_birth']) patient = auth_fb.create_user_with_email_and_password( email=email, password=password) epoch = datetime(1970, 1, 1) dt_obj = datetime.strptime(date_of_birth, '%Y-%m-%d') if dt_obj > epoch: millisec = dt_obj.timestamp() * 1000 else: millisec = (dt_obj - epoch).total_seconds() * 1000 data = { 'doctor': response.session.get('email'), 'email': email, 'first_name': first_name, 'last_name': last_name, 'gender': gender, 'mobile_phone': mobile_phone, 'clinic': clinic, 'country': country, 'hasUnansweredQuestionnaire': True, 'needToUpdateMedicine': True, 'date_of_birth': millisec, 'token': '' } db.child("Patients").child(patient['localId']).set( {'id': mobile_phone}) db.child("Patients").child( patient['localId']).child("user_details").set(data) else: return render(response, "register/add_new_patient.html", { 'form': django_form, 'ourform': patient_form }) return redirect("/home") else: # Get if response.session.get('uid') is not None: form = RegisterForm() patient_form = PatientRegisterForm() return render(response, "register/add_new_patient.html", { 'form': form, 'ourform': patient_form }) else: return redirect("/")
def postsign(request): form = Login() email, password = None, None if request.method == "GET": if request.session.get('uid') is not None: return redirect("/home", ) return render(request, "register/login.html", {"form": form}) if request.method == "POST": form = Login(request.POST) if form.is_valid(): email = form.cleaned_data['email'] password = form.cleaned_data['password'] try: user = auth_fb.sign_in_with_email_and_password(email, password) current_doctor_id = db.child("Doctors").child( user['localId']).child("details").get() name = current_doctor_id.val( )['first_name'] + " " + current_doctor_id.val()['last_name'] request.session['uid'] = str(user['idToken']) request.session['name'] = name request.session['email'] = user['email'] return redirect("/home") except: form.add_error('password', "אימייל או סיסמא אינם מתאימים!") return render(request, "register/login.html", {'form': form})
def patient_detail_check(request): patient_id = request.GET.get('data') exist = db.child("Patients").order_by_child('id').equal_to( patient_id).get() if exist.val(): return HttpResponse("True") else: return HttpResponse("False")
def create_medicine(request): medicine_form = MedicationForm(med_categories=get_medications_categories(), data=request.POST) if medicine_form.is_valid(): category = medicine_form.cleaned_data['category'] medication_name = medicine_form.cleaned_data['medication_name'] data = { 'categoryId': category, 'dosage': 0, 'name': medication_name, } med_key = db.child("Data").child('medicine_list').child( category).child("medicationList").push(data)['name'] db.child("Data").child('medicine_list').child(category).child("medicationList").child(med_key) \ .update({'id': med_key}) return redirect( '/medications') # Reload new medications and prevent resubmission
def delete_medicine(request): key_to_delete = request.POST.get('data') check = db.child("Patients").child(request.session.get('patient_key')).child('medicine_list') \ .child(key_to_delete).remove() if check is None: is_empty = db.child("Patients").child( request.session.get('patient_key')).child('medicine_list').get() if is_empty: db.child("Patients").child( request.session.get('patient_key')).child( 'user_details').child("needToUpdateMedicine").set(True) PushService.send_medicine_notification( request.session.get('patient_token')) return HttpResponse("True") else: return HttpResponse("False")
def check_if_med_exist(request): data = str(request.POST.get('data')) category = data.split(',')[0] med_name = data.split(',')[1] exist = db.child("Data").child('medicine_list').child(category).child("medicationList") \ .order_by_child('name').equal_to(med_name).get() if exist.val(): return HttpResponse("True") else: return HttpResponse("False")
def patient_detail(request): if request.session.get('uid') is not None: patient_id = request.GET.get("patient_id", 0) patients = db.child("Patients").order_by_child("id").equal_to( patient_id).get() if not patients.val(): return render(request, "dashboard/dashboard.html", {'msg': "מטופל לא נמצא, נסה שנית"}) for patient in patients.each(): # order_by returns a list request.session['patient_key'] = patient.key() patient_details = patient.val().get("user_details") patient_questionnaire = patient.val().get("questionnaire") patient_medications = db.child('Patients').child( patient.key()).child("medicine_list").get() patient_medications_reports = db.child('Patients').child( patient.key()).child("Medicine Reports").get() patient_reports = db.child('Patients').child( patient.key()).child("reports").get() patient_token = patient_details.get('token') request.session['patient_token'] = patient_token # Data for the charts reports = status_data_for_chart(patient_reports) # report_list = medications_data_for_charts(patient_medications) reports_medication_list = medications_reports( patient_medications_reports) medications = get_medications() return render( request, "patient/patient_page.html", { 'patient_details': patient_details, 'patient_medications': patient_medications, 'patient_questionnaire': patient_questionnaire, 'reports': reports, 'medications': medications, 'medication_reports': reports_medication_list, 'dosages': DOSAGES, 'token': patient_token, }) else: return redirect("/home")
def register_new_doctor(response): if response.method == "POST": django_form = RegisterForm(response.POST) # django User doctor_form = DoctorRegisterForm(response.POST) # our user if django_form.is_valid() and doctor_form.is_valid(): first_name = django_form.cleaned_data["first_name"] last_name = django_form.cleaned_data["last_name"] email = django_form.cleaned_data["email"] password = django_form.cleaned_data["password1"] gender = doctor_form.cleaned_data["gender"] office_phone = doctor_form.cleaned_data["office_phone"] mobile_phone = doctor_form.cleaned_data["mobile_phone"] organization = doctor_form.cleaned_data["organization"] doctor = auth_fb.create_user_with_email_and_password( email=email, password=password) if doctor: data = { 'email': email, 'first_name': first_name, 'last_name': last_name, 'gender': gender, 'office_phone': office_phone, 'mobile_phone': mobile_phone, 'organization': organization, } db.child("Doctors").child( doctor['localId']).child("details").set(data) else: return render(response, "register/register.html", { 'form': django_form, 'ourform': doctor_form }) return redirect("/") else: form = RegisterForm() doctor_form = DoctorRegisterForm() return render(response, "register/register.html", { 'form': form, 'ourform': doctor_form })
def delete_question(request): question_to_delete = request.POST.get('key_to_delete', 0) db.child("Data").child('questionnaire_follow_up').child("questionList").child(question_to_delete).remove() return redirect('/questionnaire')