/*******************************************************************************
 *  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.hl7model.messages.observationreporting;

import cdac.medinfo.sdk.hl7282.baselibs.messages.Message;
import cdac.medinfo.sdk.hl7282.baselibs.segments.ARV;
import cdac.medinfo.sdk.hl7282.baselibs.segments.NTE;
import cdac.medinfo.sdk.hl7282.baselibs.segments.OBR;
import cdac.medinfo.sdk.hl7282.baselibs.segments.ORC;
import cdac.medinfo.sdk.hl7282.baselibs.segments.PD1;
import cdac.medinfo.sdk.hl7282.baselibs.segments.PID;
import cdac.medinfo.sdk.hl7282.baselibs.segments.PRT;
import cdac.medinfo.sdk.hl7282.baselibs.segments.SFT;
import cdac.medinfo.sdk.hl7282.baselibs.segments.UAC;
import cdac.medinfo.sdk.hl7282.commoninterface.IGroup;
import cdac.medinfo.sdk.hl7282.commoninterface.ISegment;
import cdac.medinfo.sdk.hl7282.commoninterface.ISingleCollection;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.IMap;

/**
 * ORU_R30 - Unsolicited Point-Of-Care Observation Message Without Existing Order - Place An Order (Event R30). 
 * This message is used to fire instructs for the receiving system to create a new
 * order for the observation(s) contained in the message.
 * <p>Represents a ORU_R30 message structure (see chapter 7.3.4). This structure contains the 
 * following elements: </p>
 * 0: MSH (Message Header Segment) <b>SINGLE_COMPULSARY</b><br>
 * 1: SFT (Software Segment) <b>MULTIPLE_OPTIONAL</b><br>
 * 2: UAC (User Authentication Credential) <b>SINGLE OPTIONAL</b><br/>
 * 3: PID (Patient Identification Segment) <b>SINGLE_COMPULSARY</b><br>
 * 4: PD1 (Patient Additional Demographic Segment) <b>SINGLE_OPTIONAL</b><br>
 * 5. PRT (Participation-for patient) <b>MULTIPLE_OPTIONAL</b><br/> 
 * 6. ARV (Access Restrictions) <b>MULTIPLE_OPTIONAL</b><br/> 
 * 7: PATIENT OBSERVATION (a Group in ORU_R30 message) <b>MULTIPLE_OPTIONAL</b><br>
 * 8: VISIT (a Group of segments in ORU_R30 message) <b>SINGLE_OPTIONAL</b><br>
 * 9: ORC (Common Order Segment) <b>SINGLE_COMPULSARY</b><br>
 * 10. PRT (Participation-for common order) <b>MULTIPLE_OPTIONAL</b><br/> 
 * 11: OBR (Observation Request Segment) <b>SINGLE_COMPULSARY</b><br>
 * 12: NTE (Notes and Comments Segment) <b>MULTIPLE_OPTIONAL</b><br>
 * 13. PRT (Participation-for observation) <b>MULTIPLE_OPTIONAL</b><br/> 
 * 14: TIMING_QTY (a Group of segments in ORU_R30 message) <b>MULTIPLE_OPTIONAL</b><br>
 * 15: OBSERVATION (a Group of segments in ORU_R30 message) <b>MULTIPLE_COMPULSARY</b><br>
 * This class provides mechanism to validate message against HL7 v 2.8.2 standard.
 * The class provides accessors & mutators for the elements mentioned above.
 * These elements can be easily populated & populated values can be easily retrieved.
 * The class has validate method which validates Message against HL7 v 2.8.2 standard.
 */
public abstract class ORU_R30_Common extends Message
{
	/**
	 * Constructs the ORU_R30 segment.
	 */
	ORU_R30_Common(IMap objMessageMap, String strTriggerEvent, String strMessageCode, String strMessageStructure)
	{
		super(objMessageMap, strTriggerEvent, strMessageCode, strMessageStructure);
	}

	/**
	 * Retrieves Collection of Software Segments(SFT) present in this message.
	 * @return ISingleCollection<SFT> - Collection of Software Segments(SFT) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<SFT> getSoftwareSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_SFT);
		return (ISingleCollection<SFT>)objSegmentCollection;
	}

	/**
	 * Adds Software Segment(SFT) to this message.
	 * @param objSFT Specified Software Segment(SFT) to be added in this messageto this message.
	 */
	public void addSoftwareSegment(SFT objSFT)
	{
		addSegment(EnumSegments.HL7_SEG_SFT, objSFT);
	}

	/**
	 * Adds collection of Software Segment(SFT) to this message.
	 * @param objSFTSegmentCollection Collection of Software Segments to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addSoftwareSegment(ISingleCollection<SFT>  objSFTSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objSFTSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_SFT, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves User Authentication Credential(UAC) segment present in this message
	 * @return UAC - Specified UAC Segment
	 */
	public UAC getUserAuthenticationCredentialSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_UAC);
		if(objSingleCollection != null)
			return (UAC)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of User Authentication Credential segment for this message,overwrites if already present.
	 * @param objUAC Specified UAC Segment
	 */
	public void setUserAuthenticationCredentialSegment(UAC objUAC)
	{
		setSegment(EnumSegments.HL7_SEG_UAC,objUAC);
	}

	/**
	 * Retrieves Patient Identification(PID) segment present in this message.
	 * @return PID - the Patient Identification Segment present in this message or null if unavailable.
	 */
	public PID getPatientIdentificationSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_PID);
		if(objSingleCollection != null)
			return (PID)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of PID segment for this message,overwrites if already present.
	 * @param objPID Specified PID Segment 
	 */
	public void setPatientIdentificationSegment(PID objPID)
	{
		setSegment(EnumSegments.HL7_SEG_PID,objPID);
	}

	/**
	 * Retrieves Additinal Demographics segment(PD1) present in this message.
	 * @return PD1 - the Additinal Demographics(PD1) Segment. present in this message or null if unavailable.
	 */
	public PD1 getAdditinalDemographicsSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_PD1);
		if(objSingleCollection != null)
			return (PD1)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of Additinal Demographics segment(PD1) for this message,overwrites if already present.
	 * @param objPD1 Specified Additinal Demographics(PD1) Segment. 
	 */
	public void setAdditinalDemographicsSegment(PD1 objPD1)
	{
		setSegment(EnumSegments.HL7_SEG_PD1,objPD1);
	}

	/**
	 * Adds Participation(PRT) for Patient Identification Segment to this message.
	 * @param objPRT Specified Participation Segment to be added in message.
	 */
	public void addParticipationForPatientSegment(PRT objPRT)
	{
		addSegment(EnumSegments.HL7_SEG_PRT_PATIENT_IDENTIFICATION, objPRT);
	}

	/**
	 * Adds collection of Participation(PRT) for Patient Identification Segment to this message.
	 * @param objPRTSegmentCollection Collection of Participation(PRT) to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addParticipationForPatientSegment(ISingleCollection<PRT>  objPRTSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objPRTSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_PRT_PATIENT_IDENTIFICATION, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves Collection of Participation(PRT) for Patient Identification Segment present in this message.
	 * @return ISingleCollection<PRT> - Collection of Participation(PRT) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<PRT> getParticipationForPatientSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_PRT_PATIENT_IDENTIFICATION);
		return (ISingleCollection<PRT>)objSegmentCollection;
	}

	/**
	 * Adds Access Restrictions(ARV) to this message.
	 * @param objARV Specified Access Restrictions Segment to be added in message.
	 */
	public void addPatientIdentificationAccessRestrictionsSegment(ARV objARV)
	{
		addSegment(EnumSegments.HL7_SEG_ARV, objARV);
	}

	/**
	 * Adds collection of Access Restrictions(ARV) to this message.
	 * @param objARVSegmentCollection Collection of Access Restrictions(ARV) to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addPatientIdentificationAccessRestrictionsSegment(ISingleCollection<ARV>  objARVSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objARVSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_ARV, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves Collection of Access Restrictions(ARV) present in this message.
	 * @return ISingleCollection<ARV> - Collection of Access Restrictions(ARV) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<ARV> getPatientIdentificationAccessRestrictionsSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_ARV);
		return (ISingleCollection<ARV>)objSegmentCollection;
	}

	/**
	 * Retrieves Collection of Person Observation GROUP present in this message.
	 * @return ISingleCollection<Group> - Collection of Person Observation Group present 
	 */
	public ISingleCollection<IGroup> getPatientObservationGroups()
	{
		return getGroup(EnumSegments.HL7_GROUP_PATIENT_OBSERVATION);
	}

	/**
	 * Adds Collection of Person Observation GROUP to this message.
	 * @param objSingleCollection Specified  Person Observation GROUP Collection.
	 */
	public void addPatientObservationGroups(ISingleCollection<IGroup> objSingleCollection)
	{
		addGroup(EnumSegments.HL7_GROUP_PATIENT_OBSERVATION, objSingleCollection);
	}

	/**
	 * Adds Person Observation GROUP to this message.
	 * @param objGroup Specified Person Observation GROUP. 
	 */
	public void addPatientObservationGroup(IGroup objGroup)
	{
		addGroup(EnumSegments.HL7_GROUP_PATIENT_OBSERVATION, objGroup);
	}
	/**
	 * Retrieves  Visit Group present in this message.
	 * @return Group - Visit Group present in this message.
	 */
	public IGroup getVisitGroup()
	{
		ISingleCollection<IGroup> objGroupCollection = getGroup(EnumSegments.HL7_GROUP_VISIT);
		if(objGroupCollection != null)
			return objGroupCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of Visit Group for this message,overwrites if already present.
	 * @param objGroup Specified Visit Group 
	 */
	public void setVisitGroup(IGroup objGroup)
	{
		setGroup(EnumSegments.HL7_GROUP_VISIT,objGroup);
	}

	/**
	 * Retrieves Common Order information(ORC) segment present in this message.
	 * @return ORC - the Common Order information Segment present in this message or null if unavailable.
	 */
	public ORC getCommonOrderinformationSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_ORC);
		if(objSingleCollection != null)
			return (ORC)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of Common Order information segment for this message,overwrites if already present.
	 * @param objORC Specified Common Order information Segment 
	 */
	public void setCommonOrderinformationSegment(ORC objORC)
	{
		setSegment(EnumSegments.HL7_SEG_ORC,objORC);
	}

	/**
	 * Adds Participation(PRT) for Common Order Segment to this message.
	 * @param objPRT Specified Participation Segment to be added in message.
	 */
	public void addParticipationForCommonOrderSegment(PRT objPRT)
	{
		addSegment(EnumSegments.HL7_SEG_PRT_ORDER, objPRT);
	}

	/**
	 * Adds collection of Participation(PRT) for Common Order Segment to this message.
	 * @param objPRTSegmentCollection Collection of Participation(PRT) to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addParticipationForCommonOrderSegment(ISingleCollection<PRT>  objPRTSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objPRTSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_PRT_ORDER, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves Collection of Participation(PRT) for Common Order Segment present in this message.
	 * @return ISingleCollection<PRT> - Collection of Participation(PRT) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<PRT> getParticipationForCommonOrderSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_PRT_ORDER);
		return (ISingleCollection<PRT>)objSegmentCollection;
	}

	/**
	 * Retrieves Observation Request(OBR) segment present in this message.
	 * @return OBR - the Observation Request Segment present in this message or null if unavailable.
	 */
	public OBR getObservationRequestSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_OBR);
		if(objSingleCollection != null)
			return (OBR)objSingleCollection.elementAt(0);
		return null;
	}
	/**
	 * Sets value of Observation Request segment for this message,overwrites if already present.
	 * @param objOBR Specified Observation Request Segment 
	 */
	public void setObservationRequestSegment(OBR objOBR)
	{
		setSegment(EnumSegments.HL7_SEG_OBR,objOBR);
	}	

	/**
	 * Retrieves Collection of Notes and Comments  Segments(NTE) present in this message.
	 * @return ISingleCollection<NTE> - Collection of Notes and Comments  Segments(NTE) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<NTE> getNotesAndCommentsSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_NTE);
		return (ISingleCollection<NTE>)objSegmentCollection;
	}

	/**
	 * Adds Notes and Comments  Segment(NTE) to this message.
	 * @param objNTE Specified Notes and Comments  Segment(NTE)to add in this message.
	 */
	public void addNotesAndCommentsSegment(NTE objNTE)
	{
		addSegment(EnumSegments.HL7_SEG_NTE, objNTE);
	}

	/**
	 * Adds collection of Notes and Comments  Segment(NTE) to this message.
	 * @param objNTESegmentCollection Collection of Notes and Comments  Segments to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addNotesAndCommentsSegment(ISingleCollection<NTE>  objNTESegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objNTESegmentCollection;
		addSegment(EnumSegments.HL7_SEG_NTE, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Adds Participation(PRT) for Observation Segment to this message.
	 * @param objPRT Specified Participation Segment to be added in message.
	 */
	public void addParticipationForObservationtSegment(PRT objPRT)
	{
		addSegment(EnumSegments.HL7_SEG_PRT_OBSERVATION, objPRT);
	}

	/**
	 * Adds collection of Participation(PRT) for Observation Segment to this message.
	 * @param objPRTSegmentCollection Collection of Participation(PRT) to add in this message
	 */
	@SuppressWarnings("unchecked")
	public void addParticipationForObservationSegment(ISingleCollection<PRT>  objPRTSegmentCollection)
	{
		ISingleCollection<?> objSegmentCollection =  objPRTSegmentCollection;
		addSegment(EnumSegments.HL7_SEG_PRT_OBSERVATION, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves Collection of Participation(PRT) for Observation Segment present in this message.
	 * @return ISingleCollection<PRT> - Collection of Participation(PRT) present in this message.
	 */
	@SuppressWarnings("unchecked")
	public ISingleCollection<PRT> getParticipationForObservationSegments()
	{
		ISingleCollection<?> objSegmentCollection = getSegment(EnumSegments.HL7_SEG_PRT_OBSERVATION);
		return (ISingleCollection<PRT>)objSegmentCollection;
	}

	/**
	 * Retrieves Collection of Timing_Quantity GROUP present in this message.
	 * @return ISingleCollection<Group> - Collection of Timing_Quantity Group present 
	 */
	public ISingleCollection<IGroup> getTimingQuantityGroups()
	{
		return getGroup(EnumSegments.HL7_GROUP_TIMING_QUANTITY);
	}

	/**
	 * Adds Collection of Timing_Quantity GROUP to this message.
	 * @param objSingleCollection Specified  Timing_Quantity GROUP Collection.
	 */
	public void addTimingQuantityGroups(ISingleCollection<IGroup> objSingleCollection)
	{
		addGroup(EnumSegments.HL7_GROUP_TIMING_QUANTITY, objSingleCollection);
	}

	/**
	 * Adds TimingQuantity GROUP to this message.
	 * @param objGroup Specified TimingQuantity GROUP. 
	 */
	public void addTimingQuantityGroup(IGroup objGroup)
	{
		addGroup(EnumSegments.HL7_GROUP_TIMING_QUANTITY, objGroup);
	}	

	/**
	 * Retrieves Collection of OBSERVATION GROUP present in this message.
	 * @return ISingleCollection<Group> - Collection of OBSERVATION Group present 
	 */
	public ISingleCollection<IGroup> getObservationGroups()
	{
		return getGroup(EnumSegments.HL7_GROUP_OBSERVATION);
	}

	/**
	 * Adds Collection of OBSERVATION GROUP to this message.
	 * @param objSingleCollection Specified  OBSERVATION GROUP Collection.
	 */
	public void addObservationGroups(ISingleCollection<IGroup> objSingleCollection)
	{
		addGroup(EnumSegments.HL7_GROUP_OBSERVATION, objSingleCollection);
	}

	/**
	 * Adds Observation GROUP to this message.
	 * @param objGroup Specified Observation GROUP. 
	 */
	public void addObservationGroup(IGroup objGroup)
	{
		addGroup(EnumSegments.HL7_GROUP_OBSERVATION, objGroup);
	}
}
