# Path: pttrack/validators.py
# def validate_attending(value):
#     '''
#     Verify that a provider has attending priviledges.
#     '''
# 
#     Provider = apps.get_model('pttrack', 'Provider')
#     attending = Provider.objects.get(pk=value)
# 
#     if not attending.clinical_roles.filter(signs_charts=True).exists():
#         raise ValidationError("This provider is not allowed to sign charts.")


from builtins import str
from builtins import object
from django.db import models
from django.db.models import Q
from django.utils.timezone import now
from simple_history.models import HistoricalRecords
from django.core.urlresolvers import reverse
from django.core.validators import MinValueValidator
from pttrack.models import Note, Provider, ReferralLocation, ReferralType
from pttrack.validators import validate_attending
from . import validators as workup_validators
import datetime
    name = models.CharField(max_length=50)

    def __str__(self):
        return self.name


class ClinicDate(models.Model):

    class Meta(object):
        ordering = ["-clinic_date"]

    clinic_type = models.ForeignKey(ClinicType)

    clinic_date = models.DateField()

    def __str__(self):
        return (str(self.clinic_type) + " on " +
                datetime.datetime.strftime(self.clinic_date, '%A, %B %d, %Y'))

    def number_of_notes(self):
            return self.workup_set.count()

    def infer_attendings(self):
        qs = Provider.objects.filter(
            Q(attending_physician__clinic_day=self) |
            Q(signed_workups__clinic_day=self)).distinct()

        return qs

    def infer_volunteers(self):

# Path: pttrack/validators.py
# def validate_attending(value):
#     '''
#     Verify that a provider has attending priviledges.
#     '''
# 
#     Provider = apps.get_model('pttrack', 'Provider')
#     attending = Provider.objects.get(pk=value)
# 
#     if not attending.clinical_roles.filter(signs_charts=True).exists():
#         raise ValidationError("This provider is not allowed to sign charts.")


# Path: workup/models.py
from builtins import str
from builtins import object
from django.db import models
from django.db.models import Q
from django.utils.timezone import now
from simple_history.models import HistoricalRecords
from django.core.urlresolvers import reverse
from django.core.validators import MinValueValidator
from pttrack.models import Note, Provider, ReferralLocation, ReferralType
from pttrack.validators import validate_attending
from . import validators as workup_validators
import datetime

    name = models.CharField(max_length=50)

    def __str__(self):
        return self.name


class ClinicDate(models.Model):

    class Meta(object):
        ordering = ["-clinic_date"]

    clinic_type = models.ForeignKey(ClinicType)

    clinic_date = models.DateField()

    def __str__(self):
        return (str(self.clinic_type) + " on " +
                datetime.datetime.strftime(self.clinic_date, '%A, %B %d, %Y'))

    def number_of_notes(self):
            return self.workup_set.count()

    def infer_attendings(self):
        qs = Provider.objects.filter(
            Q(attending_physician__clinic_day=self) |
            Q(signed_workups__clinic_day=self)).distinct()

        return qs

    def infer_volunteers(self):

        return Provider.objects.filter(Q(workup__clinic_day=self) |