示例#1
0
def relationships_update(request, pk):
    patient = None
    doctor = None
    if request.user.is_patient:
        patient = request.user.patient
    elif request.user.is_doctor:
        doctor = request.user.doctor
    else:
        return JsonResponse(status=403, data='Only for doctors and patients')
    if doctor:
        relationships = get_object_or_404(Relationships, pk=pk, doctor=doctor)
        doctor_accept = request.POST.get('doctor_accept')
        if not doctor_accept:
            raise Http404('no doctor_accept param')
        doctor_accept = json.loads(doctor_accept)
        add_message(
            message=
            f"<a href='{doctor.get_absolute_url()}'>{doctor.user.username}</a>  has {'added' if doctor_accept else 'removed'} you from his contacts",
            owner=relationships.patient.user)
        relationships.doctor_accept = doctor_accept
    else:
        relationships = get_object_or_404(Relationships,
                                          pk=pk,
                                          patient=patient)
        patient_accept = request.POST.get('patient_accept')
        if not patient_accept:
            raise Http404('no patient_accept param')
        patient_accept = json.loads(patient_accept)
        add_message(
            message=
            f"<a href='{patient.get_absolute_url()}'>{patient.user.username}</a>  has {'added' if patient_accept else 'removed'} you from his contacts",
            owner=relationships.doctor.user)
        relationships.patient_accept = patient_accept
    relationships.save()
    return JsonResponse(data=model_to_dict(relationships))
示例#2
0
def doctor_create_update_decease(request, pk=None):
    d = get_object_or_404(PatientDecease, pk=pk) if pk else None
    form = PatientDeceaseForm(request.POST,
                              instance=d,
                              auto_id=str(pk) + '_%s')

    if form.is_valid():
        decease = form.save(commit=False)
        doctor = request.user.doctor

        if not has_relationships(doctor.id, decease.patient.id):
            return HttpResponseForbidden(
                'No relation ship between doctor and user')

        decease.author = request.user
        decease.decease = Decease.objects.get(
            name=form.cleaned_data['decease'])
        decease.save()

        add_message(
            message=
            f"<a href='{doctor.get_absolute_url()}'>{doctor.user.username}</a> has {'updated' if pk else 'created'} a new diagnos",
            owner=decease.patient.user)
        return HttpResponse('')
    return render_to_response(
        'deceases/_doctor_create_update_patient_decease_form.html', {
            'decease_form': form,
            'pk': pk
        })
示例#3
0
def visit_create(request):
    patient = request.user.patient
    data = deepcopy(request.POST)
    data['patient'] = patient.id
    form = VisitForm(data)
    if form.is_valid():
        visit = form.save()
        add_message(
            message=
            f"<a href='{request.user.get_absolute_url()}'>{request.user.username}</a> has created a visit on date {visit.shift.day} at time {visit.start}-{visit.end}",
            owner=visit.shift.shift_type.doctor.user,
            important=True)
        return JsonResponse({'success': True, 'visit_id': visit.id})
    return JsonResponse({'errors': form.errors, 'success': False})
示例#4
0
def review_delete(request):
    pk = request.POST.get('review_id')
    if not pk:
        raise Http404('no review_id')
    review = get_object_or_404(Review, pk=pk)
    if not review.patient == request.user.patient:
        return HttpResponseForbidden('The user is not the owner of the review')
    review.delete()
    patient = request.user.patient
    add_message(
        message=
        f"<a href='{patient.get_absolute_url()}'>{patient.user.username}</a> has removed his review",
        owner=review.doctor_sphere.doctor.user)
    return HttpResponse('')
示例#5
0
def visit_remove(request, pk):
    visit = get_object_or_404(Visit, pk=pk)
    if request.user.is_patient:
        if visit.patient.id != request.user.patient.id:
            return HttpResponseForbidden("You are not the creator")
    elif request.user.is_doctor:
        if visit.shift.shift_type.doctor.id != request.user.doctor.id:
            return HttpResponseForbidden("This isn't your visit")
    else:
        return HttpResponseForbidden("You are not either doctor or patient")
    visit.delete()
    add_message(
        message=
        f"<a href='{request.user.get_absolute_url()}'>{request.user.username}</a> has removed a visit on date {visit.shift.day} at time {visit.start}-{visit.end}",
        owner=visit.shift.shift_type.doctor.user
        if request.user.is_patient else visit.patient.user,
        important=True)
    return JsonResponse({'success': True})
示例#6
0
def review_create_update(request, doctor_sphere_id, pk=None):
    doctor_sphere = get_object_or_404(DoctorSphere, pk=doctor_sphere_id)
    patient = request.user.patient
    if not Relationships.objects.filter(patient=patient,
                                        doctor=doctor_sphere.doctor).exists():
        return HttpResponseForbidden(
            'No relation ship between the doctor and the user')
    instance = Review.objects.get(pk=pk) if pk else None
    review_form = ReviewForm(request.POST, instance=instance)
    if review_form.is_valid():
        review = review_form.save(commit=False)
        review.patient = request.user.patient
        review.doctor_sphere = doctor_sphere
        review.save()
        add_message(
            message=
            f"<a href='{patient.get_absolute_url()}'>{patient.user.username}</a>  has {'updated' if pk else 'created'} his review",
            owner=doctor_sphere.doctor.user)
        return HttpResponse('')
    return render_to_response('accounts/_review_create_update_form.html', {
        'pk': pk,
        'review_form': review_form,
        'doctor_sphere_id': doctor_sphere_id
    })