/FileExtraction/Java_unseen/IMS-MAXIMS_openMAXIMS/Source Library/openmaxims_workspace/ValueObjects/src/ims/core/vo/QuestionInformationVo.java
//#############################################################################
//#                                                                           #
//#  Copyright (C) <2015>  <IMS MAXIMS>                                       #
//#                                                                           #
//#  This program is free software: you can redistribute it and/or modify     #
//#  it under the terms of the GNU Affero General Public License as           #
//#  published by the Free Software Foundation, either version 3 of the       #
//#  License, or (at your option) any later version.                          # 
//#                                                                           #
//#  This program 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 Affero General Public License for more details.                      #
//#                                                                           #
//#  You should have received a copy of the GNU Affero General Public License #
//#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
//#                                                                           #
//#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
//#  this program.  Users of this software do so entirely at their own risk.  #
//#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
//#  software that it builds, deploys and maintains.                          #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Barbara Worwood using IMS Development Environment (version 1.80 build 5589.25814)
// Copyright (C) 1995-2015 IMS MAXIMS. All rights reserved.
// WARNING: DO NOT MODIFY the content of this file

package ims.core.vo;

/**
 * Linked to core.clinical.QuestionInformation business object (ID: 1058100000).
 */
public class QuestionInformationVo extends ims.core.vo.QuestionInformationShortVo implements ims.vo.ImsCloneable, Comparable
{
	private static final long serialVersionUID = 1L;

	public QuestionInformationVo()
	{
	}
	public QuestionInformationVo(Integer id, int version)
	{
		super(id, version);
	}
	public QuestionInformationVo(ims.core.vo.beans.QuestionInformationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.text = bean.getText();
		this.shorttext = bean.getShortText();
		this.isquestion = bean.getIsQuestion();
		this.answertypes = ims.core.vo.QuestionAnswerTypeVoCollection.buildFromBeanCollection(bean.getAnswerTypes());
		this.genderspecific = bean.getGenderSpecific() == null ? null : ims.admin.vo.lookups.GenderSpecific.buildLookup(bean.getGenderSpecific());
		this.agerangemin = bean.getAgeRangeMin();
		this.agerangemax = bean.getAgeRangeMax();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.classification = ims.core.vo.lookups.QuestionClassificationCollection.buildFromBeanCollection(bean.getClassification());
		this.legendtext = bean.getLegendText();
		this.taxonomymap = ims.core.vo.TaxonomyMapCollection.buildFromBeanCollection(bean.getTaxonomyMap());
		this.questiontype = bean.getQuestionType() == null ? null : ims.core.vo.lookups.QuestionType.buildLookup(bean.getQuestionType());
		this.keywords = ims.core.vo.KeywordVoCollection.buildFromBeanCollection(bean.getKeywords());
	}
	public void populate(ims.vo.ValueObjectBeanMap map, ims.core.vo.beans.QuestionInformationVoBean bean)
	{
		this.id = bean.getId();
		this.version = bean.getVersion();
		this.text = bean.getText();
		this.shorttext = bean.getShortText();
		this.isquestion = bean.getIsQuestion();
		this.answertypes = ims.core.vo.QuestionAnswerTypeVoCollection.buildFromBeanCollection(bean.getAnswerTypes());
		this.genderspecific = bean.getGenderSpecific() == null ? null : ims.admin.vo.lookups.GenderSpecific.buildLookup(bean.getGenderSpecific());
		this.agerangemin = bean.getAgeRangeMin();
		this.agerangemax = bean.getAgeRangeMax();
		this.status = bean.getStatus() == null ? null : ims.core.vo.lookups.PreActiveActiveInactiveStatus.buildLookup(bean.getStatus());
		this.classification = ims.core.vo.lookups.QuestionClassificationCollection.buildFromBeanCollection(bean.getClassification());
		this.legendtext = bean.getLegendText();
		this.taxonomymap = ims.core.vo.TaxonomyMapCollection.buildFromBeanCollection(bean.getTaxonomyMap());
		this.questiontype = bean.getQuestionType() == null ? null : ims.core.vo.lookups.QuestionType.buildLookup(bean.getQuestionType());
		this.keywords = ims.core.vo.KeywordVoCollection.buildFromBeanCollection(bean.getKeywords());
	}
	public ims.vo.ValueObjectBean getBean()
	{
		return this.getBean(new ims.vo.ValueObjectBeanMap());
	}
	public ims.vo.ValueObjectBean getBean(ims.vo.ValueObjectBeanMap map)
	{
		ims.core.vo.beans.QuestionInformationVoBean bean = null;
		if(map != null)
			bean = (ims.core.vo.beans.QuestionInformationVoBean)map.getValueObjectBean(this);
		if (bean == null)
		{
			bean = new ims.core.vo.beans.QuestionInformationVoBean();
			map.addValueObjectBean(this, bean);
			bean.populate(map, this);
		}
		return bean;
	}
	public Object getFieldValueByFieldName(String fieldName)
	{
		if(fieldName == null)
			throw new ims.framework.exceptions.CodingRuntimeException("Invalid field name");
		fieldName = fieldName.toUpperCase();
		if(fieldName.equals("TAXONOMYMAP"))
			return getTaxonomyMap();
		if(fieldName.equals("QUESTIONTYPE"))
			return getQuestionType();
		if(fieldName.equals("KEYWORDS"))
			return getKeywords();
		return super.getFieldValueByFieldName(fieldName);
	}
	public boolean getTaxonomyMapIsNotNull()
	{
		return this.taxonomymap != null;
	}
	public ims.core.vo.TaxonomyMapCollection getTaxonomyMap()
	{
		return this.taxonomymap;
	}
	public void setTaxonomyMap(ims.core.vo.TaxonomyMapCollection value)
	{
		this.isValidated = false;
		this.taxonomymap = value;
	}
	public boolean getQuestionTypeIsNotNull()
	{
		return this.questiontype != null;
	}
	public ims.core.vo.lookups.QuestionType getQuestionType()
	{
		return this.questiontype;
	}
	public void setQuestionType(ims.core.vo.lookups.QuestionType value)
	{
		this.isValidated = false;
		this.questiontype = value;
	}
	public boolean getKeywordsIsNotNull()
	{
		return this.keywords != null;
	}
	public ims.core.vo.KeywordVoCollection getKeywords()
	{
		return this.keywords;
	}
	public void setKeywords(ims.core.vo.KeywordVoCollection value)
	{
		this.isValidated = false;
		this.keywords = value;
	}
	/**
	* getTooltip() - returns a Textile formatted tooltip
	*/
	public String getTooltip()
	{
		StringBuffer sb = new StringBuffer();
		
		String NEWLINE = "\n";
		if(this != null)
		{
			sb.append("*Short text: &nbsp;&nbsp;*");
			sb.append(this.getShortTextIsNotNull() ? this.getShortText() : "");
			sb.append(NEWLINE);
			sb.append("*Text: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*");
			sb.append(this.getTextIsNotNull() ? this.getText() : "");
			sb.append(NEWLINE);
		}
		
		if(this.getStatusIsNotNull())
		{
			sb.append("*Status: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*");
			sb.append(this.getStatusIsNotNull() ? this.getStatus().toString() : "");
			sb.append(NEWLINE);
		}
		
		if(this.getAnswerTypesIsNotNull())
		{
			sb.append("*Answer Types: &nbsp;&nbsp;*");
			int nCount = 0;
			for (int i = 0; i < this.getAnswerTypes().size(); i++)
			{
				QuestionAnswerTypeVo answerType = this.getAnswerTypes().get(i);
				if(answerType.getActiveStatusIsNotNull() && answerType.getActiveStatus().booleanValue())
				{
					nCount++;
					sb.append(NEWLINE);
					sb.append("&nbsp;&nbsp;&nbsp;");
					sb.append(nCount);
					sb.append(")");
					sb.append("&nbsp;&nbsp;");
					sb.append(answerType.getAnswerType().getText());
					String separator = answerType.getAnswerTypeIsNotNull() && answerType.getAnswerType().equals(ims.core.vo.lookups.QuestionAnswerType.SEPARATOR)?" - " + answerType.getSeparatorText():"";
					sb.append(separator);
					if(answerType.getOptionsIsNotNull())
					{
						for (int j = 0; j < answerType.getOptions().size(); j++)
						{
							AnswerOptionVo option = answerType.getOptions().get(j);
							sb.append(NEWLINE);
							sb.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;->&nbsp;");
							sb.append(option.getOptionText());
							
							if(option.getScoreIsNotNull())
							{
								sb.append("&nbsp;&nbsp; (Score: ");
								sb.append(option.getScore().toString());
								sb.append(")");
							}
						}
					}
					sb.append("</li>");
				}
			}
		}
		return new ims.utils.textile.Textile().process(sb.toString());
	}
	public boolean isValidated()
	{
		if(this.isBusy)
			return true;
		this.isBusy = true;
	
		if(!this.isValidated)
		{
			this.isBusy = false;
			return false;
		}
		if(this.answertypes != null)
		{
			if(!this.answertypes.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.taxonomymap != null)
		{
			if(!this.taxonomymap.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		if(this.keywords != null)
		{
			if(!this.keywords.isValidated())
			{
				this.isBusy = false;
				return false;
			}
		}
		this.isBusy = false;
		return true;
	}
	public String[] validate()
	{
		return validate(null);
	}
	public String[] validate(String[] existingErrors)
	{
		if(this.isBusy)
			return null;
		this.isBusy = true;
	
		java.util.ArrayList<String> listOfErrors = new java.util.ArrayList<String>();
		if(existingErrors != null)
		{
			for(int x = 0; x < existingErrors.length; x++)
			{
				listOfErrors.add(existingErrors[x]);
			}
		}
		if(this.text == null || this.text.length() == 0)
			listOfErrors.add("Question Text is mandatory");
		else if(this.text.length() > 500)
			listOfErrors.add("The length of the field [text] in the value object [ims.core.vo.QuestionInformationVo] is too big. It should be less or equal to 500");
		if(this.shorttext == null || this.shorttext.length() == 0)
			listOfErrors.add("Short Text is mandatory");
		else if(this.shorttext.length() > 500)
			listOfErrors.add("The length of the field [shorttext] in the value object [ims.core.vo.QuestionInformationVo] is too big. It should be less or equal to 500");
		if(this.isquestion == null)
			listOfErrors.add("isQuestion is mandatory");
		if(this.answertypes != null)
		{
			String[] listOfOtherErrors = this.answertypes.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.genderspecific == null)
			listOfErrors.add("GenderSpecific is mandatory");
		if(this.agerangemin != null && (this.agerangemin.intValue() < 0 || this.agerangemin.intValue() > 150))
			listOfErrors.add("Age Range should be between 0 and 150");
		if(this.agerangemax != null && (this.agerangemax.intValue() < 0 || this.agerangemax.intValue() > 150))
			listOfErrors.add("Age Range should be between 0 and 150");
		if(this.status == null)
			listOfErrors.add("Status is mandatory");
		if(this.taxonomymap != null)
		{
			String[] listOfOtherErrors = this.taxonomymap.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		if(this.keywords != null)
		{
			String[] listOfOtherErrors = this.keywords.validate();
			if(listOfOtherErrors != null)
			{
				for(int x = 0; x < listOfOtherErrors.length; x++)
				{
					listOfErrors.add(listOfOtherErrors[x]);
				}
			}
		}
		int errorCount = listOfErrors.size();
		if(errorCount == 0)
		{
			this.isBusy = false;
			this.isValidated = true;
			return null;
		}
		String[] result = new String[errorCount];
		for(int x = 0; x < errorCount; x++)
			result[x] = (String)listOfErrors.get(x);
		this.isBusy = false;
		this.isValidated = false;
		return result;
	}
	public void clearIDAndVersion()
	{
		this.id = null;
		this.version = 0;
	}
	public Object clone()
	{
		if(this.isBusy)
			return this;
		this.isBusy = true;
	
		QuestionInformationVo clone = new QuestionInformationVo(this.id, this.version);
		
		clone.text = this.text;
		clone.shorttext = this.shorttext;
		clone.isquestion = this.isquestion;
		if(this.answertypes == null)
			clone.answertypes = null;
		else
			clone.answertypes = (ims.core.vo.QuestionAnswerTypeVoCollection)this.answertypes.clone();
		if(this.genderspecific == null)
			clone.genderspecific = null;
		else
			clone.genderspecific = (ims.admin.vo.lookups.GenderSpecific)this.genderspecific.clone();
		clone.agerangemin = this.agerangemin;
		clone.agerangemax = this.agerangemax;
		if(this.status == null)
			clone.status = null;
		else
			clone.status = (ims.core.vo.lookups.PreActiveActiveInactiveStatus)this.status.clone();
		if(this.classification == null)
			clone.classification = null;
		else
			clone.classification = (ims.core.vo.lookups.QuestionClassificationCollection)this.classification.clone();
		clone.legendtext = this.legendtext;
		if(this.taxonomymap == null)
			clone.taxonomymap = null;
		else
			clone.taxonomymap = (ims.core.vo.TaxonomyMapCollection)this.taxonomymap.clone();
		if(this.questiontype == null)
			clone.questiontype = null;
		else
			clone.questiontype = (ims.core.vo.lookups.QuestionType)this.questiontype.clone();
		if(this.keywords == null)
			clone.keywords = null;
		else
			clone.keywords = (ims.core.vo.KeywordVoCollection)this.keywords.clone();
		clone.isValidated = this.isValidated;
		
		this.isBusy = false;
		return clone;
	}
	public int compareTo(Object obj)
	{
		return compareTo(obj, true);
	}
	public int compareTo(Object obj, boolean caseInsensitive)
	{
		if (obj == null)
		{
			return -1;
		}
		if(caseInsensitive); // this is to avoid eclipse warning only.
		if (!(QuestionInformationVo.class.isAssignableFrom(obj.getClass())))
		{
			throw new ClassCastException("A QuestionInformationVo object cannot be compared an Object of type " + obj.getClass().getName());
		}
		QuestionInformationVo compareObj = (QuestionInformationVo)obj;
		int retVal = 0;
		if (retVal == 0)
		{
			if(this.getID_QuestionInformation() == null && compareObj.getID_QuestionInformation() != null)
				return -1;
			if(this.getID_QuestionInformation() != null && compareObj.getID_QuestionInformation() == null)
				return 1;
			if(this.getID_QuestionInformation() != null && compareObj.getID_QuestionInformation() != null)
				retVal = this.getID_QuestionInformation().compareTo(compareObj.getID_QuestionInformation());
		}
		return retVal;
	}
	public synchronized static int generateValueObjectUniqueID()
	{
		return ims.vo.ValueObject.generateUniqueID();
	}
	public int countFieldsWithValue()
	{
		int count = super.countFieldsWithValue();
		if(this.taxonomymap != null)
			count++;
		if(this.questiontype != null)
			count++;
		if(this.keywords != null)
			count++;
		return count;
	}
	public int countValueObjectFields()
	{
		return super.countValueObjectFields() + 3;
	}
	protected ims.core.vo.TaxonomyMapCollection taxonomymap;
	protected ims.core.vo.lookups.QuestionType questiontype;
	protected ims.core.vo.KeywordVoCollection keywords;
	private boolean isValidated = false;
	private boolean isBusy = false;
}
