# Path: pttrack/views.py
# class NoteFormView(FormView):
#     note_type = None
# 
#     def get_context_data(self, **kwargs):
#         '''Inject self.note_type and patient into the context.'''
# 
#         if self.note_type is None:
#             raise ImproperlyConfigured("NoteCreate view must have" +
#                                        "'note_type' variable set.")
# 
#         context = super(NoteFormView, self).get_context_data(**kwargs)
#         context['note_type'] = self.note_type
# 
#         if 'pt_id' in self.kwargs:
#             context['patient'] = mymodels.Patient.objects. \
#                 get(pk=self.kwargs['pt_id'])
# 
#         return context
# 
# class NoteUpdate(UpdateView):
#     note_type = None
# 
#     def get_context_data(self, **kwargs):
#         '''Inject self.note_type as the note type.'''
# 
#         if self.note_type is None:
#             raise ImproperlyConfigured("NoteUpdate view must have" +
#                                        "'note_type' variable set.")
# 
#         context = super(NoteUpdate, self).get_context_data(**kwargs)
#         context['note_type'] = self.note_type
# 
#         return context
# 
#     # TODO: add shared form_valid code here from all subclasses.
# 
# def get_current_provider_type(request):
#     '''
#     Given the request, produce the ProviderType of the logged in user. This is
#     done using session data.
#     '''
#     return get_object_or_404(mymodels.ProviderType,
#                              pk=request.session['clintype_pk'])


from builtins import str
from django.shortcuts import get_object_or_404, render
from django.http import (HttpResponseRedirect, HttpResponseServerError,
                         HttpResponse)
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template.loader import get_template
from django.utils.timezone import now
from django.views.generic.edit import FormView
from django.conf import settings
from pttrack.views import NoteFormView, NoteUpdate, get_current_provider_type
from pttrack.models import Patient, ProviderType
from xhtml2pdf import pisa
from . import models
from . import forms
from tempfile import TemporaryFile
        wu_previous = pt.latest_workup()
        if wu_previous is not None:
            date_string = wu_previous.written_datetime.strftime("%B %d, %Y")
            for field in settings.OSLER_WORKUP_COPY_FORWARD_FIELDS:
                initial[field] = settings.OSLER_WORKUP_COPY_FORWARD_MESSAGE.\
                    format(date=date_string,
                           contents=getattr(wu_previous, field))

        return initial

    def form_valid(self, form):
        pt = get_object_or_404(Patient, pk=self.kwargs['pt_id'])
        active_provider_type = get_object_or_404(
            ProviderType,
            pk=self.request.session['clintype_pk'])

        wu = form.save(commit=False)
        wu.patient = pt
        wu.author = self.request.user.provider
        wu.author_type = get_current_provider_type(self.request)
        if wu.author_type.signs_charts:
            wu.sign(self.request.user, active_provider_type)

        wu.save()

        form.save_m2m()

        return HttpResponseRedirect(reverse("patient-detail", args=(pt.id,)))



# Path: pttrack/views.py
# class NoteFormView(FormView):
#     note_type = None
# 
#     def get_context_data(self, **kwargs):
#         '''Inject self.note_type and patient into the context.'''
# 
#         if self.note_type is None:
#             raise ImproperlyConfigured("NoteCreate view must have" +
#                                        "'note_type' variable set.")
# 
#         context = super(NoteFormView, self).get_context_data(**kwargs)
#         context['note_type'] = self.note_type
# 
#         if 'pt_id' in self.kwargs:
#             context['patient'] = mymodels.Patient.objects. \
#                 get(pk=self.kwargs['pt_id'])
# 
#         return context
# 
# class NoteUpdate(UpdateView):
#     note_type = None
# 
#     def get_context_data(self, **kwargs):
#         '''Inject self.note_type as the note type.'''
# 
#         if self.note_type is None:
#             raise ImproperlyConfigured("NoteUpdate view must have" +
#                                        "'note_type' variable set.")
# 
#         context = super(NoteUpdate, self).get_context_data(**kwargs)
#         context['note_type'] = self.note_type
# 
#         return context
# 
#     # TODO: add shared form_valid code here from all subclasses.
# 
# def get_current_provider_type(request):
#     '''
#     Given the request, produce the ProviderType of the logged in user. This is
#     done using session data.
#     '''
#     return get_object_or_404(mymodels.ProviderType,
#                              pk=request.session['clintype_pk'])


# Path: workup/views.py
from builtins import str
from django.shortcuts import get_object_or_404, render
from django.http import (HttpResponseRedirect, HttpResponseServerError,
                         HttpResponse)
from django.core.urlresolvers import reverse
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.template.loader import get_template
from django.utils.timezone import now
from django.views.generic.edit import FormView
from django.conf import settings
from pttrack.views import NoteFormView, NoteUpdate, get_current_provider_type
from pttrack.models import Patient, ProviderType
from xhtml2pdf import pisa
from . import models
from . import forms
from tempfile import TemporaryFile

        wu_previous = pt.latest_workup()
        if wu_previous is not None:
            date_string = wu_previous.written_datetime.strftime("%B %d, %Y")
            for field in settings.OSLER_WORKUP_COPY_FORWARD_FIELDS:
                initial[field] = settings.OSLER_WORKUP_COPY_FORWARD_MESSAGE.\
                    format(date=date_string,
                           contents=getattr(wu_previous, field))

        return initial

    def form_valid(self, form):
        pt = get_object_or_404(Patient, pk=self.kwargs['pt_id'])
        active_provider_type = get_object_or_404(
            ProviderType,
            pk=self.request.session['clintype_pk'])

        wu = form.save(commit=False)
        wu.patient = pt
        wu.author = self.request.user.provider
        wu.author_type = get_current_provider_type(self.request)
        if wu.author_type.signs_charts:
            wu.sign(self.request.user, active_provider_type)

        wu.save()

        form.save_m2m()

        return HttpResponseRedirect(reverse("patient-detail", args=(pt.id,)))



class WorkupUpdate(NoteUpdate):