/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.dicommodel.modules;



import cdac.medinfo.sdk.dcm30_04.baselibs.Tag;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.commoninterface.ITag;
import cdac.medinfo.sdk.dcm30_04.enums.EnumBodyPartExamined;

import cdac.medinfo.sdk.dcm30_04.enums.EnumViewPosition;
import cdac.medinfo.sdk.dcm30_04.exceptions.InvalidModuleException;
import cdac.medinfo.sdk.dcm30_04.exceptions.MandatoryMissingException;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConfig;
import cdac.medinfo.sdk.dcm30_04.utils.DicomConstants;
import cdac.medinfo.sdk.dcm30_04.utils.DicomLogger;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;
import cdac.medinfo.sdk.dcm30_04.utils.SingleCollection;

// TODO: Auto-generated Javadoc
/**
 \* This module specifies IOD Attributes that describe a computed radiography series performed on
 * the patient.
 * 
 * 
 */
public class CRSeriesModule extends Module  
{


	/**
	 * The obj single collection.
	 */
	public static ISingleCollection<ITag> objSingleCollection = null;


	/**
	 * Instantiates a new cR series module.
	 * 
	 * @param objIDataSet the obj i data set
	 */
	public CRSeriesModule(IDataSet objIDataSet)
	{
		super(objIDataSet);
	}
	static
	{
		objSingleCollection = new SingleCollection<ITag>();
		objSingleCollection.add(new Tag(0x0018,0x0015));
		objSingleCollection.add(new Tag(0x0018,0x5101));
		objSingleCollection.add(new Tag(0x0018,0x1160));
		objSingleCollection.add(new Tag(0x0018,0x1180));
		objSingleCollection.add(new Tag(0x0018,0x1190));
		objSingleCollection.add(new Tag(0x0018,0x1260));
		objSingleCollection.add(new Tag(0x0018,0x1261));
		objSingleCollection.add(new Tag(0x0018,0x1152));
	}

	/**
	 * This method validates each Attribute in the Module according to the Type
	 * of the Attribute.Attributes are of 5 types.
	 * Type 1,Type 2 are Mandatory:
	 * Mandatory Attributes have to present in the Module.
	 * Type 1C,2C are Conditional:
	 * Conditional Attributes' presence depend on a condition.
	 * If the condition is satisfied the Attribute has to be present.
	 * Type 3 are Optional
	 * Optional Attributes can be added as and when required.
	 * 
	 * @return boolean - returns validation status as success or failure
	 * 
	 * @throws InvalidModuleException - If validation of Module fails
	 */
	public  boolean validateModule() throws InvalidModuleException
	{

		try
		{			/*
		 * Validation Rules for Mandatory Elements
		 */
			if(!isPresent(0x0018,0x0015))
				throw new MandatoryMissingException("Missing Mandatory Element 0x0018,0x0015");
			if(!isPresent(0x0018,0x5101))
				throw new MandatoryMissingException("Missing Mandatory Element 0x0018,0x5101");
		}
		catch(MandatoryMissingException mme)
		{
			if(DicomConfig.createInstance().isLoggingOn())
				DicomLogger.getLogger().log(mme.getMessage());

			
				throw new InvalidModuleException(this.getClass().getSimpleName(),mme);

		}
		return true;
	}

	/**
	 * Sets the Body Part Examined in General Series Module.
	 * 
	 * @param enumBodyPartExamined the enum body part examined
	 */	
	public void setBodyPartExamined(EnumBodyPartExamined enumBodyPartExamined)
	{
		/*Accept the Body Part Examined value in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Dataset
		 */
		addDataElement(0x0018, 0x0015, DicomConstants.DCM_DT_CS, enumBodyPartExamined.getValue());
	}

	/**
	 * Sets radiographic view associated with Patient Position (0018,5100). Defined Terms:
	 * AP = Anterior/Posterior,PA = Posterior/Anterior,LL = Left Lateral,RL = Right Lateral
	 * ,RLD = Right Lateral Decubitus,LLD = Left Lateral Decubitus,RLO = Right Lateral Oblique,
	 * LLO = Left Lateral Oblique.
	 * 
	 * @param enumViewPosition the enum view position
	 */
	public void setViewPosition(EnumViewPosition enumViewPosition)
	{
		/*Accept the View Position value in String format of type CS.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Dataset
		 */
		addDataElement(0x0018, 0x5101, DicomConstants.DCM_DT_CS, enumViewPosition.getValue());
	}

	/**
	 * Sets Label for the type of filter inserted into the x-ray beam.
	 * 
	 * @param strFilterType - String value of Filter Type.
	 */
	public void setFilterType(String strFilterType)
	{
		/*Accept the Filter Type value in String format of type SH.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Dataset
		 */
		addDataElement(0x0018, 0x1160, DicomConstants.DCM_DT_SH, strFilterType);
	}

	/**
	 * Sets label describing any grid inserted.
	 * 
	 * @param strCollimatorOrGridName - String value of Collimator/grid Name.
	 */
	public void setCollimatorOrGridName(String strCollimatorOrGridName)
	{
		/*Accept the Collimator/grid Name in String format of type SH.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Dataset
		 */
		addDataElement(0x0018, 0x1180, DicomConstants.DCM_DT_SH, strCollimatorOrGridName);
	}

	/**
	 * Sets size of the focal spot in mm. For devices with variable focal spot or multiple focal
	 * spots, small dimension followed by large dimension.
	 * 
	 * @param arrStrFocalSpots - String array of Focal Spot(s) values.
	 */
	public void setFocalSpots(String[] arrStrFocalSpots)
	{
		/*Accept the Focal Spot(s) in String Array format of type DS.
		 * Read the Transfer Syntax and check to create ImplicitDE or ExplicitDE .
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Hash Map
		 */
		addDataElement(0x0018, 0x1190, DicomConstants.DCM_DT_DS, arrStrFocalSpots);
	}

	/**
	 * Sets label of the type of storage phosphor plates used in this series.
	 * 
	 * @param strPlateType - String value of Plate Type.
	 */
	public void setPlateType(String strPlateType)
	{
		/*Accept the Plate Type in String format of type SH.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Dataset
		 */
		addDataElement(0x0018, 0x1260, DicomConstants.DCM_DT_SH, strPlateType);
	}

	/**
	 * Sets Label of type of phosphor on the plates.
	 * 
	 * @param strPhosphorType - String value of Phosphor Type
	 */
	public void setPhosphorType(String strPhosphorType)
	{
		/* Accept the Phosphor Type in String format of type LO.
		 * Read the Transfer Syntax and check if ImplicitDE or ExplicitDE to create
		 * Set the iGroupNumber and iElementNumber to ImplicitDE object 
		 * Set the iVRType
		 * Set length from the element
		 * Add this element to the Dataset
		 */
		addDataElement(0x0018, 0x1261, DicomConstants.DCM_DT_LO, strPhosphorType);
	}

	/**
	 * Sets the Body Part Examined in General Series Module.
	 * 
	 * @return String - String value of Body Part Examined.
	 */
	public String getBodyPartExamined()
	{
		Object objValue = getValue(0x0018,0x0015);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Retrieves radiographic view associated with Patient Position (0018,5100).
	 * 
	 * @return String - String value of View Position.
	 */
	public String getViewPosition()
	{
		Object objValue = getValue(0x0018,0x5101);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Retrieves label for the type of filter inserted into the x-ray beam.
	 * 
	 * @return String - String value of Filter Type.
	 */
	public String getFilterType()
	{
		Object objValue = getValue(0x0018,0x1160);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Retrieves label describing any grid inserted.
	 * 
	 * @return String - String value of Collimator/grid Name.
	 */
	public String getCollimatorOrGridName()
	{
		Object objValue = getValue(0x0018,0x1180);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Retrieves size of the focal spot in mm.
	 * 
	 * @return String[] -  String array of Focal Spot(s) values.
	 */
	public String[] getFocalSpots()
	{
		Object objValue = getValue(0x0018,0x1190);
		if(objValue != null)
			return (String[])objValue;
		return null;
	}

	/**
	 * Retrieves label of the type of storage phosphor plates used in this series.
	 * 
	 * @return String - String value of Plate Type.
	 */
	public String getPlateType()
	{
		Object objValue = getValue(0x0018,0x1260);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Retrieves label of type of phosphor on the plates.
	 * 
	 * @return String - String value of Phosphor Type.
	 */
	public String getPhosphorType()
	{
		Object objValue = getValue(0x0018,0x1261);
		if(objValue != null)
			return objValue.toString();
		return null;
	}

	/**
	 * Returns the collection of keys representing the DataElements that belong to this module.
	 * 
	 * @return Collection of Tags - returns the collection of tags
	 */
	public ISingleCollection<ITag> getVectorOfKeys()
	{
		return objSingleCollection;
	}
}
