Program: 144225
Project: 144225
Buggy source:
/** 
 * Create CDA section(History of past illness section)
 * @param patient
 * @return CDA section or Report errors
 * @should return CDA section
 * @should return errors in Section
 */
public static Section buildHistoryOfPastIllnessSection(Patient patient){
  Map<String,String> mappings=new HashMap<String,String>();
  Section section=CDAFactory.eINSTANCE.createSection();
  HistoryOfPastIllnessSection ccs=new HistoryOfPastIllnessSection();
  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();
  text.addText("String_Node_Str");
  section.setText(text);
  ConceptService service=Context.getConceptService();
  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");
  Entry e=CDAFactory.eINSTANCE.createEntry();
  Act act=CDAFactory.eINSTANCE.createAct();
  act.setClassCode(x_ActClassDocumentEntryAct.ACT);
  act.setMoodCode(x_DocumentActMood.EVN);
  act.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  act.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  act.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  act.getIds().add(CDAHelper.buildID("String_Node_Str",null));
  CD code=DatatypesFactory.eINSTANCE.createCD();
  code.setNullFlavor(NullFlavor.NA);
  act.setCode(code);
  act.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
  act.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(null));
  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));
      }
 else {
        if (concept.getSetMembers() != null) {
          List<Concept> conceptsetmemebers=concept.getSetMembers();
          for (          Concept conceptmem : conceptsetmemebers) {
            List<Obs> obsOFconceptsetmemebers=new ArrayList<Obs>();
            obsOFconceptsetmemebers.addAll(Context.getObsService().getObservationsByPersonAndConcept(patient,conceptmem));
            if (!obsOFconceptsetmemebers.isEmpty()) {
              for (              Obs o : obsOFconceptsetmemebers) {
                obsList.add(o);
              }
            }
          }
        }
      }
      if (obsList.isEmpty()) {
        log.error(Context.getMessageSourceService().getMessage("String_Node_Str",new Object[]{concept.getConceptId(),concept.getName()},null));
        EntryRelationship entryRelationship1=CDAFactory.eINSTANCE.createEntryRelationship();
        entryRelationship1.setTypeCode(x_ActRelationshipEntryRelationship.SUBJ);
        entryRelationship1.setInversionInd(false);
        Observation observation1=CDAFactory.eINSTANCE.createObservation();
        observation1.setClassCode(ActClassObservation.OBS);
        observation1.setMoodCode(x_ActMoodDocumentObservation.EVN);
        observation1.setNegationInd(false);
        observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation1.getIds().add(CDAHelper.buildID("String_Node_Str",null));
        observation1.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),"String_Node_Str",null,"String_Node_Str"));
        ED answerTxt=DatatypesFactory.eINSTANCE.createED();
        observation1.setText(answerTxt.addText("String_Node_Str" + concept.getName() + "String_Node_Str"+ concept.getId()));
        observation1.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
        observation1.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(null,null));
        CD codecd=DatatypesFactory.eINSTANCE.createCD();
        codecd.setCode("String_Node_Str");
        codecd.setCodeSystem("String_Node_Str");
        codecd.setDisplayName("String_Node_Str");
        codecd.setCodeSystemName("String_Node_Str");
        observation1.getValues().add(codecd);
        entryRelationship1.setObservation(observation1);
        act.getEntryRelationships().add(entryRelationship1);
      }
    }
    for (    Obs obs : obsList) {
      EntryRelationship entryRelationship1=CDAFactory.eINSTANCE.createEntryRelationship();
      entryRelationship1.setTypeCode(x_ActRelationshipEntryRelationship.SUBJ);
      entryRelationship1.setInversionInd(false);
      Observation observation1=CDAFactory.eINSTANCE.createObservation();
      observation1.setClassCode(ActClassObservation.OBS);
      observation1.setMoodCode(x_ActMoodDocumentObservation.EVN);
      observation1.setNegationInd(false);
      observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      int type=obs.getConcept().getDatatype().getId();
      String value=CDAHelper.getDatatypesValue(type,obs);
      observation1.getIds().add(CDAHelper.buildID(obs.getUuid(),null));
      if (mapentry.getKey().equals("String_Node_Str")) {
        observation1.setCode(CDAHelper.buildCodeCD("String_Node_Str","String_Node_Str",null,"String_Node_Str"));
      }
 else {
        observation1.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),"String_Node_Str",null,"String_Node_Str"));
      }
      ED answerTxt=DatatypesFactory.eINSTANCE.createED();
      observation1.setText(answerTxt.addText(value));
      observation1.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
      observation1.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(null,null));
      CD codecd=DatatypesFactory.eINSTANCE.createCD();
      codecd.setCode(obs.getConcept().getId().toString());
      codecd.setCodeSystem(CDAHelper.getCodeSystemByName(mapentry.getValue()));
      codecd.setDisplayName(obs.getConcept().getName().toString());
      codecd.setCodeSystemName(mapentry.getValue());
      observation1.getValues().add(codecd);
      entryRelationship1.setObservation(observation1);
      act.getEntryRelationships().add(entryRelationship1);
    }
  }
  e.setAct(act);
  section.getEntries().add(e);
  return section;
}

Fixed version (ground truth):
/** 
 * Create CDA section(History of past illness section)
 * @param patient
 * @return CDA section or Report errors
 * @should return CDA section
 * @should return errors in Section
 */
public static Section buildHistoryOfPastIllnessSection(Patient patient){
  Map<String,String> mappings=new HashMap<String,String>();
  Section section=CDAFactory.eINSTANCE.createSection();
  HistoryOfPastIllnessSection ccs=new HistoryOfPastIllnessSection();
  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();
  text.addText("String_Node_Str");
  section.setText(text);
  ConceptService service=Context.getConceptService();
  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");
  Entry e=CDAFactory.eINSTANCE.createEntry();
  Act act=CDAFactory.eINSTANCE.createAct();
  act.setClassCode(x_ActClassDocumentEntryAct.ACT);
  act.setMoodCode(x_DocumentActMood.EVN);
  act.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  act.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  act.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  act.getIds().add(CDAHelper.buildID("String_Node_Str",null));
  CD code=DatatypesFactory.eINSTANCE.createCD();
  code.setNullFlavor(NullFlavor.NA);
  act.setCode(code);
  act.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
  act.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(null));
  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));
      }
 else {
        if (concept.getSetMembers() != null) {
          List<Concept> conceptsetmemebers=concept.getSetMembers();
          for (          Concept conceptmem : conceptsetmemebers) {
            List<Obs> obsOFconceptsetmemebers=new ArrayList<Obs>();
            obsOFconceptsetmemebers.addAll(Context.getObsService().getObservationsByPersonAndConcept(patient,conceptmem));
            if (!obsOFconceptsetmemebers.isEmpty()) {
              for (              Obs o : obsOFconceptsetmemebers) {
                obsList.add(o);
              }
            }
          }
        }
      }
      if (!isDatatypeNA && obsList.isEmpty()) {
        log.error(Context.getMessageSourceService().getMessage("String_Node_Str",new Object[]{concept.getConceptId(),concept.getName()},null));
        EntryRelationship entryRelationship1=CDAFactory.eINSTANCE.createEntryRelationship();
        entryRelationship1.setTypeCode(x_ActRelationshipEntryRelationship.SUBJ);
        entryRelationship1.setInversionInd(false);
        Observation observation1=CDAFactory.eINSTANCE.createObservation();
        observation1.setClassCode(ActClassObservation.OBS);
        observation1.setMoodCode(x_ActMoodDocumentObservation.EVN);
        observation1.setNegationInd(false);
        observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
        observation1.getIds().add(CDAHelper.buildID("String_Node_Str",null));
        observation1.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),"String_Node_Str",null,"String_Node_Str"));
        ED answerTxt=DatatypesFactory.eINSTANCE.createED();
        observation1.setText(answerTxt.addText("String_Node_Str" + concept.getName() + "String_Node_Str"+ concept.getId()));
        observation1.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
        observation1.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(null,null));
        CD codecd=DatatypesFactory.eINSTANCE.createCD();
        codecd.setCode("String_Node_Str");
        codecd.setCodeSystem("String_Node_Str");
        codecd.setDisplayName("String_Node_Str");
        codecd.setCodeSystemName("String_Node_Str");
        observation1.getValues().add(codecd);
        entryRelationship1.setObservation(observation1);
        act.getEntryRelationships().add(entryRelationship1);
      }
    }
    for (    Obs obs : obsList) {
      EntryRelationship entryRelationship1=CDAFactory.eINSTANCE.createEntryRelationship();
      entryRelationship1.setTypeCode(x_ActRelationshipEntryRelationship.SUBJ);
      entryRelationship1.setInversionInd(false);
      Observation observation1=CDAFactory.eINSTANCE.createObservation();
      observation1.setClassCode(ActClassObservation.OBS);
      observation1.setMoodCode(x_ActMoodDocumentObservation.EVN);
      observation1.setNegationInd(false);
      observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      observation1.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
      int type=obs.getConcept().getDatatype().getId();
      String value=CDAHelper.getDatatypesValue(type,obs);
      observation1.getIds().add(CDAHelper.buildID(obs.getUuid(),null));
      if (mapentry.getKey().equals("String_Node_Str")) {
        observation1.setCode(CDAHelper.buildCodeCD("String_Node_Str","String_Node_Str",null,"String_Node_Str"));
      }
 else {
        observation1.setCode(CDAHelper.buildCodeCD(mapentry.getKey(),"String_Node_Str",null,"String_Node_Str"));
      }
      ED answerTxt=DatatypesFactory.eINSTANCE.createED();
      observation1.setText(answerTxt.addText(value));
      observation1.setStatusCode(CDAHelper.getStatusCode("String_Node_Str"));
      observation1.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(null,null));
      CD codecd=DatatypesFactory.eINSTANCE.createCD();
      codecd.setCode(obs.getConcept().getId().toString());
      codecd.setCodeSystem(CDAHelper.getCodeSystemByName(mapentry.getValue()));
      codecd.setDisplayName(obs.getConcept().getName().toString());
      codecd.setCodeSystemName(mapentry.getValue());
      observation1.getValues().add(codecd);
      entryRelationship1.setObservation(observation1);
      act.getEntryRelationships().add(entryRelationship1);
    }
  }
  e.setAct(act);
  section.getEntries().add(e);
  return section;
}