Source:
public static PersonNameType translateENListtoPersonNameType(List<ENExplicit> names) { LOG.debug("HL7Extractor.translateENListtoPersonNameType() -- Begin"); PersonNameType personName = new PersonNameType(); if (names.size() > 0 && names.get(0).getUse().size() > 0) { CeType nameType = new CeType(); nameType.setCode(names.get(0).getUse().get(0)); personName.setNameType(nameType); } if (names.size() > 0 && names.get(0).getContent() != null) { List<Serializable> choice = names.get(0).getContent(); Iterator<Serializable> iterSerialObjects = choice.iterator(); String nameString = ""; EnExplicitFamily familyName = new EnExplicitFamily(); EnExplicitGiven givenName = new EnExplicitGiven(); while (iterSerialObjects.hasNext()) { Serializable contentItem = iterSerialObjects.next(); if (contentItem instanceof String) { String strValue = (String) contentItem; if (!nameString.isEmpty()) { nameString += strValue; } else { nameString = strValue; } LOG.debug("Here is the contents of the string: {}" + strValue); } else if (contentItem instanceof JAXBElement) { JAXBElement oJAXBElement = (JAXBElement) contentItem; if (oJAXBElement.getValue() instanceof EnExplicitFamily) { familyName = (EnExplicitFamily) oJAXBElement.getValue(); } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) { givenName = (EnExplicitGiven) oJAXBElement.getValue(); } } } if (!nameString.isEmpty()) { LOG.debug("set org name text "); personName.setFamilyName(nameString); } else { if (givenName.getContent() != null && givenName.getContent().length() > 0) { LOG.debug("set org name given "); personName.setGivenName(givenName.getContent()); } if (familyName.getContent() != null && familyName.getContent().length() > 0) { LOG.debug("set org name family "); personName.setFamilyName(familyName.getContent()); } } } LOG.debug("HL7Extractor.translateENListtoPersonNameType() -- End"); return personName; }

Target:
public static PersonNameType translateENListtoPersonNameType(List<ENExplicit> names) { LOG.debug("HL7Extractor.translateENListtoPersonNameType() -- Begin"); PersonNameType personName = new PersonNameType(); if (names.size() > 0 && names.get(0).getUse().size() > 0) { CeType nameType = new CeType(); nameType.setCode(names.get(0).getUse().get(0)); personName.setNameType(nameType); } if (names.size() > 0 && names.get(0).getContent() != null) { List<Serializable> choice = names.get(0).getContent(); Iterator<Serializable> iterSerialObjects = choice.iterator(); String nameString = ""; EnExplicitFamily familyName = new EnExplicitFamily(); EnExplicitGiven givenName = new EnExplicitGiven(); while (iterSerialObjects.hasNext()) { Serializable contentItem = iterSerialObjects.next(); if (contentItem instanceof String) { String strValue = (String) contentItem; if (!nameString.isEmpty()) { nameString += strValue; } else { nameString = strValue; } LOG.debug("Here is the contents of the string: {}" , strValue); } else if (contentItem instanceof JAXBElement) { JAXBElement oJAXBElement = (JAXBElement) contentItem; if (oJAXBElement.getValue() instanceof EnExplicitFamily) { familyName = (EnExplicitFamily) oJAXBElement.getValue(); } else if (oJAXBElement.getValue() instanceof EnExplicitGiven) { givenName = (EnExplicitGiven) oJAXBElement.getValue(); } } } if (!nameString.isEmpty()) { LOG.debug("set org name text "); personName.setFamilyName(nameString); } else { if (givenName.getContent() != null && givenName.getContent().length() > 0) { LOG.debug("set org name given "); personName.setGivenName(givenName.getContent()); } if (familyName.getContent() != null && familyName.getContent().length() > 0) { LOG.debug("set org name family "); personName.setFamilyName(familyName.getContent()); } } } LOG.debug("HL7Extractor.translateENListtoPersonNameType() -- End"); return personName; }