/**
 * PQ.java
 * <p>
 * File generated from the datatypes::PQ uml Class
 * Generated by IHE - europe, gazelle team
 */
package net.ihe.gazelle.hl7v3.datatypes;

import java.io.Serial;
import java.util.ArrayList;
import java.util.List;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.XmlType;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import net.ihe.gazelle.gen.common.ConstraintValidatorModule;

import org.w3c.dom.Document;
import org.w3c.dom.Node;


/**
 * Description of the class PQ.
 *
 * 
 */

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PQ", propOrder = {
	"translation",
	"unit",
	"value"
})
@XmlRootElement(name = "PQ")
public class PQ extends net.ihe.gazelle.hl7v3.datatypes.QTY implements java.io.Serializable {
	
	/**
	 * 
	 */
	@Serial
    private static final long serialVersionUID = 1L;

	
	/**
	 * 
	                        An alternative representation of the same physical
	                        quantity expressed in a different unit, of a different
	                        unit code system and possibly with a different value.
	                     .
	 */
	@XmlElement(name = "translation", namespace = "urn:hl7-org:v3")
	public List<net.ihe.gazelle.hl7v3.datatypes.PQR> translation;
	/**
	 * 
	                     The unit of measure specified in the Unified Code for
	                     Units of Measure (UCUM)
	                     [http://aurora.rg.iupui.edu/UCUM].
	                  .
	 */
	@XmlAttribute(name = "unit")
	public String unit;
	/**
	 * 
	                     The magnitude of the quantity measured in terms of
	                     the unit.
	                  .
	 */
	@XmlAttribute(name = "value")
	@jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter(net.ihe.gazelle.adapters.DoubleAdapter.class)
	public Double value;
	
	/**
	 * An attribute containing marshalled element node
	 */
	@XmlTransient
	private org.w3c.dom.Node _xmlNodePresentation;
	
	
	/**
	 * Return translation.
	 * @return translation : 
	                        An alternative representation of the same physical
	                        quantity expressed in a different unit, of a different
	                        unit code system and possibly with a different value.

	 */
	public List<net.ihe.gazelle.hl7v3.datatypes.PQR> getTranslation() {
		if (translation == null) {
	        translation = new ArrayList<>();
	    }
	    return translation;
	}
	
	/**
	 * Set a value to attribute translation.
	 * @param translation : 
	                        An alternative representation of the same physical
	                        quantity expressed in a different unit, of a different
	                        unit code system and possibly with a different value.
	 */
	public void setTranslation(List<net.ihe.gazelle.hl7v3.datatypes.PQR> translation) {
	    this.translation = translation;
	}
	
	
	
	/**
	 * Add a translation to the translation collection.
	 * @param translation_elt Element to add.
	 */
	public void addTranslation(net.ihe.gazelle.hl7v3.datatypes.PQR translation_elt) {
	    this.translation.add(translation_elt);
	}
	
	/**
	 * Remove a translation to the translation collection.
	 * @param translation_elt Element to remove
	 */
	public void removeTranslation(net.ihe.gazelle.hl7v3.datatypes.PQR translation_elt) {
	    this.translation.remove(translation_elt);
	}
	
	/**
	 * Return unit.
	 * @return unit : 
	                     The unit of measure specified in the Unified Code for
	                     Units of Measure (UCUM)
	                     [http://aurora.rg.iupui.edu/UCUM].
	 */
	public String getUnit() {
	    return unit;
	}
	
	/**
	 * Set a value to attribute unit.
	 * @param unit : 
	                     The unit of measure specified in the Unified Code for
	                     Units of Measure (UCUM)
	                     [http://aurora.rg.iupui.edu/UCUM].
	                  
	 */
	public void setUnit(String unit) {
	    this.unit = unit;
	}
	
	
	
	
	/**
	 * Return value.
	 * @return value : 
	                     The magnitude of the quantity measured in terms of
	                     the unit.

	 */
	public Double getValue() {
	    return value;
	}
	
	/**
	 * Set a value to attribute value.
	 * @param value : 
	                     The magnitude of the quantity measured in terms of
	                     the unit.
	 */
	public void setValue(Double value) {
	    this.value = value;
	}
	
	
	
	
	
	public Node get_xmlNodePresentation() {
		if (_xmlNodePresentation == null){
				JAXBContext jc;
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
				dbf.setNamespaceAware(true);
				DocumentBuilder db = null;
				Document doc = null;
				try {
					db = dbf.newDocumentBuilder();
					doc = db.newDocument();
				} catch (ParserConfigurationException ignored) {}
				try {
					jc = JAXBContext.newInstance("net.ihe.gazelle.hl7v3.datatypes");
					Marshaller m = jc.createMarshaller();
					m.marshal(this, doc);
					_xmlNodePresentation = doc.getElementsByTagNameNS("urn:hl7-org:v3", "PQ").item(0);
				} catch (JAXBException e) {
					try{
						db = dbf.newDocumentBuilder();
						_xmlNodePresentation = db.newDocument();
					}
					catch(Exception ignored){}
				}
			}
			return _xmlNodePresentation;
	}
	
	public void set_xmlNodePresentation(Node _xmlNodePresentation) {
		this._xmlNodePresentation = _xmlNodePresentation;
	}
	
	
	

	
	/**
     * validate by a module of validation
     * 
     */
   public static void validateByModule(PQ pQ, String _location, ConstraintValidatorModule cvm, List<net.ihe.gazelle.validation.Notification> diagnostic){
   		if (pQ != null){
   			net.ihe.gazelle.hl7v3.datatypes.QTY.validateByModule(pQ, _location, cvm, diagnostic);
			{
				int i = 0;
				for (net.ihe.gazelle.hl7v3.datatypes.PQR translation: pQ.getTranslation()){
					net.ihe.gazelle.hl7v3.datatypes.PQR.validateByModule(translation, _location + "/translation[" + i + "]", cvm, diagnostic);
					i++;
				}
			}
			
    	}
    }

}