Program: 144237
Project: 144237
Buggy source:
public ClinicalDocument buildHeader(ClinicalDocument doc,BaseCdaTypeHandler bh,Patient p){
  InfrastructureRootTypeId typeId=CDAFactory.eINSTANCE.createInfrastructureRootTypeId();
  typeId.setExtension("String_Node_Str");
  typeId.setRoot("String_Node_Str");
  doc.setTypeId(typeId);
  doc.getTemplateIds().clear();
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str","String_Node_Str",null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID(bh.templateid,null,null));
  doc.setId(CDAHelper.buildID(Context.getAdministrationService().getImplementationId().getImplementationId(),bh.documentShortName));
  doc.setCode(CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,"String_Node_Str"));
  doc.setTitle(CDAHelper.buildTitle(bh.documentFullName));
  Date d=new Date();
  doc.setEffectiveTime(CDAHelper.buildEffectiveTime(d));
  CE confidentialityCode=DatatypesFactory.eINSTANCE.createCE();
  confidentialityCode.setCode("String_Node_Str");
  confidentialityCode.setCodeSystem("String_Node_Str");
  doc.setConfidentialityCode(confidentialityCode);
  CS languageCode=DatatypesFactory.eINSTANCE.createCS();
  languageCode.setCode("String_Node_Str");
  doc.setLanguageCode(languageCode);
  CS realmcode=DatatypesFactory.eINSTANCE.createCS("String_Node_Str");
  doc.getRealmCodes().add(realmcode);
  PatientRole patientRole=CDAFactory.eINSTANCE.createPatientRole();
  patientRole.getIds().add(CDAHelper.buildID(Context.getAdministrationService().getImplementationId().getImplementationId(),p.getPatientIdentifier().getIdentifier()));
  Set<PersonAddress> addresses=p.getAddresses();
  AD patientAddress=DatatypesFactory.eINSTANCE.createAD();
  patientAddress=buildAddresses(patientAddress,addresses);
  patientRole.getAddrs().add(patientAddress);
  TEL patientTelecom=DatatypesFactory.eINSTANCE.createTEL();
  patientTelecom.setNullFlavor(NullFlavor.UNK);
  patientRole.getTelecoms().add(patientTelecom);
  org.openhealthtools.mdht.uml.cda.Patient cdapatient=CDAFactory.eINSTANCE.createPatient();
  patientRole.setPatient(cdapatient);
  PN name=DatatypesFactory.eINSTANCE.createPN();
  if (p.getPersonName().getFamilyNamePrefix() != null) {
    name.addPrefix(p.getPersonName().getFamilyNamePrefix());
  }
  name.addGiven(p.getPersonName().getGivenName());
  name.addFamily(p.getPersonName().getFamilyName());
  if (p.getPersonName().getFamilyNameSuffix() != null) {
    name.addSuffix(p.getPersonName().getFamilyNameSuffix());
  }
  cdapatient.getNames().add(name);
  CE gender=DatatypesFactory.eINSTANCE.createCE();
  gender.setCode(p.getGender());
  gender.setCodeSystem("String_Node_Str");
  cdapatient.setAdministrativeGenderCode(gender);
  TS dateOfBirth=DatatypesFactory.eINSTANCE.createTS();
  SimpleDateFormat s1=new SimpleDateFormat("String_Node_Str");
  Date dobs=p.getBirthdate();
  String dob=s1.format(dobs);
  dateOfBirth.setValue(dob);
  cdapatient.setBirthTime(dateOfBirth);
  CE codes=DatatypesFactory.eINSTANCE.createCE();
  codes.setCode("String_Node_Str");
  cdapatient.setMaritalStatusCode(codes);
  CE codes1=DatatypesFactory.eINSTANCE.createCE();
  codes1.setCode("String_Node_Str");
  cdapatient.setEthnicGroupCode(codes1);
  Organization providerOrganization=CDAFactory.eINSTANCE.createOrganization();
  AD providerOrganizationAddress=DatatypesFactory.eINSTANCE.createAD();
  providerOrganizationAddress.addCounty("String_Node_Str");
  providerOrganization.getIds().add(CDAHelper.buildID(Context.getAdministrationService().getImplementationId().getImplementationId(),null));
  providerOrganization.getAddrs().add(providerOrganizationAddress);
  ON organizationName=DatatypesFactory.eINSTANCE.createON();
  organizationName.addText(Context.getAdministrationService().getImplementationId().getName());
  providerOrganization.getNames().add(organizationName);
  TEL providerOrganizationTelecon=DatatypesFactory.eINSTANCE.createTEL();
  providerOrganizationTelecon.setNullFlavor(NullFlavor.UNK);
  providerOrganization.getTelecoms().add(providerOrganizationTelecon);
  patientRole.setProviderOrganization(providerOrganization);
  doc.addPatientRole(patientRole);
  Author author=CDAFactory.eINSTANCE.createAuthor();
  author.setTime(CDAHelper.buildEffectiveTime(new Date()));
  AssignedAuthor assignedAuthor=CDAFactory.eINSTANCE.createAssignedAuthor();
  II authorId=DatatypesFactory.eINSTANCE.createII();
  authorId.setRoot(Context.getAdministrationService().getImplementationId().getImplementationId());
  assignedAuthor.getIds().add(authorId);
  AD assignedAuthorAddress=DatatypesFactory.eINSTANCE.createAD();
  assignedAuthorAddress.addCountry("String_Node_Str");
  TEL assignedAuthorTelecon=DatatypesFactory.eINSTANCE.createTEL();
  assignedAuthorTelecon.setNullFlavor(NullFlavor.UNK);
  assignedAuthor.getAddrs().add(assignedAuthorAddress);
  assignedAuthor.getTelecoms().add(assignedAuthorTelecon);
  Person assignedPerson=CDAFactory.eINSTANCE.createPerson();
  PN assignedPersonName=DatatypesFactory.eINSTANCE.createPN();
  assignedPersonName.addPrefix("String_Node_Str");
  assignedPersonName.addGiven("String_Node_Str");
  assignedPersonName.addFamily("String_Node_Str");
  assignedPerson.getNames().add(assignedPersonName);
  assignedAuthor.setAssignedPerson(assignedPerson);
  Organization representedOrganization=CDAFactory.eINSTANCE.createOrganization();
  representedOrganization.getIds().add(CDAHelper.buildID("String_Node_Str",null));
  ON representedOrganizationName=DatatypesFactory.eINSTANCE.createON();
  representedOrganizationName.addText(Context.getAdministrationService().getImplementationId().getName());
  representedOrganization.getNames().add(representedOrganizationName);
  AD representedOrganizationAddress=DatatypesFactory.eINSTANCE.createAD();
  representedOrganizationAddress.addCounty("String_Node_Str");
  representedOrganization.getAddrs().add(representedOrganizationAddress);
  TEL representedOrganizationTelecon=DatatypesFactory.eINSTANCE.createTEL();
  representedOrganizationTelecon.setNullFlavor(NullFlavor.UNK);
  representedOrganization.getTelecoms().add(representedOrganizationTelecon);
  assignedAuthor.setRepresentedOrganization(representedOrganization);
  AuthoringDevice authoringDevice=CDAFactory.eINSTANCE.createAuthoringDevice();
  SC authoringDeviceName=DatatypesFactory.eINSTANCE.createSC();
  authoringDeviceName.addText(Context.getAdministrationService().getGlobalProperty("String_Node_Str"));
  authoringDevice.setSoftwareName(authoringDeviceName);
  assignedAuthor.setAssignedAuthoringDevice(authoringDevice);
  author.setAssignedAuthor(assignedAuthor);
  doc.getAuthors().add(author);
  Custodian custodian=CDAFactory.eINSTANCE.createCustodian();
  AssignedCustodian assignedCustodian=CDAFactory.eINSTANCE.createAssignedCustodian();
  CustodianOrganization custodianOrganization=CDAFactory.eINSTANCE.createCustodianOrganization();
  AD custodianOrganizationAddress=DatatypesFactory.eINSTANCE.createAD();
  II custodianId=DatatypesFactory.eINSTANCE.createII();
  custodianId.setRoot("String_Node_Str");
  custodianOrganization.getIds().add(custodianId);
  custodianOrganizationAddress.addCountry("String_Node_Str");
  custodianOrganization.setAddr(custodianOrganizationAddress);
  ON custodianOrganizationName=DatatypesFactory.eINSTANCE.createON();
  custodianOrganizationName.addText(Context.getAdministrationService().getImplementationId().getName());
  custodianOrganization.setName(custodianOrganizationName);
  TEL custodianOrganizationTelecon=DatatypesFactory.eINSTANCE.createTEL();
  custodianOrganizationTelecon.setNullFlavor(NullFlavor.UNK);
  custodianOrganization.setTelecom(custodianOrganizationTelecon);
  assignedCustodian.setRepresentedCustodianOrganization(custodianOrganization);
  custodian.setAssignedCustodian(assignedCustodian);
  doc.setCustodian(custodian);
  List<Relationship> relationShips=Context.getPersonService().getRelationshipsByPerson(p);
  List<Participant1> participantList=new ArrayList<Participant1>(relationShips.size());
  System.out.print(participantList);
  for (int i=0; i < relationShips.size(); i++) {
    Participant1 e=CDAFactory.eINSTANCE.createParticipant1();
    e.setTypeCode(ParticipationType.IND);
    II pid1=DatatypesFactory.eINSTANCE.createII();
    pid1.setRoot("String_Node_Str");
    II pid2=DatatypesFactory.eINSTANCE.createII();
    pid2.setRoot("String_Node_Str");
    e.getTemplateIds().add(pid1);
    e.getTemplateIds().add(pid2);
    IVL_TS time=DatatypesFactory.eINSTANCE.createIVL_TS();
    time.setHigh(time.getHigh());
    time.setLow(time.getLow());
    e.setTime(time);
    Relationship relationship=relationShips.get(i);
    AssociatedEntity patientRelationShip=CDAFactory.eINSTANCE.createAssociatedEntity();
    patientRelationShip.setClassCode(RoleClassAssociative.PRS);
    CE relationShipCode=DatatypesFactory.eINSTANCE.createCE();
    relationShipCode.setCodeSystemName("String_Node_Str");
    relationShipCode.setCodeSystem("String_Node_Str");
    Person associatedPerson=CDAFactory.eINSTANCE.createPerson();
    PN associatedPersonName=DatatypesFactory.eINSTANCE.createPN();
    Iterator<PersonAddress> patientAddressIterator=null;
    TEL associatedPersonTelecon=DatatypesFactory.eINSTANCE.createTEL();
    associatedPersonTelecon.setNullFlavor(NullFlavor.UNK);
switch (relationship.getRelationshipType().getId()) {
case 1:
      relationShipCode.setDisplayName("String_Node_Str");
    associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
  associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
break;
case 2:
relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonA().getAddresses().iterator();
break;
case 3:
if (p.getId() == relationship.getPersonA().getId()) {
relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonB().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonB().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
}
 else {
relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonA().getAddresses().iterator();
}
break;
case 4:
if (p.getId() == relationship.getPersonA().getId()) {
if (relationship.getPersonB().getGender().equalsIgnoreCase("String_Node_Str")) relationShipCode.setDisplayName("String_Node_Str");
 else relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonB().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonB().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
}
 else {
if (relationship.getPersonA().getGender().equalsIgnoreCase("String_Node_Str")) relationShipCode.setDisplayName("String_Node_Str");
 else relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
}
break;
}
patientRelationShip.setCode(relationShipCode);
AD associatedPersonAddress=DatatypesFactory.eINSTANCE.createAD();
if (patientAddressIterator.hasNext()) {
PersonAddress padd=patientAddressIterator.next();
associatedPersonAddress.addStreetAddressLine(padd.getAddress1() + padd.getAddress2());
}
patientRelationShip.getAddrs().add(associatedPersonAddress);
patientRelationShip.getTelecoms().add(associatedPersonTelecon);
associatedPerson.getNames().add(associatedPersonName);
patientRelationShip.setAssociatedPerson(associatedPerson);
e.setAssociatedEntity(patientRelationShip);
participantList.add(e);
}
doc.getParticipants().addAll(participantList);
DocumentationOf dof=CDAFactory.eINSTANCE.createDocumentationOf();
ServiceEvent serviceEvent=CDAFactory.eINSTANCE.createServiceEvent();
serviceEvent.setClassCode(ActClassRoot.PCPR);
serviceEvent.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(new Date(),new Date()));
Performer1 performer=CDAFactory.eINSTANCE.createPerformer1();
performer.setTypeCode(x_ServiceEventPerformer.PPRF);
performer.setFunctionCode(CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,null));
performer.setTime(CDAHelper.buildEffectiveTimeinIVL(new Date(),new Date()));
AssignedEntity assignedEntity=CDAFactory.eINSTANCE.createAssignedEntity();
II assignedEntityId=DatatypesFactory.eINSTANCE.createII();
assignedEntityId.setRoot(Context.getAdministrationService().getImplementationId().getImplementationId());
assignedEntity.getIds().add(assignedEntityId);
AD assignedPersonAddress=DatatypesFactory.eINSTANCE.createAD();
assignedPersonAddress.addCountry("String_Node_Str");
TEL assignedPersonTelecon=DatatypesFactory.eINSTANCE.createTEL();
assignedPersonTelecon.setNullFlavor(NullFlavor.UNK);
assignedEntity.setAssignedPerson(assignedPerson);
assignedEntity.getAddrs().add(assignedPersonAddress);
assignedEntity.getTelecoms().add(assignedPersonTelecon);
assignedEntity.getRepresentedOrganizations().add(representedOrganization);
performer.setAssignedEntity(assignedEntity);
serviceEvent.getPerformers().add(performer);
dof.setServiceEvent(serviceEvent);
doc.getDocumentationOfs().add(dof);
return doc;
}

Fixed version (ground truth):
public ClinicalDocument buildHeader(ClinicalDocument doc,BaseCdaTypeHandler bh,Patient p){
  InfrastructureRootTypeId typeId=CDAFactory.eINSTANCE.createInfrastructureRootTypeId();
  typeId.setExtension("String_Node_Str");
  typeId.setRoot("String_Node_Str");
  doc.setTypeId(typeId);
  doc.getTemplateIds().clear();
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str","String_Node_Str",null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID("String_Node_Str",null,null));
  if (bh.getParentTemplateId() != null)   doc.getTemplateIds().add(CDAHelper.buildTemplateID(bh.getParentTemplateId(),null,null));
  doc.getTemplateIds().add(CDAHelper.buildTemplateID(bh.getTemplateid(),null,null));
  doc.setId(CDAHelper.buildID(Context.getAdministrationService().getImplementationId().getImplementationId(),bh.documentShortName));
  doc.setCode(CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,"String_Node_Str"));
  doc.setTitle(CDAHelper.buildTitle(bh.getDocumentFullName()));
  Date d=new Date();
  doc.setEffectiveTime(CDAHelper.buildEffectiveTime(d));
  CE confidentialityCode=DatatypesFactory.eINSTANCE.createCE();
  confidentialityCode.setCode("String_Node_Str");
  confidentialityCode.setCodeSystem("String_Node_Str");
  doc.setConfidentialityCode(confidentialityCode);
  CS languageCode=DatatypesFactory.eINSTANCE.createCS();
  languageCode.setCode("String_Node_Str");
  doc.setLanguageCode(languageCode);
  CS realmcode=DatatypesFactory.eINSTANCE.createCS("String_Node_Str");
  doc.getRealmCodes().add(realmcode);
  PatientRole patientRole=CDAFactory.eINSTANCE.createPatientRole();
  patientRole.getIds().add(CDAHelper.buildID(Context.getAdministrationService().getImplementationId().getImplementationId(),p.getPatientIdentifier().getIdentifier()));
  Set<PersonAddress> addresses=p.getAddresses();
  AD patientAddress=DatatypesFactory.eINSTANCE.createAD();
  patientAddress=buildAddresses(patientAddress,addresses);
  patientRole.getAddrs().add(patientAddress);
  TEL patientTelecom=DatatypesFactory.eINSTANCE.createTEL();
  patientTelecom.setNullFlavor(NullFlavor.UNK);
  patientRole.getTelecoms().add(patientTelecom);
  org.openhealthtools.mdht.uml.cda.Patient cdapatient=CDAFactory.eINSTANCE.createPatient();
  patientRole.setPatient(cdapatient);
  PN name=DatatypesFactory.eINSTANCE.createPN();
  if (p.getPersonName().getFamilyNamePrefix() != null) {
    name.addPrefix(p.getPersonName().getFamilyNamePrefix());
  }
  name.addGiven(p.getPersonName().getGivenName());
  name.addFamily(p.getPersonName().getFamilyName());
  if (p.getPersonName().getFamilyNameSuffix() != null) {
    name.addSuffix(p.getPersonName().getFamilyNameSuffix());
  }
  cdapatient.getNames().add(name);
  CE gender=DatatypesFactory.eINSTANCE.createCE();
  gender.setCode(p.getGender());
  gender.setCodeSystem("String_Node_Str");
  cdapatient.setAdministrativeGenderCode(gender);
  TS dateOfBirth=DatatypesFactory.eINSTANCE.createTS();
  SimpleDateFormat s1=new SimpleDateFormat("String_Node_Str");
  Date dobs=p.getBirthdate();
  String dob=s1.format(dobs);
  dateOfBirth.setValue(dob);
  cdapatient.setBirthTime(dateOfBirth);
  CE codes=DatatypesFactory.eINSTANCE.createCE();
  codes.setCode("String_Node_Str");
  cdapatient.setMaritalStatusCode(codes);
  CE codes1=DatatypesFactory.eINSTANCE.createCE();
  codes1.setCode("String_Node_Str");
  cdapatient.setEthnicGroupCode(codes1);
  Organization providerOrganization=CDAFactory.eINSTANCE.createOrganization();
  AD providerOrganizationAddress=DatatypesFactory.eINSTANCE.createAD();
  providerOrganizationAddress.addCounty("String_Node_Str");
  providerOrganization.getIds().add(CDAHelper.buildID(Context.getAdministrationService().getImplementationId().getImplementationId(),null));
  providerOrganization.getAddrs().add(providerOrganizationAddress);
  ON organizationName=DatatypesFactory.eINSTANCE.createON();
  organizationName.addText(Context.getAdministrationService().getImplementationId().getName());
  providerOrganization.getNames().add(organizationName);
  TEL providerOrganizationTelecon=DatatypesFactory.eINSTANCE.createTEL();
  providerOrganizationTelecon.setNullFlavor(NullFlavor.UNK);
  providerOrganization.getTelecoms().add(providerOrganizationTelecon);
  patientRole.setProviderOrganization(providerOrganization);
  doc.addPatientRole(patientRole);
  Author author=CDAFactory.eINSTANCE.createAuthor();
  author.setTime(CDAHelper.buildEffectiveTime(new Date()));
  AssignedAuthor assignedAuthor=CDAFactory.eINSTANCE.createAssignedAuthor();
  II authorId=DatatypesFactory.eINSTANCE.createII();
  authorId.setRoot(Context.getAdministrationService().getImplementationId().getImplementationId());
  assignedAuthor.getIds().add(authorId);
  AD assignedAuthorAddress=DatatypesFactory.eINSTANCE.createAD();
  assignedAuthorAddress.addCountry("String_Node_Str");
  TEL assignedAuthorTelecon=DatatypesFactory.eINSTANCE.createTEL();
  assignedAuthorTelecon.setNullFlavor(NullFlavor.UNK);
  assignedAuthor.getAddrs().add(assignedAuthorAddress);
  assignedAuthor.getTelecoms().add(assignedAuthorTelecon);
  Person assignedPerson=CDAFactory.eINSTANCE.createPerson();
  PN assignedPersonName=DatatypesFactory.eINSTANCE.createPN();
  assignedPersonName.addPrefix("String_Node_Str");
  assignedPersonName.addGiven("String_Node_Str");
  assignedPersonName.addFamily("String_Node_Str");
  assignedPerson.getNames().add(assignedPersonName);
  assignedAuthor.setAssignedPerson(assignedPerson);
  Organization representedOrganization=CDAFactory.eINSTANCE.createOrganization();
  representedOrganization.getIds().add(CDAHelper.buildID("String_Node_Str",null));
  ON representedOrganizationName=DatatypesFactory.eINSTANCE.createON();
  representedOrganizationName.addText(Context.getAdministrationService().getImplementationId().getName());
  representedOrganization.getNames().add(representedOrganizationName);
  AD representedOrganizationAddress=DatatypesFactory.eINSTANCE.createAD();
  representedOrganizationAddress.addCounty("String_Node_Str");
  representedOrganization.getAddrs().add(representedOrganizationAddress);
  TEL representedOrganizationTelecon=DatatypesFactory.eINSTANCE.createTEL();
  representedOrganizationTelecon.setNullFlavor(NullFlavor.UNK);
  representedOrganization.getTelecoms().add(representedOrganizationTelecon);
  assignedAuthor.setRepresentedOrganization(representedOrganization);
  AuthoringDevice authoringDevice=CDAFactory.eINSTANCE.createAuthoringDevice();
  SC authoringDeviceName=DatatypesFactory.eINSTANCE.createSC();
  authoringDeviceName.addText(Context.getAdministrationService().getGlobalProperty("String_Node_Str"));
  authoringDevice.setSoftwareName(authoringDeviceName);
  assignedAuthor.setAssignedAuthoringDevice(authoringDevice);
  author.setAssignedAuthor(assignedAuthor);
  doc.getAuthors().add(author);
  Custodian custodian=CDAFactory.eINSTANCE.createCustodian();
  AssignedCustodian assignedCustodian=CDAFactory.eINSTANCE.createAssignedCustodian();
  CustodianOrganization custodianOrganization=CDAFactory.eINSTANCE.createCustodianOrganization();
  AD custodianOrganizationAddress=DatatypesFactory.eINSTANCE.createAD();
  II custodianId=DatatypesFactory.eINSTANCE.createII();
  custodianId.setRoot("String_Node_Str");
  custodianOrganization.getIds().add(custodianId);
  custodianOrganizationAddress.addCountry("String_Node_Str");
  custodianOrganization.setAddr(custodianOrganizationAddress);
  ON custodianOrganizationName=DatatypesFactory.eINSTANCE.createON();
  custodianOrganizationName.addText(Context.getAdministrationService().getImplementationId().getName());
  custodianOrganization.setName(custodianOrganizationName);
  TEL custodianOrganizationTelecon=DatatypesFactory.eINSTANCE.createTEL();
  custodianOrganizationTelecon.setNullFlavor(NullFlavor.UNK);
  custodianOrganization.setTelecom(custodianOrganizationTelecon);
  assignedCustodian.setRepresentedCustodianOrganization(custodianOrganization);
  custodian.setAssignedCustodian(assignedCustodian);
  doc.setCustodian(custodian);
  List<Relationship> relationShips=Context.getPersonService().getRelationshipsByPerson(p);
  List<Participant1> participantList=new ArrayList<Participant1>(relationShips.size());
  System.out.print(participantList);
  for (int i=0; i < relationShips.size(); i++) {
    Participant1 e=CDAFactory.eINSTANCE.createParticipant1();
    e.setTypeCode(ParticipationType.IND);
    II pid1=DatatypesFactory.eINSTANCE.createII();
    pid1.setRoot("String_Node_Str");
    e.getTemplateIds().add(pid1);
    IVL_TS time=DatatypesFactory.eINSTANCE.createIVL_TS();
    time.setHigh(time.getHigh());
    time.setLow(time.getLow());
    e.setTime(time);
    Relationship relationship=relationShips.get(i);
    AssociatedEntity patientRelationShip=CDAFactory.eINSTANCE.createAssociatedEntity();
    patientRelationShip.setClassCode(RoleClassAssociative.PRS);
    CE relationShipCode=DatatypesFactory.eINSTANCE.createCE();
    relationShipCode.setCodeSystemName("String_Node_Str");
    relationShipCode.setCodeSystem("String_Node_Str");
    Person associatedPerson=CDAFactory.eINSTANCE.createPerson();
    PN associatedPersonName=DatatypesFactory.eINSTANCE.createPN();
    Iterator<PersonAddress> patientAddressIterator=null;
    TEL associatedPersonTelecon=DatatypesFactory.eINSTANCE.createTEL();
    associatedPersonTelecon.setNullFlavor(NullFlavor.UNK);
switch (relationship.getRelationshipType().getId()) {
case 1:
      relationShipCode.setDisplayName("String_Node_Str");
    associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
  associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
relationShipCode.setCode("String_Node_Str");
break;
case 2:
relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonA().getAddresses().iterator();
relationShipCode.setCode("String_Node_Str");
break;
case 3:
if (p.getId() == relationship.getPersonA().getId()) {
relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonB().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonB().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
relationShipCode.setCode("String_Node_Str");
}
 else {
relationShipCode.setDisplayName("String_Node_Str");
associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonA().getAddresses().iterator();
relationShipCode.setCode("String_Node_Str");
}
break;
case 4:
if (p.getId() == relationship.getPersonA().getId()) {
if (relationship.getPersonB().getGender().equalsIgnoreCase("String_Node_Str")) {
relationShipCode.setDisplayName("String_Node_Str");
relationShipCode.setCode("String_Node_Str");
}
 else {
relationShipCode.setDisplayName("String_Node_Str");
relationShipCode.setCode("String_Node_Str");
}
associatedPersonName.addFamily(relationship.getPersonB().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonB().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
}
 else {
if (relationship.getPersonA().getGender().equalsIgnoreCase("String_Node_Str")) {
relationShipCode.setDisplayName("String_Node_Str");
relationShipCode.setCode("String_Node_Str");
}
 else {
relationShipCode.setDisplayName("String_Node_Str");
relationShipCode.setCode("String_Node_Str");
}
associatedPersonName.addFamily(relationship.getPersonA().getFamilyName());
associatedPersonName.addGiven(relationship.getPersonA().getGivenName());
patientAddressIterator=relationship.getPersonB().getAddresses().iterator();
}
break;
}
patientRelationShip.setCode(relationShipCode);
AD associatedPersonAddress=DatatypesFactory.eINSTANCE.createAD();
if (patientAddressIterator.hasNext()) {
PersonAddress padd=patientAddressIterator.next();
associatedPersonAddress.addStreetAddressLine(padd.getAddress1() + padd.getAddress2());
}
patientRelationShip.getAddrs().add(associatedPersonAddress);
patientRelationShip.getTelecoms().add(associatedPersonTelecon);
associatedPerson.getNames().add(associatedPersonName);
patientRelationShip.setAssociatedPerson(associatedPerson);
e.setAssociatedEntity(patientRelationShip);
participantList.add(e);
}
doc.getParticipants().addAll(participantList);
DocumentationOf dof=CDAFactory.eINSTANCE.createDocumentationOf();
ServiceEvent serviceEvent=CDAFactory.eINSTANCE.createServiceEvent();
serviceEvent.setClassCode(ActClassRoot.PCPR);
serviceEvent.setEffectiveTime(CDAHelper.buildEffectiveTimeinIVL(new Date(),new Date()));
Performer1 performer=CDAFactory.eINSTANCE.createPerformer1();
performer.setTypeCode(x_ServiceEventPerformer.PPRF);
performer.setFunctionCode(CDAHelper.buildCodeCE("String_Node_Str","String_Node_Str",null,null));
performer.setTime(CDAHelper.buildEffectiveTimeinIVL(new Date(),new Date()));
AssignedEntity assignedEntity=CDAFactory.eINSTANCE.createAssignedEntity();
II assignedEntityId=DatatypesFactory.eINSTANCE.createII();
assignedEntityId.setRoot(Context.getAdministrationService().getImplementationId().getImplementationId());
assignedEntity.getIds().add(assignedEntityId);
AD assignedPersonAddress=DatatypesFactory.eINSTANCE.createAD();
assignedPersonAddress.addCountry("String_Node_Str");
TEL assignedPersonTelecon=DatatypesFactory.eINSTANCE.createTEL();
assignedPersonTelecon.setNullFlavor(NullFlavor.UNK);
assignedEntity.setAssignedPerson(assignedPerson);
assignedEntity.getAddrs().add(assignedPersonAddress);
assignedEntity.getTelecoms().add(assignedPersonTelecon);
assignedEntity.getRepresentedOrganizations().add(representedOrganization);
performer.setAssignedEntity(assignedEntity);
serviceEvent.getPerformers().add(performer);
dof.setServiceEvent(serviceEvent);
doc.getDocumentationOfs().add(dof);
return doc;
}