/**
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
 * If a copy of the MPL was not distributed with this file, You can obtain one at
 * http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is also subject to the terms of the Health-Related Additional
 * Disclaimer of Warranty and Limitation of Liability available at
 * http://www.carewebframework.org/licensing/disclaimer.
 */
package org.carewebframework.vista.ui.notification;

import ca.uhn.fhir.model.dstu.resource.User;

import org.apache.commons.lang.math.NumberUtils;

import org.carewebframework.common.StrUtil;
import org.carewebframework.vista.api.util.VistAUtil;

/**
 * Notification recipient.
 */
public class Recipient {
    
    private final String name;
    
    private final long ien;
    
    /**
     * Creates a recipient based on the specified user.
     *
     * @param user A user.
     */
    protected Recipient(User user) {
        this.name = user.getName().toString();
        this.ien = VistAUtil.parseIEN(user);
    }
    
    /**
     * Creates a recipient based on raw data.
     *
     * @param data Raw data.
     * @param isGroup If true, the raw data represents a group. If false, the type of recipient is
     *            to be inferred from the raw data.
     */
    protected Recipient(String data, boolean isGroup) {
        String[] pcs = StrUtil.split(data, StrUtil.U, 2);
        long val = NumberUtils.toLong(pcs[0]);
        this.ien = isGroup && val > 0 ? -val : val;
        this.name = pcs[1];
    }
    
    /**
     * Creates a recipient based on raw data.
     *
     * @param data Raw data.
     */
    protected Recipient(String data) {
        this(data, false);
    }
    
    /**
     * Returns true if this recipient is a mail group.
     *
     * @return True if a mail group.
     */
    public boolean isGroup() {
        return ien < 0;
    }
    
    /**
     * Returns the recipient name.
     *
     * @return The recipient name.
     */
    public String getName() {
        return name;
    }
    
    /**
     * Returns the recipient's internal entry number. Note that a negative value means that this is
     * a mail group, while a positive value means it is a user.
     *
     * @return Recipient's IEN.
     */
    public long getIen() {
        return ien;
    }
    
};

@@ -610,16 +610,66 @@
 trUtil;%0A
+import org.carewebframework.fhir.common.FhirUtil;%0A
 import o
@@ -1012,16 +1012,36 @@
 .name = 
+FhirUtil.formatName(
 user.get
@@ -1050,18 +1050,8 @@
 me()
-.toString(
 );%0A 

Fix incorrect formatting of user's name in schedule a notification dialog.