Skip to content

Instantly share code, notes, and snippets.

@ijharulislam
Created June 22, 2015 11:00
Show Gist options
  • Save ijharulislam/94c3ee6d0edd3f0277ee to your computer and use it in GitHub Desktop.
Save ijharulislam/94c3ee6d0edd3f0277ee to your computer and use it in GitHub Desktop.
from django.db import models
from phonenumber_field.modelfields import PhoneNumberField
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser
)
import hashlib, datetime, random
from datetime import date
from django import forms
from django.utils import timezone
class MyUserManager(BaseUserManager):
def create_user(self, email, password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(email,
password=password,
)
user.is_admin = True
user.save(using=self._db)
return user
class MyUser(AbstractBaseUser):
SINGLE = 'SIN'
MARRIED = 'MAR'
STATUS_CHOICES = ((SINGLE,'Single'),(MARRIED, 'Married'))
MALE = 'MAL'
FEMALE = 'FEM'
GENDER_CHOICES = ((MALE, 'Male'), (FEMALE, 'Female'))
email = models.EmailField(
verbose_name='e-mail',
max_length=255,
unique=True,
)
activation_key = models.CharField(max_length=40, blank=True)
key_expires = models.DateTimeField(default=datetime.date.today())
first_name = models.CharField(max_length = 20, default = "")
last_name = models.CharField(max_length = 20, default = "")
birth_date = models.DateField(default=date.today())
phone_number = PhoneNumberField(null=True)
gender = models.CharField(max_length = 7, default = "", choices = GENDER_CHOICES)
marital_Status = models.CharField(max_length = 10, default = "", choices = STATUS_CHOICES)
#Address
house_number = models.IntegerField(default = 0, blank = True, null=True)
street = models.CharField(max_length = 30, blank = True, null=True)
city = models.CharField(max_length = 20, blank = True, null=True)
#Emergency Contact
name = models.CharField(max_length = 50, default = "")
relation = models.CharField(max_length = 20, default = "")
primary_Phone = models.IntegerField(default = 0)
secondary_Phone = models.IntegerField(default = 0)
is_content_manager = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
objects = MyUserManager()
USERNAME_FIELD = 'email'
class Meta:
verbose_name = ('MyUser')
verbose_name_plural = ('MyUsers')
def get_full_name(self):
# The user is identified by their email address
return self.email
def get_short_name(self):
# The user is identified by their email address
return self.email
def __str__(self): # __unicode__ on Python 2
return self.email
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
@property
def is_staff(self):
"Is the user a member of staff?"
# Simplest possible answer: All admins are staff
return self.is_admin
def save(self, *args, **kwargs):
# if user being demoted from content manager, make sure they are not
# managing any courses
super().save(*args, **kwargs)
class Nurse(MyUser):
department = models.CharField(max_length = 30, default = "", choices=DEPT_CHOICES)
is_nurse = models.BooleanField(default=True)
is_authenticated = models.BooleanField(default=True)
class Meta:
verbose_name = ('Nurse')
def __str__(self): # __unicode__ on Python 2
return self.email
class Doctor(MyUser):
MED = 'MD'
OST = 'DO'
DEG_CHOICES = ((MED, 'M.D.'),
(OST, 'D.O.'))
degree = models.CharField(max_length = 40, default = MED, choices = DEG_CHOICES )
specialty = models.CharField(max_length = 30, default = "", choices=SPEC_CHOICES) #Try to turn into checkbox
experience = models.CharField(max_length = 60, default = "")
is_doctor = models.BooleanField(default=True)
fees = models.IntegerField(default=0)
is_authenticated = models.BooleanField(default=True)
class Meta:
verbose_name = ('Doctor')
def __str__(self): # __unicode__ on Python 2
return self.email
class Patient(MyUser):
status_choice=(('0','Waiting'),('1','Pending'),('2','Completed'))
TREATMENT_OPTIONS = (
(0, 'Implants'),
(1, 'Crowns'),
(2, 'Laser'),
(3, 'X-Rays'),
(4, 'Fluoride'),
(5, 'Fillings'),
(6, 'Root Canal Treatment'),
(7, 'Periodontal Disease'),
(8, 'Tooth Removal and Extraction'),
(9, 'Sealants'))
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
name = models.CharField(max_length=50)
medical_History = models.CharField(max_length = 400, default = "")
is_patient = models.BooleanField(default=True)
is_authenticated = models.BooleanField(default=True)
allergies = models.CharField(max_length = 40, default = "")
prescriptions = models.CharField(max_length = 400, default = "")
primaryCareProvider = models.ForeignKey(Doctor, default = 1)
status = models.CharField(max_length=1 ,choices=status_choice)
date = models.DateTimeField('date consulted')
new_patient = models.BooleanField(default=True)
treatment = models.PositiveSmallIntegerField(default=0, choices=TREATMENT_OPTIONS)
class Meta:
verbose_name = ('Patient')
def __str__(self): # __unicode__ on Python 2
return self.email
class Appointment(models.Model):
startTime = models.DateTimeField(default = timezone.now())
endTime = models.DateTimeField(default = timezone.now()+datetime.timedelta(hours=1))
doctor = models.ForeignKey(Doctor, default = 1)
patient = models.ForeignKey(Patient, default = 1)
pass
class Department(models.Model):
dnum = models.IntegerField(primary_key=True)
name = models.CharField(max_length=20)
floor = models.IntegerField(default=0)
class Medicine(models.Model):
mid = models.IntegerField(primary_key=True)
name = models.CharField(max_length=40)
charge = models.IntegerField(default=0)
class Tests(models.Model):
tid = models.IntegerField(primary_key=True)
name = models.CharField(max_length=40)
amount = models.IntegerField(default=0)
dnum = models.ForeignKey(Department)
class Prescribed(models.Model):
pid = models.ForeignKey(Patient)
mid = models.ForeignKey(Medicine)
dosage = models.FloatField(default=0.0)
class TestPrescribed(models.Model):
pid = models.ForeignKey(Patient)
tid = models.ForeignKey(Tests)
test_date = models.DateTimeField('test date')
class Bill(models.Model):
bill_no = models.IntegerField(primary_key=True)
pid = models.ForeignKey(Patient)
no_of_days = models.IntegerField(default=0, null=True, blank=True)
med_charges = models.IntegerField(default=0, null=True, blank=True)
doc_charges = models.IntegerField(default=0, null=True, blank=True)
test_charges = models.IntegerField(default=0, null=True, blank=True)
total_amount = models.IntegerField(default=0)
due_payment = models.IntegerField(default=0)
def get_due(self):
if self.due_payment:
return "Total Due = %s " %(self.total - self.due_payment)
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment