# Path: workup/models.py
# 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) |
#                                        Q(other_volunteer__clinic_day=self)) \
#                                .distinct()
# 
#     def infer_coordinators(self):
#         cd = self.clinic_date
# 
#         written_timeframe = (
#             Q(actionitem__written_datetime__lte=cd) &
#             Q(actionitem__written_datetime__gte=cd -
#               datetime.timedelta(days=1))
#         )
# 
#         cleared_timeframe = (
#             Q(pttrack_actionitem_completed__completion_date__lte=cd) &
#             Q(pttrack_actionitem_completed__completion_date__gte=cd -
#               datetime.timedelta(days=1))
#         )
# 
#         coordinator_set = Provider.objects \
#             .filter(written_timeframe | cleared_timeframe)\
#             .distinct()
# 
#         return coordinator_set


from django.shortcuts import render, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.conf import settings
from workup.models import ClinicDate
from pttrack.models import Patient
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function




def dashboard_dispatch(request):
    """Redirect an incoming user to the appropriate dashboard.

    Falls back to the 'home' url.
    """

    provider_type = request.session['clintype_pk']
    dashboard_dispatch = settings.OSLER_PROVIDERTYPE_DASHBOARDS

    if provider_type in dashboard_dispatch:
        return redirect(dashboard_dispatch[provider_type])
    else:
        return redirect(settings.OSLER_DEFAULT_DASHBOARD)


def dashboard_attending(request):

    provider = request.user.provider


# Path: workup/models.py
# 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) |
#                                        Q(other_volunteer__clinic_day=self)) \
#                                .distinct()
# 
#     def infer_coordinators(self):
#         cd = self.clinic_date
# 
#         written_timeframe = (
#             Q(actionitem__written_datetime__lte=cd) &
#             Q(actionitem__written_datetime__gte=cd -
#               datetime.timedelta(days=1))
#         )
# 
#         cleared_timeframe = (
#             Q(pttrack_actionitem_completed__completion_date__lte=cd) &
#             Q(pttrack_actionitem_completed__completion_date__gte=cd -
#               datetime.timedelta(days=1))
#         )
# 
#         coordinator_set = Provider.objects \
#             .filter(written_timeframe | cleared_timeframe)\
#             .distinct()
# 
#         return coordinator_set


# Path: dashboard/views.py
from django.shortcuts import render, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.conf import settings
from workup.models import ClinicDate
from pttrack.models import Patient

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




def dashboard_dispatch(request):
    """Redirect an incoming user to the appropriate dashboard.

    Falls back to the 'home' url.
    """

    provider_type = request.session['clintype_pk']
    dashboard_dispatch = settings.OSLER_PROVIDERTYPE_DASHBOARDS

    if provider_type in dashboard_dispatch:
        return redirect(dashboard_dispatch[provider_type])
    else:
        return redirect(settings.OSLER_DEFAULT_DASHBOARD)


def dashboard_attending(request):

    provider = request.user.provider


    clinic_list = ClinicDate.objects.filter(workup__attending=provider)