@Test public void shouldNotSendDefaulterMessagesIfTaskSoConfigured() { Date forDate = new Date(); String careGroups[] = {"ANC", "TT", "IPT"}; Location location = new Location(); location.setName("Test Facility"); location.setRegion("Upper East"); location.setCountyDistrict(new KassenaNankana().toString()); Facility facility = new Facility(); facility.setLocation(location); facility.setPhoneNumber("+1 555 123-1234"); facility.setAdditionalPhoneNumber1("+ 2 555 123-1234"); List<Facility> facilities = new ArrayList<Facility>(); facilities.add(facility); Patient p = new Patient(5716); List<ExpectedEncounter> emptyEncounters = new ArrayList<ExpectedEncounter>(); List<ExpectedObs> emptyObs = new ArrayList<ExpectedObs>(); boolean sendNoDefaulterAndNoUpcomingCareMessage = false; expect(contextService.getMotechService()).andReturn(motechService).anyTimes(); expect(contextService.getAdministrationService()).andReturn(adminService).times(2); expect(adminService.getGlobalProperty(MotechConstants.GLOBAL_PROPERTY_MAX_QUERY_RESULTS)).andReturn("35").anyTimes(); expect(motechService.getExpectedEncounter(null, facility, careGroups, null, null, forDate, forDate, 35)).andReturn(emptyEncounters); expect(motechService.getExpectedObs(null, facility, careGroups, null, null, forDate, forDate, 35)).andReturn(emptyObs); expect(motechService.getAllFacilities()).andReturn(facilities); replay(contextService, adminService, motechService, mobileService, rctService); staffMessageServiceImpl.sendStaffCareMessages(forDate, forDate, forDate, forDate, careGroups, false, false, sendNoDefaulterAndNoUpcomingCareMessage); verify(contextService, adminService, motechService, mobileService, rctService); }
public void sendStaffCareMessages(Date startDate, Date endDate, Date deliveryDate, Date deliveryTime, String[] careGroups, boolean sendUpcoming, boolean blackoutEnabled, boolean sendNoDefaulterAndNoUpcomingCareMessage) { final boolean shouldBlackOut = blackoutEnabled && isMessageTimeWithinBlackoutPeriod(deliveryDate); if (shouldBlackOut) { log.debug("Cancelling nurse messages during blackout"); return; } List<Facility> facilities = motechService().getAllFacilities(); deliveryDate = adjustTime(deliveryDate, deliveryTime); for (Facility facility : facilities) { if (facilityPhoneNumberOrLocationNotAvailable(facility)) { continue; } sendDefaulterMessages(startDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); if (sendUpcoming) { sendUpcomingMessages(startDate, endDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); } } }
StaffMessageServiceImpl implements StaffMessageService { public void sendStaffCareMessages(Date startDate, Date endDate, Date deliveryDate, Date deliveryTime, String[] careGroups, boolean sendUpcoming, boolean blackoutEnabled, boolean sendNoDefaulterAndNoUpcomingCareMessage) { final boolean shouldBlackOut = blackoutEnabled && isMessageTimeWithinBlackoutPeriod(deliveryDate); if (shouldBlackOut) { log.debug("Cancelling nurse messages during blackout"); return; } List<Facility> facilities = motechService().getAllFacilities(); deliveryDate = adjustTime(deliveryDate, deliveryTime); for (Facility facility : facilities) { if (facilityPhoneNumberOrLocationNotAvailable(facility)) { continue; } sendDefaulterMessages(startDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); if (sendUpcoming) { sendUpcomingMessages(startDate, endDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); } } } }
StaffMessageServiceImpl implements StaffMessageService { public void sendStaffCareMessages(Date startDate, Date endDate, Date deliveryDate, Date deliveryTime, String[] careGroups, boolean sendUpcoming, boolean blackoutEnabled, boolean sendNoDefaulterAndNoUpcomingCareMessage) { final boolean shouldBlackOut = blackoutEnabled && isMessageTimeWithinBlackoutPeriod(deliveryDate); if (shouldBlackOut) { log.debug("Cancelling nurse messages during blackout"); return; } List<Facility> facilities = motechService().getAllFacilities(); deliveryDate = adjustTime(deliveryDate, deliveryTime); for (Facility facility : facilities) { if (facilityPhoneNumberOrLocationNotAvailable(facility)) { continue; } sendDefaulterMessages(startDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); if (sendUpcoming) { sendUpcomingMessages(startDate, endDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); } } } StaffMessageServiceImpl();  StaffMessageServiceImpl(
            ContextService contextService,
            MessageService mobileService
    ); }
StaffMessageServiceImpl implements StaffMessageService { public void sendStaffCareMessages(Date startDate, Date endDate, Date deliveryDate, Date deliveryTime, String[] careGroups, boolean sendUpcoming, boolean blackoutEnabled, boolean sendNoDefaulterAndNoUpcomingCareMessage) { final boolean shouldBlackOut = blackoutEnabled && isMessageTimeWithinBlackoutPeriod(deliveryDate); if (shouldBlackOut) { log.debug("Cancelling nurse messages during blackout"); return; } List<Facility> facilities = motechService().getAllFacilities(); deliveryDate = adjustTime(deliveryDate, deliveryTime); for (Facility facility : facilities) { if (facilityPhoneNumberOrLocationNotAvailable(facility)) { continue; } sendDefaulterMessages(startDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); if (sendUpcoming) { sendUpcomingMessages(startDate, endDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); } } } StaffMessageServiceImpl();  StaffMessageServiceImpl(
            ContextService contextService,
            MessageService mobileService
    ); void sendStaffCareMessages(Date startDate, Date endDate,
                                      Date deliveryDate, Date deliveryTime,
                                      String[] careGroups,
                                      boolean sendUpcoming,
                                      boolean blackoutEnabled,
                                      boolean sendNoDefaulterAndNoUpcomingCareMessage); void sendUpcomingMessages(Date startDate, Date endDate, Date deliveryDate, String[] careGroups, Facility facility, Boolean sendNoUpcomingCareMessage); void sendDefaulterMessages(Date startDate, Date deliveryDate, String[] careGroups, Facility facility, Boolean sendNoDefaulterMessage); void setContextService(ContextService contextService); void setExpectedEncountersFilter(FilterChain expectedEncountersFilter); void setExpectedObsFilter(FilterChain expectedObsFilter); void setMobileService(MessageService mobileService); void setCareModelConverter(WebServiceCareModelConverter careModelConverter); }
StaffMessageServiceImpl implements StaffMessageService { public void sendStaffCareMessages(Date startDate, Date endDate, Date deliveryDate, Date deliveryTime, String[] careGroups, boolean sendUpcoming, boolean blackoutEnabled, boolean sendNoDefaulterAndNoUpcomingCareMessage) { final boolean shouldBlackOut = blackoutEnabled && isMessageTimeWithinBlackoutPeriod(deliveryDate); if (shouldBlackOut) { log.debug("Cancelling nurse messages during blackout"); return; } List<Facility> facilities = motechService().getAllFacilities(); deliveryDate = adjustTime(deliveryDate, deliveryTime); for (Facility facility : facilities) { if (facilityPhoneNumberOrLocationNotAvailable(facility)) { continue; } sendDefaulterMessages(startDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); if (sendUpcoming) { sendUpcomingMessages(startDate, endDate, deliveryDate, careGroups, facility, sendNoDefaulterAndNoUpcomingCareMessage); } } } StaffMessageServiceImpl();  StaffMessageServiceImpl(
            ContextService contextService,
            MessageService mobileService
    ); void sendStaffCareMessages(Date startDate, Date endDate,
                                      Date deliveryDate, Date deliveryTime,
                                      String[] careGroups,
                                      boolean sendUpcoming,
                                      boolean blackoutEnabled,
                                      boolean sendNoDefaulterAndNoUpcomingCareMessage); void sendUpcomingMessages(Date startDate, Date endDate, Date deliveryDate, String[] careGroups, Facility facility, Boolean sendNoUpcomingCareMessage); void sendDefaulterMessages(Date startDate, Date deliveryDate, String[] careGroups, Facility facility, Boolean sendNoDefaulterMessage); void setContextService(ContextService contextService); void setExpectedEncountersFilter(FilterChain expectedEncountersFilter); void setExpectedObsFilter(FilterChain expectedObsFilter); void setMobileService(MessageService mobileService); void setCareModelConverter(WebServiceCareModelConverter careModelConverter);  }