Skip to content
Snippets Groups Projects
Subject.java 13.1 KiB
Newer Older
package smash.appointment.parse;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class Subject {
Piotr Gawron's avatar
Piotr Gawron committed
	Logger							 logger		 = Logger.getLogger(Subject.class);

	private String			 name;
	private String			 surname;
	private String			 ndNumber;
	private String			 screeningNumber;
	private String			 sex			 = "";
Piotr Gawron's avatar
Piotr Gawron committed
	private String			 remarks;
	private String			 birthDate;
	private String			 address;
	private String			 zipCode;
	private String			 country;
	private String			 city;
	private String			 phone1;
	private String			 phone2;
	private String			 phone3;
	private String			 mail;
	private String			 diagnosisYear;
	private String			 diagnosis;
	private String			 referal;
	private String			 addDate;
	private String			 mPowerId;
	private SubjectType	 type;
	private String			 toBeSeenAt;
	private boolean			 dead			 = false;
	private boolean			 resigned	 = false;
	private boolean			 postponed = false;
Piotr Gawron's avatar
Piotr Gawron committed

	private List<String> languages = new ArrayList<>();

	public Subject(String name, String surname, String ndNumber, String screeningNumber) {
		this.setName(name);
		this.setSurname(surname);
		this.setNdNumber(ndNumber);
		this.setScreeningNumber(screeningNumber);
	}

	/**
	 * @return the name
	 * @see #name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *          the name to set
	 * @see #name
	 */
	public void setName(String name) {
		if (name != null && name.length() > 50) {
			logger.warn("Name too long. Trimming: " + name);
			name = name.substring(0, 50);
		this.name = name;
	}

	/**
	 * @return the surname
	 * @see #surname
	 */
	public String getSurname() {
		return surname;
	}

	/**
	 * @param surname
	 *          the surname to set
	 * @see #surname
	 */
	public void setSurname(String surname) {
		if (surname != null && surname.length() > 50) {
			logger.warn("Surname too long. Trimming: " + surname);
			surname = surname.substring(0, 50);
		this.surname = surname;
	}

	/**
	 * @return the ndNumber
	 * @see #ndNumber
	 */
	public String getNdNumber() {
		return ndNumber;
	}

	/**
	 * @param ndNumber
	 *          the ndNumber to set
	 * @see #ndNumber
	 */
	public void setNdNumber(String ndNumber) {
		this.ndNumber = ndNumber;
	}

	/**
	 * @return the screeningNumber
	 * @see #screeningNumber
	 */
	public String getScreeningNumber() {
		return screeningNumber;
	}

	/**
	 * @param screeningNumber
	 *          the screeningNumber to set
	 * @see #screeningNumber
	 */
	public void setScreeningNumber(String screeningNumber) {
		this.screeningNumber = screeningNumber;
	}

	@Override
	public String toString() {
		return this.getName() + " " + this.getSurname() + " (" + this.getNdNumber() + "; " + this.getScreeningNumber() + ")";
	}

	public void addLanguage(String string) {
		if (!string.trim().isEmpty() && !string.equalsIgnoreCase("OTHER")) {
			if (!languages.contains(string)) {
				this.languages.add(string);
			}
		}
	}

	/**
	 * @return the sex
	 * @see #sex
	 */
	public String getSex() {
		return sex;
	}

	/**
	 * @param sex
	 *          the sex to set
	 * @see #sex
	 */
	public void setSex(String sex) {
		this.sex = sex;
	}

	/**
	 * @return the birthDate
	 * @see #birthDate
	 */
	public String getBirthDate() {
		return birthDate;
	}

	/**
	 * @param birthDate
	 *          the birthDate to set
	 * @see #birthDate
	 */
	public void setBirthDate(String birthDate) {
		this.birthDate = birthDate;
	}

	/**
	 * @return the languages
	 * @see #languages
	 */
	public List<String> getLanguages() {
		return languages;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param languages
	 *          the languages to set
	 * @see #languages
	 */
	public void setLanguages(List<String> languages) {
		this.languages = languages;
	}

	/**
	 * @return the remarks
	 * @see #remarks
	 */
	public String getRemarks() {
		return remarks;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param remarks
	 *          the remarks to set
	 * @see #remarks
	 */
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	/**
	 * @return the address
	 * @see #address
	 */
	public String getAddress() {
		return address;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param address
	 *          the address to set
	 * @see #address
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the zipCode
	 * @see #zipCode
	 */
	public String getZipCode() {
		return zipCode;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param zipCode
	 *          the zipCode to set
	 * @see #zipCode
	 */
	public void setZipCode(String zipCode) {
		if (zipCode != null && zipCode.length() > 7) {
			logger.warn("Surname too long. Ignoring: " + zipCode);
			this.zipCode = "";
		} else {
			this.zipCode = zipCode;
		}
	}

	/**
	 * @return the country
	 * @see #country
	 */
	public String getCountry() {
		return country;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param country
	 *          the country to set
	 * @see #country
	 */
	public void setCountry(String country) {
		this.country = country;
	}

	/**
	 * @return the city
	 * @see #city
	 */
	public String getCity() {
		return city;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param city
	 *          the city to set
	 * @see #city
	 */
	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * @return the phone1
	 * @see #phone1
	 */
	public String getPhone1() {
		return phone1;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param phone1
	 *          the phone1 to set
	 * @see #phone1
	 */
	public void setPhone1(String phone1) {
Piotr Gawron's avatar
Piotr Gawron committed
		if (phone1 != null && phone1.length() > 20) {
			logger.warn("Invalid phone. Ignoring: " + phone1);
		} else if (phone1 != null) {
			this.phone1 = phone1.replace(",", "");
	}

	/**
	 * @return the phone2
	 * @see #phone2
	 */
	public String getPhone2() {
		return phone2;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param phone2
	 *          the phone2 to set
	 * @see #phone2
	 */
	public void setPhone2(String phone2) {
Piotr Gawron's avatar
Piotr Gawron committed
		if (phone2 != null && phone2.length() > 20) {
			logger.warn("Invalid phone. Ignoring: " + phone2);
		} else if (phone2 != null) {
			this.phone2 = phone2.replace(",", "");
	}

	/**
	 * @return the phone3
	 * @see #phone3
	 */
	public String getPhone3() {
		return phone3;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param phone3
	 *          the phone3 to set
	 * @see #phone3
	 */
	public void setPhone3(String phone3) {
Piotr Gawron's avatar
Piotr Gawron committed
		if (phone3 != null && phone3.length() > 20) {
			logger.warn("Invalid phone. Ignoring: " + phone3);
		} else if (phone3!=null){
			this.phone3 = phone3.replace(",", "");
	}

	/**
	 * @return the mail
	 * @see #mail
	 */
	public String getMail() {
		return mail;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param mail
	 *          the mail to set
	 * @see #mail
	 */
	public void setMail(String mail) {
		this.mail = mail;
	}

	/**
	 * @return the diagnosisYear
	 * @see #diagnosisYear
	 */
	public String getDiagnosisYear() {
		return diagnosisYear;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param diagnosisYear
	 *          the diagnosisYear to set
	 * @see #diagnosisYear
	 */
	public void setDiagnosisYear(String diagnosisYear) {
		this.diagnosisYear = diagnosisYear;
	}

	/**
	 * @return the diagnosis
	 * @see #diagnosis
	 */
	public String getDiagnosis() {
		return diagnosis;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param diagnosis
	 *          the diagnosis to set
	 * @see #diagnosis
	 */
	public void setDiagnosis(String diagnosis) {
		this.diagnosis = diagnosis;
	}

	/**
	 * @return the referal
	 * @see #referal
	 */
	public String getReferal() {
		return referal;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param referal
	 *          the referal to set
	 * @see #referal
	 */
	public void setReferal(String referal) {
		this.referal = referal;
	}

	/**
	 * @return the mPowerId
	 * @see #mPowerId
	 */
	public String getmPowerId() {
		return mPowerId;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param mPowerId
	 *          the mPowerId to set
	 * @see #mPowerId
	 */
	public void setmPowerId(String mPowerId) {
		this.mPowerId = mPowerId;
	}

	/**
	 * @return the addDate
	 * @see #addDate
	 */
	public String getAddDate() {
		return addDate;
	}

	/**
Piotr Gawron's avatar
Piotr Gawron committed
	 * @param addDate
	 *          the addDate to set
	 * @see #addDate
	 */
	public void setAddDate(String addDate) {
		this.addDate = addDate;
	}

Piotr Gawron's avatar
Piotr Gawron committed
	/**
	 * @return the type
	 * @see #type
	 */
	public SubjectType getType() {
		return type;
	}

	/**
	 * @param type
	 *          the type to set
Piotr Gawron's avatar
Piotr Gawron committed
	 * @see #type
	 */
	public void setType(SubjectType type) {
		this.type = type;
	}

	public void update(Subject subject, String errorPrefix) {
		setName(getMergedValue("name", this.getName(), subject.getName(), errorPrefix));
		setSurname(getMergedValue("surname", this.getSurname(), subject.getSurname(), errorPrefix));
		setNdNumber(getMergedValue("ndNumber", this.getNdNumber(), subject.getNdNumber(), errorPrefix));
		setScreeningNumber(getMergedValue("screeningNumber", this.getScreeningNumber(), subject.getScreeningNumber(), errorPrefix));
		setSex(getMergedValue("sex", this.getSex(), subject.getSex(), errorPrefix));
		setRemarks(getMergedValue("remarks", this.getRemarks(), subject.getRemarks(), errorPrefix));
		setBirthDate(getMergedValue("birthDate", this.getBirthDate(), subject.getBirthDate(), errorPrefix));
		setAddress(getMergedValue("address", this.getAddress(), subject.getAddress(), errorPrefix));
		setZipCode(getMergedValue("zipCode", this.getZipCode(), subject.getZipCode(), errorPrefix));
		setCountry(getMergedValue("country", this.getCountry(), subject.getCountry(), errorPrefix));
		setCity(getMergedValue("city", this.getCity(), subject.getCity(), errorPrefix));
		setPhone1(getMergedValue("phone1", this.getPhone1(), subject.getPhone1(), errorPrefix));
		setPhone2(getMergedValue("phone2", this.getPhone2(), subject.getPhone2(), errorPrefix));
		setPhone3(getMergedValue("phone3", this.getPhone3(), subject.getPhone3(), errorPrefix));
		setMail(getMergedValue("mail", this.getMail(), subject.getMail(), errorPrefix));
		setDiagnosisYear(getMergedValue("diagnosisYear", this.getDiagnosisYear(), subject.getDiagnosisYear(), errorPrefix));
		setDiagnosis(getMergedValue("diagnosis", this.getDiagnosis(), subject.getDiagnosis(), errorPrefix));
		setReferal(getMergedValue("referal", this.getReferal(), subject.getReferal(), errorPrefix));
		setAddDate(getMergedValue("addDate", this.getAddDate(), subject.getAddDate(), errorPrefix));
		setmPowerId(getMergedValue("mPowerId", this.getmPowerId(), subject.getmPowerId(), errorPrefix));
		setType(getMergedValue("type", this.getType(), subject.getType(), errorPrefix));
		setResigned(this.isResigned() || subject.isResigned());
		setDead(this.isDead() || subject.isDead());
		setPostponed(this.isPostponed() || subject.isPostponed());
		// override only when to be seen by flying team
		if (subject.getToBeSeenAt()!=null && subject.getToBeSeenAt().equals("F")) {
			setToBeSeenAt(subject.getToBeSeenAt());
		}
		addLanguages(subject.getLanguages());
	}

	private SubjectType getMergedValue(String string, SubjectType existingValue, SubjectType newValue, String errorPrefix) {
		if (existingValue == null) {
			return newValue;
		} else if (newValue == null) {
			return existingValue;
		} else if (existingValue.equals(newValue)) {
			return existingValue;
		} else {
			logger.warn(errorPrefix + "New " + string + " differs from old one. (new: " + newValue + ", " + existingValue + "). Skipping");
			return existingValue;
		}
	}

	private String getMergedValue(String string, String existingValue, String newValue, String errorPrefix) {
		if (existingValue == null || existingValue.trim().isEmpty()) {
			return newValue;
		} else if (newValue == null || newValue.trim().isEmpty()) {
			return existingValue;
		} else if (existingValue.trim().equalsIgnoreCase(newValue.trim())) {
			return existingValue;
		} else {
			logger.warn(errorPrefix + "New " + string + " differs from old one. (new: " + newValue + ", " + existingValue + "). Skipping");
			return existingValue;
		}
	}

	/**
	 * @return the toBeSeenAt
	 * @see #toBeSeenAt
	 */
	public String getToBeSeenAt() {
		return toBeSeenAt;
	}

	/**
	 * @param toBeSeenAt
	 *          the toBeSeenAt to set
	 * @see #toBeSeenAt
	 */
	public void setToBeSeenAt(String toBeSeenAt) {
		this.toBeSeenAt = toBeSeenAt;
	}

	/**
	 * @return the dead
	 * @see #dead
	 */
	public boolean isDead() {
		return dead;
	}

	/**
	 * @param dead
	 *          the dead to set
	 * @see #dead
	 */
	public void setDead(boolean dead) {
		this.dead = dead;
	}

	/**
	 * @return the resigned
	 * @see #resigned
	 */
	public boolean isResigned() {
		return resigned;
	}

	/**
	 * @param resigned
	 *          the resigned to set
	 * @see #resigned
	 */
	public void setResigned(boolean resigned) {
		this.resigned = resigned;
	}

	public void addLanguages(List<String> langs) {
		for (String string : langs) {
			addLanguage(string);
		}
	}

	/**
	 * @return the postponed
	 * @see #postponed
	 */
	public boolean isPostponed() {
		return postponed;
	}

	/**
	 * @param postponed
	 *          the postponed to set
	 * @see #postponed
	 */
	public void setPostponed(boolean postponed) {
		this.postponed = postponed;
	}