/*
 * 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.localization.service.LocalizationService;
import hu.astrid.xmltools.beantoxml.XmlToBeanConverter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.servlet.http.HttpServletRequest;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
 * Class of FISH results
 * @author inagy
 */
@Entity
public class ResultFISH extends Result {

    private static final long serialVersionUID = 1L;

    protected String fishTenyesztesiIdo;
    @Temporal(TemporalType.DATE)
    protected Date fishSampleTakenOn;
    protected String fishUsedTest;
    protected String fishOpinion;
    protected String fishResult;

    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    /**
     * Get the value of fishResult
     *
     * @return the value of fishResult
     */
    public String getFishResultForWeb() {
        try {
            return fishResult.replaceAll("\r\n", "<br />").replaceAll("\n", "<br />").replaceAll("\r", "<br />");
        } catch (Exception e) {
            return fishResult;
        }
    }

    /**
     * Get the value of fishOpinion
     *
     * @return the value of fishOpinion
     */
    public String getFishOpinionForWeb() {
        try {
            return fishOpinion.replaceAll("\r\n", "<br />").replaceAll("\n", "<br />").replaceAll("\r", "<br />");
        } catch (Exception e) {
            return fishOpinion;
        }
    }

    /**
     * Get the value of fishResult
     *
     * @return the value of fishResult
     */
    public String getFishResult() {
        return fishResult;
    }

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

    /**
     * Get the value of fishOpinion
     *
     * @return the value of fishOpinion
     */
    public String getFishOpinion() {
        return fishOpinion;
    }

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

    /**
     * Get the value of fishUsedTest
     *
     * @return the value of fishUsedTest
     */
    public String getFishUsedTest() {
        return fishUsedTest;
    }

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

    /**
     * Get the value of fishSampleTakenOn
     *
     * @return the value of fishSampleTakenOn
     */
    public Date getFishSampleTakenOn() {
        return fishSampleTakenOn;
    }

    /**
     * Get the value of fishSampleTakenOn
     *
     * @return the value of fishSampleTakenOn
     */
    public String getFishSampleTakenOnForWeb() {
        try {
            return new SimpleDateFormat("yyyy. MM. dd.").format(fishSampleTakenOn);
        } catch (Exception ex) {
            return "";
        }
    }

    /**
     * Set the value of fishSampleTakenOn
     *
     * @param fishSampleTakenOn new value of fishSampleTakenOn
     */
    public void setFishSampleTakenOn(Date fishSampleTakenOn) {
        this.fishSampleTakenOn = fishSampleTakenOn;
    }

    /**
     * Get the value of fishTenyesztesiIdo
     *
     * @return the value of fishTenyesztesiIdo
     */
    public String getFishTenyesztesiIdo() {
        return fishTenyesztesiIdo;
    }

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

    // <editor-fold defaultstate="collapsed" desc="Toucan request processing">
    @Override
    public void convert(HttpServletRequest request) throws Exception {
        super.convert(request);
        requestParser.parseRequest(ResultFISH.class, this);
        if (this.createdOn == null) {
            this.createdOn = new Date();
        }
    }// </editor-fold>

    @Override
    public String getType() {
        return "fish";
    }

    // <editor-fold defaultstate="collapsed" desc="XML conversion">
    @Override
    public void buildFromXml(Node node) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void buildFromXml(Node node, String string) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Node toXml(Document doc) throws Exception {
        return toXml(doc, "");
    }

    @Override
    public Node toXml(Document doc, String nameSpace) throws Exception {
        try {
            String prefix = nameSpace == null || nameSpace.isEmpty() ? "" : nameSpace + ":";
            Element module = doc.createElement(prefix + "module");
            module.setAttribute("objectType", this.objectType);
            this.setXmlCommonValues(doc, module);
            Element fish = doc.createElement("fishModule");
            module.appendChild(fish);
            fish.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fishTenyesztesiIdo", new LocalizationService().getMessage(this.fishTenyesztesiIdo, languageIsoCode)));
            fish.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fishSampleTakenOn", this.getFishSampleTakenOnForWeb()));
            fish.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fishUsedTest", this.fishUsedTest));
            fish.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fishOpinion", this.fishOpinion));
            fish.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fishResult", this.fishResult));
            return module;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }// </editor-fold>
}
