def view(request, pk): trial = prescription.Prescription() print(trial) (exists, instance) = trial.view(request, pk) if exists: return render(request, 'prescription/prescription_view.html', {'prescription': instance}) else: return HttpResponse("<h1>Hash does not exist in blockchain</h1>")
def upload(request): trial = prescription.Prescription() form, pk = trial.upload(request) if pk != -1: # return redirect('prescription:ocr/'+str(pk)) print("a") return HttpResponseRedirect(reverse('prescription:ocr', args=(pk, ))) else: print("b") return render(request, 'prescription/prescription_upload.html', {'form': form})
def ocr(request, pk): if request.method == "GET": trial = prescription.Prescription() ocr_instance = trial.ocr(request, pk) # pk2 = kwargs.get('pk2', none) text = ocr_instance[0] prescriptions = ocr_instance[1] elif request.method == "POST": # form = forms.VerifyOCRText(request.POST , request.FILES) # if form.is_valid(): instance = Prescriptions.objects.get(pk=pk) if instance is not None: instance.text = request.POST.get('ocr-text', "") instance.save() instance = Prescriptions.objects.get(pk=pk) text = instance.text hash_ = Web3.sha3(text=text) hash_hex = hash_.hex() # print(hash_hex) # print(hash_) # print(len(hash_hex)) if flag1 == False: b = blockchain.Blockchain(url="http://127.0.0.1:7545", abi=abi) # flag1=True if b.connect(): inserted = b.insert_hash(hash_hex) print(inserted) if inserted: return redirect('prescription:list') else: return HttpResponse('<h1>Push to blockchain failed</h1>') else: return HttpResponse("<h1>Connection failed</h1>") # return redirect('prescription:block' , args=(pk)) # return render(block(request,pk)) else: return HttpResponse("<h1>Instance is null</h1>") return render(request, 'prescription/prescription_ocr.html', { 'prescriptions': prescriptions, 'text': text })
def delete(request, pk): trial = prescription.Prescription() trial.delete_record(request, pk) # pk1 = kwargs.get('pk1', none) return redirect('prescription:list')
def record_list(request): trial = prescription.Prescription() prescriptions = trial.record_list(request) return render(request, 'prescription/prescription_list.html', {'prescriptions': prescriptions})
def test_upload(self): test = prescription.Prescription() self.assertTrue(test.upload())