from django.shortcuts import render
from django.template import loader
from django.http import HttpResponse
from django.shortcuts import render, redirect
from .models import Patient
from django.contrib import messages
import pandas as pd
from django.contrib.auth.decorators import login_required
from web3 import Web3
import datetime
import hashlib
import json

def encrypt_string(hash_string):
    sha_signature = \
        hashlib.sha256(hash_string.encode()).hexdigest()
    return sha_signature

@login_required()
def index(request):
    context = {}
    template = loader.get_template('index.html')
    return HttpResponse(template.render(context, request))



@login_required()
def patient_form(request):

    dt = pd.read_csv('contact/static/info/countries.txt', sep='\n')
    countries = []
    df = dt.to_dict() 
    for k, country in df.items():
        for k,v in country.items():
            countries.append(v)
    return render(request, 'patient_form.html', {'countries': countries})


@login_required()
def add_patients(request):

    ganache_url = 'http://127.0.0.1:7545'


    web3 = Web3(Web3.HTTPProvider(ganache_url))

    abi = json.loads('[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]')

    address = "0xa84580e93474b942b48B16CAEeaA1920962CBd90"

    contract = web3.eth.contract(address = address, abi = abi)

    print(contract)

    if request.method == 'GET':

        precord = Patient()
        
        precord.name = request.GET.get("name")
        precord.surname = request.GET.get("surname")
        precord.address = request.GET.get("address")
        precord.email = request.GET.get("email")
        precord.city = request.GET.get("city")
        precord.region = request.GET.get("region")
        precord.postal = request.GET.get("postal")
        precord.country = request.GET.get("country")
        precord.phone = request.GET.get("phone")
        precord.status = request.GET.get("status")
        precord.notes = request.GET.get("notes", None)
        precord.created_at = request.GET.get("bdate")
        precord.user = request.user
        

        name_surname = precord.name+"_"+precord.surname
        precord.hashing = encrypt_string(name_surname)
        country = precord.country
        postal = precord.postal
        status = int(precord.status)
        
        
        result = contract.functions.addPatient(status, postal, str(precord.user), encrypt_string(name_surname), country).transact({'from':'0xF49D6960fb886B6ACD1Aca017f6306134a795457'})
        num = contract.functions.getPatientsCount().call()
        print(num)

        precord.save()

        
        

        
        
        messages.success(request, 'Record Saved')

        return render(request, 'index.html')
    else:
        return render(request, 'index.html')

@login_required()
def patients_list(request):

    patients = Patient.objects.all()  
    

    return render(request, 'patient_list.html', {'patients':patients})


@login_required
def delete_patient(request, uid):  

    ganache_url = 'http://127.0.0.1:7545'

    

    web3 = Web3(Web3.HTTPProvider(ganache_url))

    abi = json.loads('[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]')
    

    address = "0xa84580e93474b942b48B16CAEeaA1920962CBd90"

    contract = web3.eth.contract(address = address, abi = abi)

    patient = Patient.objects.get(uid=uid)  
    patient.status = request.GET.get("status") 
    patient.notes = request.GET.get("notes", None)
    patient.created_at = request.GET.get("bdate")


    hashing = patient.hashing
    country = patient.country
    postal = patient.postal
    status = int(patient.status)
    

    
    result = contract.functions.addPatient(status, postal, 'deleted', str(hashing), country).transact({'from':'0xF49D6960fb886B6ACD1Aca017f6306134a795457'})
    patient.delete() 

    return redirect("http://127.0.0.1:8000/patients-list")  
    

@login_required
def update_patient_status(request, uid):  

    ganache_url = 'http://127.0.0.1:7545'

    web3 = Web3(Web3.HTTPProvider(ganache_url))

    abi = json.loads('[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]')
    

    address = "0xa84580e93474b942b48B16CAEeaA1920962CBd90"

    contract = web3.eth.contract(address = address, abi = abi)

    if request.method == 'GET':
     
        patient = Patient.objects.get(uid=uid) 
        patient.status = request.GET.get("status") 
        patient.notes = request.GET.get("notes", None)
        patient.created_at = request.GET.get("bdate")


        hashing = patient.hashing
        print(patient)
        country = patient.country
        postal = patient.postal
        status = int(patient.status)

        result = contract.functions.addPatient(status, postal, str(patient.user), str(patient.hashing), country).transact({'from':'0xF49D6960fb886B6ACD1Aca017f6306134a795457'})

        patient.save()

        return redirect("http://127.0.0.1:8000/patients-list")  
    
    return redirect("http://127.0.0.1:8000/patients-list")

   
@login_required
def edit(request, uid):  
    patient = Patient.objects.get(uid=uid)  
    return render(request,'edit.html', {'patient':patient})  


def users(request):  

    dt = pd.read_csv('countries.txt', sep='\n')
    countries = []
    df = dt.to_dict() 
    for k, country in df.items():
        for k,v in country.items():
            countries.append(v)
    
    return render(request,'users.html', {'countries':countries})  


def search_results(request):

    dt = pd.read_csv('countries.txt', sep='\n')
    countries = []
    df = dt.to_dict() 
    for k, country in df.items():
        for k,v in country.items():
            countries.append(v)

    ganache_url = 'http://127.0.0.1:7545'


    web3 = Web3(Web3.HTTPProvider(ganache_url))

    abi = json.loads('[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]')
    
    address = "0xa84580e93474b942b48B16CAEeaA1920962CBd90"

    contract = web3.eth.contract(address = address, abi = abi)


    no_patients = contract.functions.getPatientsCount().call()
    
    lpatient = []
    lhash = []
    message = 'No infected people'
    if request.method == 'GET':
    
        region = request.GET.get("city")
        postal = request.GET.get("postal")
        country = request.GET.get("country")

    counter = 0
    for i in range(0, no_patients):
        patients = contract.functions.gettPatient(i).call()
        lpatient = list(patients)
        print(lpatient)
        if lpatient[0] == 0 and lpatient[1] == postal and lpatient[4] == country:
            if lpatient[3] not in lhash and lpatient[2] != 'daleted':
                lhash.append(lpatient[3])
                counter = counter + 1
            message = 'Infected people in your area are'

    
        return render(request,'infected.html', {'countries':countries, 'infected_people': counter, 'message': message})  


[((19, 1, 19, 17), 'django.contrib.auth.decorators.login_required', 'login_required', ({}, {}), '()', False, 'from django.contrib.auth.decorators import login_required\n'), ((27, 1, 27, 17), 'django.contrib.auth.decorators.login_required', 'login_required', ({}, {}), '()', False, 'from django.contrib.auth.decorators import login_required\n'), ((39, 1, 39, 17), 'django.contrib.auth.decorators.login_required', 'login_required', ({}, {}), '()', False, 'from django.contrib.auth.decorators import login_required\n'), ((98, 1, 98, 17), 'django.contrib.auth.decorators.login_required', 'login_required', ({}, {}), '()', False, 'from django.contrib.auth.decorators import login_required\n'), ((22, 15, 22, 48), 'django.template.loader.get_template', 'loader.get_template', ({(22, 35, 22, 47): '"""index.html"""'}, {}), "('index.html')", False, 'from django.template import loader\n'), ((30, 9, 30, 67), 'pandas.read_csv', 'pd.read_csv', (), '', True, 'import pandas as pd\n'), ((36, 11, 36, 73), 'django.shortcuts.render', 'render', ({(36, 18, 36, 25): 'request', (36, 27, 36, 46): '"""patient_form.html"""', (36, 48, 36, 72): "{'countries': countries}"}, {}), "(request, 'patient_form.html', {'countries': countries})", False, 'from django.shortcuts import render, redirect\n'), ((47, 10, 47, 1731), 'json.loads', 'json.loads', ({(47, 21, 47, 1730): '"""[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]"""'}, {}), '(\n    \'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]\'\n    )', False, 'import json\n'), ((104, 11, 104, 70), 'django.shortcuts.render', 'render', ({(104, 18, 104, 25): 'request', (104, 27, 104, 46): '"""patient_list.html"""', (104, 48, 104, 69): "{'patients': patients}"}, {}), "(request, 'patient_list.html', {'patients': patients})", False, 'from django.shortcuts import render, redirect\n'), ((116, 10, 116, 1731), 'json.loads', 'json.loads', ({(116, 21, 116, 1730): '"""[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]"""'}, {}), '(\n    \'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]\'\n    )', False, 'import json\n'), ((139, 11, 139, 58), 'django.shortcuts.redirect', 'redirect', ({(139, 20, 139, 57): '"""http://127.0.0.1:8000/patients-list"""'}, {}), "('http://127.0.0.1:8000/patients-list')", False, 'from django.shortcuts import render, redirect\n'), ((149, 10, 149, 1731), 'json.loads', 'json.loads', ({(149, 21, 149, 1730): '"""[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]"""'}, {}), '(\n    \'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]\'\n    )', False, 'import json\n'), ((176, 11, 176, 58), 'django.shortcuts.redirect', 'redirect', ({(176, 20, 176, 57): '"""http://127.0.0.1:8000/patients-list"""'}, {}), "('http://127.0.0.1:8000/patients-list')", False, 'from django.shortcuts import render, redirect\n'), ((182, 11, 182, 59), 'django.shortcuts.render', 'render', ({(182, 18, 182, 25): 'request', (182, 26, 182, 37): '"""edit.html"""', (182, 39, 182, 58): "{'patient': patient}"}, {}), "(request, 'edit.html', {'patient': patient})", False, 'from django.shortcuts import render, redirect\n'), ((187, 9, 187, 47), 'pandas.read_csv', 'pd.read_csv', (), '', True, 'import pandas as pd\n'), ((194, 11, 194, 64), 'django.shortcuts.render', 'render', ({(194, 18, 194, 25): 'request', (194, 26, 194, 38): '"""users.html"""', (194, 40, 194, 63): "{'countries': countries}"}, {}), "(request, 'users.html', {'countries': countries})", False, 'from django.shortcuts import render, redirect\n'), ((199, 9, 199, 47), 'pandas.read_csv', 'pd.read_csv', (), '', True, 'import pandas as pd\n'), ((211, 10, 211, 1731), 'json.loads', 'json.loads', ({(211, 21, 211, 1730): '"""[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]"""'}, {}), '(\n    \'[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"enum Contact_tracing.Statuses","name":"_status","type":"uint8"},{"internalType":"string","name":"_postal","type":"string"},{"internalType":"string","name":"_hospitalName","type":"string"},{"internalType":"string","name":"_hashing","type":"string"},{"internalType":"string","name":"_country","type":"string"}],"name":"addPatient","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getPatientsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"gettPatient","outputs":[{"components":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"internalType":"struct Contact_tracing.Patient","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"patients","outputs":[{"internalType":"enum Contact_tracing.Statuses","name":"status","type":"uint8"},{"internalType":"string","name":"postal","type":"string"},{"internalType":"string","name":"hospitalName","type":"string"},{"internalType":"string","name":"hashing","type":"string"},{"internalType":"string","name":"country","type":"string"}],"stateMutability":"view","type":"function"}]\'\n    )', False, 'import json\n'), ((45, 16, 45, 46), 'web3.Web3.HTTPProvider', 'Web3.HTTPProvider', ({(45, 34, 45, 45): 'ganache_url'}, {}), '(ganache_url)', False, 'from web3 import Web3\n'), ((92, 8, 92, 49), 'django.contrib.messages.success', 'messages.success', ({(92, 25, 92, 32): 'request', (92, 34, 92, 48): '"""Record Saved"""'}, {}), "(request, 'Record Saved')", False, 'from django.contrib import messages\n'), ((94, 15, 94, 44), 'django.shortcuts.render', 'render', ({(94, 22, 94, 29): 'request', (94, 31, 94, 43): '"""index.html"""'}, {}), "(request, 'index.html')", False, 'from django.shortcuts import render, redirect\n'), ((96, 15, 96, 44), 'django.shortcuts.render', 'render', ({(96, 22, 96, 29): 'request', (96, 31, 96, 43): '"""index.html"""'}, {}), "(request, 'index.html')", False, 'from django.shortcuts import render, redirect\n'), ((114, 16, 114, 46), 'web3.Web3.HTTPProvider', 'Web3.HTTPProvider', ({(114, 34, 114, 45): 'ganache_url'}, {}), '(ganache_url)', False, 'from web3 import Web3\n'), ((147, 16, 147, 46), 'web3.Web3.HTTPProvider', 'Web3.HTTPProvider', ({(147, 34, 147, 45): 'ganache_url'}, {}), '(ganache_url)', False, 'from web3 import Web3\n'), ((174, 15, 174, 62), 'django.shortcuts.redirect', 'redirect', ({(174, 24, 174, 61): '"""http://127.0.0.1:8000/patients-list"""'}, {}), "('http://127.0.0.1:8000/patients-list')", False, 'from django.shortcuts import render, redirect\n'), ((209, 16, 209, 46), 'web3.Web3.HTTPProvider', 'Web3.HTTPProvider', ({(209, 34, 209, 45): 'ganache_url'}, {}), '(ganache_url)', False, 'from web3 import Web3\n'), ((241, 15, 241, 119), 'django.shortcuts.render', 'render', ({(241, 22, 241, 29): 'request', (241, 30, 241, 45): '"""infected.html"""', (241, 47, 241, 118): "{'countries': countries, 'infected_people': counter, 'message': message}"}, {}), "(request, 'infected.html', {'countries': countries, 'infected_people':\n    counter, 'message': message})", False, 'from django.shortcuts import render, redirect\n')]