Skip to content

Commit

Permalink
system complete
Browse files Browse the repository at this point in the history
  • Loading branch information
nyashaChiza committed Apr 2, 2023
1 parent 5058f48 commit 9fdf2e0
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 121 deletions.
19 changes: 14 additions & 5 deletions certificates/helpers/validate_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


11 changes: 6 additions & 5 deletions certificates/signals/validate_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

13 changes: 13 additions & 0 deletions dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions medical_insurance_system/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
108 changes: 37 additions & 71 deletions templates/dashboard/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,54 @@ <h3 class="nk-block-title page-title">Medical Insurance Dashboard</h3>
<div class="card-inner">
<div class="card-title-group align-start mb-3">
<div class="card-title">
<h6 class="title">Orders Overview</h6>
<p>In last 15 days buy and sells overview. <a href="#" class="link link-sm">Detailed
<h6 class="title">Medical Insurance </h6>
<p><a href="#" class="link link-sm">Detailed
Stats</a></p>
</div>
<div class="card-tools mt-n1 me-n1">
<div class="drodown">
<a href="#" class="dropdown-toggle btn btn-icon btn-trigger" data-toggle="dropdown"><em
class="icon ni ni-more-h"></em></a>
<div class="dropdown-menu dropdown-menu-sm dropdown-menu-end">
<ul class="link-list-opt no-bdr">
<li><a href="#" class="active"><span>15 Days</span></a></li>
<li><a href="#"><span>30 Days</span></a></li>
<li><a href="#"><span>3 Months</span></a></li>
</ul>
</div>
</div>
</div>
<div class="card-tools mt-n1 me-n1"></div>
</div><!-- .card-title-group -->
<div class="nk-order-ovwg">
<div class="row g-4 align-end">
<div class="col-xxl-8">
<div class="nk-order-ovwg-ck">
<canvas class="order-overview-chart" id="orderOverview"></canvas>
</div>
</div><!-- .col -->
<div class="col-xxl-4">
<!-- .col -->
<div class="col-md-6">
<div class="row g-4">
<div class="col-sm-6 col-xxl-12">
<div class="nk-order-ovwg-data buy">
<div class="amount">12,954.63 <small
class="currenct currency-usd">USD</small></div>
<div class="info">Last month <strong>39,485 <span
class="currenct currency-usd">USD</span></strong></div>
<div class="title"><em class="icon ni ni-arrow-down-left"></em> Buy Orders
<div class="amount"> {{ clean_claims }} <small
class="currenct currency-usd">Clean Claims</small></div>

<div class="title"><em class="icon ni ni-arrow-down-left"></em> Medical Aid Claims
</div>
</div>
</div>
<div class="col-sm-6 col-xxl-12 border-danger">
<div class="nk-order-ovwg-data buy border-danger">
<div class="amount text-danger">{{ fraud_claims }} <small
class="currenct currency-usd text-danger">Fraudulent Claims</small></div>

<div class="title"><em class="icon ni ni-arrow-down-left text-danger"></em> Medical Aid Claims
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row g-4">
<div class="col-sm-6 col-xxl-12">
<div class="nk-order-ovwg-data sell">
<div class="amount">12,954.63 <small
class="currenct currency-usd">USD</small></div>
<div class="info">Last month <strong>39,485 <span
class="currenct currency-usd">USD</span></strong></div>
<div class="title"><em class="icon ni ni-arrow-up-left"></em> Sell Orders
<div class="nk-order-ovwg-data buy">
<div class="amount">{{ clean_certificates }} <small
class="currenct currency-usd">Clean Certificates</small></div>

<div class="title"><em class="icon ni ni-arrow-down-left"></em> Medical Aid Claims
</div>
</div>
</div>
<div class="col-sm-6 col-xxl-12 border-danger">
<div class="nk-order-ovwg-data buy border-danger">
<div class="amount text-danger">{{ fake_certificates }} <small
class="currenct currency-usd text-danger">Fraudulent Certificates</small></div>

<div class="title"><em class="icon ni ni-arrow-down-left text-danger"></em> Certificates
</div>
</div>
</div>
Expand All @@ -83,44 +87,6 @@ <h6 class="title">Orders Overview</h6>
</div><!-- .card-inner -->
</div><!-- .card -->

<div class="card card-bordered">
<div class="card-inner">
<div class="card-title-group align-start gx-3 mb-3">
<div class="card-title">
<h6 class="title">Payments</h6>
<p>Monthly <a href="#">See Details</a></p>
</div>
<div class="card-tools">
<div class="dropdown">
<a href="#" class="btn btn-primary btn-dim d-none d-sm-inline-flex"
data-toggle="dropdown"><em class="icon ni ni-download-cloud"></em><span><span
class="d-none d-md-inline">Download</span> Report</span></a>
<a href="#" class="btn btn-icon btn-primary btn-dim d-sm-none"
data-toggle="dropdown"><em class="icon ni ni-download-cloud"></em></a>
<div class="dropdown-menu dropdown-menu-end">
<ul class="link-list-opt no-bdr">
<li><a href="#"><span>Download Mini Version</span></a></li>
<li><a href="#"><span>Download Full Version</span></a></li>
<li class="divider"></li>
<li><a href="#"><em class="icon ni ni-opt-alt"></em><span>More
Options</span></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="nk-sale-data-group align-center justify-between gy-3 gx-5">
<div class="nk-sale-data">
<span class="amount">82,944.60</span>
</div>
<div class="nk-sale-data">
<span class="amount sm">1,937 <small>Trained Employees</small></span>
</div>
</div>
<div class="nk-sales-ck large pt-4">
<canvas class="sales-overview-chart" id="salesOverview"></canvas>
</div>
</div>
</div><!-- .card -->
<!-- .card -->
</div>
{% endblock %}
38 changes: 3 additions & 35 deletions templates/layouts/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
<a href="#" class="nk-nav-toggle nk-quick-nav-icon" data-target="sidebarMenu"><em class="icon ni ni-menu"></em></a>
</div>
<div class="nk-header-brand d-xl-none">
<a href="html/index.html" class="logo-link">
<img class="logo-light logo-img" src="{% static 'images/logo.png' %}" srcset="{% static 'images/logo2x.png 2x' %}" alt="logo">
<img class="logo-dark logo-img" src="{% static 'images/logo-dark.png' %}" srcset="{% static 'images/logo-dark2x.png 2x' %}" alt="logo-dark">
</a>

</div><!-- .nk-header-brand -->

<div class="nk-header-tools">
Expand All @@ -24,41 +21,12 @@
</div>
<div class="user-info d-none d-md-block">
<div class="user-status">Administrator</div>
<div class="user-name dropdown-indicator">dev</div>
</div>
</div>
</a>
<div class="dropdown-menu dropdown-menu-md dropdown-menu-end dropdown-menu-s1">
<div class="dropdown-inner user-card-wrap bg-lighter d-none d-md-block">
<div class="user-card">
<div class="user-avatar">
<span>AB</span>
</div>
<div class="user-info">
<span class="lead-text"></span>
</div>
</div>
</div>
<div class="dropdown-inner">
<ul class="link-list">
<li><a href="html/user-profile-regular.html"><em class="icon ni ni-user-alt"></em><span>My Profile</span></a></li>
<li><a href="html/user-profile-setting.html"><em class="icon ni ni-setting-alt"></em><span>MFA Settings</span></a></li>
<li><a href="html/user-profile-activity.html"><em class="icon ni ni-activity-alt"></em><span>Synnc Configuration</span></a></li>
</ul>
</div>
<div class="dropdown-inner">
<ul class="link-list">
<li ><a href="#"><em class="icon ni ni-signout text-danger"></em><span class="text-danger">Log out</span></a></li>
</ul>
</div>

</div>
</li><!-- .dropdown -->
<li class="dropdown notification-dropdown me-n1">
<a href="" class="dropdown-toggle nk-quick-nav-icon">
<div class="icon-status icon-status-info"><em class="icon ni ni-setting"></em></div>
</a>

</li><!-- .dropdown -->
<!-- .dropdown -->
</ul><!-- .nk-quick-nav -->
</div><!-- .nk-header-tools -->
</div><!-- .nk-header-wrap -->
Expand Down
7 changes: 3 additions & 4 deletions templates/layouts/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<div class="nk-sidebar-element nk-sidebar-head">
<div class="nk-sidebar-brand">
<a href="html/index.html" class="logo-link nk-sidebar-logo">
<img class="logo-light logo-img" src="{% static 'images/logo.png' %}" srcset="{% static 'images/logo2x.png 2x' %}" alt="logo">
<img class="logo-dark logo-img" src="{% static 'images/logo-dark.png' %}" srcset="{% static 'images/logo-dark2x.png 2x' %}" alt="logo-dark">
<h4>Medical Insurance System</h4>
</a>
</div>
<div class="nk-menu-trigger me-n2">
Expand All @@ -31,13 +30,13 @@
</li>
<li class="nk-menu-item">
<a href="{% url 'certificates-index' %}" class="nk-menu-link">
<span class="nk-menu-icon"><em class="icon ni ni-bar-chart-fill"></em></span>
<span class="nk-menu-icon"><em class="icon ni ni-file-docs"></em></span>
<span class="nk-menu-text">Certificates</span>
</a>
</li><!-- .nk-menu-item -->
<li class="nk-menu-item">
<a href="{% url 'claims-index' %}" class="nk-menu-link">
<span class="nk-menu-icon"><em class="icon ni ni-bar-chart-fill"></em></span>
<span class="nk-menu-icon"><em class="icon ni ni-coin-alt"></em></span>
<span class="nk-menu-text">Claims</span>
</a>
</li><!-- .nk-menu-item -->
Expand Down
2 changes: 1 addition & 1 deletion templates/validation/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h3 class="nk-block-title page-title">Validate Certificate</h3>
<div class="card-head">
<h5 class="card-title">Certificate Validation</h5>
</div>
<form action="{% url 'validation-create' %}" method="post">
<form action="{% url 'validation-create' %}" enctype="multipart/form-data" method="post">
{% csrf_token %}
<div class="row g-4">

Expand Down

0 comments on commit 9fdf2e0

Please sign in to comment.