/*
 * 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.requests;

import hu.astrid.xmltools.beantoxml.XmlToBeanConverter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import javax.persistence.Entity;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Class of Constitutional Kariotyping Analisys Requests
 * @author inagy
 */
@Entity
public class AnalysisRequestConst extends AnalysisRequest {

    private static final long serialVersionUID = 1L;

    protected int coHead;
    protected int coHeight;
    protected int coWeight;
    protected String coComment;
    protected String coDoctor;

    // <editor-fold defaultstate="collapsed" desc="Getters and Setters">
    /**
     * Get the value of coDoctor
     *
     * @return the value of coDoctor
     */
    public String getCoDoctor() {
        return coDoctor;
    }

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

    /**
     * Get the value of coComment
     *
     * @return the value of coComment
     */
    public String getCoComment() {
        return coComment;
    }

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

    /**
     * Get the value of coWeight
     *
     * @return the value of coWeight
     */
    public int getCoWeight() {
        return coWeight;
    }

    /**
     * Set the value of coWeight
     *
     * @param coWeight new value of coWeight
     */
    public void setCoWeight(int coWeight) {
        this.coWeight = coWeight;
    }

    /**
     * Get the value of coHeight
     *
     * @return the value of coHeight
     */
    public int getCoHeight() {
        return coHeight;
    }

    /**
     * Set the value of coHeight
     *
     * @param coHeight new value of coHeight
     */
    public void setCoHeight(int coHeight) {
        this.coHeight = coHeight;
    }

    /**
     * Get the value of coHead
     *
     * @return the value of coHead
     */
    public int getCoHead() {
        return coHead;
    }

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

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

    // <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 analysis = doc.createElement(prefix + "analysis");
            analysis.setAttribute("objectType", this.objectType);
            this.setXmlCommonValues(doc, analysis);
            Element constRequest = doc.createElement("constRequest");
            analysis.appendChild(constRequest);
            constRequest.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "coHead", coHead + " cm"));
            constRequest.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "coWeight", coWeight + " kg"));
            constRequest.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "coHeight", coHeight + " cm"));
            constRequest.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "coComment", coComment));
            constRequest.appendChild(XmlToBeanConverter.getNodeWithValue(doc, "coDoctor", coDoctor));
            analysis.appendChild(patient.toXml(doc));
            Element biobankData = doc.createElement("biobankData");
            analysis.appendChild(biobankData);
            biobankData.appendChild(this.getLabels().toXml(doc));
            setXmlMetaData(doc, biobankData);
            return analysis;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        }
    }// </editor-fold>

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

}

