Created
September 19, 2012 18:02
-
-
Save tkh44/3751154 to your computer and use it in GitHub Desktop.
CRS models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.localflavor.us.models import PhoneNumberField, USStateField | |
#Sorl-Thumbnail | |
from sorl.thumbnail import ImageField | |
import re | |
""" | |
Benefit Definitions | |
""" | |
class Benefit(models.Model): | |
"""An Association Benefit""" | |
name = models.CharField(blank=True, max_length=100) | |
benefit_provider = models.CharField("Benefit Provider", blank=True, max_length=100) | |
content = models.TextField(blank=True) | |
''' | |
Define upload path for attachments. | |
Put the file in attachments/benefits/benefit.name/ | |
''' | |
def upload_path(self, name): | |
return 'attachments/benefits/%s/%s' % (self.name, name) | |
logo = ImageField(upload_to=upload_path, blank=True) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False) | |
def save(self, *args, **kwargs): | |
self.content = self.content.strip() | |
super(Benefit, self).save(*args, **kwargs) | |
class Meta: | |
abstract = True | |
def __unicode__(self): | |
return u"%s" % (self.name) | |
class WellnessProgram(Benefit): | |
class Meta: | |
verbose_name = "Benefits - Wellness Program" | |
class SmallBusiness(Benefit): | |
class Meta: | |
verbose_name = "Benefits - Small Business Solution" | |
class ConsumerDiscount(Benefit): | |
class Meta: | |
verbose_name = "Benefits - Consumer Discount" | |
class SharedAttachment(models.Model): | |
""" | |
Like attachment, but available to all products. Similar Behavior to Benefits | |
""" | |
""" | |
Define upload path for attachments. | |
Put the file in attachments/common/ | |
""" | |
def upload_path(self, name): | |
return 'attachments/common/%s' % (name) | |
title = models.CharField(max_length=200) | |
file = models.FileField(upload_to=upload_path, blank=True, null=True) | |
preview = ImageField("Image preview of file.", help_text="Not required, but encouraged.", upload_to=upload_path, blank=True) | |
description = models.CharField(blank=True, max_length=255) | |
make_common = models.BooleanField("Make Common", help_text="Selecting this option makes this attachment available to other products", default=True) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False) | |
class Meta: | |
ordering = ['-title'] | |
def __unicode__(self): | |
return u'%s' % self.title | |
class Carrier(models.Model): | |
name = models.CharField("Carrier Name", max_length=64) | |
slug = models.SlugField(max_length=64, blank=True) | |
logo = ImageField(upload_to='logos', blank=True) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False) | |
def save(self, *args, **kwargs): | |
if not self.slug: | |
self.slug = self.make_slug() | |
super(Carrier, self).save(*args, **kwargs) | |
class Meta: | |
ordering = ['name'] | |
def __unicode__(self): | |
return u'%s | %s' % (self.name, self.created.strftime('%m/%d/%Y') | |
) | |
def get_absolute_url(self): | |
return '/%s' % self.slug | |
def make_slug(self): | |
""" Create a (unique) slug from self.name. """ | |
""" http://pastebin.com/N5RvfDrD """ | |
sanitized = re.sub("(?i)[^a-z0-9_-]", "-", self.name).lower() #remove non-alpha-numeric-underscore-hyphen chars | |
sanitized = re.sub("^_|_$", "", sanitized) #remove underscores from start/end cos they look dumb | |
while(re.search("__", sanitized)): #remove double underscores cos they look dumb | |
sanitized = re.sub("__", "_", sanitized) | |
#now make sure that it's unique: | |
while(Carrier.objects.filter(slug__iexact=sanitized).count()): #if it's not unique | |
current_number_suffix_match = re.search("\d+$", sanitized) #get the current number suffix if there is one | |
current_number_suffix = current_number_suffix_match and current_number_suffix_match.group() or 0 | |
next = str(int(current_number_suffix) +1) #increment it, and turn back to string so re.sub doesn't die | |
sanitized = re.sub("(\d+)?$", next, sanitized) #replace current number suffix with incremented suffix, try again... | |
return sanitized | |
class Product(models.Model): | |
carrier = models.ForeignKey(Carrier) | |
name = models.CharField("Product Name", max_length=64) | |
slug = models.SlugField(max_length=64, blank=True) | |
blurb = models.TextField("Poduct Intro Text", blank=True) | |
pre_ex = models.TextField("Pre-Ex Wait", blank=True) | |
underwriter = models.CharField(max_length=200) | |
accepts_creditable_coverage = models.CharField(max_length=200) | |
maternity = models.CharField("Pregnancy", max_length=200) | |
wellness_programs = models.ManyToManyField(WellnessProgram, blank=True) | |
small_business_solutions = models.ManyToManyField(SmallBusiness, blank=True) | |
consumer_discounts = models.ManyToManyField(ConsumerDiscount, blank=True) | |
shared_attachments = models.ManyToManyField(SharedAttachment, blank=True) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False) | |
''' | |
Define upload path for attachments. | |
Put the file in attachments/carrier.name/product.name/ | |
''' | |
def upload_path(self, name): | |
return 'attachments/%s/%s/%s' % (self.carrier.name, self.name, name) | |
logo = ImageField(upload_to=upload_path, blank=True) | |
def save(self, *args, **kwargs): | |
if not self.slug: | |
self.slug = self.make_slug() | |
super(Product, self).save(*args, **kwargs) | |
class Meta: | |
permissions = ( | |
('view_product', 'Can view product'), | |
) | |
ordering = ['name'] | |
def __unicode__(self): | |
return u'%s' % self.name | |
def get_absolute_url(self): | |
return '/%s' % ( self.slug) | |
def make_slug(self): | |
""" Create a (unique) slug from self.name. """ | |
""" http://pastebin.com/N5RvfDrD """ | |
sanitized = re.sub("(?i)[^a-z0-9_-]", "-", self.name).lower() #remove non-alpha-numeric-underscore-hyphen chars | |
sanitized = re.sub("^_|_$", "", sanitized) #remove underscores from start/end cos they look dumb | |
while(re.search("__", sanitized)): #remove double underscores cos they look dumb | |
sanitized = re.sub("__", "_", sanitized) | |
#now make sure that it's unique: | |
while(Product.objects.filter(slug__iexact=sanitized).count()): #if it's not unique | |
current_number_suffix_match = re.search("\d+$", sanitized) #get the current number suffix if there is one | |
current_number_suffix = current_number_suffix_match and current_number_suffix_match.group() or 0 | |
next = str(int(current_number_suffix) +1) #increment it, and turn back to string so re.sub doesn't die | |
sanitized = re.sub("(\d+)?$", next, sanitized) #replace current number suffix with incremented suffix, try again... | |
return sanitized | |
class Attachment(models.Model): | |
''' | |
Define upload path for attachments. | |
Put the file in attachments/carrier.name/product.name/ | |
''' | |
def upload_path(self, name): | |
return 'attachments/%s/%s/%s' % (self.product.carrier.name, self.product.name, name) | |
product = models.ForeignKey(Product) | |
title = models.CharField(max_length=200) | |
file = models.FileField(upload_to=upload_path, blank=True, null=True) | |
preview = ImageField("Image preview of file.", help_text="Not required, but encouraged.", upload_to=upload_path, blank=True) | |
description = models.CharField(blank=True, max_length=255) | |
make_common = models.BooleanField("Make Common", help_text="Selecting this option makes this attachment available to other products", default=True) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False) | |
class Meta: | |
ordering = ['-title'] | |
def __unicode__(self): | |
return u'%s' % self.title | |
class Claims(models.Model): | |
product = models.ForeignKey(Product) | |
description = models.TextField(blank=True) | |
company_name = models.CharField(max_length=64, blank=True) | |
phone_number = PhoneNumberField(blank=True) | |
address_1 = models.CharField(max_length=64, blank=True) | |
address_2 = models.CharField(max_length=64, blank=True) | |
city = models.CharField(max_length=64, blank=True) | |
state = USStateField(blank=True) | |
zipcode = models.CharField(blank=True, max_length=5) | |
payer_id = models.CharField(max_length=64, blank=True) | |
def __unicode__(self): | |
return u'%s' % self.company_name | |
class Meta: | |
ordering = ['-company_name'] | |
verbose_name_plural = "Claims" | |
class Network(models.Model): | |
product = models.ForeignKey(Product) | |
name = models.CharField("Network Name", max_length=64) | |
info = models.TextField("Network Information", blank=True) | |
url = models.URLField() | |
logo = ImageField(upload_to='attachments/network', blank=True) | |
def __unicode__(self): | |
return '%s' % self.name | |
class Meta: | |
ordering = ['name'] | |
class RX(models.Model): | |
product = models.ForeignKey(Product) | |
description = models.TextField(blank=True) | |
name = models.CharField("Rx Name", max_length=64) | |
phone_number_description = models.CharField( | |
"Phone number #1 Description", | |
help_text="e.g. Pharmacy Helpdesk", | |
max_length=200, | |
blank=True | |
) | |
phone_number = PhoneNumberField("Contact Phone #1", blank=True) | |
phone_number2_description = models.CharField( | |
"Phone number #2 Description", | |
help_text="e.g. Mail-Order", | |
max_length=200, | |
blank=True | |
) | |
phone_number2 = PhoneNumberField("Contact Phone #2", blank=True) | |
url = models.URLField("Rx Site", verify_exists=True, blank=True) | |
#file = models.FileField(upload_to='attachments/rx',blank=True) | |
logo = ImageField(upload_to='attachments/rx/logos', blank=True) | |
bin = models.CharField("BIN", help_text="Example, RxBIN: 014179",blank=True, max_length=100) | |
pcn = models.CharField("PCN", help_text="Example, RxPCN: 9743", blank=True, max_length=100) | |
group = models.CharField("Group", help_text="Example, RxGRP: 5150", blank=True, max_length=100) | |
def __unicode__(self): | |
return '%s' % self.name | |
class Meta: | |
ordering = ['name'] | |
class Alert(models.Model): | |
"""Alert for product updates""" | |
product = models.ForeignKey(Product) | |
message = models.CharField(help_text="Update Description",blank=True, max_length=200) | |
created = models.DateTimeField(auto_now_add=True, editable=False) | |
updated = models.DateTimeField(auto_now=True, auto_now_add=True, editable=False) | |
def __unicode__(self): | |
return u"%s" % self.message | |
class Meta: | |
ordering = ['-created'] | |
get_latest_by = "created" | |
""" | |
Plan definitions | |
""" | |
class Plan(models.Model): | |
""" | |
Plan | |
""" | |
product = models.ForeignKey(Product) | |
name = models.CharField("Plan Name", max_length=64) | |
rank = models.PositiveSmallIntegerField("Plan Level", help_text='"Lowest" Plan would be 0') | |
class Meta: | |
ordering = ['rank'] | |
def __unicode__(self): | |
return u'%s: %s | Plan Rank: %s' % (self.product.name, self.name, self.rank) | |
class Pricing(models.Model): | |
description = models.CharField(blank=True, max_length=255) | |
product = models.ForeignKey(Product) | |
pricing = models.TextField( | |
'Pricing Grid', | |
help_text='For example: [pricing level="Insured+1" prices="$199;$249;$309;$349;$400"]', | |
blank=True | |
) | |
position = models.PositiveSmallIntegerField("Position") | |
custom_table_headers = models.BooleanField("Custom Headers", help_text="To turn on custom headers check this. Custom header: [header titles=\"CUSTOM1;CUSTOM2\"]", default=False) | |
headers = models.CharField(blank=True, max_length=255) | |
class Meta: | |
verbose_name_plural = 'Plan Pricing' | |
def __unicode__(self): | |
return u'%s: %s' % (self.product.name, self.description) | |
class Category(models.Model): | |
""" | |
Benefit Category | |
Example "Provider Office Visits" | |
Uses shortcodes to parse benefits into tables | |
""" | |
product = models.ForeignKey(Product) | |
title = models.CharField(max_length=64) | |
cert_text = models.TextField(blank=True) | |
position = models.PositiveSmallIntegerField("Position") | |
is_popup = models.BooleanField("Make Popup-Modal", help_text="Check this box if you would like to make this information show in a modal.", default=False) | |
benefits = models.TextField( | |
'Benefit List', | |
help_text='List each benefit under the category in the form of "[benefit name=\"BENEFIT_NAME\" values=\"VALUE1;VALUE2;VALUE3;VALUE4\"]". For example: [benefit name="Benefit Per Visit" values="$50;$50;$75;$75;$100"]', | |
blank=True | |
) | |
custom_table_headers = models.BooleanField("Custom Headers", help_text="To turn on custom headers check this. Custom header: [header titles=\"CUSTOM1;CUSTOM2\"]", default=False) | |
headers = models.CharField(blank=True, max_length=255) | |
class Meta: | |
verbose_name_plural = 'Categories' | |
ordering = ['position'] | |
def __unicode__(self): | |
return u'%s' % self.title | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment