@Test public void shouldMakeACallForActivePatient_AndRecordDosageAsNotReported_WhenCalledFirstTime() { String PHONE_NUMBER = "1234567890"; Patient patient = mock(Patient.class); PillRegimen pillRegimen = mock(PillRegimen.class); Dose dose = mock(Dose.class); DateTime now = DateUtil.now(); when(patient.allowAdherenceCalls()).thenReturn(true); when(patient.getMobilePhoneNumber()).thenReturn(PHONE_NUMBER); when(allPatients.get(PATIENT_DOC_ID)).thenReturn(patient); when(dailyPillReminderService.getPillRegimen(anyString())).thenReturn(pillRegimen); when(pillRegimen.getDoseAt(Matchers.<DateTime>any())).thenReturn(dose); when(pillRegimen.getId()).thenReturn("pillRegimenId"); when(dose.getDoseTime()).thenReturn(now); pillReminderCall.execute( PATIENT_DOC_ID, NOW.toDate(), TIMES_SENT, TOTAL_TIMES_TO_SEND, RETRY_INTERVAL); ArgumentCaptor<CallRequest> callRequestArgumentCaptor = ArgumentCaptor.forClass(CallRequest.class); verify(callService).initiateCall(callRequestArgumentCaptor.capture()); verify(dailyPillReminderAdherenceService) .recordDosageAdherenceAsNotCaptured( PATIENT_DOC_ID, "pillRegimenId", dose, DosageStatus.NOT_RECORDED, now); Map<String, String> payload = callRequestArgumentCaptor.getValue().getPayload(); assertEquals( String.valueOf(TOTAL_TIMES_TO_SEND), payload.get(PillReminderCall.TOTAL_TIMES_TO_SEND)); assertEquals(String.valueOf(TIMES_SENT), payload.get(PillReminderCall.TIMES_SENT)); assertEquals(String.valueOf(RETRY_INTERVAL), payload.get(PillReminderCall.RETRY_INTERVAL)); }
@Test public void shouldMakeACallForActivePatient_DoesNotRecordDosageAsNotReported_WhenCalledAfterFirstTime() { String PHONE_NUMBER = "1234567890"; Patient patient = mock(Patient.class); PillRegimen pillRegimen = mock(PillRegimen.class); Dose dose = mock(Dose.class); DateTime now = DateUtil.now(); TIMES_SENT = 1; when(patient.allowAdherenceCalls()).thenReturn(true); when(patient.getMobilePhoneNumber()).thenReturn(PHONE_NUMBER); when(allPatients.get(PATIENT_DOC_ID)).thenReturn(patient); pillReminderCall.execute( PATIENT_DOC_ID, NOW.toDate(), TIMES_SENT, TOTAL_TIMES_TO_SEND, RETRY_INTERVAL); ArgumentCaptor<CallRequest> callRequestArgumentCaptor = ArgumentCaptor.forClass(CallRequest.class); verify(callService).initiateCall(callRequestArgumentCaptor.capture()); verifyZeroInteractions(dailyPillReminderAdherenceService); verifyZeroInteractions(dailyPillReminderService); Map<String, String> payload = callRequestArgumentCaptor.getValue().getPayload(); assertEquals( String.valueOf(TOTAL_TIMES_TO_SEND), payload.get(PillReminderCall.TOTAL_TIMES_TO_SEND)); assertEquals(String.valueOf(TIMES_SENT), payload.get(PillReminderCall.TIMES_SENT)); assertEquals(String.valueOf(RETRY_INTERVAL), payload.get(PillReminderCall.RETRY_INTERVAL)); }
@Test public void shouldNotMakeACallWhenCurrentTimeIsConfiguredMinutesLessThanScheduledTime() { String PHONE_NUMBER = "1234567890"; Patient patient = mock(Patient.class); PillRegimen pillRegimen = mock(PillRegimen.class); Dose dose = mock(Dose.class); DateTime now = DateUtil.now(); when(patient.allowAdherenceCalls()).thenReturn(true); when(patient.getMobilePhoneNumber()).thenReturn(PHONE_NUMBER); when(allPatients.get(PATIENT_DOC_ID)).thenReturn(patient); when(dailyPillReminderService.getPillRegimen(anyString())).thenReturn(pillRegimen); when(pillRegimen.getDoseAt(Matchers.<DateTime>any())).thenReturn(dose); when(pillRegimen.getId()).thenReturn("pillRegimenId"); when(dose.getDoseTime()).thenReturn(now); pillReminderCall.execute( PATIENT_DOC_ID, NOW.minusMinutes(16).toDate(), TIMES_SENT, TOTAL_TIMES_TO_SEND, RETRY_INTERVAL); ArgumentCaptor<CallRequest> callRequestArgumentCaptor = ArgumentCaptor.forClass(CallRequest.class); verify(callService, never()).initiateCall(callRequestArgumentCaptor.capture()); }
@Test public void shouldMarkDoseAsNotRecordedWhenCurrentTimeIsConfiguredMinutesMoreThanScheduledTime() { String PHONE_NUMBER = "1234567890"; Patient patient = mock(Patient.class); PillRegimen pillRegimen = mock(PillRegimen.class); Dose dose = mock(Dose.class); DateTime now = DateUtil.now(); when(patient.allowAdherenceCalls()).thenReturn(true); when(patient.getMobilePhoneNumber()).thenReturn(PHONE_NUMBER); when(allPatients.get(PATIENT_DOC_ID)).thenReturn(patient); when(dailyPillReminderService.getPillRegimen(anyString())).thenReturn(pillRegimen); when(pillRegimen.getDoseAt(Matchers.<DateTime>any())).thenReturn(dose); when(pillRegimen.getId()).thenReturn("pillRegimenId"); when(dose.getDoseTime()).thenReturn(now); pillReminderCall.execute( PATIENT_DOC_ID, NOW.plusMinutes(16).toDate(), TIMES_SENT, TOTAL_TIMES_TO_SEND, RETRY_INTERVAL); verify(dailyPillReminderAdherenceService) .recordDosageAdherenceAsNotCaptured( PATIENT_DOC_ID, "pillRegimenId", dose, DosageStatus.NOT_RECORDED, now); }
@Test public void shouldNotMakeACallForSuspendedPatient() { Patient patient = mock(Patient.class); when(patient.allowAdherenceCalls()).thenReturn(false); when(allPatients.get(PATIENT_DOC_ID)).thenReturn(patient); pillReminderCall.execute( PATIENT_DOC_ID, NOW.toDate(), TIMES_SENT, TOTAL_TIMES_TO_SEND, RETRY_INTERVAL); verify(callService, never()).initiateCall(any(CallRequest.class)); }
@Override public String[] executeCommand(DailyPillReminderContext context) { List<String> messages = new ArrayList<String>(); Patient patient = allPatients.get(context.patientDocumentId()); Clinic clinic = allClinics.get(patient.getClinic_id()); messages.add( clinicNameMessageBuilder.getOutboundMessage( clinic, patient.getPatientPreferences().getIvrLanguage())); messages.add(TamaIVRMessage.ITS_TIME_FOR_THE_PILL_OUTGOING_CALL_FOR_CURRENT_DOSAGE); return messages.toArray(new String[messages.size()]); }
public void disEnroll(Patient patient, TreatmentAdvice treatmentAdvice) { if (treatmentAdvice != null) { pillReminderService.remove(patient.getId()); dailyPillReminderSchedulerService.unscheduleDailyPillReminderJobs(patient); } }