/*
 * This file is part of DebGen Biobank Software developed by ASTRID Research.
 * All rights reserved. Reproduction, modification, use or disclosure
 * to third parties without express authority is forbidden.
 *
 * Copyright ASTRID Research Inc., Hungary, 2009-2011.
 *
 * ASTRID Research
 * Headquaters: Csapo utca 42. Debrecen H-4029 HUNGARY
 * Phone: +36-52-533-173        Fax: +36-52-533-174
 * Web: http://www.astrid.hu    E-mail: info@astrid.hu
 *
 * Project name: DebGen Biobank Software project.
 * URLS:
 * Developers: Istvan Zoltan Nagy (istvan.nagy@astrid.hu)
 */
package hu.astrid.debgen.patientmanagement.domain.modules;

import hu.astrid.debgen.exception.DebGenException;
import hu.astrid.debgen.exception.ValidationFailedException;
import hu.astrid.debgen.localization.service.LocalizationService;
import hu.astrid.debgen.patientmanagement.domain.Patient;
import hu.astrid.debgen.patientmanagement.domain.modules.requests.AnalysisRequest;
import hu.astrid.debgen.patientmanagement.domain.modules.requests.AnalysisRequestCommon;
import hu.astrid.debgen.patientmanagement.domain.modules.requests.LabelList;
import hu.astrid.toucan.control.bean.ToucanBean;
import hu.astrid.toucan.servlet.httprequesttoobjectparser.HttpRequestToObjectParser;
import hu.astrid.xmltools.beans.XmlConvertable;
import hu.astrid.xmltools.beantoxml.BeanToXmlConverter;
import hu.astrid.xmltools.beantoxml.XmlToBeanConverter;

import java.io.OutputStream;
import java.io.Serializable;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 * The class of result objects (module)
 * @author inagy
 */
@Entity
@Table(name = "debgen_modules_results")
public abstract class Result extends DebGenModule implements ToucanBean, Serializable, XmlConvertable {

    private static final long serialVersionUID = 1L;

    // <editor-fold defaultstate="collapsed" desc="Inherited from DebGenModule">
    public String getLocalizeableName() {
        return getObjectType() + getClassType();
    }

    public String getClassType() {
        return "Module";
    }// </editor-fold>
    @Transient
    protected HttpRequestToObjectParser requestParser;

    public static Result getInstance(String objectType) throws DebGenException {
        if (objectType.equals("")) {
            throw new hu.astrid.debgen.exception.DebGenException("UNKNOWN_RESULT_TYPE");
        } else if (objectType.equals("citogen")) {
            return new ResultCitogenetics();
        } else if (objectType.equals("fish")) {
            return new ResultFISH();
        } else if (objectType.equals("hypo")) {
            return new ResultHypo();
        } else if (objectType.equals("acho")) {
            return new ResultAcho();
        } else if (objectType.equals("fmr1")) {
            return new ResultFmr1();
        } else {
            throw new hu.astrid.debgen.exception.DebGenException("UNKNOWN_RESULT_TYPE");
        }
    }
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Long id;
    @Temporal(TemporalType.DATE)
    protected Date createdOn;
    protected String sampleOfAnalysis;
    protected String indicationOfAnalysis;
    @ManyToOne
    protected Patient patient;
    protected String objectType = getType();
    @Transient
    protected String languageIsoCode = "hun";
    protected boolean template;
    protected String templateName;
    @ManyToOne(cascade = CascadeType.ALL)
    protected AnalysisRequest request;
    
    @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @JoinColumn(name = "RESULT_FK",insertable = true, updatable = true, nullable = true)
    protected Set<Kariogram> kariograms;
    
    //protected boolean useAtCommon;
    //protected boolean useAtFish;
    protected boolean useAtConst;
    //protected boolean useAtChromo;
    protected boolean useAtOncohaem;
    protected boolean useAtBorn;

    // <editor-fold defaultstate="collapsed" desc="congenital connection">
    //born (congenital)
    protected boolean bdCitogeneticalAnalysis;
    protected boolean bdDNAPreparation;
    protected boolean bdFish;
    protected boolean bdDiGeorge;
    protected boolean bdWilliams;
    protected boolean bdPraderWilli;
    protected boolean bdSmithMagenis;
    protected boolean bdSRY;
    protected boolean bdSubtelomericFish;
    protected boolean bdTurnerMozaicizm;
    protected boolean bdTurnerRemainingY;
    protected boolean bdMulticolorFish;
    protected boolean bdFragX;
    protected boolean bdCitogenetic;
    protected boolean bdMolecular;
    protected boolean bdFGFR2OrFGFR3;
    protected boolean bdSCE;// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="oncohaem connection">
    //oncohaem
    protected boolean onCitogenetical;
    protected boolean onCitBone;
    protected boolean onCitBlood;
    protected boolean onCitTumor;
    protected boolean onDNAPreparation;
    protected boolean onRTPCR;
    protected boolean onFish;
    protected boolean onFishCML1; //első sor első oszlop
    protected boolean onFishCML2; //első sor második oszlop
    protected boolean onFishCML3; //második sor első oszlop
    protected boolean onFishCML4; //második sor második oszlop (mindenhol sorfolytonos a továbbiakban)
    protected boolean onFishCLL1;
    protected boolean onFishCLL2;
    protected boolean onFishCLL3;
    protected boolean onFishCLL4;
    protected boolean onFishMDS1;
    protected boolean onFishMDS2;
    protected boolean onFishMDS3;
    protected boolean onFishMDS4;
    protected boolean onFishMDS5;
    protected boolean onFishMDS6;
    protected boolean onFishMyeloma1;
    protected boolean onFishMyeloma2;
    protected boolean onFishMyeloma3;
    protected boolean onFishMyeloma4;
    protected boolean onFishAML1;
    protected boolean onFishAML2;
    protected boolean onFishAML3;
    protected boolean onFishAML4;
    protected boolean onFishAML5;
    protected boolean onFishAML6;
    protected boolean onFishAML7;
    protected boolean onFishAML8;
    protected boolean onFishALL1;
    protected boolean onFishALL2;
    protected boolean onFishALL3;
    protected boolean onFishALL4;
    protected boolean onFishALL5;
    protected boolean onFishALL6;
    protected boolean onFishALL7;// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="constitutional connection (empty)">
    //constitutional
    //NONE// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    public boolean isBdCitogenetic() {
        return bdCitogenetic;
    }

    public void setBdCitogenetic(boolean bdCitogenetic) {
        this.bdCitogenetic = bdCitogenetic;
    }

    public boolean isBdCitogeneticalAnalysis() {
        return bdCitogeneticalAnalysis;
    }

    public void setBdCitogeneticalAnalysis(boolean bdCitogeneticalAnalysis) {
        this.bdCitogeneticalAnalysis = bdCitogeneticalAnalysis;
    }

    public boolean isBdDNAPreparation() {
        return bdDNAPreparation;
    }

    public void setBdDNAPreparation(boolean bdDNAPreparation) {
        this.bdDNAPreparation = bdDNAPreparation;
    }

    public boolean isBdDiGeorge() {
        return bdDiGeorge;
    }

    public void setBdDiGeorge(boolean bdDiGeorge) {
        this.bdDiGeorge = bdDiGeorge;
    }

    public boolean isBdFGFR2OrFGFR3() {
        return bdFGFR2OrFGFR3;
    }

    public void setBdFGFR2OrFGFR3(boolean bdFGFR2OrFGFR3) {
        this.bdFGFR2OrFGFR3 = bdFGFR2OrFGFR3;
    }

    public boolean isBdFish() {
        return bdFish;
    }

    public void setBdFish(boolean bdFish) {
        this.bdFish = bdFish;
    }

    public boolean isBdFragX() {
        return bdFragX;
    }

    public void setBdFragX(boolean bdFragX) {
        this.bdFragX = bdFragX;
    }

    public boolean isBdMolecular() {
        return bdMolecular;
    }

    public void setBdMolecular(boolean bdMolecular) {
        this.bdMolecular = bdMolecular;
    }

    public boolean isBdMulticolorFish() {
        return bdMulticolorFish;
    }

    public void setBdMulticolorFish(boolean bdMulticolorFish) {
        this.bdMulticolorFish = bdMulticolorFish;
    }

    public boolean isBdPraderWilli() {
        return bdPraderWilli;
    }

    public void setBdPraderWilli(boolean bdPraderWilli) {
        this.bdPraderWilli = bdPraderWilli;
    }

    public boolean isBdSCE() {
        return bdSCE;
    }

    public void setBdSCE(boolean bdSCE) {
        this.bdSCE = bdSCE;
    }

    public boolean isBdSRY() {
        return bdSRY;
    }

    public void setBdSRY(boolean bdSRY) {
        this.bdSRY = bdSRY;
    }

    public boolean isBdSmithMagenis() {
        return bdSmithMagenis;
    }

    public void setBdSmithMagenis(boolean bdSmithMagenis) {
        this.bdSmithMagenis = bdSmithMagenis;
    }

    public boolean isBdSubtelomericFish() {
        return bdSubtelomericFish;
    }

    public void setBdSubtelomericFish(boolean bdSubtelomericFish) {
        this.bdSubtelomericFish = bdSubtelomericFish;
    }

    public boolean isBdTurnerMozaicizm() {
        return bdTurnerMozaicizm;
    }

    public void setBdTurnerMozaicizm(boolean bdTurnerMozaicizm) {
        this.bdTurnerMozaicizm = bdTurnerMozaicizm;
    }

    public boolean isBdTurnerRemainingY() {
        return bdTurnerRemainingY;
    }

    public void setBdTurnerRemainingY(boolean bdTurnerRemainingY) {
        this.bdTurnerRemainingY = bdTurnerRemainingY;
    }

    public boolean isBdWilliams() {
        return bdWilliams;
    }

    public void setBdWilliams(boolean bdWilliams) {
        this.bdWilliams = bdWilliams;
    }

    public boolean isOnCitBlood() {
        return onCitBlood;
    }

    public void setOnCitBlood(boolean onCitBlood) {
        this.onCitBlood = onCitBlood;
    }

    public boolean isOnCitBone() {
        return onCitBone;
    }

    public void setOnCitBone(boolean onCitBone) {
        this.onCitBone = onCitBone;
    }

    public boolean isOnCitTumor() {
        return onCitTumor;
    }

    public void setOnCitTumor(boolean onCitTumor) {
        this.onCitTumor = onCitTumor;
    }

    public boolean isOnCitogenetical() {
        return onCitogenetical;
    }

    public void setOnCitogenetical(boolean onCitogenetical) {
        this.onCitogenetical = onCitogenetical;
    }

    public boolean isOnDNAPreparation() {
        return onDNAPreparation;
    }

    public void setOnDNAPreparation(boolean onDNAPreparation) {
        this.onDNAPreparation = onDNAPreparation;
    }

    public boolean isOnFish() {
        return onFish;
    }

    public void setOnFish(boolean onFish) {
        this.onFish = onFish;
    }

    public boolean isOnFishALL1() {
        return onFishALL1;
    }

    public void setOnFishALL1(boolean onFishALL1) {
        this.onFishALL1 = onFishALL1;
    }

    public boolean isOnFishALL2() {
        return onFishALL2;
    }

    public void setOnFishALL2(boolean onFishALL2) {
        this.onFishALL2 = onFishALL2;
    }

    public boolean isOnFishALL3() {
        return onFishALL3;
    }

    public void setOnFishALL3(boolean onFishALL3) {
        this.onFishALL3 = onFishALL3;
    }

    public boolean isOnFishALL4() {
        return onFishALL4;
    }

    public void setOnFishALL4(boolean onFishALL4) {
        this.onFishALL4 = onFishALL4;
    }

    public boolean isOnFishALL5() {
        return onFishALL5;
    }

    public void setOnFishALL5(boolean onFishALL5) {
        this.onFishALL5 = onFishALL5;
    }

    public boolean isOnFishALL6() {
        return onFishALL6;
    }

    public void setOnFishALL6(boolean onFishALL6) {
        this.onFishALL6 = onFishALL6;
    }

    public boolean isOnFishALL7() {
        return onFishALL7;
    }

    public void setOnFishALL7(boolean onFishALL7) {
        this.onFishALL7 = onFishALL7;
    }

    public boolean isOnFishAML1() {
        return onFishAML1;
    }

    public void setOnFishAML1(boolean onFishAML1) {
        this.onFishAML1 = onFishAML1;
    }

    public boolean isOnFishAML2() {
        return onFishAML2;
    }

    public void setOnFishAML2(boolean onFishAML2) {
        this.onFishAML2 = onFishAML2;
    }

    public boolean isOnFishAML3() {
        return onFishAML3;
    }

    public void setOnFishAML3(boolean onFishAML3) {
        this.onFishAML3 = onFishAML3;
    }

    public boolean isOnFishAML4() {
        return onFishAML4;
    }

    public void setOnFishAML4(boolean onFishAML4) {
        this.onFishAML4 = onFishAML4;
    }

    public boolean isOnFishAML5() {
        return onFishAML5;
    }

    public void setOnFishAML5(boolean onFishAML5) {
        this.onFishAML5 = onFishAML5;
    }

    public boolean isOnFishAML6() {
        return onFishAML6;
    }

    public void setOnFishAML6(boolean onFishAML6) {
        this.onFishAML6 = onFishAML6;
    }

    public boolean isOnFishAML7() {
        return onFishAML7;
    }

    public void setOnFishAML7(boolean onFishAML7) {
        this.onFishAML7 = onFishAML7;
    }

    public boolean isOnFishAML8() {
        return onFishAML8;
    }

    public void setOnFishAML8(boolean onFishAML8) {
        this.onFishAML8 = onFishAML8;
    }

    public boolean isOnFishCLL1() {
        return onFishCLL1;
    }

    public void setOnFishCLL1(boolean onFishCLL1) {
        this.onFishCLL1 = onFishCLL1;
    }

    public boolean isOnFishCLL2() {
        return onFishCLL2;
    }

    public void setOnFishCLL2(boolean onFishCLL2) {
        this.onFishCLL2 = onFishCLL2;
    }

    public boolean isOnFishCLL3() {
        return onFishCLL3;
    }

    public void setOnFishCLL3(boolean onFishCLL3) {
        this.onFishCLL3 = onFishCLL3;
    }

    public boolean isOnFishCLL4() {
        return onFishCLL4;
    }

    public void setOnFishCLL4(boolean onFishCLL4) {
        this.onFishCLL4 = onFishCLL4;
    }

    public boolean isOnFishCML1() {
        return onFishCML1;
    }

    public void setOnFishCML1(boolean onFishCML1) {
        this.onFishCML1 = onFishCML1;
    }

    public boolean isOnFishCML2() {
        return onFishCML2;
    }

    public void setOnFishCML2(boolean onFishCML2) {
        this.onFishCML2 = onFishCML2;
    }

    public boolean isOnFishCML3() {
        return onFishCML3;
    }

    public void setOnFishCML3(boolean onFishCML3) {
        this.onFishCML3 = onFishCML3;
    }

    public boolean isOnFishCML4() {
        return onFishCML4;
    }

    public void setOnFishCML4(boolean onFishCML4) {
        this.onFishCML4 = onFishCML4;
    }

    public boolean isOnFishMDS1() {
        return onFishMDS1;
    }

    public void setOnFishMDS1(boolean onFishMDS1) {
        this.onFishMDS1 = onFishMDS1;
    }

    public boolean isOnFishMDS2() {
        return onFishMDS2;
    }

    public void setOnFishMDS2(boolean onFishMDS2) {
        this.onFishMDS2 = onFishMDS2;
    }

    public boolean isOnFishMDS3() {
        return onFishMDS3;
    }

    public void setOnFishMDS3(boolean onFishMDS3) {
        this.onFishMDS3 = onFishMDS3;
    }

    public boolean isOnFishMDS4() {
        return onFishMDS4;
    }

    public void setOnFishMDS4(boolean onFishMDS4) {
        this.onFishMDS4 = onFishMDS4;
    }

    public boolean isOnFishMDS5() {
        return onFishMDS5;
    }

    public void setOnFishMDS5(boolean onFishMDS5) {
        this.onFishMDS5 = onFishMDS5;
    }

    public boolean isOnFishMDS6() {
        return onFishMDS6;
    }

    public void setOnFishMDS6(boolean onFishMDS6) {
        this.onFishMDS6 = onFishMDS6;
    }

    public boolean isOnFishMyeloma1() {
        return onFishMyeloma1;
    }

    public void setOnFishMyeloma1(boolean onFishMyeloma1) {
        this.onFishMyeloma1 = onFishMyeloma1;
    }

    public boolean isOnFishMyeloma2() {
        return onFishMyeloma2;
    }

    public void setOnFishMyeloma2(boolean onFishMyeloma2) {
        this.onFishMyeloma2 = onFishMyeloma2;
    }

    public boolean isOnFishMyeloma3() {
        return onFishMyeloma3;
    }

    public void setOnFishMyeloma3(boolean onFishMyeloma3) {
        this.onFishMyeloma3 = onFishMyeloma3;
    }

    public boolean isOnFishMyeloma4() {
        return onFishMyeloma4;
    }

    public void setOnFishMyeloma4(boolean onFishMyeloma4) {
        this.onFishMyeloma4 = onFishMyeloma4;
    }

    public boolean isOnRTPCR() {
        return onRTPCR;
    }

    public void setOnRTPCR(boolean onRTPCR) {
        this.onRTPCR = onRTPCR;
    }

    /**
     * Get the value of useAtBorn
     *
     * @return the value of useAtBorn
     */
    public boolean isUseAtBorn() {
        return useAtBorn;
    }

    /**
     * Set the value of useAtBorn
     *
     * @param useAtBorn new value of useAtBorn
     */
    public void setUseAtBorn(boolean useAtBorn) {
        this.useAtBorn = useAtBorn;
    }

    /**
     * Get the value of useAtOncohaem
     *
     * @return the value of useAtOncohaem
     */
    public boolean isUseAtOncohaem() {
        return useAtOncohaem;
    }

    /**
     * Set the value of useAtOncohaem
     *
     * @param useAtOncohaem new value of useAtOncohaem
     */
    public void setUseAtOncohaem(boolean useAtOncohaem) {
        this.useAtOncohaem = useAtOncohaem;
    }

//    /**
//     * Get the value of useAtChromo
//     *
//     * @return the value of useAtChromo
//     */
//    public boolean isUseAtChromo() {
//        return useAtChromo;
//    }
//
//    /**
//     * Set the value of useAtChromo
//     *
//     * @param useAtChromo new value of useAtChromo
//     */
//    public void setUseAtChromo(boolean useAtChromo) {
//        this.useAtChromo = useAtChromo;
//    }

    /**
     * Get the value of useAtConst
     *
     * @return the value of useAtConst
     */
    public boolean isUseAtConst() {
        return useAtConst;
    }

    /**
     * Set the value of useAtConst
     *
     * @param useAtConst new value of useAtConst
     */
    public void setUseAtConst(boolean useAtConst) {
        this.useAtConst = useAtConst;
    }

//    /**
//     * Get the value of useAtFish
//     *
//     * @return the value of useAtFish
//     */
//    public boolean isUseAtFish() {
//        return useAtFish;
//    }
//
//    /**
//     * Set the value of useAtFish
//     *
//     * @param useAtFish new value of useAtFish
//     */
//    public void setUseAtFish(boolean useAtFish) {
//        this.useAtFish = useAtFish;
//    }
//
//
//    /**
//     * Get the value of useAtCommon
//     *
//     * @return the value of useAtCommon
//     */
//    public boolean isUseAtCommon() {
//        return useAtCommon;
//    }
//
//    /**
//     * Set the value of useAtCommon
//     *
//     * @param useAtCommon new value of useAtCommon
//     */
//    public void setUseAtCommon(boolean useAtCommon) {
//        this.useAtCommon = useAtCommon;
//    }

    /**
     * Get the value of request
     *
     * @return the value of request
     */
    public AnalysisRequest getRequest() {
        return request;
    }

    /**
     * Set the value of request
     *
     * @param request new value of request
     */
    public void setRequest(AnalysisRequest request) {
        this.request = request;
    }

    /**
     * Get the value of templateName
     *
     * @return the value of templateName
     */
    public String getTemplateName() {
        return templateName;
    }

    /**
     * Set the value of templateName
     *
     * @param templateName new value of templateName
     */
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }

    /**
     * Get the value of template
     *
     * @return the value of template
     */
    public boolean isTemplate() {
        return template;
    }

    /**
     * Set the value of template
     *
     * @param template new value of template
     */
    public void setTemplate(boolean template) {
        this.template = template;
    }

    /**
     * Get the value of indicationOfAnalysis
     *
     * @return the value of indicationOfAnalysis
     */
    public String getIndicationOfAnalysis() {
        return indicationOfAnalysis;
    }

    /**
     * Set the value of indicationOfAnalysis
     *
     * @param indicationOfAnalysis new value of indicationOfAnalysis
     */
    public void setIndicationOfAnalysis(String indicationOfAnalysis) {
        this.indicationOfAnalysis = indicationOfAnalysis;
    }

    /**
     * Get the value of sampleOfAnalysis
     *
     * @return the value of sampleOfAnalysis
     */
    public String getSampleOfAnalysis() {
        return sampleOfAnalysis;
    }

    /**
     * Set the value of sampleOfAnalysis
     *
     * @param sampleOfAnalysis new value of sampleOfAnalysis
     */
    public void setSampleOfAnalysis(String sampleOfAnalysis) {
        this.sampleOfAnalysis = sampleOfAnalysis;
    }

    public void setLanguageIsoCode(String languageIsoCode) {
        this.languageIsoCode = languageIsoCode;
    }

    public String getCreatedOnForWeb() {
        try {
            return new SimpleDateFormat("yyyy. MM. dd.").format(createdOn);
        } catch (Exception e) {
            return "";
        }
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public Patient getPatient() {
        return patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }

	public Set<Kariogram> getKariograms() {
		return kariograms;
	}

	public void setKariograms(Set<Kariogram> kariograms) {
		this.kariograms = kariograms;
	}

	/**
     * Get the value of objectType
     *
     * @return the value of objectType
     */
    public String getObjectType() {
        return objectType;
    }

    /**
     * Set the value of objectType
     *
     * @param objectType new value of objectType
     */
    public void setObjectType(String objectType) {
        this.objectType = objectType;
    }

    /**
     * Returns the type of the class such as: common
     * @return The type of the class;
     */
    public abstract String getType();

    /**
     * Get the value of id
     *
     * @return the value of id
     */
    public Long getId() {
        return id;
    }

    /**
     * Set the value of id
     *
     * @param id new value of id
     */
    public void setId(Long id) {
        this.id = id;
    }// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Toucan request processing">
    public void convert(HttpServletRequest request) throws Exception {
        requestParser = HttpRequestToObjectParser.getInstance(request);
        this.template = false;
        this.useAtBorn = false;
//        this.useAtChromo = false;
//        this.useAtCommon = false;
        this.useAtConst = false;
//        this.useAtFish = false;
        this.useAtOncohaem = false;

        onCitogenetical = false;
        onCitBone = false;
        onCitBlood = false;
        onCitTumor = false;
        onDNAPreparation = false;
        onRTPCR = false;
        onFish = false;
        onFishCML1 = false;
        onFishCML2 = false;
        onFishCML3 = false;
        onFishCML4 = false;
        onFishCLL1 = false;
        onFishCLL2 = false;
        onFishCLL3 = false;
        onFishCLL4 = false;
        onFishMDS1 = false;
        onFishMDS2 = false;
        onFishMDS3 = false;
        onFishMDS4 = false;
        onFishMDS5 = false;
        onFishMDS6 = false;
        onFishMyeloma1 = false;
        onFishMyeloma2 = false;
        onFishMyeloma3 = false;
        onFishMyeloma4 = false;
        onFishAML1 = false;
        onFishAML2 = false;
        onFishAML3 = false;
        onFishAML4 = false;
        onFishAML5 = false;
        onFishAML6 = false;
        onFishAML7 = false;
        onFishAML8 = false;
        onFishALL1 = false;
        onFishALL2 = false;
        onFishALL3 = false;
        onFishALL4 = false;
        onFishALL5 = false;
        onFishALL6 = false;
        onFishALL7 = false;

        bdCitogeneticalAnalysis = false;
        bdDNAPreparation = false;
        bdFish = false;
        bdDiGeorge = false;
        bdWilliams = false;
        bdPraderWilli = false;
        bdSmithMagenis = false;
        bdSRY = false;
        bdSubtelomericFish = false;
        bdTurnerMozaicizm = false;
        bdTurnerRemainingY = false;
        bdMulticolorFish = false;
        bdFragX = false;
        bdCitogenetic = false;
        bdMolecular = false;
        bdFGFR2OrFGFR3 = false;
        bdSCE = false;

        requestParser.parseRequest(Result.class, this);
        if (this.createdOn == null) {
            this.createdOn = new Date();
        }
    }// </editor-fold>

    /**
     * Validate the current results datas
     * @return True if the current result (this) is valid
     * @throws ValidationFailedException When the result is not valid
     */
    public boolean validate() throws ValidationFailedException {
        if (this.createdOn == null) {
            this.createdOn = new Date();
        }
        ArrayList<String> properties = new ArrayList<String>(4);
        if (this.template && (this.templateName == null || this.templateName.equals(""))) {
            properties.add("TEMPLATE");
        }
        if (this.sampleOfAnalysis == null || this.sampleOfAnalysis.equals("")) {
            properties.add("SAMPLE");
        }
        if (!this.template && (this.indicationOfAnalysis == null || this.indicationOfAnalysis.equals(""))) {
            properties.add("INDICATION");
        }
        /*if (this.request == null && !this.isTemplate()) {
        properties.add("REQUESTEMPTY");
        }*/
        if (properties.isEmpty()) {
            return true;
        } else {
            throw new ValidationFailedException(properties);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="XML conversion">
    public void convertToXml(URL schema, OutputStream output) throws Exception {
        BeanToXmlConverter beanToXmlConverter = new BeanToXmlConverter(schema, output);
        beanToXmlConverter.setNameSpacePrefix("debgenbiobank");
        if (this.request == null) {
            this.request = new AnalysisRequestCommon();
            this.request.setLabels(new LabelList());
            this.request.setPatient(this.patient);
            this.request.setCreatedOn(this.createdOn);
            this.request.setBNOCode("");
            this.request.setDNAIndex("");
            this.request.setDiagnosis("");
            this.request.setImmuneFenotypeFAB("");
            this.request.setLanguageIsoCode(this.languageIsoCode);
            this.request.setNameOfSenderInstitute("");
            this.request.setSenderCode("");
            this.request.setLogNumber("");
            this.request.setEmpty(true);
        }
        this.request.setResult(this);
        beanToXmlConverter.convertToXml(this.getRequest());
    }

    public abstract void buildFromXml(Node node) throws Exception;

    public abstract void buildFromXml(Node node, String string) throws Exception;

    public abstract Node toXml(Document doc) throws Exception;

    public abstract Node toXml(Document doc, String string) throws Exception;

    public XmlToBeanConverter getXmlConverter() throws Exception {
        return new XmlToBeanConverter();
    }

    protected void setXmlCommonValues(Document doc, Node root) {
        root.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "indicationOfAnalysis", indicationOfAnalysis));
        root.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "sampleOfAnalysis", new LocalizationService().getMessage(sampleOfAnalysis, languageIsoCode)));
        try {
            root.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "createdOn", new SimpleDateFormat("yyyy. MM. dd.").format(createdOn)));
        } catch (Exception ex) {
            root.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "createdOn", ""));
        }
    }
    // </editor-fold>
}

