Esempio n. 1
0
 def verify_config (self):
     """perform some basic validation for the config, namely that notifications for all days are
     defined in all languages"""
     if config.default_language not in config.itext:
         raise ValueError('default language [%s] not defined' % config.default_language)
     
     for lang in config.itext.keys():
         for day in config.notification_days:
             try:
                 get_notification(day, lang)
             except ValueError:
                 raise ValueError('no notification set for day %d in language [%s]' % (day, lang))
Esempio n. 2
0
def sending_report():
    #if each day's message is not unique within a given language, we won't be able to
    #reliably tell when a particular day's message was sent
    validate_message_uniqueness()

    sendlog = []

    patients = Registration.objects.filter(contact_time__isnull=False)
    messages = Message.objects.filter(direction='O')
    scheduled_msgs = EventSchedule.objects.all()

    for p in patients:
        for d in config.notification_days:
            try:
                event = scheduled_msgs.get(description='patient %s; day %d' % (p.patient_id, d))
                scheduled_send = normalize_datetime(event.start_time)
                should_be_sent = event.start_time <= datetime.now()
            except EventSchedule.DoesNotExist:
                scheduled_send = None
                should_be_sent = False

            text = get_notification(d, p.language) % {}
            #messages in localization config are escaped, while those in message log are not

            try:
                outgoing = messages.get(text=text, connection=p.connection)
                sent_on = normalize_datetime(outgoing.date)
            except Message.DoesNotExist:
                sent_on = None

            sendlog.append({'pat': p.patient_id, 'day': d, 'sched': scheduled_send, 'sent': sent_on, 'should_be_sent': should_be_sent})

    return sendlog
Esempio n. 3
0
def send_notification (router, patient_pk, day):
    """send the notification for day N"""
    reg = Registration.objects.get(pk=patient_pk)
    send_message(reg.connection, get_notification(day, reg.language))
    #check for success?
    
    log = SentNotif(patient_id=reg, day=day)
    log.save()
Esempio n. 4
0
def validate_message_uniqueness():
    for lang in config.itext:
        msgs = [get_notification(d, lang) for d in config.notification_days]
        if len(set(msgs)) != len(config.notification_days):
            raise ValueError('messages for language [%s] are not unique!' % lang)