/*******************************************************************************
 *  Copyright 2017 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.hl7282.baselibs.segments;

import cdac.medinfo.sdk.hl7282.baselibs.CWE;
import cdac.medinfo.sdk.hl7282.baselibs.EI;
import cdac.medinfo.sdk.hl7282.baselibs.HD;
import cdac.medinfo.sdk.hl7282.baselibs.PL;
import cdac.medinfo.sdk.hl7282.commoninterface.IDataType;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.exceptions.FieldMissingException;
import cdac.medinfo.sdk.hl7282.exceptions.InvalidSegmentException;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;

/**
 * NPU - Bed Status Update Segment<p>
 * The NPU segment allows the updating of census (bed status) data without sending patient-specific data.  
 * <p>Represents an HL7 NPU message segment. 
 * This segment has the following fields:</p><p>
 * NPU-1: Bed Location (PL)<b>Required</b><br> 
 * NPU-2: Bed Status (CWE)<b>Optional</b><br><p>
 * This class provides mechanism to validate message against HL7 v 2.8.2 standard.
 * The class provides accessors & mutators for the elements mentioned above.
 * The class has validate method which validates Message against HL7 v 2.8.2 standard.
 *
 * <p>User can also create Segment through {@link SegmentFactory}
 */
 public class NPU extends Segment   
{

	

	/**
	 * Constructs the NPU segment.
	 */
	public NPU()
	{super(EnumSegments.HL7_SEG_NPU);
	}
	//Integer values used in getter/setter is unique item id defined 
	//for each attribute.

	/**
	 * Retrieves the Bed Location.
	 * This field contains the bed location that is a valid bed location.
	 * @return PL - bedLocation
	 */
	public PL getBedLocation() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(209);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (PL)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Retrieves the Bed Status.
	 * This field contains the bed status.   
	 * @return String - bedStatus
	 */
	public CWE getBedStatus() 
	{
		ISingleCollection<IDataType> objDataCollection =getDataType(170);
		if(objDataCollection != null && objDataCollection.size() != 0) 
			return (CWE)objDataCollection.elementAt(0);
		else
			return null;
	}

	/**
	 * Set the Bed Location.
	 * This field contains the bed location that is a valid bed location.
	 * @param strPointOfCare Used as PointOfCare
	 * @param strRoom Used as Room
	 * @param strBed Used as Bed
	 * @param objFacility Used as Facility
	 * @param strLocationStatus Used as LocationStatus
	 * @param strPersonLocationType Used as PersonLocationType
	 * @param strBuilding Used as Building
	 * @param strFloor Used as Floor
	 * @param strLocationDescription Used as LocationDescription
	 * @param objComprehensiveLocationIdentifier Used as ComprehensiveLocationIdentifier
	 * @param objAssigningAuthorityForLocation Used as AssigningAuthorityForLocation
	 */ 
	public void setBedLocation (HD objPointOfCare,HD objRoom,HD objBed,HD objFacility,
			String strLocationStatus,String strPersonLocationType,String strBuilding,String strFloor,
			String strLocationDescription,EI objComprehensiveLocationIdentifier,HD objAssigningAuthorityForLocation
	)
	{
		PL attestationDateTime  = (PL)getDataElement(209);
		attestationDateTime.setPointOfCare(objPointOfCare);
		attestationDateTime.setRoom(objRoom);
		attestationDateTime.setBed(objBed);
		attestationDateTime.setFacility(objFacility);
		attestationDateTime.setLocationStatus(strLocationStatus);
		attestationDateTime.setPersonLocationType(strPersonLocationType);
		attestationDateTime.setBuilding(strBuilding);
		attestationDateTime.setFloor(strFloor);
		attestationDateTime.setLocationDescription(strLocationDescription);
		attestationDateTime.setComprehensiveLocationIdentifier(objComprehensiveLocationIdentifier);
		attestationDateTime.setAssigningAuthorityForLocation(objAssigningAuthorityForLocation); 
		setBedLocation(attestationDateTime);
	} 

	/** Set the Bed Location.
	 * This field contains the bed location that is a valid bed location.
	 * @param objBedLocation object of Bed Location.
	 */ 
	public void setBedLocation(PL objBedLocation)
	{
		setDataType(209,objBedLocation);
	}	
	/**
	 * Set the Bed Status.
	 * This field contains the bed status.
	 * @param strIdentifier Specifies of characters (the code) that uniquely identifies the item being referenced. 
	 * @param strText Specifies The descriptive or textual name of the identifier, e.g., myocardial infarction. 
	 * @param strNameOfCodingSystem Identifies the coding scheme being used in the identifier component.
	 * @param strAlternateIdentifier Specifies an alternate sequence of characters (the code) that uniquely identifies the item being referenced.
	 * @param strAlternateText Specifies the descriptive or textual name of the alternate identifier. See usage note in section introduction.
	 * @param strNameOfAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component. 
	 * @param strCodingSystemVersionID A sequence of characters that uniquely identifies a second alternate code.
	 * @param strAlternateCodingSystemVersionId This component carries the version for the coding system identified by components 4-6.
	 * @param strOriginalText The text as seen and/or selected by the user who entered the data.
	 * @param strSecondAlternateIdentifier A sequence of characters that uniquely identifies a second alternate code.
	 * @param strSecondAlternateText The descriptive or textual name of the alternate identifier.
	 * @param strNameofSecondAlternateCodingSystem Identifies the coding scheme being used in the alternate identifier component.
	 * @param strSecondAlternateCodingSystemVersionID This component carries the version for the coding system identified by components 10-12.
	 * @param strCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.3.
	 * @param strValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.1 is obtained.
	 * @param strValueSetVersionID This component carries the version for the value set identified by CWE.15. The version is a date. The date is the date/time that the value set being used was published.
	 * @param strAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.6.
	 * @param strAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.4 is obtained.
	 * @param strAlternateValueSetVersionID This component carries the version for the value set identified by CWE.18. The version is a date.
	 * @param strSecondAlternateCodingSystemOID This component contains the ISO Object Identifier (OID) for the coding system or value set named in CWE.12.
	 * @param strSecondAlternateValueSetOID This component contains the ISO Object Identifier (OID) to allow identification of the value set from which the value in CWE.10 is obtained.
	 * @param strSecondAlternateValueSetVersionID This component carries the version for the value set identified by CWE.21. The version is a date.
	 */
	public void setBedStatus (String strIdentifier,String strText,String strNameOfCodingSystem,
			String strAlternateIdentifier,String strAlternateText,String strNameOfAlternateCodingSystem, String strCodingSystemVersionID, String 				strAlternateCodingSystemVersionId,
			String strOriginalText, String  strSecondAlternateIdentifier, String strSecondAlternateText, 
			String strNameofSecondAlternateCodingSystem, String strSecondAlternateCodingSystemVersionID, String strCodingSystemOID, String strValueSetOID,
			String strValueSetVersionID, String strAlternateCodingSystemOID, String strAlternateValueSetOID, String strAlternateValueSetVersionID,
			String  strSecondAlternateCodingSystemOID, String strSecondAlternateValueSetOID, String strSecondAlternateValueSetVersionID) 
	{
		CWE bedStatus  = (CWE)getDataElement(170);
		bedStatus.setIdentifier(strIdentifier);
		bedStatus.setText(strText);
		bedStatus.setNameOfCodingSystem(strNameOfCodingSystem);
		bedStatus.setAlternateIdentifier(strAlternateIdentifier);
		bedStatus.setAlternateText(strAlternateText);
		bedStatus.setNameOfAlternateCodingSystem(strNameOfAlternateCodingSystem); 
		bedStatus.setCodingSystemVersionID(strCodingSystemVersionID);
		bedStatus.setAlternateCodingSystemVersionId(strAlternateCodingSystemVersionId);
		bedStatus.setOriginalText(strOriginalText);
		bedStatus.setSecondAlternateIdentifier(strSecondAlternateIdentifier);
		bedStatus.setSecondAlternateText(strSecondAlternateText);
		bedStatus.setNameofSecondAlternateCodingSystem(strNameofSecondAlternateCodingSystem);
		bedStatus.setSecondAlternateCodingSystemVersionID(strSecondAlternateCodingSystemVersionID);
		bedStatus.setCodingSystemOID(strCodingSystemOID);
		bedStatus.setValueSetOID(strValueSetOID);
		bedStatus.setValueSetVersionID(strValueSetVersionID);
		bedStatus.setAlternateCodingSystemOID(strAlternateCodingSystemOID);
		bedStatus.setAlternateValueSetOID(strAlternateValueSetOID);
		bedStatus.setAlternateValueSetVersionID(strAlternateValueSetVersionID);
		bedStatus.setSecondAlternateCodingSystemOID(strSecondAlternateCodingSystemOID);
		bedStatus.setSecondAlternateValueSetOID(strSecondAlternateValueSetOID);
		bedStatus.setSecondAlternateValueSetVersionID(strSecondAlternateValueSetVersionID);
		setBedStatus(bedStatus);
	} 

	/** Set the Bed Status.
	 * This field contains the bed status.
	 * @param objbedStatus object of Bed Status.
	 */ 
	public void setBedStatus(CWE objbedStatus)
	{
		setDataType(170,objbedStatus);
	}	
	/**
	 * Validates HL7 Message objects .
	 * Validate method checks for validation each and every segments in side the Message object against specified message Structure. 
	 * Validation chcecks include optionality of segment or group.
	 * It also verifies the number of times segment or group is repeated in message.
	 * e.g 
	 * {PSH} while parsing PSH segment validate method will check for its mandatory presence.
	 * [PSH] in this case validate will throw exception if one tries to enter more than one PSH segment.
	 * @return boolean - true or false.
	 * @throws InvalidSegmentException Throws when Segment Validation fails
	 */
	public boolean validate()throws InvalidSegmentException
	{
		try
		{
			super.validate();
			return true;
		}
		catch(FieldMissingException ex)
		{
			throw new InvalidSegmentException(enumSegments.getValue(),ex);
		}
	}
}