MotherReportingService { public void closePNC(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_MOTHER_VALUE.equals(reportData.get(CLOSE_REASON_FIELD_NAME)) && BOOLEAN_TRUE_VALUE.equals(reportData.get(IS_MATERNAL_LEAVE_FIELD_NAME)) && mother.dateOfDelivery().plusDays(NUMBER_OF_DAYS_IN_PNC_PERIOD) .isAfter(parse(reportData.get(DEATH_DATE_FIELD_NAME)))) { reportDeath(mother, MMP, reportData.get(DEATH_DATE_FIELD_NAME), reportData.get(SUBMISSION_DATE_FIELD_NAME), location); return; } } @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 shouldReportMotherDeathDuringPNCClose() { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER.withDeliveryOutCome("2012-01-01")); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); when(reportMonth.areDatesBelongToSameReportingMonth(parse("2012-02-01"), parse("2012-02-01"))).thenReturn(true); Map<String, String> reportData = create("id", "CASE-1") .put("closeReason", "death_of_mother") .put("isMaternalDeath", "yes") .put("deathDate", "2012-02-01") .put("submissionDate", "2012-02-01") .map(); service.closePNC(new SafeMap(reportData)); verifyBothReportingCalls(MMP, "2012-02-01", "CASE-1"); verifyBothReportingCalls(MOTHER_MORTALITY, "2012-02-01", "CASE-1"); verify(reportingService, never()).deleteReportData(any(ReportDataDeleteRequest.class)); }
@Test public void shouldDeleteReportsWhenPNCCloseReasonIsWrongEntry() { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER.withDeliveryOutCome("2012-01-01")); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); Map<String, String> reportData = create("id", "CASE-1") .put("closeReason", "wrong_entry") .map(); service.closePNC(new SafeMap(reportData)); verify(reportingService).deleteReportData(serviceProvidedDataDeleteRequest("CASE-1")); verify(reportingService).deleteReportData(anmReportDataDeleteRequest("CASE-1")); verifyNoMoreInteractions(reportingService); }
@Test public void shouldNotReportMotherDeathDuringPNCCloseIfCloseReasonIsNotDeath() { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER.withDeliveryOutCome("2012-01-01")); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); Map<String, String> reportData = create("id", "CASE-1") .put("closeReason", "") .put("isMaternalDeath", "") .put("deathDate", "2012-02-01") .map(); service.closePNC(new SafeMap(reportData)); verifyNoReportingCalls(MMP, "2012-02-01", "CASE-1"); verifyNoReportingCalls(MOTHER_MORTALITY, "2012-02-01", "CASE-1"); verify(reportingService, never()).deleteReportData(any(ReportDataDeleteRequest.class)); }
@Test public void shouldNotReportMotherDeathDuringPNCCloseIfNotMaternalDeath() { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER.withDeliveryOutCome("2012-01-01")); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); Map<String, String> reportData = create("id", "CASE-1") .put("closeReason", "death_of_mother") .put("isMaternalDeath", "") .put("deathDate", "2012-02-01") .map(); service.closePNC(new SafeMap(reportData)); verifyNoReportingCalls(MMP, "2012-02-01", "CASE-1"); verifyNoReportingCalls(MOTHER_MORTALITY, "2012-02-01", "CASE-1"); verify(reportingService, never()).deleteReportData(any(ReportDataDeleteRequest.class)); }
@Test public void shouldNotReportMotherDeathDuringPNCCloseIfNotWithin42DaysOfDeliveryOutcome() { when(allMothers.findByCaseId("CASE-1")).thenReturn(MOTHER.withDeliveryOutCome("2012-01-01")); when(allEligibleCouples.findByCaseId("EC-CASE-1")).thenReturn(new EligibleCouple().withLocation("bherya", "Sub Center", "PHC X")); Map<String, String> reportData = create("id", "CASE-1") .put("closeReason", "death_of_mother") .put("isMaternalDeath", "yes") .put("deathDate", "2012-02-12") .map(); service.closePNC(new SafeMap(reportData)); verifyNoReportingCalls(MMP, "2012-02-01", "CASE-1"); verifyNoReportingCalls(MOTHER_MORTALITY, "2012-02-01", "CASE-1"); verify(reportingService, never()).deleteReportData(any(ReportDataDeleteRequest.class)); }