Skip to content

Commit

Permalink
Merge pull request #5203 from dimagi/opm
Browse files Browse the repository at this point in the history
don't crash on mothers with edd's way in the future
  • Loading branch information
esoergel committed Jan 5, 2015
2 parents d2a6eac + 40ee595 commit 1c3acfb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion custom/opm/beneficiary.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ def preg_month(self):
if not self.edd:
raise InvalidRow('No edd found for pregnant mother.')
base_window_start = add_months_to_date(self.edd, -9)
non_adjusted_month = len(months_between(base_window_start, self.reporting_window_start)) - 1
try:
non_adjusted_month = len(months_between(base_window_start, self.reporting_window_start)) - 1
except AssertionError:
raise InvalidRow('Mother LMP ({}) was after the reporting window date ({})'.format(
base_window_start, self.reporting_window_start
))

# the date to check one month after they first become eligible,
# aka the end of their fourth month of pregnancy
Expand Down
8 changes: 8 additions & 0 deletions custom/opm/tests/test_windows_and_months.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def test_not_yet_in_range(self):
)
self.assertRaises(InvalidRow, MockCaseRow, case, self.report)

def test_not_yet_in_range_by_a_lot(self):
# 12 or more months in the future you also don't count
case = OPMCase(
forms=[],
edd=self._offset_date(12),
)
self.assertRaises(InvalidRow, MockCaseRow, case, self.report)

def test_past_range(self):
# anytime after the period you don't count
case = OPMCase(
Expand Down

0 comments on commit 1c3acfb

Please sign in to comment.