Exemplo n.º 1
0
def edit_benefit_detail(request, patient_id, detail_id):
    if request.method == 'POST':
        patient = get_object_or_404(Patient, id=patient_id)
        if patient.social_work and patient.social_work.initial == 'APROSS':
            detail = DetailApross.objects.get(id=detail_id)
            detail_form = detailAprossForm(request.POST, instance=detail)
            template = 'register/monthly_detail/apross/details.html'
        else:
            detail = DetailBenefit.objects.get(id=detail_id)
            detail_form = detailBenefitForm(request.POST, instance=detail)
            template = 'register/monthly_detail/benefit/details.html'

        if detail_form.is_valid():
            detail = detail_form.save()
            if patient.social_work and patient.social_work.initial == 'APROSS':
                detail_form = detailAprossForm(instance=detail)
            else:
                detail_form = detailBenefitForm(instance=detail)
            return render_to_response(
                template,
                {
                    'counter': request.POST.get('counter'),
                    'detail': detail,
                    'bf': detail.benefit,
                    'patient': patient
                },
                RequestContext(request)
            )
        else:
            return JsonResponse({'status': 'ERROR', 'errors': detail_form.errors})
Exemplo n.º 2
0
def social_work(request, id):
    dentist = request.user.dentist
    patient = get_object_or_404(
        Patient, id=id,
        dentist=dentist
    )
    if request.method == 'GET':
        if patient.social_work and patient.social_work.initial == 'APROSS':
            benefits = Apross.objects.filter(patient=patient).order_by('-real_date')
            if benefits.exists():
                last_benefit = benefits.first()
            else:
                last_benefit = None
            benefit_form = AprossForm()
            detail_form = detailAprossForm()
        else:
            benefits = Benefit.objects.filter(patient=patient).order_by('-real_date')
            if benefits.exists():
                last_benefit = benefits.first()
            else:
                last_benefit = None
            benefit_form = BenefitForm()
            detail_form = detailBenefitForm()
        odontogram_form = OdontogramForm(instance=patient.odontogram)
        rec_added = request.GET.get('add', None)
        return render_to_response(
            'person/social_work.html',
            {
                'dentist': dentist,
                'patient': patient,
                'benefits': benefits,
                'last_benefit': last_benefit,
                'benefit_form': benefit_form,
                'detail_form': detail_form,
                'work_types': WORK_TYPES,
                'odontogram_form': odontogram_form,
                'rec_added': rec_added,
            },
            RequestContext(request)
        )
Exemplo n.º 3
0
def benefit_detail_form(detail_id):
    """Return a form of the given benefit detail"""
    detail = DetailBenefit.objects.get(id=detail_id)
    form = detailBenefitForm(instance=detail)
    return form