コード例 #1
0
def edit_treatment(request, code):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if auth_user['role'] != 'admin':
        error(request, "You don't have permissions for this module")
        return redirect('/')
    if request.method == 'GET':
        treatment = Treatments.find_treatment(code)
        if treatment is None:
            error(request, "This treatment does not exist")
            return redirect('treatments')
        return render(request, 'treatments/edit.html', {
            'auth_user': auth_user,
            'treatment': treatment
        })
    else:
        name = request.POST['name']
        price = request.POST['price']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('edit_treatment', code=code)
        result = Treatments.edit_treatment(code, name, price)
        if result is not True:
            error(request, result)
            return redirect('edit_treatment', code=code)
        response = redirect('treatments')
        success(request, "Treatment updated successfully")
        return response
コード例 #2
0
def signup(request):
    if request.method == 'GET':
        return render(request, 'auth/signup.html')
    else:
        name = request.POST['name']  # "Alexander Gonzalez"
        email = request.POST['email']  # "*****@*****.**"
        phone = request.POST['phone']  # "04128418822"
        role = request.POST['role']  # "admin"
        username = request.POST['username']  # "alex"
        password = request.POST['password']  # "123456"
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return render(
                request, 'auth/signup.html', {
                    'name': name,
                    'email': email,
                    'phone': phone,
                    'role': role,
                    'username': username
                })
        result = Users.add_user(name, email, phone, role, username, password)
        if result is not True:
            error(request, result)
            return render(
                request, 'auth/signup.html', {
                    'name': name,
                    'email': email,
                    'phone': phone,
                    'role': role,
                    'username': username
                })
        success(request, "Registered successfully")
        response = redirect('login')
        return response
コード例 #3
0
ファイル: views.py プロジェクト: acknowledgeHim/dental-admin
def edit_patient(request, dni):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if request.method == 'GET':
        patient = Patients.find_patient(dni)
        if patient is None:
            error(request, "This patient does not exist")
            return redirect('patients')
        return render(request, 'patients/edit.html', {
            'auth_user': auth_user,
            'patient': patient
        })
    else:
        name = request.POST['name']
        date_of_birth = request.POST['date_of_birth']
        email = request.POST['email']
        phone = request.POST['phone']
        address = request.POST['address']
        visit_reason = request.POST['visit_reason']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('edit_patient', dni=dni)
        result = Patients.edit_patient(dni, name, date_of_birth, email, phone,
                                       address, visit_reason)
        if result is not True:
            error(request, result)
            return redirect('edit_patient', dni=dni)
        response = redirect('patients')
        success(request, "Patient updated successfully")
        return response
コード例 #4
0
ファイル: views.py プロジェクト: acknowledgeHim/dental-admin
def check_patient(request, dni):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if request.method == 'GET':
        patient = Patients.find_patient(dni)
        diagnostics = Patients.find_diagnostics(dni)
        if patient is None:
            error(request, "This patient does not exist")
            return redirect('patients')
        return render(request, 'patients/check.html', {
            'auth_user': auth_user,
            'patient': patient,
            'diagnostics': diagnostics
        })
    else:
        notes = request.POST['notes']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('check_patient', dni=dni)
        result = Patients.edit_patient_notes(dni, notes)
        if result is not True:
            error(request, result)
        else:
            success(request, "Patient updated successfully")
        return redirect('check_patient', dni=dni)
コード例 #5
0
ファイル: views.py プロジェクト: acknowledgeHim/dental-admin
def create_patient(request):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if request.method == 'GET':
        return render(request, 'patients/create.html',
                      {'auth_user': auth_user})
    else:
        dni = request.POST['dni']
        name = request.POST['name']
        date_of_birth = request.POST['date_of_birth']
        email = request.POST['email']
        phone = request.POST['phone']
        address = request.POST['address']
        visit_reason = request.POST['visit_reason']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return render(
                request, 'patients/create.html', {
                    'auth_user': auth_user,
                    'dni': dni,
                    'name': name,
                    'date_of_birth': date_of_birth,
                    'email': email,
                    'phone': phone,
                    'address': address,
                    'visit_reason': visit_reason
                })
        result = Patients.add_patient(dni, name, date_of_birth, email, phone,
                                      address, visit_reason)
        if result is not True:
            error(request, result)
            return render(
                request, 'patients/create.html', {
                    'auth_user': auth_user,
                    'dni': dni,
                    'name': name,
                    'date_of_birth': date_of_birth,
                    'email': email,
                    'phone': phone,
                    'address': address,
                    'visit_reason': visit_reason
                })
        success(request, "Patient registered successfully")
        response = redirect('patients')
        return response
コード例 #6
0
def process_sequence(request, code):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if request.method == 'GET':
        sequence = Sequences.find_sequence(code)
        sequence_treatments = Sequences.find_sequence_treatments(code)
        patient_diagnostics = Patients.find_diagnostics(
            sequence['patient'])  # Combo data
        clinic_treatments = Treatments.list_treatments()  # Combo data
        if sequence is None:
            error(request, "This sequence does not exist")
            return redirect('sequences')
        return render(
            request, 'sequences/process.html', {
                'auth_user': auth_user,
                'sequence': sequence,
                'patient_diagnostics': patient_diagnostics,
                'clinic_treatments': clinic_treatments,
                'sequence_treatments': sequence_treatments
            })
    else:
        patient_dni = request.POST['patient_dni']
        status = 1
        diagnostic_code = request.POST['diagnostic_code']
        treatment_code = request.POST['treatment_code']
        treatment_quantity = request.POST['treatment_quantity']
        treatment_price = Treatments.get_treatment_by_code(
            treatment_code)['price']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('process_sequence', code=code)
        result = Sequences.process_sequence(code, diagnostic_code,
                                            treatment_code, treatment_price,
                                            treatment_quantity)
        if result is not True:
            error(request, result)
        else:
            Patients.edit_diagnostic(patient_dni, diagnostic_code, status)
            success(request, "Treatment sequence updated successfully")
        return redirect('process_sequence', code=code)
コード例 #7
0
def delete_sequence_treatment(request, code, code2):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if request.method == 'POST':
        subtotal = request.POST['subtotal']
        patient_dni = request.POST['patient_dni']
        status = 0
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('process_sequence', code=code)
        result = Sequences.delete_sequence_treatment(code, code2, subtotal)
        if result is not True:
            error(request, result)
        else:
            Patients.edit_diagnostic(patient_dni, code2, status)
            success(request, "Treatment deleted successfully")
        return redirect('process_sequence', code=code)
コード例 #8
0
ファイル: views.py プロジェクト: acknowledgeHim/dental-admin
def create_diagnostic(request, dni):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if request.method == 'POST':
        date = request.POST['date']
        doctor = request.POST['doctor']
        tooths = request.POST['tooths']
        diagnostic = request.POST['diagnostic']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('check_patient', dni=dni)
        result = Patients.add_diagnostic(dni, date, doctor, tooths, diagnostic)
        if result is not True:
            error(request, result)
        else:
            success(request, "Patient updated successfully")
        return redirect('check_patient', dni=dni)
コード例 #9
0
ファイル: views.py プロジェクト: acknowledgeHim/dental-admin
def edit_user(request, username):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if auth_user['role'] != 'admin':
        error(request, "You don't have permissions for this module")
        return redirect('/')
    if request.method == 'GET':
        user = Users.find_user(username)
        if user is None:
            error(request, "This user does not exist")
            return redirect('users')
        return render(request, 'users/edit.html', {
            'auth_user': auth_user,
            'user': user
        })
    else:
        name = request.POST['name']
        email = request.POST['email']
        phone = request.POST['phone']
        role = request.POST['role']
        pic = None
        if 'file' in request.FILES:
            pic = upload_file_verification(request.FILES['file'], username)
            if pic is False:
                error(request, "The image format must be jpg, png or bmp")
                return redirect('edit_user', username=username)
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return redirect('edit_user', username=username)
        result = Users.edit_user(username, name, email, phone, role, pic)
        if result is not True:
            error(request, result)
            return redirect('edit_user', username=username)
        if pic is not None:
            upload_file(pic, request.FILES['file'])
        response = redirect('users')
        success(request, "User updated successfully")
        return response
コード例 #10
0
def create_treatment(request):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if auth_user['role'] != 'admin':
        error(request, "You don't have permissions for this module")
        return redirect('/')
    if request.method == 'GET':
        return render(request, 'treatments/create.html',
                      {'auth_user': auth_user})
    else:
        code = request.POST['code']
        name = request.POST['name']
        price = request.POST['price']
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return render(request, 'treatments/create.html', {
                'auth_user': auth_user,
                'code': code,
                'name': name,
                'price': price
            })
        result = Treatments.add_treatment(code, name, price)
        if result is not True:
            error(request, result)
            return render(request, 'treatments/create.html', {
                'auth_user': auth_user,
                'code': code,
                'name': name,
                'price': price
            })
        success(request, "Treatment registered successfully")
        response = redirect('treatments')
        return response
コード例 #11
0
ファイル: views.py プロジェクト: acknowledgeHim/dental-admin
def create_user(request):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    if auth_user['role'] != 'admin':
        error(request, "You don't have permissions for this module")
        return redirect('/')
    if request.method == 'GET':
        return render(request, 'users/create.html', {'auth_user': auth_user})
    else:
        name = request.POST['name']
        email = request.POST['email']
        phone = request.POST['phone']
        role = request.POST['role']
        username = request.POST['username']
        password = request.POST['password']
        pic = None
        if 'file' in request.FILES:
            pic = upload_file_verification(request.FILES['file'], username)
            if pic is False:
                error(request, "The image format must be jpg, png or bmp")
                return render(
                    request, 'users/create.html', {
                        'auth_user': auth_user,
                        'name': name,
                        'email': email,
                        'phone': phone,
                        'role': role,
                        'username': username
                    })
        form = validate_form(request.POST)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return render(
                request, 'users/create.html', {
                    'auth_user': auth_user,
                    'name': name,
                    'email': email,
                    'phone': phone,
                    'role': role,
                    'username': username
                })
        result = Users.add_user(name, email, phone, role, username, password,
                                pic)
        if result is not True:
            error(request, result)
            return render(
                request, 'users/create.html', {
                    'auth_user': auth_user,
                    'name': name,
                    'email': email,
                    'phone': phone,
                    'role': role,
                    'username': username
                })
        if pic is not None:
            upload_file(pic, request.FILES['file'])
        success(request, "User registered successfully")
        response = redirect('users')
        return response
コード例 #12
0
def create_sequence(request):
    auth_user = Sessions.validate_auth(request)
    if auth_user is None:
        error(request, "You must log in first")
        return redirect('login')
    doctors = Users.list_users('doctor')  # Combo data
    patients = Patients.list_patients()  # Combo data
    if request.method == 'GET':
        return render(request, 'sequences/create.html', {
            'auth_user': auth_user,
            'doctors': doctors,
            'patients': patients
        })
    else:
        date = request.POST['date']
        shift = request.POST['shift']
        doctor_username = request.POST['doctor_username']
        patient_dni = request.POST['patient_dni']
        form = validate_form(request.POST)
        # From check patient
        if 'direct_appointment' in request.POST:
            code = Sequences.add_sequence_from_patient(date, shift,
                                                       doctor_username,
                                                       patient_dni)
            if code is False:
                error(
                    request,
                    "There was a problem creating the direct treatment sequence"
                )
                return redirect('check_patient', dni=patient_dni)
            success(request, "Treatment sequence created successfully")
            return redirect('process_sequence', code=code)
        if form is not True:
            error(request, "There is a problem with your info, please check")
            return render(
                request, 'sequences/create.html', {
                    'auth_user': auth_user,
                    'doctors': doctors,
                    'patients': patients,
                    'date': date,
                    'shift': shift,
                    'doctor_username': doctor_username,
                    'patient_dni': patient_dni
                })
        result = Sequences.add_sequence(date, shift, doctor_username,
                                        patient_dni)
        if result is not True:
            error(request, result)
            return render(
                request, 'sequences/create.html', {
                    'auth_user': auth_user,
                    'doctors': doctors,
                    'patients': patients,
                    'date': date,
                    'shift': shift,
                    'doctor_username': doctor_username,
                    'patient_dni': patient_dni
                })
        success(request, "Treatment sequence registered successfully")
        response = redirect('sequences')
        return response