diff --git a/certificates/helpers/validate_certificate.py b/certificates/helpers/validate_certificate.py index 952f184..07173c5 100644 --- a/certificates/helpers/validate_certificate.py +++ b/certificates/helpers/validate_certificate.py @@ -8,18 +8,27 @@ def __init__(self, path): self.status = None self.hash = None - def set_hash(self): - text = docx2txt.process(self.path) - self.hash = text[:36] + def set_hash(self): + try: + text = docx2txt.process(self.path) + self.hash = text[:36] + except: + self.hash = None + def get_certificate(self): - self.set_hash() + if self.set_hash(): + return None + return Certificate.objects.filter(hash=self.hash).first() def validate(path:str): - validator = CertificateValidator(path) + try: + validator = CertificateValidator(path) + except: + return None return validator.get_certificate() \ No newline at end of file diff --git a/certificates/signals/validate_certificate.py b/certificates/signals/validate_certificate.py index b969cd0..0b00a78 100644 --- a/certificates/signals/validate_certificate.py +++ b/certificates/signals/validate_certificate.py @@ -4,20 +4,21 @@ from certificates.models import Certificate, CertificateValidation from certificates.helpers import validate import random +import os @receiver(post_save, sender=CertificateValidation, dispatch_uid='validate_certificate') def validate_certificate(sender, instance, created, **kwargs): if created: settings.LOGGER.critical(instance.certificate) - status = random.choice(['Clean', 'Fake']) - certificate = Certificate.objects.first() - + + path = os.path.join(settings.MEDIA_ROOT,instance.certificate.path ) + certificate = validate(path) if certificate: - instance.status = status + instance.status = 'Clean' instance.save() settings.LOGGER.success(f'{instance.title} generated successfully') else: - instance.status = status + instance.status = 'Fake' instance.save() settings.LOGGER.error(f'{instance.title} certificate generation failed') \ No newline at end of file diff --git a/dashboard/views.py b/dashboard/views.py index 303eb4e..31e3e3b 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -2,7 +2,20 @@ from django.shortcuts import render, redirect from django.views.generic import TemplateView from django.contrib import messages +from certificates.models import CertificateValidation +from claims.models import Claim + class DashboardListView(TemplateView): template_name = 'dashboard/dashboard.html' + + def get_context_data(self, **kwargs) : + context = super().get_context_data(**kwargs) + context['clean_certificates'] = CertificateValidation.objects.filter(status = 'Clean').count() + context['fake_certificates'] = CertificateValidation.objects.filter(status = 'Fake').count() + context['clean_claims'] = Claim.objects.filter(classification = 'Clean').count() + context['fraud_claims'] = Claim.objects.filter(classification = 'Fraud').count() + + return context + diff --git a/medical_insurance_system/settings.py b/medical_insurance_system/settings.py index 170b122..9e40ec4 100644 --- a/medical_insurance_system/settings.py +++ b/medical_insurance_system/settings.py @@ -146,6 +146,7 @@ MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_URL = "/media/" DATASET_PATH = os.path.join(BASE_DIR, "claims/datasets") +VALIDATION_PATH = os.path.join(MEDIA_ROOT, "uploade_certificates") # Default primary key field type # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field diff --git a/templates/dashboard/dashboard.html b/templates/dashboard/dashboard.html index 3143666..9c459d6 100644 --- a/templates/dashboard/dashboard.html +++ b/templates/dashboard/dashboard.html @@ -29,50 +29,54 @@

Medical Insurance Dashboard

-
Orders Overview
-

In last 15 days buy and sells overview. Detailed +

Medical Insurance
+

Detailed Stats

-
-
- - -
-
+
-
-
- -
-
-
+ +
-
12,954.63 USD
-
Last month 39,485 USD
-
Buy Orders +
{{ clean_claims }} Clean Claims
+ +
Medical Aid Claims +
+
+
+
+
+
{{ fraud_claims }} Fraudulent Claims
+ +
Medical Aid Claims
+
+
+
+
-
-
12,954.63 USD
-
Last month 39,485 USD
-
Sell Orders +
+
{{ clean_certificates }} Clean Certificates
+ +
Medical Aid Claims +
+
+
+
+
+
{{ fake_certificates }} Fraudulent Certificates
+ +
Certificates
@@ -83,44 +87,6 @@
Orders Overview
-
-
-
-
-
Payments
-

Monthly See Details

-
- -
-
-
- 82,944.60 -
-
- 1,937 Trained Employees -
-
-
- -
-
-
+
{% endblock %} diff --git a/templates/layouts/header.html b/templates/layouts/header.html index 2e62da7..a896bc7 100644 --- a/templates/layouts/header.html +++ b/templates/layouts/header.html @@ -7,10 +7,7 @@
@@ -24,41 +21,12 @@
- - - +
diff --git a/templates/layouts/sidebar.html b/templates/layouts/sidebar.html index 71ad06f..3c87e7c 100644 --- a/templates/layouts/sidebar.html +++ b/templates/layouts/sidebar.html @@ -4,8 +4,7 @@
@@ -31,13 +30,13 @@
  • - + Certificates
  • - + Claims
  • diff --git a/templates/validation/create.html b/templates/validation/create.html index 3e609c2..ba6815f 100644 --- a/templates/validation/create.html +++ b/templates/validation/create.html @@ -32,7 +32,7 @@

    Validate Certificate

    Certificate Validation
    -
    + {% csrf_token %}