Program: 86828
Project: 86828
Buggy source:
public Cohort getPatientsHavingNumericObs(TimeModifier timeModifier,Concept question,Concept groupingConcept,Date onOrAfter,Date onOrBefore,List<Location> locationList,List<EncounterType> encounterTypeList,Modifier modifier1,Double value1,Modifier modifier2,Double value2){
  Integer questionConceptId=question == null ? null : question.getId();
  Integer groupingConceptId=groupingConcept == null ? null : groupingConcept.getId();
  if (groupingConceptId != null)   throw new RuntimeException("String_Node_Str");
  List<Integer> locationIds=null;
  if (locationList != null && locationList.size() > 0) {
    for (    Location l : locationList)     locationIds.add(l.getId());
  }
  List<Integer> encounterTypeIds=null;
  if (encounterTypeList != null && encounterTypeList.size() > 0) {
    for (    EncounterType t : encounterTypeList)     encounterTypeIds.add(t.getId());
  }
  String dateSql="String_Node_Str";
  String dateSqlForSubquery="String_Node_Str";
  if (onOrAfter != null) {
    dateSql+="String_Node_Str";
    dateSqlForSubquery+="String_Node_Str";
  }
  if (onOrBefore != null) {
    dateSql+="String_Node_Str";
    dateSqlForSubquery+="String_Node_Str";
  }
  boolean doSqlAggregation=timeModifier == TimeModifier.MIN || timeModifier == TimeModifier.MAX || timeModifier == TimeModifier.AVG;
  boolean doInvert=timeModifier == TimeModifier.NO;
  String valueSql="String_Node_Str";
  if (doSqlAggregation) {
    valueSql="String_Node_Str" + timeModifier.toString() + "String_Node_Str"+ valueSql+ "String_Node_Str";
  }
  List<String> valueClauses=new ArrayList<String>();
  if (value1 != null)   valueClauses.add(valueSql + modifier1.getSqlRepresentation() + "String_Node_Str");
  if (value2 != null)   valueClauses.add(valueSql + modifier2.getSqlRepresentation() + "String_Node_Str");
  if (locationIds != null)   valueClauses.add("String_Node_Str");
  if (encounterTypeIds != null)   throw new RuntimeException("String_Node_Str");
  StringBuilder sql=new StringBuilder();
  if (timeModifier == TimeModifier.ANY || timeModifier == TimeModifier.NO) {
    sql.append("String_Node_Str");
    if (questionConceptId != null)     sql.append("String_Node_Str");
    sql.append(dateSql);
  }
 else   if (timeModifier == TimeModifier.FIRST || timeModifier == TimeModifier.LAST) {
    boolean isFirst=timeModifier == PatientSetService.TimeModifier.FIRST;
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str" + (isFirst ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str");
    sql.append("String_Node_Str" + dateSqlForSubquery + "String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
  }
 else   if (doSqlAggregation) {
    sql.append("String_Node_Str");
    sql.append("String_Node_Str" + dateSql);
    sql.append("String_Node_Str");
  }
 else {
    throw new IllegalArgumentException("String_Node_Str" + timeModifier + "String_Node_Str");
  }
  if (valueClauses.size() > 0) {
    sql.append(doSqlAggregation ? "String_Node_Str" : "String_Node_Str");
    for (Iterator<String> i=valueClauses.iterator(); i.hasNext(); ) {
      sql.append(i.next());
      if (i.hasNext())       sql.append("String_Node_Str");
    }
  }
  log.debug("String_Node_Str" + sql);
  System.out.println("String_Node_Str" + sql);
  Query query=sessionFactory.getCurrentSession().createSQLQuery(sql.toString());
  query.setCacheMode(CacheMode.IGNORE);
  if (questionConceptId != null)   query.setInteger("String_Node_Str",questionConceptId);
  if (value1 != null)   query.setDouble("String_Node_Str",value1);
  if (value2 != null)   query.setDouble("String_Node_Str",value2);
  if (onOrAfter != null)   query.setDate("String_Node_Str",onOrAfter);
  if (onOrBefore != null)   query.setDate("String_Node_Str",onOrBefore);
  if (locationIds != null)   query.setParameterList("String_Node_Str",locationIds);
  Cohort ret;
  if (doInvert) {
    ret=Context.getPatientSetService().getAllPatients();
    ret.getMemberIds().removeAll(query.list());
  }
 else {
    ret=new Cohort(query.list());
  }
  return ret;
}

Fixed version (ground truth):
public Cohort getPatientsHavingNumericObs(TimeModifier timeModifier,Concept question,Concept groupingConcept,Date onOrAfter,Date onOrBefore,List<Location> locationList,List<EncounterType> encounterTypeList,Modifier modifier1,Double value1,Modifier modifier2,Double value2){
  Integer questionConceptId=question == null ? null : question.getId();
  Integer groupingConceptId=groupingConcept == null ? null : groupingConcept.getId();
  if (groupingConceptId != null)   throw new RuntimeException("String_Node_Str");
  List<Integer> locationIds=null;
  if (locationList != null && locationList.size() > 0) {
    locationIds=new ArrayList<Integer>();
    for (    Location l : locationList)     locationIds.add(l.getId());
  }
  List<Integer> encounterTypeIds=null;
  if (encounterTypeList != null && encounterTypeList.size() > 0) {
    encounterTypeIds=new ArrayList<Integer>();
    for (    EncounterType t : encounterTypeList)     encounterTypeIds.add(t.getId());
  }
  String dateAndLocationSql="String_Node_Str";
  String dateAndLocationSqlForSubquery="String_Node_Str";
  if (onOrAfter != null) {
    dateAndLocationSql+="String_Node_Str";
    dateAndLocationSqlForSubquery+="String_Node_Str";
  }
  if (onOrBefore != null) {
    dateAndLocationSql+="String_Node_Str";
    dateAndLocationSqlForSubquery+="String_Node_Str";
  }
  if (locationIds != null) {
    dateAndLocationSql+="String_Node_Str";
    dateAndLocationSqlForSubquery+="String_Node_Str";
  }
  if (encounterTypeIds != null)   throw new RuntimeException("String_Node_Str");
  boolean doSqlAggregation=timeModifier == TimeModifier.MIN || timeModifier == TimeModifier.MAX || timeModifier == TimeModifier.AVG;
  boolean doInvert=timeModifier == TimeModifier.NO;
  String valueSql="String_Node_Str";
  if (doSqlAggregation) {
    valueSql="String_Node_Str" + timeModifier.toString() + "String_Node_Str"+ valueSql+ "String_Node_Str";
  }
  List<String> valueClauses=new ArrayList<String>();
  if (value1 != null)   valueClauses.add(valueSql + modifier1.getSqlRepresentation() + "String_Node_Str");
  if (value2 != null)   valueClauses.add(valueSql + modifier2.getSqlRepresentation() + "String_Node_Str");
  StringBuilder sql=new StringBuilder();
  if (timeModifier == TimeModifier.ANY || timeModifier == TimeModifier.NO) {
    sql.append("String_Node_Str");
    if (questionConceptId != null)     sql.append("String_Node_Str");
    sql.append(dateAndLocationSql);
  }
 else   if (timeModifier == TimeModifier.FIRST || timeModifier == TimeModifier.LAST) {
    boolean isFirst=timeModifier == PatientSetService.TimeModifier.FIRST;
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str" + (isFirst ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str");
    sql.append("String_Node_Str" + dateAndLocationSqlForSubquery + "String_Node_Str");
    sql.append("String_Node_Str");
    sql.append("String_Node_Str");
  }
 else   if (doSqlAggregation) {
    sql.append("String_Node_Str");
    sql.append("String_Node_Str" + dateAndLocationSql);
    sql.append("String_Node_Str");
  }
 else {
    throw new IllegalArgumentException("String_Node_Str" + timeModifier + "String_Node_Str");
  }
  if (valueClauses.size() > 0) {
    sql.append(doSqlAggregation ? "String_Node_Str" : "String_Node_Str");
    for (Iterator<String> i=valueClauses.iterator(); i.hasNext(); ) {
      sql.append(i.next());
      if (i.hasNext())       sql.append("String_Node_Str");
    }
  }
  log.debug("String_Node_Str" + sql);
  Query query=sessionFactory.getCurrentSession().createSQLQuery(sql.toString());
  query.setCacheMode(CacheMode.IGNORE);
  if (questionConceptId != null)   query.setInteger("String_Node_Str",questionConceptId);
  if (value1 != null)   query.setDouble("String_Node_Str",value1);
  if (value2 != null)   query.setDouble("String_Node_Str",value2);
  if (onOrAfter != null)   query.setDate("String_Node_Str",onOrAfter);
  if (onOrBefore != null)   query.setDate("String_Node_Str",onOrBefore);
  if (locationIds != null)   query.setParameterList("String_Node_Str",locationIds);
  Cohort ret;
  if (doInvert) {
    ret=Context.getPatientSetService().getAllPatients();
    ret.getMemberIds().removeAll(query.list());
  }
 else {
    ret=new Cohort(query.list());
  }
  return ret;
}