MotherReportingService { public void closeANC(SafeMap reportData) { Mother mother = allMothers.findByCaseId(reportData.get(ID)); Location location = loadLocationFromEC(mother); String closeReason = reportData.get(CLOSE_REASON_FIELD_NAME); if (WRONG_ENTRY_VALUE.equalsIgnoreCase(closeReason)) { deleteReports(reportData.get(ID)); return; } if (DEATH_OF_WOMAN_VALUE.equals(closeReason) && BOOLEAN_TRUE_VALUE.equalsIgnoreCase(reportData.get(IS_MATERNAL_LEAVE_FIELD_NAME))) { reportDeath(mother, MMA, reportData.get(ANC_DEATH_DATE_FIELD_NAME), reportData.get(SUBMISSION_DATE_FIELD_NAME), location); return; } reportAbortion(reportData, mother, location); } @Autowired  MotherReportingService(ReportingService reportingService, AllMothers allMothers, AllEligibleCouples allEligibleCouples, ReportMonth reportMonth); void registerANC(SafeMap reportData); void ancVisit(SafeMap reportData); void ttProvided(SafeMap reportData); void deliveryOutcome(SafeMap reportData); void pncVisitHappened(SafeMap reportData); void closeANC(SafeMap reportData); void closePNC(SafeMap reportData); void reportToBoth(Mother mother, Indicator indicator, String date, String submissionDate, Location location); void pncRegistrationOA(SafeMap reportData); void deleteReports(String motherCaseId); static final int NUMBER_OF_DAYS_IN_12_WEEKS; static final int NUMBER_OF_DAYS_IN_PNC_PERIOD; }
@Test public void shouldReportMTPIndicatorBasedOnMTPTime() throws Exception { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-12-12"), parse("2012-12-12"))).thenReturn(true); service.closeANC(reportDataForANCClose("greater_12wks", "spontaneous_abortion", null)); verifyBothReportingCalls(MTP_GREATER_THAN_12_WEEKS, "2012-12-12", "CASE-1"); }
@Test public void shouldReportMaternalDeath() throws Exception { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-12-12"), parse("2012-12-12"))).thenReturn(true); service.closeANC(reportDataForANCClose("", "death_of_woman", "yes")); verifyBothReportingCalls(MMA, "2012-12-12", "CASE-1"); verifyBothReportingCalls(MOTHER_MORTALITY, "2012-12-12", "CASE-1"); }
@Test public void shouldDeleteReportsIfCloseReasonIsWrongEntry() throws Exception { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-12-12"), parse("2012-12-12"))).thenReturn(true); service.closeANC(reportDataForANCClose("", "wrong_entry", "no")); verify(reportingService).deleteReportData(serviceProvidedDataDeleteRequest("CASE-1")); verify(reportingService).deleteReportData(anmReportDataDeleteRequest("CASE-1")); verifyNoMoreInteractions(reportingService); }
@Test public void shouldNotReportMaternalDeathIfItIsNot() throws Exception { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-12-12"), parse("2012-12-12"))).thenReturn(true); service.closeANC(reportDataForANCClose("", "death_of_woman", "no")); verifyNoReportingCalls(MMA, "2012-12-12", "CASE-1"); }
@Test public void shouldNotReportIfReasonIsNotDeath() throws Exception { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-12-12"), parse("2012-12-12"))).thenReturn(true); service.closeANC(reportDataForANCClose("greater_12wks", null, null)); verifyNoReportingCalls(MOTHER_MORTALITY, "2012-01-01", "CASE-1"); }
@Test public void shouldReportIfReasonIsSpontaneousAbortion() throws Exception { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-12-12"), parse("2012-12-12"))).thenReturn(true); service.closeANC(reportDataForANCClose("", "spontaneous_abortion", null)); verifyBothReportingCalls(SPONTANEOUS_ABORTION, "2012-12-12", "CASE-1"); }