Пример #1
0
 def test_mambo(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(
         slug=self.backend.slug)[0]
     patient, response = wfl.get_or_create_patient("BA1-1-08", \
                                                   phone_number="1250", \
                                                   backend=backend,
                                                   gender="f",
                                                   date_registered=datetime.now())
     schedule = EventSchedule(callback="weltel.callbacks.send_mambo", \
                              minutes='*', callback_args=[patient.id] )
     schedule.save()
     # speedup the scheduler so that 1 second == 1 minute
     self.router.start()
     self.router.get_app('scheduler').schedule_thread._debug_speedup(
         minutes=1)
     time.sleep(3.0)
     script = """
         1250 < Mambo?
         1250 < Mambo?
         1250 < Mambo?
     """
     self.runScript(script)
     self.router.stop()
     schedule.delete()
Пример #2
0
 def test_multiple_patient_creation(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     patient, response = wfl.get_or_create_patient("BA1-1-08", \
                                                   phone_number="1250", \
                                                   backend=backend, 
                                                   gender="f", 
                                                   date_registered=datetime.now())
     patient, response = wfl.get_or_create_patient("BA1-1-08", \
                                                   phone_number="1250", \
                                                   backend=backend, 
                                                   gender="f", 
                                                   date_registered=datetime.now())
     patient, response = wfl.get_or_create_patient("BA1-1-08", \
                                                   phone_number="1250", \
                                                   backend=backend, 
                                                   gender="f", 
                                                   date_registered=datetime.now())
     try:
         e = EventSchedule.objects.get(callback="weltel.callbacks.send_mambo",
                                       callback_args=[patient.id])
     except EventSchedule.DoesNotExist:
         self.fail('Mambo schedule not created with new patient')
     except EventSchedule.MultipleObjectsReturned:
         self.fail('Multiple mambo schedules created for a single patient')
Пример #3
0
 def test_shida_report(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     nurse, response = wfl.get_or_create_nurse(site_code="tst", \
                                               phone_number="1252", \
                                               backend=backend)
     # timeout after one week
     schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                              minutes='*')
     schedule.save()
     # create problem patients
     patient, response = wfl.get_or_create_patient("tst/10", \
                                                   phone_number="1257", \
                                                   backend=backend, 
                                                   gender="m",
                                                   date_registered=datetime.now())
     patient.register_event(SHIDA_CODE)
     # create problem patients
     patient2, response = wfl.get_or_create_patient("tst/11", \
                                                   phone_number="1258", \
                                                   backend=backend, 
                                                   gender="m",
                                                   date_registered=datetime.now())
     patient2.register_event(SHIDA_CODE)
     # speedup the scheduler so that 1 second == 7 days
     self.router.start()
     self.router.get_app('scheduler').schedule_thread._debug_speedup(minutes=1)
     time.sleep(1.0)
     # test regular report
     script = """
         1252 < tst/10 1257 shida tst/11 1258 shida
     """
     self.runScript(script)
     schedule.delete()
Пример #4
0
    def start(self):
        """Configure your app in the start phase."""
        if not self.bootstrapped:
            # initialize the forms app for registration
            self._form_app = self.router.get_app("form")
            # this tells the form app to add itself as a message handler
            # which registers the regex and function that this will dispatch to
            self._form_app.add_message_handler_to(self)

            formslogic = WeltelFormsLogic()
            formslogic.app = self
            # this tells the form app that this is also a form handler
            self._form_app.add_form_handler("weltel", formslogic)

            self.boostrapped = True

            # set up bi-daily shida report
            try:
                EventSchedule.objects.get(callback="weltel.callbacks.shida_report")
            except EventSchedule.DoesNotExist:
                schedule = EventSchedule(callback="weltel.callbacks.shida_report", hours=set([8, 14]), minutes=set([0]))
                schedule.save()

            # set up daily inactive check
            try:
                EventSchedule.objects.get(callback="weltel.callbacks.mark_inactive")
            except EventSchedule.DoesNotExist:
                set_daily_event("weltel.callbacks.mark_inactive", hour=0, minute=15, callback_args=[3])

            # set up daily 'other report'
            try:
                EventSchedule.objects.get(callback="weltel.callbacks.other_report")
            except EventSchedule.DoesNotExist:
                set_daily_event("weltel.callbacks.other_report", hour=14, minute=30, callback_args=[])
Пример #5
0
 def start (self):
     """Configure your app in the start phase."""
     if not self.bootstrapped:
         # initialize the forms app for registration
         self._form_app = self.router.get_app("form")
         # this tells the form app to add itself as a message handler
         # which registers the regex and function that this will dispatch to
         self._form_app.add_message_handler_to(self)
         
         formslogic = WeltelFormsLogic()
         formslogic.app = self
         # this tells the form app that this is also a form handler 
         self._form_app.add_form_handler("weltel", formslogic)
         
         self.boostrapped = True
         
         # we could also put this in the fixture
         # set up automatic deregistration event
         try:
             EventSchedule.objects.get(callback="weltel.callbacks.automatic_deregistration")
         except EventSchedule.DoesNotExist:
             # automatically deregister users we haven't seen in 3 weeks
             set_daily_event("weltel.callbacks.automatic_deregistration", \
                             hour=0, minute=15, callback_args=3)
             
         # set up bi-weekly shida report
         try:
             EventSchedule.objects.get(callback="weltel.callbacks.shida_report")
         except EventSchedule.DoesNotExist:
             schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                                      hours=set([8,15]), minutes=set([0]) )
             schedule.save()
Пример #6
0
    def test_automatic_deregistration(self):
        # create patient
        wfl = WeltelFormsLogic()
        backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
        delta = timedelta(weeks=3)
        registered = datetime.now() - delta
        patient, response = wfl.get_or_create_patient("tst/9", \
                                                      phone_number="1251", \
                                                      backend=backend, 
                                                      gender="m", 
                                                      date_registered=registered)
        # setup timeout after one week
        schedule = EventSchedule(callback="weltel.callbacks.automatic_deregistration", \
                                 days_of_week='*', hours='*', minutes='*', callback_args=[1] )
        schedule.save()
        self.router.start()
        # speedup the scheduler so that 1 second == 7 days
        self.router.get_app('scheduler').schedule_thread._debug_speedup(days=7)

        # test tst/9 is inactive
        time.sleep(3.0)
        updated_patient = Patient.objects.get(id=patient.id)
        self.assertTrue(updated_patient.active==False)

        # reactivate
        patient.register_event(SAWA_CODE)
        time.sleep(1.0)
        updated_patient = Patient.objects.get(id=patient.id)
        self.assertTrue(updated_patient.active==True)
        
        #wrap up
        self.router.stop()
        schedule.delete()
Пример #7
0
    def test_shida_report_basic(self):
        """ it's difficult to check shida_empty and shida in sequence
        since self.runScript stops the router (without any sleep's)
        and we rely on activities in different threads)
        """
        wfl = WeltelFormsLogic()
        backend = PersistantBackend.objects.get_or_create(
            slug=self.backend.slug)[0]
        nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                                  phone_number="1252", \
                                                  backend=backend)
        # timeout after one week
        schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                                 minutes='*')
        schedule.save()
        # speedup the scheduler so that 1 second == 7 days
        self.router.start()
        self.router.get_app('scheduler').schedule_thread._debug_speedup(
            minutes=1)
        time.sleep(1.0)
        # test regular report
        script = """
            1252 < No problem patients
        """
        self.runScript(script)

        # wrap up
        self.router.stop()
        schedule.delete()
Пример #8
0
 def test_shida_report_basic(self):
     """ it's difficult to check shida_empty and shida in sequence
     since self.runScript stops the router (without any sleep's)
     and we rely on activities in different threads)
     """
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     nurse, response = wfl.get_or_create_nurse(site_code="tst", \
                                               phone_number="1252", \
                                               backend=backend)
     # timeout after one week
     schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                              minutes='*')
     schedule.save()
     # speedup the scheduler so that 1 second == 7 days
     self.router.start()
     self.router.get_app('scheduler').schedule_thread._debug_speedup(minutes=1)
     time.sleep(1.0)
     # test regular report
     script = """
         1252 < No problem patients
     """
     self.runScript(script)
     
     # wrap up
     self.router.stop()
     schedule.delete()
Пример #9
0
 def test_nurse_subscription(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                               phone_number="1252", \
                                               backend=backend)
     self.assertTrue(nurse.subscribed==True)
     nurse.unsubscribe()
     self.assertTrue(nurse.subscribed==False)
     nurse.subscribe()
     self.assertTrue(nurse.subscribed==True)
Пример #10
0
    def test_inactive_and_other(self):
        # create patient
        wfl = WeltelFormsLogic()
        backend = PersistantBackend.objects.get_or_create(
            slug=self.backend.slug)[0]
        delta = timedelta(weeks=3)
        registered = datetime.now() - delta
        patient, response = wfl.get_or_create_patient("BA1-1-09", \
                                                      phone_number="1251", \
                                                      backend=backend,
                                                      gender="m",
                                                      date_registered=registered)
        nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                                  phone_number="1252", \
                                                  backend=backend)
        # setup timeout after one week
        schedule_inactive = EventSchedule(callback="weltel.callbacks.mark_inactive", \
                                 days_of_week='*', hours='*', minutes='*', callback_args=[1] )
        schedule_inactive.save()
        # other report
        schedule_other_report = EventSchedule(callback="weltel.callbacks.other_report", \
                                 minutes='*')
        schedule_other_report.save()
        self.router.start()
        # speedup the scheduler so that 1 second == 7 days
        self.router.get_app('scheduler').schedule_thread._debug_speedup(days=8)

        # test BA109 is inactive
        time.sleep(3.0)
        updated_patient = Patient.objects.get(id=patient.id)
        self.assertTrue(updated_patient.active == False)

        # test regular report
        script = """
            1252 < Inactive: 09-1251
        """
        self.runScript(script)

        # reactivate
        patient.register_event(SAWA_CODE)
        time.sleep(1.0)
        updated_patient = Patient.objects.get(id=patient.id)
        self.assertTrue(updated_patient.active == True)

        #wrap up
        self.router.stop()
        schedule_inactive.delete()
        schedule_other_report.delete()
Пример #11
0
 def test_inactive_and_other(self):
     # create patient
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     delta = timedelta(weeks=3)
     registered = datetime.now() - delta
     patient, response = wfl.get_or_create_patient("BA1-1-09", \
                                                   phone_number="1251", \
                                                   backend=backend, 
                                                   gender="m", 
                                                   date_registered=registered)
     nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                               phone_number="1252", \
                                               backend=backend)
     # setup timeout after one week
     schedule_inactive = EventSchedule(callback="weltel.callbacks.mark_inactive", \
                              days_of_week='*', hours='*', minutes='*', callback_args=[1] )
     schedule_inactive.save()
     # other report
     schedule_other_report = EventSchedule(callback="weltel.callbacks.other_report", \
                              minutes='*')
     schedule_other_report.save()
     self.router.start()
     # speedup the scheduler so that 1 second == 7 days
     self.router.get_app('scheduler').schedule_thread._debug_speedup(days=8)
 
     # test BA109 is inactive
     time.sleep(3.0)
     updated_patient = Patient.objects.get(id=patient.id)
     self.assertTrue(updated_patient.active==False)
 
     # test regular report
     script = """
         1252 < Inactive: 09-1251
     """
     self.runScript(script)
     
     # reactivate
     patient.register_event(SAWA_CODE)
     time.sleep(1.0)
     updated_patient = Patient.objects.get(id=patient.id)
     self.assertTrue(updated_patient.active==True)
     
     #wrap up
     self.router.stop()
     schedule_inactive.delete()
     schedule_other_report.delete()
Пример #12
0
    def test_other_report_the_day_after(self):
        # create patient
        wfl = WeltelFormsLogic()
        backend = PersistantBackend.objects.get_or_create(
            slug=self.backend.slug)[0]
        delta = timedelta(weeks=3)
        registered = datetime.now() - delta
        patient, response = wfl.get_or_create_patient("BA1-1-09", \
                                                      phone_number="1251", \
                                                      backend=backend,
                                                      gender="m",
                                                      date_registered=registered)
        # configure patient ot be inactivated 3 weeks ago
        patient.register_event(INACTIVE_CODE)
        patient.active = False
        patient.save()
        inactive = EventType.objects.get(code=INACTIVE_CODE)
        inactivated = EventLog.objects.get(patient=patient, event=inactive)
        inactivated.date = datetime.now() - delta
        inactivated.save()

        nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                                  phone_number="1252", \
                                                  backend=backend)
        # other report
        schedule = EventSchedule(callback="weltel.callbacks.other_report", \
                                 minutes='*')
        schedule.save()
        self.router.start()
        # speedup the scheduler so that 1 second == 7 days
        self.router.get_app('scheduler').schedule_thread._debug_speedup(days=8)

        # test BA109 does not appear in shida_report
        time.sleep(1.0)
        script = """
            1252 < No patients unsubscribed or were marked inactive today.
        """
        self.runScript(script)

        #wrap up
        self.router.stop()
        schedule.delete()
Пример #13
0
    def test_other_report_the_day_after(self):
        # create patient
        wfl = WeltelFormsLogic()
        backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
        delta = timedelta(weeks=3)
        registered = datetime.now() - delta
        patient, response = wfl.get_or_create_patient("BA1-1-09", \
                                                      phone_number="1251", \
                                                      backend=backend, 
                                                      gender="m", 
                                                      date_registered=registered)
        # configure patient ot be inactivated 3 weeks ago
        patient.register_event(INACTIVE_CODE)
        patient.active = False
        patient.save()
        inactive = EventType.objects.get(code=INACTIVE_CODE)
        inactivated = EventLog.objects.get(patient=patient, event=inactive)
        inactivated.date = datetime.now() - delta
        inactivated.save()
        
        nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                                  phone_number="1252", \
                                                  backend=backend)
        # other report
        schedule = EventSchedule(callback="weltel.callbacks.other_report", \
                                 minutes='*')
        schedule.save()
        self.router.start()
        # speedup the scheduler so that 1 second == 7 days
        self.router.get_app('scheduler').schedule_thread._debug_speedup(days=8)

        # test BA109 does not appear in shida_report
        time.sleep(1.0)        
        script = """
            1252 < No patients unsubscribed or were marked inactive today.
        """
        self.runScript(script)

        #wrap up
        self.router.stop()
        schedule.delete()
Пример #14
0
 def test_mambo(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     patient, response = wfl.get_or_create_patient("tst/8", \
                                                   phone_number="1250", \
                                                   backend=backend, 
                                                   gender="f", 
                                                   date_registered=datetime.now())
     schedule = EventSchedule(callback="weltel.callbacks.send_mambo", \
                              minutes='*', callback_args=[patient.id] )
     schedule.save()
     # speedup the scheduler so that 1 second == 1 minute
     self.router.start()
     self.router.get_app('scheduler').schedule_thread._debug_speedup(minutes=1)
     time.sleep(3.0)
     script = """
         1250 < Mambo?
         1250 < Mambo?
         1250 < Mambo?
     """
     self.runScript(script)
     self.router.stop()
     schedule.delete()
Пример #15
0
 def test_shida_report(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(slug=self.backend.slug)[0]
     nurse, response = wfl.get_or_create_nurse(site_code="tst", \
                                               phone_number="1252", \
                                               backend=backend)
     # timeout after one week
     schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                              minutes='*')
     schedule.save()
     # speedup the scheduler so that 1 second == 7 days
     self.router.start()
     self.router.get_app('scheduler').schedule_thread._debug_speedup(minutes=1)
     time.sleep(1.0)
     # test regular report
     script = """
         1252 < No problem patients
     """
     self.runScript(script)
     
     # wrap up
     self.router.stop()
     schedule.delete()
Пример #16
0
    def start (self):
        """Configure your app in the start phase."""
        if not self.bootstrapped:
            # initialize the forms app for registration
            self._form_app = self.router.get_app("form")
            # this tells the form app to add itself as a message handler
            # which registers the regex and function that this will dispatch to
            self._form_app.add_message_handler_to(self)
            
            formslogic = WeltelFormsLogic()
            formslogic.app = self
            # this tells the form app that this is also a form handler 
            self._form_app.add_form_handler("weltel", formslogic)
            
            self.boostrapped = True
            
            # set up bi-daily shida report
            try:
                EventSchedule.objects.get(callback="weltel.callbacks.shida_report")
            except EventSchedule.DoesNotExist:
                schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                                         hours=set([8,14]), minutes=set([0]) )
                schedule.save()

            # set up daily inactive check
            try:
                EventSchedule.objects.get(callback="weltel.callbacks.mark_inactive")
            except EventSchedule.DoesNotExist:
                set_daily_event("weltel.callbacks.mark_inactive", 
                                hour=0, minute=15, callback_args=[3])

            # set up daily 'other report'
            try:
                EventSchedule.objects.get(callback="weltel.callbacks.other_report")
            except EventSchedule.DoesNotExist:
                set_daily_event("weltel.callbacks.other_report", 
                                hour=14, minute=30, callback_args=[])
Пример #17
0
 def test_shida_report(self):
     wfl = WeltelFormsLogic()
     backend = PersistantBackend.objects.get_or_create(
         slug=self.backend.slug)[0]
     nurse, response = wfl.get_or_create_nurse(site_code="BA1-1", \
                                               phone_number="1252", \
                                               backend=backend)
     # timeout after one week
     schedule = EventSchedule(callback="weltel.callbacks.shida_report", \
                              minutes='*')
     schedule.save()
     # create problem patients
     patient, response = wfl.get_or_create_patient("BA1-1-010", \
                                                   phone_number="1257", \
                                                   backend=backend,
                                                   gender="m",
                                                   date_registered=datetime.now())
     patient.register_event(SHIDA_CODE)
     # create problem patients
     patient2, response = wfl.get_or_create_patient("BA1-1-011", \
                                                   phone_number="1258", \
                                                   backend=backend,
                                                   gender="m",
                                                   date_registered=datetime.now())
     patient2.register_event(SHIDA_CODE)
     # speedup the scheduler so that 1 second == 7 days
     self.router.start()
     self.router.get_app('scheduler').schedule_thread._debug_speedup(
         minutes=1)
     time.sleep(1.0)
     # test regular report
     script = """
         1252 < 010-1257 011-1258
     """
     self.runScript(script)
     schedule.delete()