Program: 144223
Project: 144223
Buggy source:
/** 
 * Create CDA section(History of Infection section)
 * @param patient
 * @return CDA section or Report errors
 * @should return CDA section
 * @should return errors in Section
 */
public static Section buildHistoryOfInfectionSection(Patient patient){
  Map<String,String> mappings=new HashMap<String,String>();
  Section section=CDAFactory.eINSTANCE.createSection();
  HistoryOfInfectionSection ccs=new HistoryOfInfectionSection();
  section.getTemplateIds().add(CDAHelper.buildTemplateID(ccs.getTemplateid(),null,null));
  section.setCode(CDAHelper.buildCodeCE(ccs.getCode(),ccs.getCodeSystem(),ccs.getSectionName(),ccs.getCodeSystemName()));
  section.setTitle(CDAHelper.buildTitle(ccs.getSectionDescription()));
  StrucDocText text=CDAFactory.eINSTANCE.createStrucDocText();
  StringBuilder builder=new StringBuilder();
  String delimeter="String_Node_Str";
  builder.append(delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  ConceptService service=Context.getConceptService();
  for (  Map.Entry<String,String> mapentry : mappings.entrySet()) {
    List<Concept> ConceptsList=new ArrayList<Concept>();
    for (    Concept concepts : service.getConceptsByMapping(mapentry.getKey(),mapentry.getValue(),false)) {
      if (concepts == null) {
        throw new APIException(Context.getMessageSourceService().getMessage("String_Node_Str",new Object[]{mapentry.getKey(),mapentry.getValue()},null));
      }
 else {
        ConceptsList.add(concepts);
      }
    }
    List<Obs> obsList=new ArrayList<Obs>();
    for (    Concept concept : ConceptsList) {
      if (!concept.getDatatype().getName().equals("String_Node_Str")) {
        obsList.addAll(Context.getObsService().getObservationsByPersonAndConcept(patient,concept));
      }
      if (obsList.isEmpty()) {
        log.error(Context.getMessageSourceService().getMessage("String_Node_Str",new Object[]{concept.getConceptId(),concept.getName()},null));
        builder.append("String_Node_Str" + delimeter);
        builder.append("String_Node_Str" + concept.getId() + "String_Node_Str"+ delimeter);
        builder.append("String_Node_Str");
        builder.append("String_Node_Str" + "String_Node_Str" + delimeter);
        builder.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ delimeter);
        builder.append("String_Node_Str" + delimeter);
        Entry entry=CDAFactory.eINSTANCE.createEntry();
        entry.setTypeCode(x_ActRelationshipEntry.DRIV);
        Observation observation=CDAFactory.eINSTANCE.createObservation();
        observation.setClassCode(ActClassObservation.OBS);
        observation.setMoodCode(x_ActMoodDocumentObservation.EVN);
        observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation.getIds().add(CDAHelper.buildID("String_Node_Str",null));
        observation.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),CDAHelper.getCodeSystemByName(mapentry.getValue()),"String_Node_Str",mapentry.getValue()));
        observation.setText(CDAHelper.buildEDText("String_Node_Str"));
        observation.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
        observation.setEffectiveTime(CDAHelper.buildDateTime(new Date()));
        ED value1=DatatypesFactory.eINSTANCE.createED("String_Node_Str");
        observation.getValues().add(value1);
        CE interpretationcode=CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,null);
        observation.getInterpretationCodes().add(interpretationcode);
        CE methodcode=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
        observation.getMethodCodes().add(methodcode);
        CE targetsite=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
        observation.getTargetSiteCodes().add(targetsite);
        entry.setObservation(observation);
        section.getEntries().add(entry);
      }
    }
    for (    Obs obs : obsList) {
      builder.append("String_Node_Str" + delimeter);
      builder.append("String_Node_Str" + obs.getId() + "String_Node_Str"+ obs.getConcept().getName()+ "String_Node_Str"+ delimeter);
      builder.append("String_Node_Str");
      int type=obs.getConcept().getDatatype().getId();
      String value=CDAHelper.getDatatypesValue(type,obs);
      builder.append(value + "String_Node_Str" + delimeter);
      builder.append("String_Node_Str" + CDAHelper.getDateFormat().format(obs.getObsDatetime()) + "String_Node_Str"+ delimeter);
      builder.append("String_Node_Str" + delimeter);
      Entry entry=CDAFactory.eINSTANCE.createEntry();
      entry.setTypeCode(x_ActRelationshipEntry.DRIV);
      Observation observation=CDAFactory.eINSTANCE.createObservation();
      observation.setClassCode(ActClassObservation.OBS);
      observation.setMoodCode(x_ActMoodDocumentObservation.EVN);
      observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      observation.getIds().add(CDAHelper.buildID(obs.getUuid(),null));
      observation.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),CDAHelper.getCodeSystemByName(mapentry.getValue()),obs.getConcept().getName().toString(),mapentry.getValue()));
      observation.setText(CDAHelper.buildEDText("String_Node_Str" + obs.getId()));
      observation.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
      observation.setEffectiveTime(CDAHelper.buildDateTime(new Date()));
      ED value1=DatatypesFactory.eINSTANCE.createED("String_Node_Str");
      observation.getValues().add(value1);
      CE interpretationcode=CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,null);
      observation.getInterpretationCodes().add(interpretationcode);
      CE methodcode=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
      observation.getMethodCodes().add(methodcode);
      CE targetsite=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
      observation.getTargetSiteCodes().add(targetsite);
      entry.setObservation(observation);
      section.getEntries().add(entry);
    }
  }
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  text.addText(builder.toString());
  section.setText(text);
  return section;
}

Fixed version (ground truth):
/** 
 * Create CDA section(History of Infection section)
 * @param patient
 * @return CDA section or Report errors
 * @should return CDA section
 * @should return errors in Section
 */
public static Section buildHistoryOfInfectionSection(Patient patient){
  Map<String,String> mappings=new HashMap<String,String>();
  Section section=CDAFactory.eINSTANCE.createSection();
  HistoryOfInfectionSection ccs=new HistoryOfInfectionSection();
  section.getTemplateIds().add(CDAHelper.buildTemplateID(ccs.getTemplateid(),null,null));
  section.setCode(CDAHelper.buildCodeCE(ccs.getCode(),ccs.getCodeSystem(),ccs.getSectionName(),ccs.getCodeSystemName()));
  section.setTitle(CDAHelper.buildTitle(ccs.getSectionDescription()));
  StrucDocText text=CDAFactory.eINSTANCE.createStrucDocText();
  StringBuilder builder=new StringBuilder();
  String delimeter="String_Node_Str";
  builder.append(delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  mappings.put("String_Node_Str","String_Node_Str");
  ConceptService service=Context.getConceptService();
  for (  Map.Entry<String,String> mapentry : mappings.entrySet()) {
    List<Concept> ConceptsList=new ArrayList<Concept>();
    for (    Concept concepts : service.getConceptsByMapping(mapentry.getKey(),mapentry.getValue(),false)) {
      if (concepts == null) {
        throw new APIException(Context.getMessageSourceService().getMessage("String_Node_Str",new Object[]{mapentry.getKey(),mapentry.getValue()},null));
      }
 else {
        ConceptsList.add(concepts);
      }
    }
    List<Obs> obsList=new ArrayList<Obs>();
    for (    Concept concept : ConceptsList) {
      boolean isDatatypeNA=concept.getDatatype().getName().equals("String_Node_Str");
      if (!isDatatypeNA) {
        obsList.addAll(Context.getObsService().getObservationsByPersonAndConcept(patient,concept));
      }
      if (!isDatatypeNA && obsList.isEmpty()) {
        log.error(Context.getMessageSourceService().getMessage("String_Node_Str",new Object[]{concept.getConceptId(),concept.getName()},null));
        builder.append("String_Node_Str" + delimeter);
        builder.append("String_Node_Str" + concept.getId() + "String_Node_Str"+ delimeter);
        builder.append("String_Node_Str");
        builder.append("String_Node_Str" + "String_Node_Str" + delimeter);
        builder.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ delimeter);
        builder.append("String_Node_Str" + delimeter);
        Entry entry=CDAFactory.eINSTANCE.createEntry();
        entry.setTypeCode(x_ActRelationshipEntry.DRIV);
        Observation observation=CDAFactory.eINSTANCE.createObservation();
        observation.setClassCode(ActClassObservation.OBS);
        observation.setMoodCode(x_ActMoodDocumentObservation.EVN);
        observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation.getIds().add(CDAHelper.buildID("String_Node_Str",null));
        observation.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),CDAHelper.getCodeSystemByName(mapentry.getValue()),"String_Node_Str",mapentry.getValue()));
        observation.setText(CDAHelper.buildEDText("String_Node_Str"));
        observation.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
        observation.setEffectiveTime(CDAHelper.buildDateTime(new Date()));
        ED value1=DatatypesFactory.eINSTANCE.createED("String_Node_Str");
        observation.getValues().add(value1);
        CE interpretationcode=CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,null);
        observation.getInterpretationCodes().add(interpretationcode);
        CE methodcode=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
        observation.getMethodCodes().add(methodcode);
        CE targetsite=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
        observation.getTargetSiteCodes().add(targetsite);
        entry.setObservation(observation);
        section.getEntries().add(entry);
      }
    }
    for (    Obs obs : obsList) {
      builder.append("String_Node_Str" + delimeter);
      builder.append("String_Node_Str" + obs.getId() + "String_Node_Str"+ obs.getConcept().getName()+ "String_Node_Str"+ delimeter);
      builder.append("String_Node_Str");
      int type=obs.getConcept().getDatatype().getId();
      String value=CDAHelper.getDatatypesValue(type,obs);
      builder.append(value + "String_Node_Str" + delimeter);
      builder.append("String_Node_Str" + CDAHelper.getDateFormat().format(obs.getObsDatetime()) + "String_Node_Str"+ delimeter);
      builder.append("String_Node_Str" + delimeter);
      Entry entry=CDAFactory.eINSTANCE.createEntry();
      entry.setTypeCode(x_ActRelationshipEntry.DRIV);
      Observation observation=CDAFactory.eINSTANCE.createObservation();
      observation.setClassCode(ActClassObservation.OBS);
      observation.setMoodCode(x_ActMoodDocumentObservation.EVN);
      observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      observation.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      observation.getIds().add(CDAHelper.buildID(obs.getUuid(),null));
      observation.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),CDAHelper.getCodeSystemByName(mapentry.getValue()),obs.getConcept().getName().toString(),mapentry.getValue()));
      observation.setText(CDAHelper.buildEDText("String_Node_Str" + obs.getId()));
      observation.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
      observation.setEffectiveTime(CDAHelper.buildDateTime(new Date()));
      ED value1=DatatypesFactory.eINSTANCE.createED("String_Node_Str");
      observation.getValues().add(value1);
      CE interpretationcode=CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,null);
      observation.getInterpretationCodes().add(interpretationcode);
      CE methodcode=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
      observation.getMethodCodes().add(methodcode);
      CE targetsite=CDAHelper.buildCodeCE(null,CDAHelper.getCodeSystemByName(mapentry.getValue()),null,mapentry.getValue());
      observation.getTargetSiteCodes().add(targetsite);
      entry.setObservation(observation);
      section.getEntries().add(entry);
    }
  }
  builder.append("String_Node_Str" + delimeter);
  builder.append("String_Node_Str" + delimeter);
  text.addText(builder.toString());
  section.setText(text);
  return section;
}