/**
 * CD.java
 * <p>
 * File generated from the datatypes::CD 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 CD.
 *
 * 
 */

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CD", propOrder = {
	"originalText",
	"qualifier",
	"translation",
	"code",
	"codeSystem",
	"codeSystemName",
	"codeSystemVersion",
	"displayName"
})
@XmlRootElement(name = "CD")
public class CD extends net.ihe.gazelle.hl7v3.datatypes.ANY implements java.io.Serializable {
	
	/**
	 * 
	 */
	@Serial
    private static final long serialVersionUID = 1L;

	
	/**
	 * 
	                        The text or phrase used as the basis for the coding.
	                     .
	 */
	@XmlElement(name = "originalText", namespace = "urn:hl7-org:v3")
	public net.ihe.gazelle.hl7v3.datatypes.ED originalText;
	/**
	 * 
	                        Specifies additional codes that increase the
	                        specificity of the primary code.
	                     .
	 */
	@XmlElement(name = "qualifier", namespace = "urn:hl7-org:v3")
	public List<net.ihe.gazelle.hl7v3.datatypes.CR> qualifier;
	/**
	 * 
	                        A set of other concept descriptors that translate
	                        this concept descriptor into other code systems.
	                     .
	 */
	@XmlElement(name = "translation", namespace = "urn:hl7-org:v3")
	public List<net.ihe.gazelle.hl7v3.datatypes.CD> translation;
	/**
	 * 
	                     The plain code symbol defined by the code system.
	                     For example, "784.0" is the code symbol of the ICD-9
	                     code "784.0" for headache.
	                  .
	 */
	@XmlAttribute(name = "code")
	public String code;
	/**
	 * 
	                     Specifies the code system that defines the code.
	                  .
	 */
	@XmlAttribute(name = "codeSystem")
	public String codeSystem;
	/**
	 * 
	                     A common name of the coding system.
	                  .
	 */
	@XmlAttribute(name = "codeSystemName")
	public String codeSystemName;
	/**
	 * 
	                     If applicable, a version descriptor defined
	                     specifically for the given code system.
	                  .
	 */
	@XmlAttribute(name = "codeSystemVersion")
	public String codeSystemVersion;
	/**
	 * 
	                     A name or title for the code, under which the sending
	                     system shows the code value to its users.
	                  .
	 */
	@XmlAttribute(name = "displayName")
	public String displayName;
	
	/**
	 * An attribute containing marshalled element node
	 */
	@XmlTransient
	private org.w3c.dom.Node _xmlNodePresentation;
	
	public CD(){
		super();
	}
	
	public CD(String inCode, String inDisplayName, String inCodeSystem){
		super();
		this.code = inCode;
		this.displayName = inDisplayName;
		this.codeSystem = inCodeSystem;
	}

	public CD(String inCode, String inDisplayName, String inCodeSystem, String codeSystemName){
		super();
		this.code = inCode;
		this.displayName = inDisplayName;
		this.codeSystem = inCodeSystem;
		this.codeSystemName = codeSystemName;
	}

	/**
	 * Return originalText.
	 * @return originalText : 
	                        The text or phrase used as the basis for the coding.
	                     
	 */
	public net.ihe.gazelle.hl7v3.datatypes.ED getOriginalText() {
	    return originalText;
	}
	
	/**
	 * Set a value to attribute originalText.
	 * @param originalText : 
	                        The text or phrase used as the basis for the coding.
	                     
	 */
	public void setOriginalText(net.ihe.gazelle.hl7v3.datatypes.ED originalText) {
	    this.originalText = originalText;
	}
	
	
	
	
	/**
	 * Return qualifier.
	 * @return qualifier : 
	                        Specifies additional codes that increase the
	                        specificity of the primary code.
	 */
	public List<net.ihe.gazelle.hl7v3.datatypes.CR> getQualifier() {
		if (qualifier == null) {
	        qualifier = new ArrayList<>();
	    }
	    return qualifier;
	}
	
	/**
	 * Set a value to attribute qualifier.
	 * @param qualifier : 
	                        Specifies additional codes that increase the
	                        specificity of the primary code.
	                     
	 */
	public void setQualifier(List<net.ihe.gazelle.hl7v3.datatypes.CR> qualifier) {
	    this.qualifier = qualifier;
	}
	
	
	
	/**
	 * Add a qualifier to the qualifier collection.
	 * @param qualifier_elt Element to add.
	 */
	public void addQualifier(net.ihe.gazelle.hl7v3.datatypes.CR qualifier_elt) {
	    this.qualifier.add(qualifier_elt);
	}
	
	/**
	 * Remove a qualifier to the qualifier collection.
	 * @param qualifier_elt Element to remove
	 */
	public void removeQualifier(net.ihe.gazelle.hl7v3.datatypes.CR qualifier_elt) {
	    this.qualifier.remove(qualifier_elt);
	}
	
	/**
	 * Return translation.
	 * @return translation : 
	                        A set of other concept descriptors that translate
	                        this concept descriptor into other code systems.

	 */
	public List<net.ihe.gazelle.hl7v3.datatypes.CD> getTranslation() {
		if (translation == null) {
	        translation = new ArrayList<>();
	    }
	    return translation;
	}
	
	/**
	 * Set a value to attribute translation.
	 * @param translation : 
	                        A set of other concept descriptors that translate
	                        this concept descriptor into other code systems.
	 */
	public void setTranslation(List<net.ihe.gazelle.hl7v3.datatypes.CD> 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.CD 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.CD translation_elt) {
	    this.translation.remove(translation_elt);
	}
	
	/**
	 * Return code.
	 * @return code : 
	                     The plain code symbol defined by the code system.
	                     For example, "784.0" is the code symbol of the ICD-9
	                     code "784.0" for headache.
	                  

	 */
	public String getCode() {
	    return code;
	}
	
	/**
	 * Set a value to attribute code.
	 * @param code : 
	                     The plain code symbol defined by the code system.
	                     For example, "784.0" is the code symbol of the ICD-9
	                     code "784.0" for headache.
	                  
	 */
	public void setCode(String code) {
	    this.code = code;
	}
	
	
	/**
	 * Return codeSystem.
	 * @return codeSystem : 
	                     Specifies the code system that defines the code.

	 */
	public String getCodeSystem() {
	    return codeSystem;
	}
	
	/**
	 * Set a value to attribute codeSystem.
	 * @param codeSystem : 
	                     Specifies the code system that defines the code.
	                  
	 */
	public void setCodeSystem(String codeSystem) {
	    this.codeSystem = codeSystem;
	}

	
	/**
	 * Return codeSystemName.
	 * @return codeSystemName : 
	                     A common name of the coding system.

	 */
	public String getCodeSystemName() {
	    return codeSystemName;
	}
	
	/**
	 * Set a value to attribute codeSystemName.
	 * @param codeSystemName : 
	                     A common name of the coding system.

	 */
	public void setCodeSystemName(String codeSystemName) {
	    this.codeSystemName = codeSystemName;
	}
	

	/**
	 * Return codeSystemVersion.
	 * @return codeSystemVersion : 
	                     If applicable, a version descriptor defined
	                     specifically for the given code system.
	                  
	 */
	public String getCodeSystemVersion() {
	    return codeSystemVersion;
	}
	
	/**
	 * Set a value to attribute codeSystemVersion.
	 * @param codeSystemVersion : 
	                     If applicable, a version descriptor defined
	                     specifically for the given code system.
	 */
	public void setCodeSystemVersion(String codeSystemVersion) {
	    this.codeSystemVersion = codeSystemVersion;
	}
	

	/**
	 * Return displayName.
	 * @return displayName : 
	                     A name or title for the code, under which the sending
	                     system shows the code value to its users.
	                  
	 */
	public String getDisplayName() {
	    return displayName;
	}
	
	/**
	 * Set a value to attribute displayName.
	 * @param displayName : 
	                     A name or title for the code, under which the sending
	                     system shows the code value to its users.
	 */
	public void setDisplayName(String displayName) {
	    this.displayName = displayName;
	}
	
	

	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", "CD").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(CD cD, String _location, ConstraintValidatorModule cvm, List<net.ihe.gazelle.validation.Notification> diagnostic){
   		if (cD != null){
   			net.ihe.gazelle.hl7v3.datatypes.ANY.validateByModule(cD, _location, cvm, diagnostic);
			net.ihe.gazelle.hl7v3.datatypes.ED.validateByModule(cD.getOriginalText(), _location + "/originalText", cvm, diagnostic);
			{
				int i = 0;
				for (net.ihe.gazelle.hl7v3.datatypes.CR qualifier: cD.getQualifier()){
					net.ihe.gazelle.hl7v3.datatypes.CR.validateByModule(qualifier, _location + "/qualifier[" + i + "]", cvm, diagnostic);
					i++;
				}
			}
			
			{
				int i = 0;
				for (net.ihe.gazelle.hl7v3.datatypes.CD translation: cD.getTranslation()){
					net.ihe.gazelle.hl7v3.datatypes.CD.validateByModule(translation, _location + "/translation[" + i + "]", cvm, diagnostic);
					i++;
				}
			}
			
    	}
    }

}