@Test public void defaultersAlertCountShouldBeIncreasedForExistingAlerts() { String[] careGroups = new String[]{"ANC","TT1"}; List<Facility> facilities = facilitiesFor("Central Region"); Patient patient = new Patient(1); ExpectedEncounter enc = new ExpectedEncounter(); enc.setId(1L); enc.setPatient(patient); enc.setName("ANC"); List<ExpectedEncounter> expectedEncounters = new ArrayList<ExpectedEncounter>(); expectedEncounters.add(enc); ExpectedObs obs = new ExpectedObs(); obs.setId(1L); obs.setPatient(patient); obs.setName("TT1"); List<ExpectedObs> expectedObservations = new ArrayList<ExpectedObs>(); expectedObservations.add(obs); WebServicePatientModelConverterImpl converter = new WebServicePatientModelConverterImpl(); converter.setRegistrarBean(registrarBean); CareConfiguration careConfigurationForANC = new CareConfiguration(1L, "ANC", 3); CareConfiguration careConfigurationForTT1 = new CareConfiguration(2L, "TT1", 3); Date someDate = new Date(); Integer maxResults = 1; expect(contextService.getMotechService()).andReturn(motechService).anyTimes(); expect(contextService.getAdministrationService()).andReturn(adminService).times(2); expect(motechService.getBlackoutSettings()).andReturn(null); expect(motechService.getAllFacilities()).andReturn(facilities); expect(adminService.getGlobalProperty(MotechConstants.GLOBAL_PROPERTY_MAX_QUERY_RESULTS)).andReturn(maxResults.toString()).times(2); expect(motechService.getExpectedEncounter(null, facilities.get(0), careGroups, null, null, someDate, someDate, maxResults)).andReturn(expectedEncounters); expect(motechService.getExpectedObs(null, facilities.get(0), careGroups, null, null, someDate, someDate, maxResults)).andReturn(expectedObservations); expect(motechService.getCommunityByPatient(same(patient))).andReturn(null).times(2); expect(mobileService.sendDefaulterMessage(EasyMock.<String>isNull(), eq("0123456789"), EasyMock.<Care[]>anyObject(), EasyMock.<CareMessageGroupingStrategy>anyObject(), EasyMock.<MediaType>anyObject(), EasyMock.<Date>anyObject(), EasyMock.<Date>isNull())) .andReturn(org.motechproject.ws.MessageStatus.DELIVERED); expect(motechService.getDefaultedEncounterAlertFor(enc)).andReturn(new DefaultedExpectedEncounterAlert(enc, careConfigurationForANC, 1, 1)); expect(motechService.getDefaultedObsAlertFor(obs)).andReturn((new DefaultedExpectedObsAlert(obs, careConfigurationForTT1, 2, 1))); motechService.saveOrUpdateDefaultedEncounterAlert(equalsExpectedEncounterAlert(new DefaultedExpectedEncounterAlert(enc, careConfigurationForANC, 2, 2))); expectLastCall(); motechService.saveOrUpdateDefaultedObsAlert(equalsExpectedObsAlert(new DefaultedExpectedObsAlert(obs, careConfigurationForTT1, 3, 2))); expectLastCall(); replay(contextService, motechService, adminService, mobileService); staffMessageServiceImpl.sendStaffCareMessages(someDate, someDate, someDate, someDate, careGroups, false, true, true); verify(contextService, motechService, adminService, mobileService); }
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);  }