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

    private static final long serialVersionUID = 1L;

    
    @Temporal(TemporalType.DATE)
    protected Date achoSampleTakenOn;
    protected String achoUsedTest;
    protected String achoOpinion;
    protected String achoResult;
    protected String achoDifference;

    public String getAchoDifference() {
        return achoDifference;
    }

    public void setAchoDifference(String achoDifference) {
        this.achoDifference = achoDifference;
    }

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

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

    /**
     * Get the value of achoResult
     *
     * @return the value of achoResult
     */
    public String getAchoResult() {
        return achoResult;
    }

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

    /**
     * Get the value of achoOpinion
     *
     * @return the value of achoOpinion
     */
    public String getAchoOpinion() {
        return achoOpinion;
    }

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

    /**
     * Get the value of achoUsedTest
     *
     * @return the value of achoUsedTest
     */
    public String getAchoUsedTest() {
        return achoUsedTest;
    }

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

    /**
     * Get the value of achoSampleTakenOn
     *
     * @return the value of achoSampleTakenOn
     */
    public Date getAchoSampleTakenOn() {
        return achoSampleTakenOn;
    }

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

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

   // </editor-fold>

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

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

    // <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 acho = doc.createElement("achoModule");
            module.appendChild(acho);
            acho.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "achoSampleTakenOn", this.getAchoSampleTakenOnForWeb()));
            acho.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "achoUsedTest", this.achoUsedTest));
            acho.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "achoOpinion", this.achoOpinion));
            acho.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "achoResult", this.achoResult));
            acho.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "achoDifference", this.achoDifference));
            return module;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }// </editor-fold>
}
