예제 #1
0
def save_medical(request):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'add_medicalmodel'):
        m_form = PostMedical(request.POST)
        if m_form.is_valid():
            name = m_form.cleaned_data['name']
            effect = m_form.cleaned_data['effect']
            r = requests.post('http://127.0.0.1:8000/api/medical/',
                              data={
                                  'name': name,
                                  'effect': effect
                              })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('medical_list')
        else:
            # Added else statment
            msg = 'Errors: %s' % m_form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        m_form = PostMedical()

    context = {
        'selected_tab': 'medical',
        'permissions': utilities.get_user_permissions(request.user),
        'm_form': m_form
    }

    return render(
        request,
        utilities.get_template_name(request.user, 'add_medicalmodel',
                                    'create_medical_form.html'), context)
예제 #2
0
def update_physical(request, id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'change_physicalmodel'):
        form = PutPhysical(request.POST)
        #form = PutPhysical(request.POST,instance=request.physical)
        if form.is_valid():
            height = form.cleaned_data['height']
            weight = form.cleaned_data['weight']
            date = form.cleaned_data['date']
            user = form.cleaned_data['user']
            r = requests.put(
                'http://127.0.0.1:8000/api/physical/{}/'.format(id),
                data={
                    'height': height,
                    'weight': weight,
                    'date': date,
                    'user': user.id
                })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('physical_list')
        else:
            msg = 'Errors: %s' % form.errors.as_text()
            return HttpResponse(msg, status=400)
예제 #3
0
def update_medical_detail(request, hospital_record_id, id, medical_detail_id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'change_medicaldetailmodel'):
        md_form = PutMedicalDetail(request.POST)
        if md_form.is_valid():
            #medical = md_form.cleaned_data['medical']
            quantity = md_form.cleaned_data['quantity']
            time = md_form.cleaned_data['time']
            print("-----------" + str(quantity) + "----------" + str(time) +
                  "--------------" + str(medical_detail_id) + "---------" +
                  str(id))
            r = requests.put(
                'http://127.0.0.1:8000/api/medical-detail/get/{}/{}/'.format(
                    id, medical_detail_id),
                data={
                    'quantity': quantity,
                    'time': time,
                    'medical': medical_detail_id,
                    're_examination': id
                })
            print(str(r.status_code) + "aaaaaaaaaaaa")
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('medical_detail_list',
                                hospital_record_id=hospital_record_id,
                                id=id)
        else:
            msg = 'Errors: %s' % md_form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        msg = 'Method is not supported'
        return HttpResponse(msg, status=400)
예제 #4
0
def update_re_examination(request, hospital_record_id, id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'change_reexaminationmodel'):
        r_form = PutReExamination(request.POST)
        if r_form.is_valid():
            doctor = r_form.cleaned_data['doctor']
            result = r_form.cleaned_data['result']
            date = r_form.cleaned_data['date']
            appointment_date = r_form.cleaned_data['appointment_date']
            r = requests.put(
                'http://127.0.0.1:8000/api/re-examination/{}/'.format(id),
                data={
                    'doctor': doctor,
                    'result': result,
                    'date': date,
                    'appointment_date': appointment_date,
                    'hospital_record': hospital_record_id
                })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('re_examination_list',
                                hospital_record_id=hospital_record_id)
        else:
            msg = 'Errors: %s' % r_form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        msg = 'Method is not supported'
        return HttpResponse(msg, status=400)
예제 #5
0
def update_hospital_record(request, id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'change_hospitalrecordmodel'):
        h_form = PutHospitalRecord(request.POST)
        if h_form.is_valid():
            hospital = h_form.cleaned_data['hospital']
            disease = h_form.cleaned_data['disease']
            start_time = h_form.cleaned_data['start_time']
            status = h_form.cleaned_data['status']
            user = h_form.cleaned_data['user']
            r = requests.put(
                'http://127.0.0.1:8000/api/hospital-record/{}/'.format(id),
                data={
                    'hospital': hospital,
                    'disease': disease,
                    'start_time': start_time,
                    'status': status,
                    'user': user.id
                })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('hospital_record_list')
        else:
            # Added else statment
            msg = 'Errors: %s' % h_form.errors.as_text()
            return HttpResponse(msg, status=400)
예제 #6
0
def delete_medical(request, id):
    if utilities.is_permission_granted(request.user, 'delete_medicalmodel'):
        r = requests.delete('http://127.0.0.1:8000/api/medical/{}/'.format(id))

        if r.status_code == 200:
            messages.success(request, f'Delete successfully')
            data = r.json()
            print(data)

    return redirect('medical_list')
예제 #7
0
def delete_re_examination(request, hospital_record_id, id):
    if utilities.is_permission_granted(request.user,
                                       'delete_reexaminationmodel'):
        r = requests.delete(
            'http://127.0.0.1:8000/api/re-examination/{}/'.format(id))

        if r.status_code == 200:
            messages.success(request, f'Delete successfully')
            data = r.json()
            print(data)

    return redirect('re_examination_list',
                    hospital_record_id=hospital_record_id)
예제 #8
0
def save_re_examination(request, hospital_record_id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'add_reexaminationmodel'):
        r_form = PostReExamination(request.POST)
        if r_form.is_valid():
            #doctor = r_form.cleaned_data['doctor']
            doctor = request.user.username
            result = r_form.cleaned_data['result']
            date = r_form.cleaned_data['date']
            #appointment_date = r_form.cleaned_data['appointment_date']
            appointment_date = request.GET.get('appointment_date')
            r = requests.post(
                'http://127.0.0.1:8000/api/re-examination/hospital_record/{}/'.
                format(hospital_record_id),
                data={
                    'doctor': doctor,
                    'result': result,
                    'date': date,
                    'appointment_date': appointment_date,
                    'hospital_record': hospital_record_id
                })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('re_examination_list',
                                hospital_record_id=hospital_record_id)
        else:
            # Added else statment
            msg = 'Errors: %s' % r_form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        print("----------------------------")
        r_form = PostReExamination()

    context = {
        'selected_tab': 'hospital_record',
        'permissions': utilities.get_user_permissions(request.user),
        'hospital_record_id': hospital_record_id,
        'r_form': r_form
    }

    return render(
        request,
        utilities.get_template_name(request.user, 'add_reexaminationmodel',
                                    'create_re_examination_form.html'),
        context)
예제 #9
0
def save_medical_detail(request, hospital_record_id, id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'change_medicaldetailmodel'):
        md_form = PostMedicalDetail(request.POST)
        if md_form.is_valid():
            medical = md_form.cleaned_data['medical']
            quantity = md_form.cleaned_data['quantity']
            time = md_form.cleaned_data['time']
            dates = md_form.cleaned_data['dates']
            r = requests.post(
                'http://127.0.0.1:8000/api/medical-detail/post/{}/'.format(id),
                data={
                    'medical': medical.id,
                    'quantity': quantity,
                    'time': time,
                    'dates': dates,
                    're_examination': id
                })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('medical_detail_list',
                                hospital_record_id=hospital_record_id,
                                id=id)
        else:
            msg = 'Errors: %s' % md_form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        md_form = PostMedicalDetail()

    context = {
        'selected_tab': 'hospital_record',
        'permissions': utilities.get_user_permissions(request.user),
        're_examination': id,
        'md_form': md_form
    }

    return render(
        request,
        utilities.get_template_name(request.user, 'add_medicaldetailmodel',
                                    'create_medical_detail_form.html'),
        context)
예제 #10
0
def update_medical(request, id):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'change_medicalmodel'):
        m_form = PutMedical(request.POST)
        if m_form.is_valid():
            name = m_form.cleaned_data['name']
            effect = m_form.cleaned_data['effect']
            r = requests.put(
                'http://127.0.0.1:8000/api/medical/{}/'.format(id),
                data={
                    'name': name,
                    'effect': effect
                })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('medical_list')
        else:
            # Added else statment
            msg = 'Errors: %s' % m_form.errors.as_text()
            return HttpResponse(msg, status=400)
예제 #11
0
def save_physical(request):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'add_physicalmodel'):
        form = PostPhysical(request.POST)
        if form.is_valid():
            height = form.cleaned_data['height']
            weight = form.cleaned_data['weight']
            date = form.cleaned_data['date']
            user = form.cleaned_data['user']
            r = requests.post('http://127.0.0.1:8000/api/physical/',
                              data={
                                  'height': height,
                                  'weight': weight,
                                  'date': date,
                                  'user': user.id
                              })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('physical_list')
            else:
                msg = r.json()
                return HttpResponse(msg)
        else:
            # Added else statement
            msg = 'Errors: %s' % form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        form = PostPhysical()

    context = {
        'selected_tab': 'physical',
        'permissions': utilities.get_user_permissions(request.user),
        'form': form
    }

    return render(
        request,
        utilities.get_template_name(request.user, 'add_physicalmodel',
                                    'create_form.html'), context)
예제 #12
0
def save_hospital_record(request):
    if request.method == "POST" and utilities.is_permission_granted(
            request.user, 'add_hospitalrecordmodel'):
        h_form = PostHospitalRecord(request.POST)
        if h_form.is_valid():
            hospital = h_form.cleaned_data['hospital']
            disease = h_form.cleaned_data['disease']
            start_time = h_form.cleaned_data['start_time']
            status = h_form.cleaned_data['status']
            user = h_form.cleaned_data['user']
            r = requests.post('http://127.0.0.1:8000/api/hospital-record/',
                              data={
                                  'hospital': hospital,
                                  'disease': disease,
                                  'start_time': start_time,
                                  'status': status,
                                  'user': user.id
                              })
            if r.status_code == 200 or 201:
                data = r.json()
                print(data)
                return redirect('hospital_record_list')
        else:
            # Added else statment
            msg = 'Errors: %s' % h_form.errors.as_text()
            return HttpResponse(msg, status=400)
    else:
        h_form = PostHospitalRecord()

    context = {
        'selected_tab': 'hospital_record',
        'permissions': utilities.get_user_permissions(request.user),
        'h_form': h_form
    }

    return render(
        request,
        utilities.get_template_name(request.user, 'add_hospitalrecordmodel',
                                    'create_hospital_record_form.html'),
        context)