/*
 * 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.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 Hypo results
 * @author inagy
 */
@Entity
public class ResultHypo extends Result {

    private static final long serialVersionUID = 1L;

   
    @Temporal(TemporalType.DATE)
    protected Date hypoSampleTakenOn;
    protected String hypoUsedTest;
    protected String hypoOpinion;
    protected String hypoResult;
    protected String hypoDifference;

    public String getHypoDifference() {
        return hypoDifference;
    }

    public void setHypoDifference(String hypoDifference) {
        this.hypoDifference = hypoDifference;
    }

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

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

    /**
     * Get the value of hypoResult
     *
     * @return the value of hypoResult
     */
    public String getHypoResult() {
        return hypoResult;
    }

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

    /**
     * Get the value of hypoOpinion
     *
     * @return the value of hypoOpinion
     */
    public String getHypoOpinion() {
        return hypoOpinion;
    }

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

    /**
     * Get the value of hypoUsedTest
     *
     * @return the value of hypoUsedTest
     */
    public String getHypoUsedTest() {
        return hypoUsedTest;
    }

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

    /**
     * Get the value of hypoSampleTakenOn
     *
     * @return the value of hypoSampleTakenOn
     */
    public Date getHypoSampleTakenOn() {
        return hypoSampleTakenOn;
    }

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

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

  

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

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

    // <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 hypo = doc.createElement("hypoModule");
            module.appendChild(hypo);
            hypo.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "hypoSampleTakenOn", this.getHypoSampleTakenOnForWeb()));
            hypo.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "hypoUsedTest", this.hypoUsedTest));
            hypo.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "hypoOpinion", this.hypoOpinion));
            hypo.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "hypoResult", this.hypoResult));
            hypo.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "hypoDifference", this.hypoDifference));
            return module;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }// </editor-fold>
}
