Пример #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
    })
Пример #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
    })
Пример #3
0
def dashboard(request):
    doctor = Doctor.objects.filter(email=request.user).values()[0]
    doctor_account = blockchain.load_account(doctor['privatekey'])
    doctorInfo = contracts.doctorInfo(doctor_account)
    patient_access = len(doctorInfo[1])
    return render(request, 'doctor/dashboard.html', {
        'patient_access': patient_access,
        'doctor': doctor
    })
Пример #4
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')
Пример #5
0
def view_reports(request):
    user = request.user
    patient = Patient.objects.filter(email=user).values()[0]
    patient_account = blockchain.load_account(patient['privatekey'])
    report = contracts.viewReport(patient_account)
    for i in range(len(report)):
        report[i] = list(report[i])
        report[i][0] = (datetime.datetime.fromtimestamp(
            int(report[i][0]),
            tz.gettz('Asia/Kolkata')).strftime('%d/%m/%Y %I:%M %p'))
    return render(request, 'patient/view_report.html', {'report': report})
Пример #6
0
def revoke_doctor(request):
    user = request.user
    patient = Patient.objects.filter(email=user).values()[0]
    patient_account = blockchain.load_account(patient['privatekey'])
    patientInfo = contracts.patientInfo(patient_account)
    doctor_address = patientInfo[2]
    doctors = []
    for i in doctor_address:
        doc = Doctor.objects.filter(address=i).values()[0]
        doctors.append(doc)
    return render(request, 'patient/revoke_doctor.html', {'doctors': doctors})
Пример #7
0
def patient_reports(request):
    doctor = Doctor.objects.filter(email=request.user).values()[0]
    doctor_account = blockchain.load_account(doctor['privatekey'])
    doctorInfo = contracts.doctorInfo(doctor_account)
    patients = []
    report = []
    for i in doctorInfo[1]:
        patients.append(Patient.objects.filter(address=i).values()[0])
    return render(request, 'doctor/patient_reports.html', {
        'patients': patients,
        'report': report
    })
Пример #8
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')
Пример #9
0
def view_patients(request):
    doctor = Doctor.objects.filter(email=request.user).values()[0]
    doctor_account = blockchain.load_account(doctor['privatekey'])
    doctorInfo = contracts.doctorInfo(doctor_account)
    patients = []
    basicinfo = []
    for i in doctorInfo[1]:
        patient = Patient.objects.filter(address=i).values()[0]
        patients.append(patient)
        basicinfo.append(
            Basic.objects.filter(email=patient['email_id']).values()[0])
    return render(request, 'doctor/view_patients.html',
                  {'data': zip(patients, basicinfo)})
Пример #10
0
def dashboard(request):
    user = request.user
    patient = Patient.objects.filter(email=user).values()[0]
    basic_data = Basic.objects.filter(email=user).values()[0]
    patient_account = blockchain.load_account(patient['privatekey'])
    patientInfo = contracts.patientInfo(patient_account)

    totalreports = len(patientInfo[1])
    doctor_access = len(patientInfo[2])

    blockchain.check_for_sufficient_balance(patient_account.address)
    return render(
        request, 'patient/dashboard.html', {
            'totalreports': totalreports,
            'doctor_access': doctor_access,
            'basic_data': basic_data,
            'patient': patient
        })
Пример #11
0
def show_reports(request):
    patient = Patient.objects.filter(email=request.POST['patient']).values()[0]
    doctor = Doctor.objects.filter(email=request.user).values()[0]
    doctor_account = blockchain.load_account(doctor['privatekey'])
    doctorInfo = contracts.doctorInfo(doctor_account)
    report = contracts.viewPatientReport(patient['address'], doctor_account)
    patients = []
    val = patient['email_id']
    for i in doctorInfo[1]:
        patients.append(Patient.objects.filter(address=i).values()[0])
    for i in range(len(report)):
        report[i] = list(report[i])
        report[i][0] = (datetime.datetime.fromtimestamp(
            int(report[i][0]),
            tz.gettz('Asia/Kolkata')).strftime('%d/%m/%Y %I:%M %p'))
    basicinfo = Basic.objects.filter(email=request.POST['patient']).values()[0]
    return render(request, 'doctor/patient_reports.html', {
        'patients': patients,
        'report': report,
        'val': val,
        'basicinfo': basicinfo
    })