ANCSchedulesService { public void ttVisitHasHappened(String entityId, String anmId, String ttDose, String ttDate) { if (AllConstants.ANCFormFields.TT_BOOSTER_DOSE_VALUE.equals(ttDose)) { unEnrollFromSchedule(entityId, anmId, SCHEDULE_TT_1); } else if (AllConstants.ANCFormFields.TT1_DOSE_VALUE.equals(ttDose)) { fulfillMilestoneIfPossible(entityId, anmId, SCHEDULE_TT_1, SCHEDULE_TT_1, parse(ttDate)); scheduleService.enroll(entityId, SCHEDULE_TT_2, ttDate); } else if (AllConstants.ANCFormFields.TT2_DOSE_VALUE.equals(ttDose)) { fulfillMilestoneIfPossible(entityId, anmId, SCHEDULE_TT_2, SCHEDULE_TT_2, parse(ttDate)); } } @Autowired  ANCSchedulesService(ScheduleTrackingService trackingService, ActionService actionService, ScheduleService scheduleService); void enrollMother(String caseId, LocalDate referenceDateForSchedule); void ancVisitHasHappened(String entityId, String anmId, int visitNumberToFulfill, String visitDate); void deliveryHasBeenPlanned(String entityId, String anmId, String deliveryPlanDate); void ttVisitHasHappened(String entityId, String anmId, String ttDose, String ttDate); void ifaTabletsGiven(String entityId, String anmId, String numberOfIFATabletsGiven, String ifaGivenDate); void hbTestDone(String entityId, String anmId, String date, String anaemicStatus, LocalDate lmp); void forceFulfillMilestone(String externalId, String scheduleName); void unEnrollFromAllSchedules(String entityId); static final int NUMBER_OF_WEEKS_BEFORE_HB_TEST_2_BECOMES_DUE; }
@Test public void shouldEnrollMotherInTT2ScheduleIfTT1IsProvided() throws Exception { fakeIt(parse("2012-01-01")); when(trackingService.getEnrollment("entity id 1", "TT 1")).thenReturn( new EnrollmentRecord("entity id 1", "TT 1", "TT 1", null, null, null, null, null, null, null)); ancSchedulesService.ttVisitHasHappened("entity id 1", "ANM 1", "tt1", "2012-01-01"); verify(trackingService).fulfillCurrentMilestone(eq("entity id 1"), eq("TT 1"), eq(today()), any(Time.class)); verify(actionService).markAlertAsClosed("entity id 1", "ANM 1", "TT 1", "2012-01-01"); verify(scheduleService).enroll("entity id 1", "TT 2", "2012-01-01"); }
@Test public void shouldFullFillTT1AndTT2IfTTBoosterIsProvided() throws Exception { fakeIt(parse("2012-01-01")); when(trackingService.getEnrollment("entity id 1", "TT 1")).thenReturn( new EnrollmentRecord("entity id 1", "TT 1", "TT 1", null, null, null, null, null, null, null)); when(trackingService.getEnrollment("entity id 1", "TT 2")).thenReturn( new EnrollmentRecord("entity id 1", "TT 2", "TT 2", null, null, null, null, null, null, null)); ancSchedulesService.ttVisitHasHappened("entity id 1", "ANM 1", "ttbooster", "2012-01-01"); verify(actionService).markAlertAsInactive("ANM 1", "entity id 1", "TT 1"); verify(trackingService).unenroll("entity id 1", asList("TT 1")); verifyZeroInteractions(scheduleService); }
@Test public void shouldNotEnrollMotherInTT2ScheduleIfSomeOtherThingIsProvided() throws Exception { ancSchedulesService.ttVisitHasHappened("entity id 1", "ANM 1", "some other", "2012-01-01"); verifyZeroInteractions(trackingService); }