All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.vgregion.portal.patient.event.PatientEvent Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2010 Västra Götalandsregionen
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of version 2.1 of the GNU Lesser General Public
 *   License as published by the Free Software Foundation.
 *
 *   This library is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 *   Boston, MA 02111-1307  USA
 *
 */

package se.vgregion.portal.patient.event;

import org.apache.commons.lang.builder.ToStringBuilder;

import java.io.Serializable;

/**
 * The PatientEvent is the event bean used to communicate patient information.
 *
 * @author David Rosell
 */
public class PatientEvent implements Serializable {

    private static final long serialVersionUID = 1196374164899537338L;

    public static final String DEFAULT_GROUP_CODE = "Default";

    private final String groupCode;

    private final String inputText;

    private final PersonNummer personNummer;

    /**
     * PatientEvent are immutable and cannot be changed after creation.
     *
     * @param inputText String representing a patient identifier.
     */
    public PatientEvent(String inputText, String groupCode) {
        this.groupCode = groupCode;
        this.inputText = inputText;

        PersonNummer pNo = PersonNummer.personummer(inputText);
        if (pNo.getType() != PersonNummer.Type.INVALID) {
            personNummer = pNo;
        } else {
            personNummer = null;
        }
    }

    public String getGroupCode() {
        return groupCode;
    }

    public String getInputText() {
        return inputText;
    }

    public PersonNummer getPersonNummer() {
        return personNummer;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof PatientEvent)) {
            return false;
        }

        PatientEvent that = (PatientEvent) o;

        if (personNummer != null && that.personNummer != null) {
            return personNummer.equals(that.personNummer);
        } else if ((personNummer != null && that.personNummer == null) 
                        || (personNummer == null && that.personNummer != null)) {
            return false;
        } else {
            if (inputText != null ? !inputText.equals(that.inputText) : that.inputText != null) {
                return false;
            }
        }

        return true;
    }

    @Override
    public int hashCode() {
        return ((personNummer != null)
                ? personNummer.hashCode() : ((inputText != null) ? inputText.hashCode() : 0));
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                append("inputText", inputText).
                append("personNummer", personNummer).
                toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy