ahmsayat / CyberSeed

CyberSeed 2017
http://ahmsayat.pythonanywhere.com/
MIT License
0 stars 0 forks source link

Models + Forms + Views #5

Open ahmsayat opened 7 years ago

ahmsayat commented 7 years ago

Models are the DB.

ahmsayat commented 7 years ago

Models.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User

# Create your models here.
#System Administrator Role
class System_Administrator(models.Model):
    Date = models.DateTimeField('Date')

#Doctor Role
class Doctor(models.Model):
    Practice_Name = models.CharField(max_length=200)
    Practice_Address = models.CharField(max_length=200)
    Recovery_Phrase = models.CharField(max_length=200)
    #Username = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True,)
    username = models.ForeignKey(User, blank=True, null=True)
    #created_by = models.ForeignKey(User, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return self.Practice_Name

#Nurse Role
class Nurse(models.Model):
    Practice_Name = models.CharField(max_length=200)
    Practice_Address = models.CharField(max_length=200)
    Associated_Doctors = models.ManyToManyField(Doctor)
    username = models.ForeignKey(User, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return self.Practice_Name

#Medical Administrator Role
class Medical_Administrator(models.Model):
    Practice_Name = models.CharField(max_length=200)
    Practice_Address = models.CharField(max_length=200)
    Associated_Doctors = models.ManyToManyField(Doctor)
    Associated_Nurses = models.ManyToManyField(Nurse)
    username = models.ForeignKey(User, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return self.Practice_Name

#Insurance Administrator Role
class Insurance_Administrator(models.Model):
    Company_Name = models.CharField(max_length=200)
    Company_Address = models.CharField(max_length=200)
    username = models.ForeignKey(User, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return self.Company_Name

#Patient Role
class Patient(models.Model):
    SSN = models.CharField(max_length=200)
    Address = models.CharField(max_length=200)
    DOB =  models.DateTimeField('Date')
    username = models.ForeignKey(User, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return self.Company_Name

#Record
class Record(models.Model):
    Record_ID =  models.AutoField(primary_key=True)
    lst = ['Doctor Exam','Test Result','Diagnosis','Insurance Claim','Patient Doctor Correspondence','Raw']
    options = [(str(i), str(i)) for i in lst]
    Record_Type = models.CharField(max_length=200, choices=options, default='Doctor Exam')
    Record_Date =  models.DateTimeField('Record_Date', auto_now=True)
    Owner = models.ForeignKey(User, blank=True, null=True, related_name='Owner')
    Patient = models.ForeignKey(User, blank=True, null=True, related_name='Patient')
    Edit_Permissions = models.ManyToManyField(User, related_name='Edit_Permissions')
    View_Permissions = models.ManyToManyField(User, related_name='View_Permissions')
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.Record_ID)

#Doctor Exam Record
class Doctor_Exam_Record(models.Model):
    Date =  models.DateTimeField('Date of exam', auto_now=True)
    Doctor = models.ForeignKey(User, blank=True, null=True)
    Notes = models.CharField(max_length=200)
    Record = models.ForeignKey(Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

#Diagnosis Record
class Diagnosis_Record(models.Model):
    Date =  models.DateTimeField('Date of exam', auto_now=True)
    Doctor = models.ForeignKey(User, blank=True, null=True)
    Diagnosis = models.CharField(max_length=200)
    Record = models.ForeignKey(Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

#Test Results Record
class Test_Results_Record(models.Model):
    Date =  models.DateTimeField('Date of exam', auto_now=True)
    Doctor = models.ForeignKey(User, blank=True, null=True)
    Lab = models.CharField(max_length=200)
    Notes = models.CharField(max_length=200)
    Record = models.ForeignKey(Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

#Insurance Claim Record
class Insurance_Claim_Record(models.Model):
    Date =  models.DateTimeField('Date of exam', auto_now=True)
    Medical_Administrator = models.ForeignKey(User, blank=True, null=True, related_name='Medical_Administrator_handling_claim_for_doctor')
    Amount = models.FloatField(default=0.0) # models.FloatField(null=True, blank=True, default=None)
    Status_Options = (('Filed', 'Filed'), ('Examining', 'Examining'),  ('Rejected', 'Rejected'),('Accepted', 'Accepted'), ( 'Paid', 'Paid'))
    Status = models.CharField(max_length=200, choices=Status_Options)
    Record = models.ForeignKey(Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

#Patient_Doctor_Correspondence_Record
class Patient_Doctor_Correspondence_Record(models.Model):
    Doctor = models.ForeignKey(User, blank=True, null=True, related_name='Doctor')
    Notes = models.ManyToManyField('Note')
    Record = models.ForeignKey(Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

#Raw Record
class Raw_Record(models.Model):
    Description = models.CharField(max_length=200)
    File = models.FileField(upload_to='documents')
    Record = models.ForeignKey(Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

#Note
class Note(models.Model):
    Date =  models.DateTimeField('Note Date', auto_now=True)
    Text = models.CharField(max_length=200)
    Patient_Doctor_Correspondence = models.ForeignKey(Patient_Doctor_Correspondence_Record, blank=True, null=True)
    created_at = models.DateTimeField('Date', auto_now=True)
    def __str__(self):
        return str(self.id)

ahmsayat commented 7 years ago

Admin.py

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.contrib import admin
from .models import System_Administrator, Doctor, Nurse, Medical_Administrator, Insurance_Administrator, Patient, Record, Doctor_Exam_Record, Diagnosis_Record, Test_Results_Record, Insurance_Claim_Record, Patient_Doctor_Correspondence_Record, Raw_Record, Note

# Register your models here.
admin.site.register(System_Administrator)
admin.site.register(Doctor)
admin.site.register(Nurse)
admin.site.register(Medical_Administrator)
admin.site.register(Insurance_Administrator)
admin.site.register(Patient)
admin.site.register(Record)
admin.site.register(Doctor_Exam_Record)
admin.site.register(Diagnosis_Record)
admin.site.register(Test_Results_Record)
admin.site.register(Insurance_Claim_Record)
admin.site.register(Patient_Doctor_Correspondence_Record)
admin.site.register(Raw_Record)
admin.site.register(Note)
ahmsayat commented 7 years ago

Forms.py

from django.forms import ModelForm
from app.models import System_Administrator, Doctor, Nurse, Medical_Administrator, Insurance_Administrator, Patient, Record, Doctor_Exam_Record, Diagnosis_Record, Test_Results_Record, Insurance_Claim_Record, Patient_Doctor_Correspondence_Record, Raw_Record, Note

class Doctor_Form(ModelForm):
    class Meta:
        model = Doctor
        fields = ['Practice_Name', 'Practice_Address', 'Recovery_Phrase']

class Nurse_Form(ModelForm):
    class Meta:
        model = Nurse
        fields = ['Practice_Name', 'Practice_Address', 'Associated_Doctors']

class Medical_Administrator_Form(ModelForm):
    class Meta:
        model = Medical_Administrator
        fields = ['Practice_Name', 'Practice_Address', 'Associated_Doctors', 'Associated_Nurses']

class Insurance_Administrator_Form(ModelForm):
    class Meta:
        model = Insurance_Administrator
        fields = ['Company_Name', 'Company_Address']

class Patient_Form(ModelForm):
    class Meta:
        model = Patient
        fields = ['SSN', 'Address', 'DOB']

class Record_Form(ModelForm):
    class Meta:
        model = Record
        fields = ['Record_Type', 'Patient']

class Doctor_Exam_Record_Form(ModelForm):
    class Meta:
        model = Doctor_Exam_Record
        fields = ['Notes']

class Diagnosis_Record_Form(ModelForm):
    class Meta:
        model = Diagnosis_Record
        fields = ['Doctor', 'Diagnosis']

class Test_Results_Record_Form(ModelForm):
    class Meta:
        model = Test_Results_Record
        fields = ['Lab', 'Notes', 'Record']

class Insurance_Claim_Record_Form(ModelForm):
    class Meta:
        model = Insurance_Claim_Record
        fields = ['Amount', 'Status']

class Patient_Doctor_Correspondence_Record_Form(ModelForm):
    class Meta:
        model = Patient_Doctor_Correspondence_Record
        fields = ['Doctor', 'Notes']

class Raw_Record_Form(ModelForm):
    class Meta:
        model = Raw_Record
        fields = ['File', 'Description']

class Note_Form(ModelForm):
    class Meta:
        model = Note
        fields = ['Text', 'Patient_Doctor_Correspondence']

ahmsayat commented 7 years ago

Views.py


# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.http import HttpResponse
from django import forms
from django.shortcuts import render, redirect
from django.utils import timezone
from app.forms import *

def Doctor(request):
    if request.method == "POST":
        form = Doctor_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Doctor_Form()})

def Nurse(request):
    if request.method == "POST":
        form = Nurse_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Nurse_Form()})

def Medical_Administrator(request):
    if request.method == "POST":
        form = Medical_Administrator_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Medical_Administrator()})

def Insurance_Administrator(request):
    if request.method == "POST":
        form = Insurance_Administrator_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Insurance_Administrator()})

def Patient(request):
    if request.method == "POST":
        form = Patient_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Patient()})

def Record(request):
    if request.method == "POST":
        form = Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Record()})

def Doctor_Exam_Record(request):
    if request.method == "POST":
        form = Doctor_Exam_Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Doctor_Exam_Record()})

def Diagnosis_Record(request):
    if request.method == "POST":
        form = Diagnosis_Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Diagnosis_Record()})

def Test_Results_Record(request):
    if request.method == "POST":
        form = Test_Results_Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Test_Results_Record()})

def Insurance_Claim_Record(request):
    if request.method == "POST":
        form =Insurance_Claim_Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Insurance_Claim_Record()})

def Patient_Doctor_Correspondence_Record(request):
    if request.method == "POST":
        form =Patient_Doctor_Correspondence_Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Patient_Doctor_Correspondence_Record()})

def Raw_Record(request):
    if request.method == "POST":
        form =Raw_Record_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Raw_Record()})

def Note(request):
    if request.method == "POST":
        form = Note_Form(request.POST)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.timestamp = timezone.now()
            model_instance.save()
            return redirect('/admin')
    else:
        return render(request, "app/my_template.html", {'form': Note_Form()})

ahmsayat commented 7 years ago

urls.py

#app/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^doctor/$', views.Doctor, name='doctor'),
    url(r'^nurse/$', views.Nurse, name='nurse'),
    url(r'^medical_administrator/$', views.Medical_Administrator, name='medical_administrator'),
    url(r'^insurance_administrator/$', views.Insurance_Administrator, name='insurance_administrator'),
    url(r'^patient/$', views.Patient, name='patient'),
    url(r'^record/$', views.Record, name='record'),
    url(r'^doctor_exam_record/$', views.Doctor_Exam_Record, name='doctor_exam_record'),
    url(r'^diagnosis_record/$', views.Diagnosis_Record, name='diagnosis_record'),
    url(r'^test_results_record/$', views.Test_Results_Record, name='test_results_record'),
    url(r'^insurance_claim_record/$', views.Insurance_Claim_Record, name='insurance_claim_record'),
    url(r'^patient_doctor_correspondence_record/$', views.Patient_Doctor_Correspondence_Record, name='patient_doctor_correspondence_record'),
    url(r'^raw_record/$', views.Raw_Record, name='raw_record'),
    url(r'^note/$', views.Note, name='note'),
    ]