# Path: sendinel/settings.py
# REMINDER_TIME_BEFORE_APPOINTMENT = timedelta(days = 1)
# 
# Path: sendinel/backend/texthelper.py
# def date_to_text(weekday, day, month, hour, minutes):
# def generate_text(contents, template, is_sms = True):
# def get_content_length(contents):
# def replace_dollar_signs(contents):
# def reduce_contents(contents, chars_left):
# 
# Path: sendinel/backend/vcal.py
# def create_vcal_string(start_date, location, content, uid):
# def get_uid():
# 
# Path: sendinel/backend/models.py
# class Hospital(models.Model):
#     """
#     Represent a Hospital.
#     """
#     
#     name = models.CharField(max_length = 255)
#     current_hospital = models.BooleanField(default=True)
#     
#     def __unicode__(self):
#         return self.name
#     
#     @classmethod
#     def get_current_hospital(cls):
#         """
#         Return the standard current hospital
#         """
#         
#         try:
#             hospital = Hospital.objects.get(current_hospital = True)
#         except Hospital.DoesNotExist:
#             hospital = Hospital(name = DEFAULT_HOSPITAL_NAME, \
#             current_hospital = True)
#             hospital.save() 
#         return hospital    
# 
# class Sendable(models.Model):
#     """
#     Define an interface for a Sendable object.
#     """
# 
#     class Meta:
#         abstract = True
#         
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     recipient = models.ForeignKey(Patient)
#     
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.recipient), self.way_of_communication.verbose_name)
#     
#     def get_data_for_sending(self):
#         """
#         Prepare OutputData for selected way_of_communication.
#         Return an object of a subclass of OutputData.
#         """
#         
#         call = "self.get_data_for_%s()" % self.way_of_communication.name      
#         logger.info("sendable.get_data_for_sending() calling method: " + call)        
#         return eval(call)
#         
#     def create_scheduled_event(self, send_time):
#         """
#         Create a scheduled event for a specific send_time
#         @param send_time: Datetime object with the time of the reminder 
#         """        
#         scheduled_event = ScheduledEvent(sendable = self,
#                                          send_time = send_time)
#         scheduled_event.save()
# 
# Path: sendinel/backend/output.py
# class SMSOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via sms.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via SMS")
#         vc = voicecall.Voicecall()
#         return vc.conduct_sms(self.phone_number, self.data, "outbound-sms")
# 
# class VoiceOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via voice.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via Phone Call")
#         call = voicecall.Voicecall()
#         return call.conduct_call(self.phone_number, self.data, "outbound-call")
# 
# class BluetoothOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via bluetooth.
#     """
#     
#     bluetooth_mac_address = None
#     server_address = None
#     
#     def send(self):
#         logger.info("Sending via Bluetooth")
#         return bluetooth.send_vcal(self.server_address, 
#                             self.bluetooth_mac_address,
#                             self.data)
# 
# Path: sendinel/logger.py
# LOG_MSG_FORMAT = '%(asctime)s %(levelname)s %(filename)s#%(lineno)d %(message)s'
# def log_request(viewfunc):
#     def do_log_request(*args, **kwargs):


from string import Template
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from sendinel.settings import REMINDER_TIME_BEFORE_APPOINTMENT
from sendinel.backend import texthelper, vcal
from sendinel.backend.models import Hospital, Sendable
from sendinel.backend.output import SMSOutputData, \
                                    VoiceOutputData, \
                                    BluetoothOutputData
from sendinel.logger import logger     

    def get_data_for_bluetooth(self):
        """
        Prepare OutputData for voice.
        Generate the message for a Notification.
        Return BluetoothOutputData for sending.

        """
        logger.info("starting get_data_for_bluetooth() in Notification")
        
        data = BluetoothOutputData()
        data.bluetooth_mac_address = self.bluetooth_mac_address
        data.server_address = self.bluetooth_server_address
        
        logger.info("Sending to Bluetooth Mac Address " + data.bluetooth_mac_address +
                    " and Bluetooth Server " + data.server_address)
        
        try:
            self.hospital
        except Hospital.DoesNotExist:
            self.hospital = Hospital.get_current_hospital()
        
        content = self.reminder_text()

        uid = vcal.get_uid()
        data.data = vcal.create_vcal_string(self.date, 
                                            self.hospital, 
                                            content,
                                            uid)
                                            

# Path: sendinel/settings.py
# REMINDER_TIME_BEFORE_APPOINTMENT = timedelta(days = 1)
# 
# Path: sendinel/backend/texthelper.py
# def date_to_text(weekday, day, month, hour, minutes):
# def generate_text(contents, template, is_sms = True):
# def get_content_length(contents):
# def replace_dollar_signs(contents):
# def reduce_contents(contents, chars_left):
# 
# Path: sendinel/backend/vcal.py
# def create_vcal_string(start_date, location, content, uid):
# def get_uid():
# 
# Path: sendinel/backend/models.py
# class Hospital(models.Model):
#     """
#     Represent a Hospital.
#     """
#     
#     name = models.CharField(max_length = 255)
#     current_hospital = models.BooleanField(default=True)
#     
#     def __unicode__(self):
#         return self.name
#     
#     @classmethod
#     def get_current_hospital(cls):
#         """
#         Return the standard current hospital
#         """
#         
#         try:
#             hospital = Hospital.objects.get(current_hospital = True)
#         except Hospital.DoesNotExist:
#             hospital = Hospital(name = DEFAULT_HOSPITAL_NAME, \
#             current_hospital = True)
#             hospital.save() 
#         return hospital    
# 
# class Sendable(models.Model):
#     """
#     Define an interface for a Sendable object.
#     """
# 
#     class Meta:
#         abstract = True
#         
#     way_of_communication = models.ForeignKey(WayOfCommunication)
# 
#     recipient = models.ForeignKey(Patient)
#     
#     def __unicode__(self):
#         return "%s %s" % (unicode(self.recipient), self.way_of_communication.verbose_name)
#     
#     def get_data_for_sending(self):
#         """
#         Prepare OutputData for selected way_of_communication.
#         Return an object of a subclass of OutputData.
#         """
#         
#         call = "self.get_data_for_%s()" % self.way_of_communication.name      
#         logger.info("sendable.get_data_for_sending() calling method: " + call)        
#         return eval(call)
#         
#     def create_scheduled_event(self, send_time):
#         """
#         Create a scheduled event for a specific send_time
#         @param send_time: Datetime object with the time of the reminder 
#         """        
#         scheduled_event = ScheduledEvent(sendable = self,
#                                          send_time = send_time)
#         scheduled_event.save()
# 
# Path: sendinel/backend/output.py
# class SMSOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via sms.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via SMS")
#         vc = voicecall.Voicecall()
#         return vc.conduct_sms(self.phone_number, self.data, "outbound-sms")
# 
# class VoiceOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via voice.
#     """
#     
#     phone_number = None
#     
#     def send(self):
#         logger.info("Sending via Phone Call")
#         call = voicecall.Voicecall()
#         return call.conduct_call(self.phone_number, self.data, "outbound-call")
# 
# class BluetoothOutputData(OutputData):
#     """
#     Define necessary OutputData for sending via bluetooth.
#     """
#     
#     bluetooth_mac_address = None
#     server_address = None
#     
#     def send(self):
#         logger.info("Sending via Bluetooth")
#         return bluetooth.send_vcal(self.server_address, 
#                             self.bluetooth_mac_address,
#                             self.data)
# 
# Path: sendinel/logger.py
# LOG_MSG_FORMAT = '%(asctime)s %(levelname)s %(filename)s#%(lineno)d %(message)s'
# def log_request(viewfunc):
#     def do_log_request(*args, **kwargs):


# Path: sendinel/notifications/models.py
from string import Template
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from sendinel.settings import REMINDER_TIME_BEFORE_APPOINTMENT
from sendinel.backend import texthelper, vcal
from sendinel.backend.models import Hospital, Sendable
from sendinel.backend.output import SMSOutputData, \
                                    VoiceOutputData, \
                                    BluetoothOutputData
from sendinel.logger import logger     


    def get_data_for_bluetooth(self):
        """
        Prepare OutputData for voice.
        Generate the message for a Notification.
        Return BluetoothOutputData for sending.

        """
        logger.info("starting get_data_for_bluetooth() in Notification")
        
        data = BluetoothOutputData()
        data.bluetooth_mac_address = self.bluetooth_mac_address
        data.server_address = self.bluetooth_server_address
        
        logger.info("Sending to Bluetooth Mac Address " + data.bluetooth_mac_address +
                    " and Bluetooth Server " + data.server_address)
        
        try:
            self.hospital
        except Hospital.DoesNotExist:
            self.hospital = Hospital.get_current_hospital()
        
        content = self.reminder_text()

        uid = vcal.get_uid()
        data.data = vcal.create_vcal_string(self.date, 
                                            self.hospital, 
                                            content,
                                            uid)
                                            

        logger.info("Created vCal with uid %s" % str(uid))