nus-yam/ex-repair huggingface dataset:
Program: 84792
Project: 84792
Buggy source:
public void raiseAdherenceFallingAlert(String patientId){
  int adherencePercentageForCurrentWeek=getAdherencePercentageForCurrentWeek(patientId);
  if (adherencePercentageForCurrentWeek >= getAdherencePercentageForPreviousWeek(patientId))   return;
  final Map<String,String> data=new HashMap<String,String>();
  final int previousWeekPercentage=getAdherencePercentageForPreviousWeek(patientId);
  final double fall=((previousWeekPercentage - adherencePercentageForCurrentWeek) / previousWeekPercentage) * 100.0;
  final String description=String.format("String_Node_Str",fall,previousWeekPercentage,adherencePercentageForCurrentWeek);
  patientAlertService.createAlert(patientId,TAMAConstants.NO_ALERT_PRIORITY,DailyReminderAdherenceTrendService.FALLING_ADHERENCE,description,PatientAlertType.FallingAdherence,data);
}

Fixed version (ground truth):
public void raiseAdherenceFallingAlert(String patientId){
  int adherencePercentageForCurrentWeek=getAdherencePercentageForCurrentWeek(patientId);
  if (adherencePercentageForCurrentWeek >= getAdherencePercentageForPreviousWeek(patientId))   return;
  final Map<String,String> data=new HashMap<String,String>();
  final int previousWeekPercentage=getAdherencePercentageForPreviousWeek(patientId);
  final double fall=((previousWeekPercentage - adherencePercentageForCurrentWeek) / (double)previousWeekPercentage) * 100.0;
  final String description=String.format("String_Node_Str",fall,(double)previousWeekPercentage,(double)adherencePercentageForCurrentWeek);
  patientAlertService.createAlert(patientId,TAMAConstants.NO_ALERT_PRIORITY,DailyReminderAdherenceTrendService.FALLING_ADHERENCE,description,PatientAlertType.FallingAdherence,data);
}
Program: 84793
Project: 84793
Buggy source:
protected double getAdherencePercentage(String patientId,DateTime asOfDate){
  PillRegimenResponse pillRegimen=pillReminderService.getPillRegimen(patientId);
  String regimenId=pillRegimen.getPillRegimenId();
  int scheduledDosagesTotalCountForLastFourWeeksAsOfNow=DosageUtil.getScheduledDosagesTotalCountForLastFourWeeks(asOfDate.minusWeeks(4),asOfDate,pillRegimen);
  int dosagesTakenForLastFourWeeksAsOfNow=allDosageAdherenceLogs.findScheduledDosagesSuccessCount(regimenId,asOfDate.minusWeeks(4).toLocalDate(),asOfDate.toLocalDate());
  return ((double)dosagesTakenForLastFourWeeksAsOfNow) / scheduledDosagesTotalCountForLastFourWeeksAsOfNow;
}

Fixed version (ground truth):
protected double getAdherencePercentage(String patientId,DateTime asOfDate){
  PillRegimenResponse pillRegimen=pillReminderService.getPillRegimen(patientId);
  String regimenId=pillRegimen.getPillRegimenId();
  int scheduledDosagesTotalCountForLastFourWeeksAsOfNow=DosageUtil.getScheduledDosagesTotalCountForLastFourWeeks(asOfDate.minusWeeks(4),asOfDate,pillRegimen);
  int dosagesTakenForLastFourWeeksAsOfNow=allDosageAdherenceLogs.findScheduledDosagesSuccessCount(regimenId,asOfDate.minusWeeks(4).toLocalDate(),asOfDate.toLocalDate());
  return ((double)dosagesTakenForLastFourWeeksAsOfNow) / scheduledDosagesTotalCountForLastFourWeeksAsOfNow * 100.0;
}
Program: 84794
Project: 84794
Buggy source:
private void unscheduleDailyReminderJobs(Patient patient){
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patient.getId());
  if (treatmentAdvice != null) {
    pillReminderService.unscheduleJobs(patient.getId());
    tamaSchedulerService.unscheduleJobForAdherenceTrendFeedbackForDailyPillReminder(treatmentAdvice);
  }
}

Fixed version (ground truth):
private void unscheduleDailyReminderJobs(Patient patient){
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patient.getId());
  if (treatmentAdvice != null) {
    pillReminderService.unscheduleJobs(patient.getId());
    tamaSchedulerService.unscheduleJobForAdherenceTrendFeedbackForDailyPillReminder(treatmentAdvice);
    tamaSchedulerService.unscheduleJobForDeterminingAdherenceQualityInDailyPillReminder(patient);
  }
}
Program: 84795
Project: 84795
Buggy source:
@Test public void shouldUnscheduleJobsForAdherenceTrendFeedbackOutboxMessage(){
  Patient patient=PatientBuilder.startRecording().withDefaults().withId("String_Node_Str").withCallPreference(CallPreference.FourDayRecall).withBestCallTime(new TimeOfDay(null,null,null)).build();
  TreatmentAdvice treatmentAdvice=TreatmentAdvice.newDefault();
  when(allTreatmentAdvices.currentTreatmentAdvice(patient.getId())).thenReturn(treatmentAdvice);
  patientService.update(patient);
  verify(tamaSchedulerService).unscheduleJobForAdherenceTrendFeedbackForDailyPillReminder(treatmentAdvice);
}

Fixed version (ground truth):
@Test public void shouldUnscheduleJobsForAdherenceTrendFeedbackOutboxMessage(){
  Patient patient=PatientBuilder.startRecording().withDefaults().withId("String_Node_Str").withCallPreference(CallPreference.FourDayRecall).withBestCallTime(new TimeOfDay(null,null,null)).build();
  TreatmentAdvice treatmentAdvice=TreatmentAdvice.newDefault();
  when(allTreatmentAdvices.currentTreatmentAdvice(patient.getId())).thenReturn(treatmentAdvice);
  patientService.update(patient);
  verify(tamaSchedulerService).unscheduleJobForAdherenceTrendFeedbackForDailyPillReminder(treatmentAdvice);
  verify(tamaSchedulerService).unscheduleJobForDeterminingAdherenceQualityInDailyPillReminder(patient);
}
Program: 84796
Project: 84796
Buggy source:
public boolean isAdherenceBeingCapturedForFirstWeek(String patientId){
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patientId);
  Patient patient=allPatients.get(patientId);
  LocalDate treatmentAdviceStartDate=DateUtil.newDate(treatmentAdvice.getStartDate());
  DateTime callPreferenceTransitionDate=patient.getPatientPreferences().getCallPreferenceTransitionDate();
  if (callPreferenceTransitionDate != null && callPreferenceTransitionDate.toLocalDate().isAfter(treatmentAdviceStartDate)) {
    return DateUtil.today().minusWeeks(1).isBefore(callPreferenceTransitionDate.toLocalDate());
  }
  return getStartDateForCurrentWeek(patientId).equals(treatmentAdviceStartDate);
}

Fixed version (ground truth):
public boolean isAdherenceBeingCapturedForFirstWeek(String patientId){
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patientId);
  Patient patient=allPatients.get(patientId);
  LocalDate treatmentAdviceStartDate=DateUtil.newDate(treatmentAdvice.getStartDate());
  DateTime callPreferenceTransitionDate=patient.getPatientPreferences().getCallPreferenceTransitionDate();
  if (callPreferenceTransitionDate != null && callPreferenceTransitionDate.toLocalDate().isAfter(treatmentAdviceStartDate)) {
    return dateIsAtLeastOneWeekAgo(callPreferenceTransitionDate);
  }
  return getStartDateForCurrentWeek(patientId).equals(treatmentAdviceStartDate);
}
Program: 84797
Project: 84797
Buggy source:
public LocalDate findFourDayRecallDateForAnyWeek(String patientDocId,LocalDate week){
  Patient patient=allPatients.get(patientDocId);
  LocalDate startDayOfWeek=getStartDateForAnyWeek(patientDocId,week);
  DayOfWeek preferredDayOfWeek=patient.getPatientPreferences().getDayOfWeeklyCall();
  while (true) {
    if (startDayOfWeek.getDayOfWeek() == preferredDayOfWeek.getValue()) {
      return startDayOfWeek;
    }
    startDayOfWeek=startDayOfWeek.plusDays(1);
  }
}

Fixed version (ground truth):
public LocalDate findFourDayRecallDateForAnyWeek(String patientDocId,LocalDate week){
  Patient patient=allPatients.get(patientDocId);
  LocalDate startDayOfWeek=getStartDateForAnyWeek(patientDocId,week);
  LocalDate iteratingDayOfWeek=startDayOfWeek;
  DayOfWeek preferredDayOfWeek=patient.getPatientPreferences().getDayOfWeeklyCall();
  while (true) {
    if (iteratingDayOfWeek.getDayOfWeek() == preferredDayOfWeek.getValue()) {
      if (isStartDayEqualToOrSufficientlyBehindFourDayRecallDate(startDayOfWeek,iteratingDayOfWeek)) {
        return iteratingDayOfWeek;
      }
 else {
        return iteratingDayOfWeek.plusWeeks(1);
      }
    }
    iteratingDayOfWeek=iteratingDayOfWeek.plusDays(1);
  }
}
Program: 84798
Project: 84798
Buggy source:
private int getRetryDaysCount(DayOfWeek preferredDayOfWeek){
  int count=0;
  LocalDate date=DateUtil.today();
  while (date.getDayOfWeek() != preferredDayOfWeek.getValue()) {
    date=date.minusDays(1);
    count++;
  }
  return count;
}

Fixed version (ground truth):
private int getRetryDaysCount(DayOfWeek preferredDayOfWeek,LocalDate date){
  int count=0;
  while (date.getDayOfWeek() != preferredDayOfWeek.getValue()) {
    date=date.minusDays(1);
    count++;
  }
  return count;
}
Program: 84799
Project: 84799
Buggy source:
public LocalDate getStartDateForAnyWeek(String patientDocId,LocalDate week){
  Patient patient=allPatients.get(patientDocId);
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patientDocId);
  DayOfWeek preferredDayOfWeek=patient.getPatientPreferences().getDayOfWeeklyCall();
  int retryDayCount=0;
  boolean isRetry=DateUtil.today().getDayOfWeek() != preferredDayOfWeek.getValue();
  if (isRetry)   retryDayCount=getRetryDaysCount(preferredDayOfWeek);
  DayOfWeek treatmentAdviceStartDay=DayOfWeek.getDayOfWeek(DateUtil.newDate(treatmentAdvice.getStartDate()));
  return dateWith(treatmentAdviceStartDay,DAYS_TO_RECALL,week.minusDays(retryDayCount));
}

Fixed version (ground truth):
public LocalDate getStartDateForAnyWeek(String patientDocId,LocalDate week){
  Patient patient=allPatients.get(patientDocId);
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patientDocId);
  DayOfWeek preferredDayOfWeek=patient.getPatientPreferences().getDayOfWeeklyCall();
  int retryDayCount=0;
  boolean isRetry=week.getDayOfWeek() != preferredDayOfWeek.getValue();
  if (isRetry)   retryDayCount=getRetryDaysCount(preferredDayOfWeek,week);
  DayOfWeek treatmentAdviceStartDay=DayOfWeek.getDayOfWeek(DateUtil.newDate(treatmentAdvice.getStartDate()));
  return dateWith(treatmentAdviceStartDay,DAYS_TO_RECALL,week.minusDays(retryDayCount));
}
Program: 84800
Project: 84800
Buggy source:
public TamaSchedulerService(MotechSchedulerService motechSchedulerService,Properties properties,AllPatients allPatients){
  this.motechSchedulerService=motechSchedulerService;
  this.properties=properties;
  this.allPatients=allPatients;
}

Fixed version (ground truth):
public TamaSchedulerService(MotechSchedulerService motechSchedulerService,Properties properties,AllPatients allPatients,FourDayRecallService fourDayRecallService){
  this.motechSchedulerService=motechSchedulerService;
  this.properties=properties;
  this.allPatients=allPatients;
  this.fourDayRecallService=fourDayRecallService;
}
Program: 84801
Project: 84801
Buggy source:
public void scheduleFallingAdherenceAlertJobs(Patient patient,TreatmentAdvice treatmentAdvice){
  String patientDocId=patient.getId();
  DayOfWeek dayOfWeeklyCall=patient.getPatientPreferences().getDayOfWeeklyCall();
  Time eventTime=new TimeOfDay(0,0,TimeMeridiem.AM).toTime();
  Integer daysToRetry=Integer.valueOf(properties.getProperty(TAMAConstants.FOUR_DAY_RECALL_DAYS_TO_RETRY));
  LocalDate startDate=getWeeklyAdherenceTrackingStartDate(patient,treatmentAdvice).plusDays(4 + 14);
  for (int count=0; count <= daysToRetry; count++) {
    DayOfWeek eventDay=dayOfWeek(dayOfWeeklyCall,count + 1);
    FourDayRecallEventPayloadBuilder paramsBuilder=new FourDayRecallEventPayloadBuilder().withJobId(count + patientDocId).withPatientDocId(patientDocId);
    if (count == daysToRetry)     paramsBuilder.withLastRetryDayFlagSet();
    scheduleWeeklyEvent(getJobStartDate(startDate),getJobEndDate(treatmentAdvice),eventDay,eventTime,paramsBuilder.payload(),TAMAConstants.WEEKLY_FALLING_TREND_SUBJECT);
  }
}

Fixed version (ground truth):
public void scheduleFallingAdherenceAlertJobs(Patient patient,TreatmentAdvice treatmentAdvice){
  String patientDocId=patient.getId();
  DayOfWeek dayOfWeeklyCall=patient.getPatientPreferences().getDayOfWeeklyCall();
  Time eventTime=new TimeOfDay(0,0,TimeMeridiem.AM).toTime();
  Integer daysToRetry=Integer.valueOf(properties.getProperty(TAMAConstants.FOUR_DAY_RECALL_DAYS_TO_RETRY));
  LocalDate startDate=fourDayRecallService.findFirstFourDayRecallDateForTreatmentAdvice(patientDocId,getWeeklyAdherenceTrackingStartDate(patient,treatmentAdvice)).plusDays(1);
  for (int count=0; count <= daysToRetry; count++) {
    DayOfWeek eventDay=dayOfWeek(dayOfWeeklyCall,count + 1);
    FourDayRecallEventPayloadBuilder paramsBuilder=new FourDayRecallEventPayloadBuilder().withJobId(count + patientDocId).withPatientDocId(patientDocId);
    if (count == daysToRetry)     paramsBuilder.withLastRetryDayFlagSet();
    scheduleWeeklyEvent(getJobStartDate(startDate),getJobEndDate(treatmentAdvice),eventDay,eventTime,paramsBuilder.payload(),TAMAConstants.WEEKLY_FALLING_TREND_SUBJECT);
  }
}
Program: 84802
Project: 84802
Buggy source:
@MotechListener(subjects=TAMAConstants.WEEKLY_FALLING_TREND_SUBJECT) public void handleWeeklyFallingAdherence(MotechEvent motechEvent){
  String patientDocId=motechEvent.getParameters().get(PATIENT_DOC_ID_KEY).toString();
  Patient patient=allPatients.get(patientDocId);
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patient.getId());
  if (fourDayRecallService.isAdherenceCapturedForCurrentWeek(patientDocId,treatmentAdvice.getId()) || isLastRetryDay(motechEvent)) {
    if (fourDayRecallService.hasAdherenceFallingAlertBeenRaisedForCurrentWeek(PATIENT_DOC_ID_KEY))     return;
    fourDayRecallService.raiseAdherenceFallingAlert(patientDocId);
  }
}

Fixed version (ground truth):
@MotechListener(subjects=TAMAConstants.WEEKLY_FALLING_TREND_SUBJECT) public void handleWeeklyFallingAdherence(MotechEvent motechEvent){
  String patientDocId=motechEvent.getParameters().get(PATIENT_DOC_ID_KEY).toString();
  Patient patient=allPatients.get(patientDocId);
  TreatmentAdvice treatmentAdvice=allTreatmentAdvices.currentTreatmentAdvice(patient.getId());
  if (fourDayRecallService.isAdherenceCapturedForCurrentWeek(patientDocId,treatmentAdvice.getId()) || isLastRetryDay(motechEvent)) {
    if (fourDayRecallService.hasAdherenceFallingAlertBeenRaisedForCurrentWeek(patientDocId))     return;
    fourDayRecallService.raiseAdherenceFallingAlert(patientDocId);
  }
}
Program: 84803
Project: 84803
Buggy source:
@Test public void shouldReturnAdhrenceTrendPercentage(){
  String externalId="String_Node_Str";
  String pillRegimenId="String_Node_Str";
  int successCountThisWeek=25;
  int scheduledDosageCount=100;
  Mockito.when(pillReminderService.getPillRegimen(Mockito.anyString())).thenReturn(pillRegimenResponse);
  Mockito.when(pillRegimenResponse.getPillRegimenId()).thenReturn(pillRegimenId);
  Mockito.when(allDosageAdherenceLogs.findScheduledDosagesSuccessCount(pillRegimenId,dateTime.minusWeeks(4).toLocalDate(),dateTime.toLocalDate())).thenReturn(successCountThisWeek);
  PowerMockito.when(DosageUtil.getScheduledDosagesTotalCountForLastFourWeeks(Mockito.any(DateTime.class),Mockito.any(DateTime.class),Mockito.any(PillRegimenResponse.class))).thenReturn(scheduledDosageCount);
  DailyReminderAdherenceTrendService dailyReminderAdherenceTrendService=new DailyReminderAdherenceTrendService(allDosageAdherenceLogs,pillReminderService,patientAlertService);
  assertEquals(0.25,dailyReminderAdherenceTrendService.getAdherencePercentage(externalId));
}

Fixed version (ground truth):
@Test public void shouldReturnAdhrenceTrendPercentage(){
  String externalId="String_Node_Str";
  String pillRegimenId="String_Node_Str";
  int successCountThisWeek=25;
  int scheduledDosageCount=100;
  Mockito.when(pillReminderService.getPillRegimen(Mockito.anyString())).thenReturn(pillRegimenResponse);
  Mockito.when(pillRegimenResponse.getPillRegimenId()).thenReturn(pillRegimenId);
  Mockito.when(allDosageAdherenceLogs.findScheduledDosagesSuccessCount(pillRegimenId,dateTime.minusWeeks(4).toLocalDate(),dateTime.toLocalDate())).thenReturn(successCountThisWeek);
  PowerMockito.when(DosageUtil.getScheduledDosagesTotalCountForLastFourWeeks(Mockito.any(DateTime.class),Mockito.any(DateTime.class),Mockito.any(PillRegimenResponse.class))).thenReturn(scheduledDosageCount);
  DailyReminderAdherenceTrendService dailyReminderAdherenceTrendService=new DailyReminderAdherenceTrendService(allDosageAdherenceLogs,pillReminderService,patientAlertService);
  assertEquals(25.0,dailyReminderAdherenceTrendService.getAdherencePercentage(externalId));
}
Program: 84804
Project: 84804
Buggy source:
@Override protected double getAdherencePercentageForCurrentWeek(String patientId){
  if (patientId.equals(testPatientId))   return 23.0;
  return 0.0;
}

Fixed version (ground truth):
@Override public double getAdherencePercentageForCurrentWeek(String patientId){
  return 20.0;
}
Program: 84805
Project: 84805
Buggy source:
@Test public void shouldRaiseAlertWhenAdherenceIsFalling(){
  DailyReminderAdherenceTrendService dailyReminderAdherenceTrendService=new DailyReminderAdherenceTrendService(allDosageAdherenceLogs,pillReminderService,patientAlertService){
    @Override public boolean isAdherenceFalling(    String patientId){
      return true;
    }
    @Override public double getAdherencePercentage(    String patientId){
      return 20.0;
    }
    @Override protected double getAdherencePercentage(    String patientId,    DateTime asOfDate){
      return 30.0;
    }
  }
;
  final String patientId="String_Node_Str";
  dailyReminderAdherenceTrendService.raiseAdherenceFallingAlert(patientId);
  verify(patientAlertService).createAlert(eq(patientId),eq(0),eq("String_Node_Str"),eq("String_Node_Str"),eq(PatientAlertType.FallingAdherence),argThat(emptyMapMatcher));
}

Fixed version (ground truth):
@Test public void shouldRaiseAlertWhenAdherenceIsFalling(){
  DailyReminderAdherenceTrendService dailyReminderAdherenceTrendService=new DailyReminderAdherenceTrendService(allDosageAdherenceLogs,pillReminderService,patientAlertService){
    @Override public boolean isAdherenceFalling(    String patientId){
      return true;
    }
    @Override public double getAdherencePercentageForCurrentWeek(    String patientId){
      return 20.0;
    }
    @Override protected double getAdherencePercentage(    String patientId,    DateTime asOfDate){
      return 30.0;
    }
  }
;
  final String patientId="String_Node_Str";
  dailyReminderAdherenceTrendService.raiseAdherenceFallingAlert(patientId);
  verify(patientAlertService).createAlert(eq(patientId),eq(0),eq("String_Node_Str"),eq("String_Node_Str"),eq(PatientAlertType.FallingAdherence),argThat(emptyMapMatcher));
}
Program: 84806
Project: 84806
Buggy source:
public void scheduleJobsForFourDayRecall(Patient patient,TreatmentAdvice treatmentAdvice){
  String patientDocId=patient.getId();
  LocalDate treatmentAdviceStartDate=DateUtil.newDate(treatmentAdvice.getStartDate());
  LocalDate endDate=DateUtil.newDate(treatmentAdvice.getEndDate());
  DayOfWeek dayOfWeeklyCall=patient.getPatientPreferences().getDayOfWeeklyCall();
  Time callTime=patient.getPatientPreferences().getBestCallTime().toTime();
  Integer daysToRetry=Integer.valueOf(properties.getProperty(TAMAConstants.FOUR_DAY_RECALL_DAYS_TO_RETRY));
  for (int count=0; count <= daysToRetry; count++) {
    Map<String,Object> eventParams=new FourDayRecallEventPayloadBuilder().withJobId(count + patientDocId).withPatientDocId(patientDocId).payload();
    MotechEvent fourDayRecallEvent=new MotechEvent(TAMAConstants.FOUR_DAY_RECALL_SUBJECT,eventParams);
    String cronExpression=new WeeklyCronJobExpressionBuilder(dayOfWeek(dayOfWeeklyCall,count)).withTime(callTime).build();
    Date jobEndDate=endDate == null ? null : endDate.toDate();
    LocalDate startDate=treatmentAdviceStartDate.plusDays(4 + count);
    Date jobStartDate=getJobStartDate(startDate);
    CronSchedulableJob cronJobForFourDayRecall=new CronSchedulableJob(fourDayRecallEvent,cronExpression,jobStartDate,jobEndDate);
    motechSchedulerService.scheduleJob(cronJobForFourDayRecall);
  }
}

Fixed version (ground truth):
public void scheduleJobsForFourDayRecall(Patient patient,TreatmentAdvice treatmentAdvice){
  String patientDocId=patient.getId();
  LocalDate treatmentAdviceStartDate=DateUtil.newDate(treatmentAdvice.getStartDate());
  LocalDate endDate=DateUtil.newDate(treatmentAdvice.getEndDate());
  DayOfWeek dayOfWeeklyCall=patient.getPatientPreferences().getDayOfWeeklyCall();
  Time callTime=patient.getPatientPreferences().getBestCallTime().toTime();
  Integer daysToRetry=Integer.valueOf(properties.getProperty(TAMAConstants.FOUR_DAY_RECALL_DAYS_TO_RETRY));
  for (int count=0; count <= daysToRetry; count++) {
    Map<String,Object> eventParams=new FourDayRecallEventPayloadBuilder().withJobId(count + patientDocId).withPatientDocId(patientDocId).payload();
    MotechEvent fourDayRecallEvent=new MotechEvent(TAMAConstants.FOUR_DAY_RECALL_SUBJECT,eventParams);
    String cronExpression=new WeeklyCronJobExpressionBuilder(dayOfWeek(dayOfWeeklyCall,count)).withTime(callTime).build();
    Date jobEndDate=endDate == null ? null : endDate.toDate();
    LocalDate startDate=treatmentAdviceStartDate.plusDays(4 + count);
    Date jobStartDate=getJobStartDate(startDate);
    CronSchedulableJob cronJobForFourDayRecall=new CronSchedulableJob(fourDayRecallEvent,cronExpression,jobStartDate,jobEndDate);
    motechSchedulerService.scheduleJob(cronJobForFourDayRecall);
  }
  scheduleFallingAdherenceAlertJob(patient,treatmentAdvice);
}
Program: 84807
Project: 84807
Buggy source:
@Test public void shouldScheduleFourDayRecallJobs_StartDateIsToday(){
  DayOfWeek dayOfWeek=DayOfWeek.Friday;
  int numDaysToRetry=2;
  patient.getPatientPreferences().setDayOfWeeklyCall(dayOfWeek);
  when(properties.getProperty(TAMAConstants.FOUR_DAY_RECALL_DAYS_TO_RETRY)).thenReturn(String.valueOf(numDaysToRetry));
  schedulerService.scheduleJobsForFourDayRecall(patient,treatmentAdvice);
  ArgumentCaptor<CronSchedulableJob> cronSchedulableJobArgumentCaptor=ArgumentCaptor.forClass(CronSchedulableJob.class);
  verify(motechSchedulerService,times(numDaysToRetry + 1)).scheduleJob(cronSchedulableJobArgumentCaptor.capture());
  List<CronSchedulableJob> cronSchedulableJobList=cronSchedulableJobArgumentCaptor.getAllValues();
  assertCronSchedulableJob(cronSchedulableJobList.get(0),"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(4).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
  assertCronSchedulableJob(cronSchedulableJobList.get(1),"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(5).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
  assertCronSchedulableJob(cronSchedulableJobList.get(2),"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(6).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
}

Fixed version (ground truth):
@Test public void shouldScheduleFourDayRecallJobs_StartDateIsToday(){
  DayOfWeek dayOfWeek=DayOfWeek.Friday;
  int numDaysToRetry=2;
  patient.getPatientPreferences().setDayOfWeeklyCall(dayOfWeek);
  when(properties.getProperty(TAMAConstants.FOUR_DAY_RECALL_DAYS_TO_RETRY)).thenReturn(String.valueOf(numDaysToRetry));
  schedulerService.scheduleJobsForFourDayRecall(patient,treatmentAdvice);
  ArgumentCaptor<CronSchedulableJob> cronSchedulableJobArgumentCaptor=ArgumentCaptor.forClass(CronSchedulableJob.class);
  verify(motechSchedulerService,times(numDaysToRetry + 1 + 1)).scheduleJob(cronSchedulableJobArgumentCaptor.capture());
  List<CronSchedulableJob> cronSchedulableJobList=cronSchedulableJobArgumentCaptor.getAllValues();
  assertCronSchedulableJob(cronSchedulableJobList.get(0),"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(4).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
  assertCronSchedulableJob(cronSchedulableJobList.get(1),"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(5).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
  assertCronSchedulableJob(cronSchedulableJobList.get(2),"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(6).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
  final CronSchedulableJob fallingAdherenceAlertJob=cronSchedulableJobList.get(3);
  assertCronSchedulableJob(fallingAdherenceAlertJob,"String_Node_Str",TREATMENT_ADVICE_START_DATE.plusDays(14).toDate(),TREATMENT_ADVICE_END_DATE.toDate());
  assertEquals(TAMAConstants.WEEKLY_FALLING_TREND_SUBJECT,fallingAdherenceAlertJob.getMotechEvent().getSubject());
}
Program: 84808
Project: 84808
Buggy source:
public List<CallLogView> toCallLogView(List<CallLog> callLogs){
  List<CallLogView> callLogViews=new ArrayList<CallLogView>();
  for (  CallLog callLog : callLogs) {
    String patientDocumentId=callLog.getPatientDocumentId();
    List<String> likelyPatientDocIds=callLog.getLikelyPatientIds();
    Patient patient=patientDocumentId == null ? null : allPatients.get(patientDocumentId);
    String patientId=patient == null ? "String_Node_Str" : patient.getPatientId();
    String clinicName=patient == null ? allPatients.get(likelyPatientDocIds.get(0)).getClinic().getName() : patient.getClinic().getName();
    callLogViews.add(new CallLogView(patientId,callLog,clinicName,getLikelyPatientIds(likelyPatientDocIds)));
  }
  return callLogViews;
}

Fixed version (ground truth):
public List<CallLogView> toCallLogView(List<CallLog> callLogs){
  List<CallLogView> callLogViews=new ArrayList<CallLogView>();
  for (  CallLog callLog : callLogs) {
    String patientDocumentId=callLog.getPatientDocumentId();
    List<String> likelyPatientDocIds=callLog.getLikelyPatientIds();
    Patient patient=patientDocumentId == null ? null : allPatients.get(patientDocumentId);
    String patientId=patient == null ? "String_Node_Str" : patient.getPatientId();
    String clinicName=null;
    if (patient != null) {
      clinicName=patient.getClinic().getName();
    }
 else     if (likelyPatientDocIds != null && likelyPatientDocIds.size() > 0) {
      clinicName=allPatients.get(likelyPatientDocIds.get(0)).getClinic().getName();
    }
    callLogViews.add(new CallLogView(patientId,callLog,clinicName,getLikelyPatientIds(likelyPatientDocIds)));
  }
  return callLogViews;
}
Program: 84809
Project: 84809
Buggy source:
@View(name="String_Node_Str",map="String_Node_Str",reduce="String_Node_Str") public int findScheduledDosagesFailureCount(String regimenId){
  ComplexKey key=ComplexKey.of(regimenId,DosageStatus.NOT_TAKEN);
  ViewQuery q=createQuery("String_Node_Str").key(key);
  ViewResult viewResult=db.queryView(q);
  return rowCount(viewResult);
}

Fixed version (ground truth):
@View(name="String_Node_Str",map="String_Node_Str",reduce="String_Node_Str") public int findScheduledDosagesFailureCount(String regimenId){
  ComplexKey startKey=ComplexKey.of(regimenId,DosageStatus.WILL_TAKE_LATER);
  ComplexKey endKey=ComplexKey.of(regimenId,DosageStatus.NOT_TAKEN);
  ViewQuery q=createQuery("String_Node_Str").startKey(startKey).endKey(endKey);
  ViewResult viewResult=db.queryView(q);
  return rowCount(viewResult);
}
Program: 84810
Project: 84810
Buggy source:
private String getStartingTree(TAMAIVRContext tamaivrContext){
  Patient patient=tamaivrContext.patient(allPatients);
  boolean isPatientOnDailyPillReminder=CallPreference.DailyPillReminder.equals(patient.getPatientPreferences().getCallPreference());
  if (tamaivrContext.isIncomingCall()) {
    if (Patient.Status.Suspended.equals(patient.getStatus()))     return TAMATreeRegistry.MENU_TREE;
    if (!isPatientOnDailyPillReminder) {
      return TAMATreeRegistry.FOUR_DAY_RECALL_INCOMING_CALL;
    }
    PillRegimenSnapshot pillRegimenSnapshot=pillRegimenSnapshot(tamaivrContext);
    if (pillRegimenSnapshot.isCurrentDosageTaken()) {
      return TAMATreeRegistry.CURRENT_DOSAGE_TAKEN;
    }
 else {
      return TAMATreeRegistry.CURRENT_DOSAGE_CONFIRM;
    }
  }
 else {
    if (tamaivrContext.isOutBoxCall()) {
      return TAMATreeRegistry.OUTBOX_CALL;
    }
  }
  if (isPatientOnDailyPillReminder)   return TAMATreeRegistry.CURRENT_DOSAGE_REMINDER;
 else   return TAMATreeRegistry.FOUR_DAY_RECALL;
}

Fixed version (ground truth):
private String getStartingTree(TAMAIVRContext tamaivrContext){
  Patient patient=tamaivrContext.patient(allPatients);
  boolean isPatientOnDailyPillReminder=CallPreference.DailyPillReminder.equals(patient.getPatientPreferences().getCallPreference());
  if (tamaivrContext.isIncomingCall()) {
    if (!isPatientOnDailyPillReminder)     return TAMATreeRegistry.FOUR_DAY_RECALL_INCOMING_CALL;
 else {
      if (Patient.Status.Suspended.equals(patient.getStatus()))       return TAMATreeRegistry.MENU_TREE;
      PillRegimenSnapshot pillRegimenSnapshot=pillRegimenSnapshot(tamaivrContext);
      if (pillRegimenSnapshot.isCurrentDosageTaken()) {
        return TAMATreeRegistry.CURRENT_DOSAGE_TAKEN;
      }
 else {
        return TAMATreeRegistry.CURRENT_DOSAGE_CONFIRM;
      }
    }
  }
 else {
    if (tamaivrContext.isOutBoxCall()) {
      return TAMATreeRegistry.OUTBOX_CALL;
    }
  }
  if (isPatientOnDailyPillReminder)   return TAMATreeRegistry.CURRENT_DOSAGE_REMINDER;
 else   return TAMATreeRegistry.FOUR_DAY_RECALL;
}
Program: 84811
Project: 84811
Buggy source:
@Before public void setUp(){
  initMocks(this);
  treeRegistry=new TAMATreeRegistry(null,null,null,null,null,null,null);
  callFlowController=new TAMACallFlowController(treeRegistry,pillReminderService,voiceOutboxService,allPatients,contextFactory);
  ivrContext=new TAMAIVRContextForTest();
  Patient patient=new Patient();
  patientPreferences=new PatientPreferences();
  patient.setPatientPreferences(patientPreferences);
  ivrContext.pillRegimenSnapshot(pillRegimenSnapshot).patient(patient).callState(CallState.STARTED);
  when(contextFactory.create(kooKooIVRContext)).thenReturn(ivrContext);
}

Fixed version (ground truth):
@Before public void setUp(){
  initMocks(this);
  treeRegistry=new TAMATreeRegistry(null,null,null,null,null,null,null,null);
  callFlowController=new TAMACallFlowController(treeRegistry,pillReminderService,voiceOutboxService,allPatients,contextFactory);
  ivrContext=new TAMAIVRContextForTest();
  Patient patient=new Patient();
  patientPreferences=new PatientPreferences();
  patient.setPatientPreferences(patientPreferences);
  ivrContext.pillRegimenSnapshot(pillRegimenSnapshot).patient(patient).callState(CallState.STARTED);
  when(contextFactory.create(kooKooIVRContext)).thenReturn(ivrContext);
}
Program: 84812
Project: 84812
Buggy source:
@Test public void completionOfSymptomReportingTreeOrPreviousDosageReminderTreeShouldCompleteTheTrees(){
  when(treeRegistry.isLeafTree(TAMATreeRegistry.REGIMEN_1_TO_6)).thenReturn(true);
  tamaCallFlowController.treeComplete(TAMATreeRegistry.REGIMEN_1_TO_6,kooKooIVRContext);
  assertEquals(CallState.ALL_TREES_COMPLETED,tamaIVRContextForTest.callState());
}

Fixed version (ground truth):
@Test public void completionOfSymptomReportingTreeOrPreviousDosageReminderTreeShouldCompleteTheTrees(){
  when(treeRegistry.isLeafTree(TAMATreeRegistry.REGIMEN_1_TO_6)).thenReturn(true);
  tamaCallFlowController.treeComplete(TAMATreeRegistry.REGIMEN_1_TO_6,kooKooIVRContext);
  assertEquals(CallState.ALL_TREES_COMPLETED,ivrContext.callState());
}
Program: 84813
Project: 84813
Buggy source:
@Test public void completionOfOutboxShouldLeadToHangup(){
  tamaIVRContextForTest.callState(CallState.OUTBOX);
  tamaIVRContextForTest.outboxCompleted(true);
  String patientId="String_Node_Str";
  tamaIVRContextForTest.patientId(patientId);
  assertEquals(TAMACallFlowController.HANG_UP_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}

Fixed version (ground truth):
@Test public void completionOfOutboxShouldLeadToHangup(){
  ivrContext.callState(CallState.OUTBOX);
  ivrContext.outboxCompleted(true);
  String patientId="String_Node_Str";
  ivrContext.patientId(patientId);
  assertEquals(TAMACallFlowController.HANG_UP_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}
Program: 84814
Project: 84814
Buggy source:
@Before public void setUp(){
  initMocks(this);
  tamaCallFlowController=new TAMACallFlowController(treeRegistry,pillReminderService,voiceOutboxService,allPatients,contextFactory);
  tamaIVRContextForTest=new TAMAIVRContextForTest();
  when(contextFactory.create(kooKooIVRContext)).thenReturn(tamaIVRContextForTest);
}

Fixed version (ground truth):
@Before public void setUp(){
  initMocks(this);
  tamaCallFlowController=new TAMACallFlowController(treeRegistry,pillReminderService,voiceOutboxService,allPatients,contextFactory);
  ivrContext=new TAMAIVRContextForTest();
  when(contextFactory.create(kooKooIVRContext)).thenReturn(ivrContext);
}
Program: 84815
Project: 84815
Buggy source:
@Test public void returnAuthenticationURLWhenTheCallStarts(){
  tamaIVRContextForTest.callState(CallState.STARTED);
  assertEquals(TAMACallFlowController.AUTHENTICATION_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}

Fixed version (ground truth):
@Test public void returnAuthenticationURLWhenTheCallStarts(){
  ivrContext.callState(CallState.STARTED);
  assertEquals(TAMACallFlowController.AUTHENTICATION_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}
Program: 84816
Project: 84816
Buggy source:
@Test public void outboxURLShouldBeReturnedWhenTheDecisionTreesAreComplete(){
  tamaIVRContextForTest.callState(CallState.ALL_TREES_COMPLETED);
  String patientId="String_Node_Str";
  tamaIVRContextForTest.patientId(patientId);
  when(voiceOutboxService.getNumberPendingMessages(patientId)).thenReturn(3);
  assertEquals(TAMACallFlowController.PRE_OUTBOX_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}

Fixed version (ground truth):
@Test public void outboxURLShouldBeReturnedWhenTheDecisionTreesAreComplete(){
  ivrContext.callState(CallState.ALL_TREES_COMPLETED);
  String patientId="String_Node_Str";
  ivrContext.patientId(patientId);
  when(voiceOutboxService.getNumberPendingMessages(patientId)).thenReturn(3);
  assertEquals(TAMACallFlowController.PRE_OUTBOX_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}
Program: 84817
Project: 84817
Buggy source:
@Test public void hangupURLShouldBeReturnedWhenThereAreNoMessagesInOutbox(){
  tamaIVRContextForTest.callState(CallState.ALL_TREES_COMPLETED);
  String patientId="String_Node_Str";
  tamaIVRContextForTest.patientId(patientId);
  when(voiceOutboxService.getNumberPendingMessages(patientId)).thenReturn(0);
  assertEquals(TAMACallFlowController.HANG_UP_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}

Fixed version (ground truth):
@Test public void hangupURLShouldBeReturnedWhenThereAreNoMessagesInOutbox(){
  ivrContext.callState(CallState.ALL_TREES_COMPLETED);
  String patientId="String_Node_Str";
  ivrContext.patientId(patientId);
  when(voiceOutboxService.getNumberPendingMessages(patientId)).thenReturn(0);
  assertEquals(TAMACallFlowController.HANG_UP_URL,tamaCallFlowController.urlFor(kooKooIVRContext));
}
Program: 84818
Project: 84818
Buggy source:
@Override public KookooIVRResponseBuilder gotDTMF(KooKooIVRContext kooKooIVRContext){
  TAMAIVRContext ivrContext=ivrContextFactory.create(kooKooIVRContext);
  return new KookooIVRResponseBuilder().withSid(ivrContext.callId()).withPlayAudios(TamaIVRMessage.MORE_OPTIONS,TamaIVRMessage.SIGNATURE_MUSIC).language(ivrContext.preferredLanguage());
}

Fixed version (ground truth):
@Override public KookooIVRResponseBuilder gotDTMF(KooKooIVRContext kooKooIVRContext){
  TAMAIVRContext ivrContext=ivrContextFactory.create(kooKooIVRContext);
  return new KookooIVRResponseBuilder().withSid(ivrContext.callId()).withPlayAudios(TamaIVRMessage.MORE_OPTIONS,TamaIVRMessage.SIGNATURE_MUSIC).language(ivrContext.preferredLanguage()).withHangUp();
}
Program: 84819
Project: 84819
Buggy source:
@MotechListener(subjects=TAMAConstants.ADHERENCE_WEEKLY_TREND_SCHEDULER_SUBJECT) public void handleWeeklyAdherenceTrendToOutboxEvent(MotechEvent motechEvent){
  OutboundVoiceMessage voiceMessage=new OutboundVoiceMessage();
  String externalId=(String)motechEvent.getParameters().get(EventKeys.EXTERNAL_ID_KEY);
  voiceMessage.setPartyId(externalId);
  voiceMessage.setStatus(OutboundVoiceMessageStatus.PENDING);
  voiceMessage.setExpirationDate(DateUtil.today().plusWeeks(1).toDate());
  VoiceMessageType voiceMessageType=new VoiceMessageType();
  voiceMessageType.setPriority(MessagePriority.MEDIUM);
  voiceMessageType.setVoiceMessageTypeName(OutboxController.VOICE_MESSAGE_COMMAND_AUDIO);
  voiceMessage.setVoiceMessageType(voiceMessageType);
  Map<String,Object> parameters=new HashMap<String,Object>();
  List<String> commands=Arrays.asList("String_Node_Str");
  parameters.put(OutboxController.VOICE_MESSAGE_COMMAND,commands);
  voiceMessage.setParameters(parameters);
  outboxService.addMessage(voiceMessage);
}

Fixed version (ground truth):
@MotechListener(subjects=TAMAConstants.ADHERENCE_WEEKLY_TREND_SCHEDULER_SUBJECT) public void handleWeeklyAdherenceTrendToOutboxEvent(MotechEvent motechEvent){
  OutboundVoiceMessage voiceMessage=new OutboundVoiceMessage();
  String externalId=(String)motechEvent.getParameters().get(EventKeys.EXTERNAL_ID_KEY);
  voiceMessage.setPartyId(externalId);
  voiceMessage.setStatus(OutboundVoiceMessageStatus.PENDING);
  voiceMessage.setExpirationDate(DateUtil.today().plusWeeks(1).toDate());
  VoiceMessageType voiceMessageType=new VoiceMessageType();
  voiceMessageType.setPriority(MessagePriority.MEDIUM);
  voiceMessageType.setVoiceMessageTypeName(OutboxController.VOICE_MESSAGE_COMMAND_AUDIO);
  voiceMessage.setVoiceMessageType(voiceMessageType);
  voiceMessage.setCreationTime(DateUtil.now().toDate());
  Map<String,Object> parameters=new HashMap<String,Object>();
  List<String> commands=Arrays.asList("String_Node_Str");
  parameters.put(OutboxController.VOICE_MESSAGE_COMMAND,commands);
  voiceMessage.setParameters(parameters);
  outboxService.addMessage(voiceMessage);
}
Program: 84820
Project: 84820
Buggy source:
public void scheduleRepeatingJobForOutBoxCall(Patient patient){
  if (patient.getPatientPreferences().getCallPreference().equals(CallPreference.DailyPillReminder)) {
    Map<String,Object> eventParams=new SchedulerPayloadBuilder().withJobId(patient.getId()).withExternalId(patient.getId()).payload();
    eventParams.put(IS_RETRY,"String_Node_Str");
    MotechEvent outboxCallEvent=new MotechEvent(TAMAConstants.OUTBOX_CALL_SCHEDULER_SUBJECT,eventParams);
    Integer maxOutboundRetries=Integer.valueOf(properties.getProperty(TAMAConstants.OUT_BOX_CALL_RETRIES_PER_DAY));
    int repeatIntervalInMinutes=Integer.valueOf(properties.getProperty(TAMAConstants.OUT_BOX_CALL_RETRY_INTERVAL));
    RepeatingSchedulableJob outboxCallJob=new RepeatingSchedulableJob(outboxCallEvent,DateUtil.now().plusMinutes(repeatIntervalInMinutes).toDate(),DateUtil.today().plusDays(1).toDate(),maxOutboundRetries,repeatIntervalInMinutes * 60 * 1000);
    motechSchedulerService.scheduleRepeatingJob(outboxCallJob);
  }
}

Fixed version (ground truth):
public void scheduleRepeatingJobForOutBoxCall(Patient patient){
  if (patient.getPatientPreferences().getCallPreference().equals(CallPreference.DailyPillReminder)) {
    Map<String,Object> eventParams=new SchedulerPayloadBuilder().withJobId(patient.getId()).withExternalId(patient.getId()).payload();
    eventParams.put(IS_RETRY,"String_Node_Str");
    MotechEvent outboxCallEvent=new MotechEvent(TAMAConstants.OUTBOX_CALL_SCHEDULER_SUBJECT,eventParams);
    Integer maxOutboundRetries=Integer.valueOf(properties.getProperty(TAMAConstants.OUT_BOX_CALL_RETRIES_PER_DAY)) - 1;
    int repeatIntervalInMinutes=Integer.valueOf(properties.getProperty(TAMAConstants.OUT_BOX_CALL_RETRY_INTERVAL));
    RepeatingSchedulableJob outboxCallJob=new RepeatingSchedulableJob(outboxCallEvent,DateUtil.now().plusMinutes(repeatIntervalInMinutes).toDate(),DateUtil.today().plusDays(1).toDate(),maxOutboundRetries,repeatIntervalInMinutes * 60 * 1000);
    motechSchedulerService.scheduleRepeatingJob(outboxCallJob);
  }
}
Program: 84821
Project: 84821
Buggy source:
public void unscheduleJobForOutboxCall(Patient patient){
  motechSchedulerService.unscheduleJob(TAMAConstants.OUTBOX_CALL_SCHEDULER_SUBJECT,patient.getId());
}

Fixed version (ground truth):
public void unscheduleJobForOutboxCall(Patient patient){
  motechSchedulerService.unscheduleJob(TAMAConstants.OUTBOX_CALL_SCHEDULER_SUBJECT,patient.getId());
  motechSchedulerService.unscheduleRepeatingJob(TAMAConstants.OUTBOX_CALL_SCHEDULER_SUBJECT,patient.getId());
}
Program: 84822
Project: 84822
Buggy source:
public void setCallDateFromCallLogDateTime(){
  String dateToBeFormatted=DateUtil.newDate(callLog.getStartTime().toDate()).toDate().toString();
  callDateFromCallLogDateTime=dateToBeFormatted.substring(STRING_BEGIN_INDEX,dateToBeFormatted.indexOf(RIGHT_BOUNDING_SUBSEQUENCE)).trim() + dateToBeFormatted.substring(dateToBeFormatted.indexOf(LEFT_BOUNDING_SUBSEQUENCE) + EXCLUDING_FACTOR,dateToBeFormatted.length());
}

Fixed version (ground truth):
public void setCallDateFromCallLogDateTime(){
  DateTimeFormatter formatter=DateTimeFormat.forPattern("String_Node_Str");
  callDateFromCallLogDateTime=formatter.print(callLog.getStartTime());
}
Program: 84823
Project: 84823
Buggy source:
@Override public void treeComplete(String treeName,KooKooIVRContext kooKooIVRContext){
  TAMAIVRContext tamaivrContext=factory.create(kooKooIVRContext);
  tamaivrContext.lastCompletedTree(treeName);
  if (treeRegistry.isLeafTree(treeName))   tamaivrContext.callState(CallState.ALL_TREES_COMPLETED);
}

Fixed version (ground truth):
@Override public void treeComplete(String treeName,KooKooIVRContext kooKooIVRContext){
  TAMAIVRContext ivrContext=factory.create(kooKooIVRContext);
  ivrContext.lastCompletedTree(treeName);
  if ((onCurrentDosage(treeName) && previousDosageCaptured(ivrContext) && CallState.AUTHENTICATED.equals(ivrContext.callState())) || treeRegistry.isLeafTree(treeName))   ivrContext.callState(CallState.ALL_TREES_COMPLETED);
}
Program: 84825
Project: 84825
Buggy source:
public void log(String callId,String patientDocumentId){
  KookooCallDetailRecord kookooCallDetailRecord=kookooCallDetailRecordsService.get(callId);
  CallLog callLog=callDetailRecordMapper.toCallLog(patientDocumentId,kookooCallDetailRecord);
  callLog.maskAuthenticationPin();
  if (patientDocumentId != null)   callLog.setClinicId(allPatients.get(patientDocumentId).getClinic_id());
  allCallLogs.add(callLog);
}

Fixed version (ground truth):
public void log(String callId,String patientDocumentId){
  KookooCallDetailRecord kookooCallDetailRecord=kookooCallDetailRecordsService.get(callId);
  CallLog callLog=callDetailRecordMapper.toCallLog(patientDocumentId,kookooCallDetailRecord);
  callLog.maskAuthenticationPin();
  if (patientDocumentId != null)   callLog.clinicId(allPatients.get(patientDocumentId).getClinic_id());
  allCallLogs.add(callLog);
}
Program: 84826
Project: 84826
Buggy source:
public void scheduleRepeatingJobsForFourDayRecall(String patientDocId,String treatmentAdviceId,LocalDate treatmentAdviceStartDate){
  Patient patient=allPatients.get(patientDocId);
  Integer maxOutboundRetries=Integer.valueOf(properties.getProperty(TAMAConstants.RETRIES_PER_DAY));
  Integer retryInterval=Integer.valueOf(properties.getProperty(TAMAConstants.RETRY_INTERVAL));
  TimeOfDay callTime=patient.getPatientPreferences().getBestCallTime();
  DateTime jobStartTime=DateUtil.newDateTime(DateUtil.today(),callTime.getHour(),callTime.getMinute(),0).plusMinutes(retryInterval);
  DateTime jobEndTime=jobStartTime.plusDays(1);
  Map<String,Object> eventParams=new FourDayRecallEventPayloadBuilder().withJobId(FOUR_DAY_RECALL_JOB_ID_PREFIX + UUIDUtil.newUUID()).withPatientDocId(patientDocId).withTreatmentAdviceId(treatmentAdviceId).withTreatmentAdviceStartDate(treatmentAdviceStartDate).withRetryFlag(true).payload();
  MotechEvent fourDayRecallRepeatingEvent=new MotechEvent(TAMAConstants.FOUR_DAY_RECALL_SUBJECT,eventParams);
  RepeatingSchedulableJob repeatingSchedulableJob=new RepeatingSchedulableJob(fourDayRecallRepeatingEvent,jobStartTime.toDate(),jobEndTime.toDate(),maxOutboundRetries,retryInterval * 60 * 1000);
  motechSchedulerService.scheduleRepeatingJob(repeatingSchedulableJob);
}

Fixed version (ground truth):
public void scheduleRepeatingJobsForFourDayRecall(String patientDocId,String treatmentAdviceId,LocalDate treatmentAdviceStartDate){
  Patient patient=allPatients.get(patientDocId);
  Integer maxOutboundRetries=Integer.valueOf(properties.getProperty(TAMAConstants.RETRIES_PER_DAY));
  int repeatIntervalInMinutes=Integer.valueOf(properties.getProperty(TAMAConstants.RETRY_INTERVAL));
  TimeOfDay callTime=patient.getPatientPreferences().getBestCallTime();
  DateTime todayCallTime=DateUtil.now().withHourOfDay(callTime.toTime().getHour()).withMinuteOfHour(callTime.toTime().getMinute());
  DateTime jobStartTime=todayCallTime.plusMinutes(repeatIntervalInMinutes);
  DateTime jobEndTime=jobStartTime.plusDays(1);
  Map<String,Object> eventParams=new FourDayRecallEventPayloadBuilder().withJobId(FOUR_DAY_RECALL_JOB_ID_PREFIX + UUIDUtil.newUUID()).withPatientDocId(patientDocId).withTreatmentAdviceId(treatmentAdviceId).withTreatmentAdviceStartDate(treatmentAdviceStartDate).withRetryFlag(true).payload();
  MotechEvent fourDayRecallRepeatingEvent=new MotechEvent(TAMAConstants.FOUR_DAY_RECALL_SUBJECT,eventParams);
  RepeatingSchedulableJob repeatingSchedulableJob=new RepeatingSchedulableJob(fourDayRecallRepeatingEvent,jobStartTime.toDate(),jobEndTime.toDate(),maxOutboundRetries,repeatIntervalInMinutes * 60 * 1000);
  motechSchedulerService.scheduleRepeatingJob(repeatingSchedulableJob);
}
Program: 84827
Project: 84827
Buggy source:
@Test public void numberOfAttemptsShouldBeInitiatized(){
  HttpSession session=mock(HttpSession.class);
  String callerId="String_Node_Str";
  when(kookooRequest.getCid()).thenReturn(callerId);
  when(request.getSession()).thenReturn(session);
  TAMAIVRContext tamaivrContext=new TAMAIVRContext(kookooRequest,request,cookies);
  tamaivrContext.initialize();
  verify(session).setAttribute(TAMAIVRContext.CALLER_ID,callerId);
  verify(session).setAttribute(TAMAIVRContext.NUMBER_OF_ATTEMPTS,"String_Node_Str");
  verify(cookies).add(TAMAIVRContext.NUMBER_OF_TIMES_REMINDER_SENT,"String_Node_Str");
}

Fixed version (ground truth):
@Test public void numberOfAttemptsShouldBeInitiatized(){
  HttpSession session=mock(HttpSession.class);
  String callerId="String_Node_Str";
  when(kookooRequest.getCid()).thenReturn(callerId);
  when(request.getSession()).thenReturn(session);
  TAMAIVRContext tamaivrContext=new TAMAIVRContext(kookooRequest,request,cookies);
  tamaivrContext.initialize();
  verify(session).setAttribute(TAMAIVRContext.CALLER_ID,callerId);
  verify(session).setAttribute(TAMAIVRContext.NUMBER_OF_ATTEMPTS,"String_Node_Str");
}
Program: 84828
Project: 84828
Buggy source:
public int totalNumberOfTimesToSendReminder(){
  return Integer.parseInt(httpRequest.getParameter(TOTAL_NUMBER_OF_TIMES_TO_SEND_REMINDER));
}

Fixed version (ground truth):
public int totalNumberOfTimesToSendReminder(){
  return Integer.parseInt(kookooRequest.getParameter(TOTAL_NUMBER_OF_TIMES_TO_SEND_REMINDER));
}
Program: 84829
Project: 84829
Buggy source:
void initialize(){
  callerId(requestedCallerId());
  setInSession(NUMBER_OF_ATTEMPTS,"String_Node_Str");
  cookies.add(NUMBER_OF_TIMES_REMINDER_SENT,"String_Node_Str");
}

Fixed version (ground truth):
void initialize(){
  callerId(requestedCallerId());
  setInSession(NUMBER_OF_ATTEMPTS,"String_Node_Str");
}
Program: 84830
Project: 84830
Buggy source:
public int numberOfTimesReminderSent(){
  return Integer.parseInt(httpRequest.getParameter(NUMBER_OF_TIMES_REMINDER_SENT));
}

Fixed version (ground truth):
public int numberOfTimesReminderSent(){
  return Integer.parseInt(kookooRequest.getParameter(NUMBER_OF_TIMES_REMINDER_SENT));
}