MotherReportingService { public void pncRegistrationOA(SafeMap reportData) { Mother mother = allMothers.findByCaseId(reportData.get(AllConstants.ANCFormFields.MOTHER_ID)); Location location = loadLocationFromEC(mother); reportPregnancyOutcome(reportData, mother, location); reportIfInstitutionalDelivery(reportData, mother, location); reportToBoth(mother, DELIVERY, reportData.get(REFERENCE_DATE), reportData.get(SUBMISSION_DATE_FIELD_NAME), location); reportPlaceOfDelivery(reportData, mother, location); reportCesareans(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 shouldReportCesareanAndInstitutionalDeliveryWhenOAPNCIsRegisteredAndDeliveryTypeIsCesareanAndAtPHC() { 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-01-01"), parse("2012-01-02"))).thenReturn(true); Map<String, String> reportData = create("motherId", "CASE-1") .put("referenceDate", "2012-01-01") .put("deliveryType", "cesarean") .put("deliveryPlace", "phc") .put("deliveryOutcome", "live_birth") .put("submissionDate", "2012-01-02") .map(); service.pncRegistrationOA(new SafeMap(reportData)); verifyBothReportingCalls(CESAREAN, "2012-01-01", "CASE-1"); verifyBothReportingCalls(DELIVERY, "2012-01-01", "CASE-1"); verifyBothReportingCalls(INSTITUTIONAL_DELIVERY, "2012-01-01", "CASE-1"); verifyBothReportingCalls(D_PHC, "2012-01-01", "CASE-1"); }
@Test public void shouldReportCesareanPrivateFacilityAndInstitutionalDeliveryWhenOAPNCIsRegisteredAndDeliveryTypeIsCesareanAndDeliveryPlaceIsPrivateFacility() { 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-01-01"), parse("2012-01-02"))).thenReturn(true); Map<String, String> reportData = create("motherId", "CASE-1") .put("referenceDate", "2012-01-01") .put("deliveryType", "cesarean") .put("deliveryPlace", "private_facility") .put("deliveryOutcome", "live_birth") .put("submissionDate", "2012-01-02") .map(); service.pncRegistrationOA(new SafeMap(reportData)); verifyBothReportingCalls(CESAREAN_PRIVATE_FACILITY, "2012-01-01", "CASE-1"); verifyBothReportingCalls(INSTITUTIONAL_DELIVERY, "2012-01-01", "CASE-1"); verifyBothReportingCalls(D_PRI, "2012-01-01", "CASE-1"); }
@Test public void shouldReportCesareanGovernmentFacilityWhenOAPNCIsRegisteredAndDeliveryTypeIsCesareanAndPlaceNotPrivateFacility() { 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-01-01"), parse("2012-01-02"))).thenReturn(true); Map<String, String> reportData = create("motherId", "CASE-1") .put("referenceDate", "2012-01-01") .put("deliveryType", "cesarean") .put("deliveryPlace", "phc") .put("deliveryOutcome", "live_birth") .put("submissionDate", "2012-01-02") .map(); service.pncRegistrationOA(new SafeMap(reportData)); verifyBothReportingCalls(CESAREAN_GOVERNMENT_FACILITY, "2012-01-01", "CASE-1"); }
@Test public void shouldReportLiveBirthAndNRHMLiveBirthAndNotReportInstitutionalDeliveryWhenOAPNCIsRegisteredWithDeliveryOutcomeAsLiveBirthAndAtHome() { 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-01-01"), parse("2012-01-02"))).thenReturn(true); Map<String, String> reportData = create("motherId", "CASE-1") .put("referenceDate", "2012-01-01") .put("deliveryOutcome", "live_birth") .put("deliveryPlace", "home") .put("deliveryType", "normal") .put("submissionDate", "2012-01-02") .map(); service.pncRegistrationOA(new SafeMap(reportData)); verifyBothReportingCalls(LIVE_BIRTH, "2012-01-01", "CASE-1"); verifyBothReportingCalls(NRHM_LIVE_BIRTH, "2012-01-01", "CASE-1"); verifyNoReportingCalls(INSTITUTIONAL_DELIVERY, "2012-01-01", "CASE-1"); verifyBothReportingCalls(D_HOM, "2012-01-01", "CASE-1"); }