# 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
            raise ValueError(
                "Provider {p} doesn't have role {r}!".format(
                    p=user.provider, r=active_role))

        if active_role.signs_charts:
            assert active_role in user.provider.clinical_roles.all()

            self.signed_date = now()
            self.signer = user.provider
        else:
            raise ValueError("You must be an attending to sign workups.")

    def signed(self):
        '''Has this workup been attested? Returns True if yes, False if no.'''
        return self.signer is not None

    def attribution(self):
        '''Builds an attribution string of the form Doe, John on DATE'''
        return " ".join([str(self.author), "on", str(self.written_date())])


class ProgressNote(AttestableNote):
    title = models.CharField(max_length=200)
    text = models.TextField()

    history = HistoricalRecords()

    signer = models.ForeignKey(Provider,
                               blank=True, null=True,
                               related_name="signed_progress_notes",

# 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

            raise ValueError(
                "Provider {p} doesn't have role {r}!".format(
                    p=user.provider, r=active_role))

        if active_role.signs_charts:
            assert active_role in user.provider.clinical_roles.all()

            self.signed_date = now()
            self.signer = user.provider
        else:
            raise ValueError("You must be an attending to sign workups.")

    def signed(self):
        '''Has this workup been attested? Returns True if yes, False if no.'''
        return self.signer is not None

    def attribution(self):
        '''Builds an attribution string of the form Doe, John on DATE'''
        return " ".join([str(self.author), "on", str(self.written_date())])


class ProgressNote(AttestableNote):
    title = models.CharField(max_length=200)
    text = models.TextField()

    history = HistoricalRecords()

    signer = models.ForeignKey(Provider,
                               blank=True, null=True,
                               related_name="signed_progress_notes",

                               validators=[validate_attending])