Esempio n. 1
0
    def testCalculateEDD(self):
        # simple case first
        date = datetime.date(2010, 1, 1)
        edd = Report.calculate_edd(date)
        self.assertEquals(2010, edd.year)
        self.assertEquals(10, edd.month)
        self.assertEquals(8, edd.day)

        # assert the opposite
        menses = Report.calculate_last_menses(edd)
        self.assertEquals(2010, menses.year)
        self.assertEquals(1, menses.month)
        self.assertEquals(1, menses.day)

        # now one that rolls over
        date = datetime.date(2010, 5, 28)
        edd = Report.calculate_edd(date)
        self.assertEquals(2011, edd.year)
        self.assertEquals(3, edd.month)
        self.assertEquals(4, edd.day)

        # assert the opposite
        menses = Report.calculate_last_menses(edd)
        self.assertEquals(2010, menses.year)
        self.assertEquals(5, menses.month)
        self.assertEquals(28, menses.day)
Esempio n. 2
0
    def testCalculateEDD(self):
        # simple case first
        date = datetime.date(2010, 1, 1)
        edd = Report.calculate_edd(date)
        self.assertEquals(2010, edd.year)
        self.assertEquals(10, edd.month)
        self.assertEquals(8, edd.day)

        # assert the opposite
        menses = Report.calculate_last_menses(edd)
        self.assertEquals(2010, menses.year)
        self.assertEquals(1, menses.month)
        self.assertEquals(1, menses.day)

        # now one that rolls over
        date = datetime.date(2010, 5, 28)
        edd = Report.calculate_edd(date)
        self.assertEquals(2011, edd.year)
        self.assertEquals(3, edd.month)
        self.assertEquals(4, edd.day)

        # assert the opposite
        menses = Report.calculate_last_menses(edd)
        self.assertEquals(2010, menses.year)
        self.assertEquals(5, menses.month)
        self.assertEquals(28, menses.day)
Esempio 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))
    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
Esempio n. 5
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))
Esempio n. 6
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
Esempio n. 7
0
    def testCalculateReminderRange(self):
        # the edd reminder must happen one week before EDD, we bracket our 
        # query by 2 days in each direction to make sure to catch any stragglers.

        # let's say today is november 8th
        today = datetime.date(2010, 11, 8)

        # so we want to remind people who are going to deliver on the 15th
        edd = datetime.date(2010, 11, 15)

        # so those people had a last menses of Feb 8th
        menses = datetime.date(2010, 2, 8)

        (start, end) = Report.calculate_reminder_range(today, 7)

        # two days before menses
        self.assertEquals(2010, start.year)
        self.assertEquals(2, start.month)
        self.assertEquals(6, start.day)

        # two days after menses
        self.assertEquals(2010, end.year)
        self.assertEquals(2, end.month)
        self.assertEquals(10, end.day)
Esempio n. 8
0
    def testCalculateReminderRange(self):
        # the edd reminder must happen one week before EDD, we bracket our
        # query by 2 days in each direction to make sure to catch any stragglers.

        # let's say today is november 8th
        today = datetime.date(2010, 11, 8)

        # so we want to remind people who are going to deliver on the 15th
        edd = datetime.date(2010, 11, 15)

        # so those people had a last menses of Feb 8th
        menses = datetime.date(2010, 2, 8)

        (start, end) = Report.calculate_reminder_range(today, 7)

        # two days before menses
        self.assertEquals(2010, start.year)
        self.assertEquals(2, start.month)
        self.assertEquals(6, start.day)

        # two days after menses
        self.assertEquals(2010, end.year)
        self.assertEquals(2, end.month)
        self.assertEquals(10, end.day)