Exemple #1
0
    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))
        logger.debug("Created vCal: " + data.data)
        
        return data
Exemple #2
0
def send_message(request):
    '''
        Display the form and send a message to all 
        patients waiting for the medicine. 
        Afterwards, the medicine information group is deleted.
    '''
    if request.method == 'POST':
        form = MedicineMessageValidationForm(request.POST)
        
        if form.is_valid():
            med_id = form.cleaned_data['medicine'].pk
            medicine = get_object_or_404(InfoService, pk = med_id)
            create_messages_for_infoservice(medicine, form.cleaned_data['text'])
                
            medicine.delete()
            
            backurl = reverse('medicines_send_message')
            nexturl = reverse('web_index')
            title = _("Message created")
            message = _("All patients who were waiting for the medicine "
                        "\"%s\" will be informed. The waiting list"
                        " will also be removed.") % medicine.name
            new_button_label = _("Send another message")
            success = True

            return render_to_response('web/status_message.html', 
                          locals(),
                          context_instance = RequestContext(request))
                                      
    medicines = []
    for medicine in InfoService.objects.all().filter(type='medicine'):
        if medicine.members.count() > 0:
            medicines.append(medicine)
    
    current_hospital = Hospital.get_current_hospital()
    template_text = MEDICINE_MESSAGE_TEMPLATE
    template_text = template_text.replace("$hospital", current_hospital.name)
    return render_to_response('medicine/message_create.html',
                              locals(),
                              context_instance = RequestContext(request))
 def test_get_hospital_with_hospital(self):
     hospital = Hospital.objects.get(current_hospital = True)
     self.assertEquals(Hospital.get_current_hospital(), hospital)
 def test_get_hospital_no_hospital(self):
     Hospital.objects.all().delete()
     hospital = Hospital.get_current_hospital()
     self.assertTrue(1, Hospital.objects.all().count())
     self.assertEquals(Hospital.objects.all()[0].name, settings.DEFAULT_HOSPITAL_NAME)
     self.assertEquals(hospital.name, settings.DEFAULT_HOSPITAL_NAME)
Exemple #5
0
def create_notification(request, notification_type_name = None):
    '''
        Display the form and creates a new notification, but does not
        save it yet. Redirect to authentication if switched on
    '''
    notification_type = NotificationType.objects. \
                              filter(name = notification_type_name)[0]
    nexturl = ""
    backurl = reverse('web_index')
    
    ways_of_communication = get_ways_of_communication(
                                    notification_type.notify_immediately)
    
    if request.method == "POST":
        data = deepcopy(request.POST)
        if notification_type.notify_immediately:
            data['date'] = date.today().strftime('%Y-%m-%d') + \
                            ' ' + DEFAULT_SEND_TIME
        else:
            data['date'] = data.get('date', '') + ' ' + DEFAULT_SEND_TIME
			
        form = NotificationValidationForm(data)

        woc = get_woc_by_id( request.POST['way_of_communication'] )
        if not woc.can_send_immediately:
		    form = NotificationValidationFormBluetooth(data)
		
        if form.is_valid():
            notification = Notification()
            patient = Patient()
            if woc.can_send_immediately:
                patient.phone_number = form.cleaned_data['phone_number']
            notification.date = form.cleaned_data['date']
            notification.notification_type = notification_type
            notification.hospital = Hospital.get_current_hospital()
            notification.way_of_communication = \
                                    form.cleaned_data['way_of_communication']
                                    
            request.session['notification'] = notification
            request.session['patient'] = patient            
            
            logger.info("Create notification via %s" %
                            notification.way_of_communication.verbose_name)
            if notification.way_of_communication == get_woc('bluetooth'):
                return HttpResponseRedirect(reverse("web_list_devices") + \
                                "?next=" + reverse("notifications_send"))
            elif notification.way_of_communication.name in ('sms', 'voice' ):
                return redirect_to_authentication_or(
                                reverse("notifications_save"))

            else:
                logger.error("Unknown way of communication selected.")
                raise Exception ("Unknown way of communication %s " \
                                 %notification.way_of_communication.\
                                 verbose_name + "(this is neither " + \
                                 "bluetooth nor sms or voice)") 
                                
        else:
        
            logger.info("create_notification: Invalid form.")
        
    return render_to_response('notifications/create.html',
                            locals(),
                            context_instance=RequestContext(request))