Ejemplo n.º 1
0
def add(request, patient_id):
    patient = get_object_or_404(Patient, pk=patient_id)
    if request.method == 'GET':
        form = AddAnalysisForm()
    else:
        post_data = request.POST.copy()
        post_data['patient'] = patient.id
        form = AddAnalysisForm(post_data)
        if form.is_valid():
            with transaction.commit_on_success():
                tests = Test.objects.filter(id__in=form.cleaned_data['tests'])
                labs = form.cleaned_data['labs']
                analysis = form.save()
                patient.analysis.add(analysis)
                infos =[]
                for i, test in enumerate(tests):
                    info = AnalysisTestInfo()
                    info.analysis = analysis
                    info.test = test
                    if labs[i]  != '0':
                        info.lab = OtherLabs.objects.get(pk=labs[i])
                        info.from_lab = True
                    infos.append(info)
                AnalysisTestInfo.objects.bulk_create(infos)
                Income.objects.create(analysis=analysis)

            return HttpResponseRedirect(reverse('list_analysis'))
    return render(request, 'add_edit_analysis.html', {'form':form,
        'patient_name':patient.name, 'tests':Test.objects.all(), 'labs':OtherLabs.objects.all()})
Ejemplo n.º 2
0
def add(request, patient_id):
    patient = get_object_or_404(Patient, pk=patient_id)
    if request.method == 'GET':
        form = AddAnalysisForm()
    else:
        post_data = request.POST.copy()
        post_data['patient'] = patient.id
        form = AddAnalysisForm(post_data)
        if form.is_valid():
            with transaction.commit_on_success():
                tests = Test.objects.filter(id__in=form.cleaned_data['tests'])
                labs = form.cleaned_data['labs']
                analysis = form.save()
                patient.analysis.add(analysis)
                infos = []
                for i, test in enumerate(tests):
                    info = AnalysisTestInfo()
                    info.analysis = analysis
                    info.test = test
                    if labs[i] != '0':
                        info.lab = OtherLabs.objects.get(pk=labs[i])
                        info.from_lab = True
                    infos.append(info)
                AnalysisTestInfo.objects.bulk_create(infos)
                Income.objects.create(analysis=analysis)

            return HttpResponseRedirect(reverse('list_analysis'))
    return render(
        request, 'add_edit_analysis.html', {
            'form': form,
            'patient_name': patient.name,
            'tests': Test.objects.all(),
            'labs': OtherLabs.objects.all()
        })
Ejemplo n.º 3
0
def edit(request, id=0):
    analysis = get_object_or_404(Analysis, pk=id)
    if request.method == 'GET':
        form = AddAnalysisForm(instance=analysis)
    else:
        old_cost = analysis.paid
        post_data = request.POST.copy()
        post_data['patient'] = analysis.patient.id
        form = AddAnalysisForm(post_data, instance=analysis)
        if form.is_valid():
            new_cost = post_data.get('paid')
            Income.objects.get(date=datetime.date.today()).update(income=new_cost-old_cost)
            form.save()
             
            return HttpResponseRedirect(reverse('list_analysis'))
    return render(request, 'add_edit_analysis.html', {'form':form, 'patient_name':analysis.patient.name})
Ejemplo n.º 4
0
def edit(request, id=0):
    analysis = get_object_or_404(Analysis, pk=id)
    if request.method == 'GET':
        form = AddAnalysisForm(instance=analysis)
    else:
        old_cost = analysis.paid
        post_data = request.POST.copy()
        post_data['patient'] = analysis.patient.id
        form = AddAnalysisForm(post_data, instance=analysis)
        if form.is_valid():
            new_cost = post_data.get('paid')
            Income.objects.get(date=datetime.date.today()).update(
                income=new_cost - old_cost)
            form.save()

            return HttpResponseRedirect(reverse('list_analysis'))
    return render(request, 'add_edit_analysis.html', {
        'form': form,
        'patient_name': analysis.patient.name
    })