Exemplo n.º 1
0
    def testEDDReminder(self):
        # our location
        location = Location.objects.get(code="F01001")

        # create a reporter
        reporter = Reporter.objects.create(first_name="Laurence",
                                           last_name="Lessig")

        # create a test patient
        patient = Patient.objects.create(location=location, national_id="101")

        # pregnancy type
        report_type = ReportType.objects.get(pk=4)

        # and a pregnancy report
        report = Report.objects.create(reporter=reporter,
                                       location=location,
                                       patient=patient,
                                       type=report_type)

        # our proxy current date
        today = datetime.date(2010, 11, 8)

        # the menses we will use, these people will deliver on the 15th
        last_menses = datetime.date(2010, 2, 8)

        date_string = "%02d.%02d.%d" % (last_menses.day, last_menses.month,
                                        last_menses.year)
        report.set_date_string(date_string)
        report.save()

        # our EDD reminder type
        edd_reminder = ReminderType.objects.get(pk=4)

        # get all the reports which need reminders now, which haven't already had an EDD
        # reminder
        reports = Report.get_reports_with_edd_in(today, 7, edd_reminder)

        self.assertEquals(1, len(reports))
        self.assertEquals(report.pk, reports[0].pk)

        # now insert a reminder for this report
        report.reminders.create(type=edd_reminder,
                                date=datetime.datetime.now(),
                                reporter=reporter)

        # and check that there are no pending reminders now
        reports = Report.get_reports_with_edd_in(today, 7, edd_reminder)
        self.assertEquals(0, len(reports))
    def check_reminders(self, today, days, reminder_type, to_sup=False):
        try:
            # get the matching reminders
            pending = Report.get_reports_with_edd_in(today, days,
                                                     reminder_type)

            # for each one, send a reminder
            for report in pending:
                if to_sup:
                    try:
                        print "supervisors of: %s" % report.reporter.alias

                        # look up the supervisors for the reporter's location
                        sups = Reporter.objects.filter(
                            location=report.reporter.location, groups__pk=2)
                        for sup in sups:
                            # determine the right messages to send for this reporter
                            message = reminder_type.message_kw
                            if sup.language == 'en':
                                message = reminder_type.message_en
                            elif sup.language == 'fr':
                                message = reminder_type.message_fr

                            message = message % report.patient.national_id

                            print "sending reminder to %s of '%s'" % (
                                sup.connection().identity, message)

                            # and send it off
                            if not self.dry:
                                self.send_message(sup.connection(), message)
                    except Reporter.DoesNotExist:
                        pass

                else:
                    try:
                        message = reminder_type.message_kw
                        if report.reporter.language == 'en':
                            message = reminder_type.message_en
                        elif report.reporter.language == 'fr':
                            message = reminder_type.message_fr

                        message = message % report.patient.national_id

                        print "sending reminder to %s of '%s'" % (
                            report.reporter.connection().identity, message)
                        if not self.dry:
                            self.send_message(report.reporter.connection(),
                                              message)
                    except Reporter.DoesNotExist:
                        pass

                if not self.dry:
                    report.reminders.create(type=reminder_type,
                                            date=datetime.datetime.now(),
                                            reporter=report.reporter)
        except Reporter.DoesNotExist:
            pass
Exemplo n.º 3
0
    def testEDDReminder(self):
        # our location
        location = Location.objects.get(code="F01001")

        # create a reporter
        reporter = Reporter.objects.create(first_name="Laurence", last_name="Lessig")

        # create a test patient
        patient = Patient.objects.create(location=location, national_id="101")

        # pregnancy type
        report_type = ReportType.objects.get(pk=4)

        # and a pregnancy report
        report = Report.objects.create(reporter=reporter, location=location,
                                       patient=patient, type=report_type)

        # our proxy current date
        today = datetime.date(2010, 11, 8)

        # the menses we will use, these people will deliver on the 15th
        last_menses = datetime.date(2010, 2, 8)

        date_string = "%02d.%02d.%d" % (last_menses.day, last_menses.month, last_menses.year)
        report.set_date_string(date_string)
        report.save()

        # our EDD reminder type
        edd_reminder = ReminderType.objects.get(pk=4)

        # get all the reports which need reminders now, which haven't already had an EDD
        # reminder
        reports = Report.get_reports_with_edd_in(today, 7, edd_reminder)

        self.assertEquals(1, len(reports))
        self.assertEquals(report.pk, reports[0].pk)

        # now insert a reminder for this report
        report.reminders.create(type=edd_reminder, date=datetime.datetime.now(), reporter=reporter)

        # and check that there are no pending reminders now
        reports = Report.get_reports_with_edd_in(today, 7, edd_reminder)
        self.assertEquals(0, len(reports))
Exemplo n.º 4
0
    def check_reminders(self, today, days, reminder_type, to_sup=False):
        try:
            # get the matching reminders
            pending = Report.get_reports_with_edd_in(today, days, reminder_type)

            # for each one, send a reminder
            for report in pending:
                if to_sup:
                    try:
                        print "supervisors of: %s" % report.reporter.alias
    
                        # look up the supervisors for the reporter's location
                        sups = Reporter.objects.filter(location=report.reporter.location, groups__pk=2)
                        for sup in sups:
                            # determine the right messages to send for this reporter
                            message = reminder_type.message_kw
                            if sup.language == 'en':
                                message = reminder_type.message_en
                            elif sup.language == 'fr':
                                message = reminder_type.message_fr

                            message = message % report.patient.national_id

                            print "sending reminder to %s of '%s'" % (sup.connection().identity, message)

                            # and send it off
                            if not self.dry:
                                self.send_message(sup.connection(), message)
                    except Reporter.DoesNotExist:
                        pass

                else:
                    try:
                        message = reminder_type.message_kw
                        if report.reporter.language == 'en':
                            message = reminder_type.message_en
                        elif report.reporter.language == 'fr':
                            message = reminder_type.message_fr

                        message = message % report.patient.national_id

                        print "sending reminder to %s of '%s'" % (report.reporter.connection().identity, message)
                        if not self.dry:
                            self.send_message(report.reporter.connection(), message)
                    except Reporter.DoesNotExist:
                        pass

                if not self.dry:
                    report.reminders.create(type=reminder_type, date=datetime.datetime.now(), reporter=report.reporter)
        except Reporter.DoesNotExist:
            pass