Exemplo n.º 1
0
def create_doctor(request):
    if request.method == 'POST':
        user_form = UserRegisterForm(request.POST)
        doctor_form = DoctorRegisterForm(request.POST)
        if user_form.is_valid() and doctor_form.is_valid():
            address, key = blockchain.create_account()
            txn_hash = blockchain.send_ether(address)
            user = user_form.save(commit=False)
            user.is_doctor = True
            doctor = doctor_form.save(commit=False)
            doctor.email = user
            doctor.address = address
            doctor.privatekey = key
            user.save()
            doctor.save()
            blockchain.is_mined(txn_hash)
            doctor_account = blockchain.load_account(key)
            tx = contracts.addDoctor(doctor_account, doctor.aadhaar_no)
            blockchain.is_mined(tx)
            login(request, user)

            return redirect('doctor_dashboard')
    else:
        user_form = UserRegisterForm()
        doctor_form = DoctorRegisterForm()
    return render(request, 'doctor/register.html', {
        'user_form': user_form,
        'doctor_form': doctor_form
    })
Exemplo n.º 2
0
def create_patient(request):
    if request.method == 'POST':
        user_form = UserRegisterForm(request.POST)
        patient_form = PatientRegisterForm(request.POST)
        if user_form.is_valid() and patient_form.is_valid():
            address, key = blockchain.create_account()
            txn_hash = blockchain.send_ether(address)
            user = user_form.save(commit=False)
            user.is_patient = True
            patient = patient_form.save(commit=False)
            patient.email = user
            patient.address = address
            patient.privatekey = key
            user.save()
            patient.save()
            Basic.objects.create(email=user)
            blockchain.is_mined(txn_hash)
            patient_account = blockchain.load_account(key)
            tx = contracts.addPatient(patient_account, patient.aadhaar_no)
            blockchain.is_mined(tx)
            login(request, user)

            return redirect('basic')
    else:
        user_form = UserRegisterForm()
        patient_form = PatientRegisterForm()
    return render(request, 'patient/register.html', {
        'user_form': user_form,
        'patient_form': patient_form
    })
Exemplo n.º 3
0
def revoke_access(request):
    if request.method == "POST":
        patient = Patient.objects.filter(email=request.user).values()[0]
        patient_account = blockchain.load_account(patient['privatekey'])
        doctor_address = Doctor.objects.filter(
            email=request.POST['email_id']).values()[0]['address']
        txn_hash = contracts.revokeAccess(doctor_address, patient_account)
        blockchain.is_mined(txn_hash)
        return redirect('patient_dashboard')
Exemplo n.º 4
0
def upload_report(request):
    if request.method == 'POST':
        user = request.user
        report = request.FILES['file']
        patient = Patient.objects.filter(email=user).values()[0]
        patient_account = blockchain.load_account(patient['privatekey'])
        file_hash = files.upload_file(report)
        txn_hash = contracts.addReport(request.POST['file_name'], file_hash,
                                       patient_account)
        blockchain.is_mined(txn_hash)
        return redirect('patient_dashboard')
    return render(request, 'patient/upload_report.html')