def opinions_history(request): ''' View used to list the completed telefiles of the user The Opinions are ordered descendant by date of solve ''' requests = Request.objects.filter(expert_id=request.user, is_close=True).order_by('-solve_date') # From all the requests take the search choices: original_requests = requests # Filter using search bar inputs: ## Is Urgent if 'search_urgent' in request.GET: search_urgent = request.GET['search_urgent'] if search_urgent: requests = requests.filter(is_urgent=True) ## Patient: if 'search_patient' in request.GET: search_patient = request.GET['search_patient'] if search_patient: requests = requests.filter(patient_id=search_patient) ## Request owner: if 'search_doctor' in request.GET: search_doctor = request.GET['search_doctor'] if search_doctor: requests = requests.filter(doctor_id=search_doctor) ## Exam Date: if 'search_exam_date' in request.GET: search_exam_date = request.GET['search_exam_date'] if search_exam_date: requests = requests.filter(exam_date=search_exam_date) ## Subject: if 'search_subject' in request.GET: search_subject = request.GET['search_subject'] if search_subject: requests = requests.filter(subject__icontains=search_subject) # Show val(paginator_max) elements paginator = Paginator(requests, paginator_max) page_number = request.GET.get('page') paged_requests = paginator.get_page(page_number) context = { 'requests': paged_requests, # Set of unique values of patients that have requests for the select search 'unique_patients': Patient.objects.filter( pk__in=set(original_requests.values_list( 'patient_id', flat=True))).order_by('last_name'), # Set of unique values of Expert that have requests for the select search 'unique_doctors': User.objects.filter( pk__in=set(original_requests.values_list( 'doctor_id', flat=True))).order_by('last_name'), # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user), # Resend the previous inputs of the user 'values': request.GET } return render(request, 'pages/opinions_history.html', context)
def add_patient(request): if request.method == 'POST': form = PatientForm(request.POST) values = request.POST if form.is_valid(): # Get patient infos: last_name = form.cleaned_data['last_name'] first_name = form.cleaned_data['first_name'] cin = form.cleaned_data['cin'] phone = form.cleaned_data['phone'] gender = request.POST.get('gender', 'Homme') birthdate = request.POST.get('birthdate', datetime.now()) # Check if the CIN is already used with this doctor: if Patient.objects.filter(pk__in=Relation.objects.filter( doctor_id=request.user).values_list('patient_id', flat=True), cin=cin).exists(): patient = Patient.objects.get(cin=cin) # Check if data entred by the user is like the one in the db if patient.first_name != first_name or patient.last_name != last_name or patient.gender != gender or patient.birthdate != birthdate: messages.error( request, 'Faux informations! Un autre patient est déjà enregistrer avec ce C.I.N ou ce patient a donné une fause information!' ) return redirect('patients:add_patient') else: patient = Patient(last_name=last_name, first_name=first_name, cin=cin, birthdate=birthdate, gender=gender) # Save the new patient in the db patient.save() # Create the relation between the logged doctor and the new patient if Relation.objects.filter(doctor_id=request.user, patient_id=patient).exists(): messages.warning( request, 'Vous avez déjà ce patient dans votre base de données!') else: relation = Relation(doctor_id=request.user, patient_id=patient, phone=phone) # Save the relation relation.save() messages.success(request, 'Le nouveau patient est ajouté avec succès') return redirect('patients:add_patient') else: form = PatientForm() values = {} context = { 'form': form, 'values': values, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'patients/add_patient.html', context)
def index(request): # The 3 doctors that have the most opinion given in this app top_members = User.objects.filter( is_staff=False).order_by('-count_opinion')[:3] context = { 'doctors': top_members, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'echoTeleExpertise/index.html', context)
def doctor(request, doctor_id): ''' View used to show the detail of a specifique doctor with the id = doctor_id ''' doctor = get_object_or_404(User, pk=doctor_id) context = { 'doctor': doctor, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'pages/doctor.html', context)
def opinion_solved_detail(request, req_id): req = get_object_or_404(Request, pk=req_id) doctor_documents = Document.objects.filter(request_id=req_id, is_answer=False) expert_documents = Document.objects.filter(request_id=req_id, is_answer=True) context = { 'doctor_documents': doctor_documents, 'expert_documents': expert_documents, 'req': req, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'exams/opinion_solved_detail.html', context)
def list_doctors(request): ''' View used to list the doctors The doctors are ordered Ascendent Alphabeticaly with there last name ''' users = User.objects.filter( is_staff=False, is_active=True).exclude(email=request.user.email).order_by('last_name') # Filter using search bar inputs: ## Available if 'search_available' in request.GET: search_available = request.GET['search_available'] if search_available: users = users.filter(online_status='AVAILABLE') ## Name if 'search_name' in request.GET: search_name = request.GET['search_name'] if search_name: users = users.filter( Q(last_name__istartswith=search_name) | Q(first_name__istartswith=search_name)) ## Speciality if 'search_speciality' in request.GET: search_speciality = request.GET['search_speciality'] if search_speciality: users = users.filter(speciality__startswith=search_speciality) ## Institution if 'search_institution' in request.GET: search_institution = request.GET['search_institution'] if search_institution: users = users.filter(institution__icontains=search_institution) ## City if 'search_city' in request.GET: search_city = request.GET['search_city'] if search_city: users = users.filter(city__startswith=search_city) # Show val(paginator_max) elements paginator = Paginator(users, paginator_max) page_number = request.GET.get('page') paged_users = paginator.get_page(page_number) context = { 'doctors': paged_users, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user), # Resend the previous inputs of the user 'values': request.GET } return render(request, 'pages/list_doctors.html', context)
def patient(request, patient_id): patient = get_object_or_404(Patient, pk=patient_id) phone = Relation.objects.values_list('phone', flat=True).get(patient_id=patient_id, doctor_id=request.user) other_phones = Relation.objects.filter(patient_id=patient_id).exclude( doctor_id=request.user).order_by('-join_date').values_list('phone', flat=True) context = { 'patient': patient, 'main_phone': phone, 'phones': other_phones, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'patients/patient.html', context)
def telefile(request, request_id): ''' View used to show the detail of a specifique telefile with the id = request_id ''' req = get_object_or_404(Request, pk=request_id) # Mark the telefile as visited req.is_expert_visited = True req.notification_date = datetime.now() req.save() documents = Document.objects.filter(request_id=request_id) context = { 'req': req, 'documents': documents, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'pages/telefile.html', context)
def edit_patient(request, patient_id): # Get the patient with th id = patient_id from the database patient = get_object_or_404(Patient, pk=patient_id) # Get the relation doctor/patient from the database try: relation = Relation.objects.get(patient_id=patient_id, doctor_id=request.user) except Relation.DoesNotExist: raise Http404("No Relation with this query.") # if the request is made with the method POST (the user submit some informations) if request.method == 'POST': form = EditPatientForm(request.POST) values = request.POST if form.is_valid(): # Get infos last_name = form.cleaned_data['last_name'] first_name = form.cleaned_data['first_name'] phone = form.cleaned_data['phone'] birthdate = request.POST['birthdate'] gender = request.POST['gender'] # Edit Infos patient.last_name = last_name patient.first_name = first_name patient.gender = gender patient.birthdate = birthdate relation.phone = phone # Save modifications in the database relation.save() patient.save() messages.success(request, 'La modification est enregister') else: form = EditPatientForm() values = {} context = { 'form': form, 'values': values, 'patient': patient, 'phone': relation.phone, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'patients/edit_patient.html', context)
def list_patients(request): ''' View used to list the patients The Patients are ordered Ascendent Alphabeticaly with there last name ''' my_relations = Relation.objects.filter( doctor_id__pk=request.user.pk).order_by('patient_id__last_name') # Filters using search bar inputs: ## Name if 'search_name' in request.GET: search_name = request.GET['search_name'] if search_name: my_relations = my_relations.filter( Q(patient_id__last_name__startswith=search_name) | Q(patient_id__first_name__startswith=search_name)) ## C.I.N if 'search_cin' in request.GET: search_cin = request.GET['search_cin'] if search_cin: my_relations = my_relations.filter( patient_id__cin__icontains=search_cin) ## Gender if 'search_gender' in request.GET: search_gender = request.GET['search_gender'] if search_gender: my_relations = my_relations.filter( patient_id__gender__iexact=search_gender) # Show val(paginator_max) elements paginator = Paginator(my_relations, paginator_max) page_number = request.GET.get('page') paged_relations = paginator.get_page(page_number) context = { 'relations': paged_relations, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user), # Resend the previous inputs of the user 'values': request.GET } return render(request, 'pages/list_patients.html', context)
def share_telefile(request, request_id): req = get_object_or_404(Request, pk=request_id) experts = User.objects.filter(is_staff=False, is_active=True).exclude( pk=request.user.pk).exclude(pk=req.doctor_id.pk) # The Select Expert Filter if 'search_speciality' in request.GET: search_speciality = request.GET['search_speciality'] if search_speciality: experts = experts.filter(speciality=search_speciality) if 'search_city' in request.GET: search_city = request.GET['search_city'] if search_city: experts = experts.filter(city=search_city) documents = Document.objects.filter(request_id=request_id) context = { 'req': req, 'experts': experts, 'documents': documents, 'values': request.GET, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'pages/share_telefile.html', context)
def patient_request(request, patient_id): # Search the Patient if not find display 404 Error patient = get_object_or_404(Patient, pk=patient_id) if request.method == 'POST': form = RequestForm(request.POST) # the old values of the request values = request.POST if form.is_valid(): # Get infos: exam_date = request.POST.get('exam_date', datetime.now()) is_urgent = request.POST.get('is_urgent', 'NONE') expert_id = request.POST['expert_id'] subject = form.cleaned_data['subject'] description = form.cleaned_data['description'] # Test Expert id: if expert_id == '': messages.error(request, "Veuillez selectionner un expert valid!") return redirect('exams:patient_request', patient_id) # Search the instance Expert try: expert = User.objects.get(pk=expert_id) except User.DoesNotExist: messages.error(request, "Veuillez selectionner un expert valid!") return redirect('exams:patient_request', patient_id) req = Request.objects.create( exam_date=exam_date, patient_id=patient, doctor_id=request.user, expert_id=expert, subject=subject, text_doctor=description, ) # If urgent change is_urgent to True if is_urgent == 'URGENT': req.is_urgent = True # Save the request in db req.save() # Iterate in files and save them: files = request.FILES.getlist('files') for f in files: document = Document.objects.create(request_id=req, file=f, name=basename(f.name), ext=f.name.rsplit('.', 1)[1]) # Save the document in db document.save() # Send the New Request Email to the Owner if req.doctor_id.is_enable_mail: send_mail( # Subject "ETE: Votre demande d'avis d'expertise est crée avec succès.", # Message "Votre demande:\nL'objet: " + req.subject + ".\nL'expert: " + str_docname(req.expert_id) + ".\nLe patient: " + str_fullname(req.patient_id) + ".\n- Meryem Rkach", # From (Email) ## A variable that contain the ete mail ete_email, # To (Email) [ req.doctor_id.email, ], # If the send fail do not affich any errors fail_silently=True) # Send the New Request Email to the Expert if req.expert_id.is_enable_mail: send_mail( # Subject "ETE: Vous avez recu une nouvelle demande d'avis.", # Message "Le tele-dossier:\nL'objet: " + req.subject + ".\nDemandeur d'avis: " + str_docname(req.doctor_id) + ".\nLe patient: " + str_fullname(req.patient_id) + ".\n- Meryem Rkach", # From (Email) ## A variable that contain the ete mail ete_email, # To (Email) [ req.expert_id.email, ], # If the send fail do not affich any errors fail_silently=True) messages.success(request, "La nouvelle demande est envoyé") return redirect('pages:list_patients') else: form = RequestForm() values = {} users = User.objects.exclude(email=request.user.email).exclude( is_staff=True) context = { 'form': form, 'values': values, 'patient': patient, 'doctors': users, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'exams/patient_request.html', context)
def request_detail(request, request_id): req = get_object_or_404(Request, pk=request_id) # When the send the infos to complete the request: if request.method == 'POST': # Get the infos: subject = request.POST['subject'] description = request.POST['description'] is_urgent = request.POST.get('is_urgent', 'NONE') files = request.FILES.getlist('files') if subject != '': req.subject = subject if description: req.text_doctor = add_new_description(req.text_doctor, req.text_expert, description) if is_urgent == 'URGENT': req.is_urgent = True else: req.is_urgent = False # Unmark the seens for both the doctor and the expert req.is_expert_visited = False req.is_doctor_visited = False req.is_incomplete = False req.create_date = datetime.now() req.notification_date = datetime.now() # save the request in the db: req.save() # Add files and save them: files = request.FILES.getlist('new_files') for f in files: document = Document.objects.create(request_id=req, file=f, name=basename(f.name), ext=f.name.rsplit('.', 1)[1]) # Save the document in db document.save() # Send the Complete Request Email if req.doctor_id.is_enable_mail: send_mail( # Subject 'ETE: Vous avez compléter les informations complémentaire demandé', # Message "Vous avez compléter les informations demandés:\nPar: " + str_docname(req.expert_id) + ".\nA propos le patient: " + str_fullname(req.patient_id) + ".\nAvec l'objet: " + req.subject + ".\n- Meryem Rkach", # From (Email) ## A variable that contain the ete mail ete_email, # To (Email) [ req.doctor_id.email, ], # If the send fail do not affich any errors fail_silently=True) # Send the Complete Request Email to the Expert if req.expert_id.is_enable_mail: send_mail( # Subject "ETE: Un demandeur d'avis d'expertise a complété les informations complémentaire.", # Message "Des informations complémentaire sont envoyé à propos la demande:\nL'objet: " + req.subject + ".\nPar: " + str_docname(req.doctor_id) + ".\nLe patient: " + str_fullname(req.patient_id) + ".\n- Meryem Rkach", # From (Email) ## A variable that contain the ete mail ete_email, # To (Email) [ req.expert_id.email, ], # If the send fail do not affich any errors fail_silently=True) messages.success( request, 'La completion de la demande est effectuer avec succès.') return HttpResponseRedirect('/requests/detail/' + str(request_id)) # if the request is marked incomplete we should mark it seen if req.is_incomplete == True and req.is_doctor_visited == False: req.is_doctor_visited = True req.save() documents = Document.objects.filter(request_id=request_id) context = { 'documents': documents, 'req': req, # Get the summary of notifications via the fonction 'notifications': get_summary_notifs(request.user) } return render(request, 'exams/request.html', context)