class RecipientTransformer {

    public String toEbXML(Recipient recipient) {
        if (recipient == null) {
            return null;
        }
        
        String person = Hl7v2Based.render(recipient.getPerson());
        String organization = Hl7v2Based.render(recipient.getOrganization());
        String telecom = Hl7v2Based.render(recipient.getTelecom());

        if ((person == null) && (organization == null) && (telecom == null)) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        if (organization != null) {
            sb.append(organization);
        }
        if ((person != null) || (telecom != null)) {
            sb.append('|');
            if (person != null) {
                sb.append(person);
            }
            if (telecom != null) {
                sb.append('|').append(telecom);
            }
        }

        return sb.toString();
    }

}