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

    private static final long serialVersionUID = 1L;

    
    @Temporal(TemporalType.DATE)
    protected Date fmrSampleTakenOn;
    protected String fmrUsedTest;
    protected String fmrResult;



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


    /**
     * Get the value of fmrResult
     *
     * @return the value of fmrResult
     */
    public String getFmrResult() {
        return fmrResult;
    }

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

    /**
     * Get the value of fmrUsedTest
     *
     * @return the value of fmrUsedTest
     */
    public String getFmrUsedTest() {
        return fmrUsedTest;
    }

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

    /**
     * Get the value of fmrSampleTakenOn
     *
     * @return the value of fmrSampleTakenOn
     */
    public Date getFmrSampleTakenOn() {
        return fmrSampleTakenOn;
    }

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

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

   // </editor-fold>

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

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

    // <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 fmr = doc.createElement("fmrModule");
            module.appendChild(fmr);
            fmr.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fmrSampleTakenOn", this.getFmrSampleTakenOnForWeb()));
            fmr.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fmrUsedTest", this.fmrUsedTest));
            fmr.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "fmrResult", this.fmrResult));
            return module;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }// </editor-fold>
}
