/*******************************************************************************
 *  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.NTE;
import cdac.medinfo.sdk.hl7282.baselibs.segments.PRT;
import cdac.medinfo.sdk.hl7282.baselibs.segments.PV1;
import cdac.medinfo.sdk.hl7282.baselibs.segments.PV2;
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.EnumMessageCode;
import cdac.medinfo.sdk.hl7282.utils.EnumMessageStructure;
import cdac.medinfo.sdk.hl7282.utils.EnumSegments;
import cdac.medinfo.sdk.hl7282.utils.EnumTriggerEvent;
import cdac.medinfo.sdk.hl7282.utils.IMap;

/**
 *  OPU_R25 – Unsolicited Population/Location-Based Laboratory Observation Message (Event R25 ).
 *  This message supports unsolicited population or location-based surveillance reporting to a central repository
 *  where the accession / visit may contain references to multiple patients, multiple specimens, 
 *  non-patient specimens, and multiple orders per specimen.   
 *  <p>Represents a OPU_R25 message structure (see chapter 7.3.11). 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: NTE ( Notes And Comments) <b> SINGLE OPTIONAL </b> <br>
 *  4: PV1 (Patient Visit Segment) <b>SINGLE_COMPULSARY</b><br>
 *  5: PV2 (Patient Visit - Additional Information Segment) <b>SINGLE_OPTIONAL</b><br>
 *  6: PRT (Participation- for patient) <b>MULTIPLE_OPTIONAL</b><br>
 *  7: PATIENT VISIT OBSERVATION (a Group of segments in OPU_R25 message) <b>MULTIPLE_OPTIONAL</b><br>
 *  8. ACCESSION DETAILS (a Group of segments in OPU_R25 message) <b>SINGLE_OPTIONAL</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 final class OPU_R25 extends Message{
	
	/**
	 * Constructs the OPU_R25 message.
	 */
	OPU_R25(IMap objMessageMap)
	{
		super(objMessageMap, EnumMessageCode.OPU.getValue(), EnumTriggerEvent.R25.getValue(), EnumMessageStructure.OPU_R25.getValue());
	}

	/**
	 * Adds Software Segment(SFT) to this message.
	 * @param objSFT Specified Software Segment(SFT)to be added in 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 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;
	}
	
	/**
	 * 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 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);
	}
	
	/**
	 * Retrieves Patient Visit(PV1) segment present in this message
	 * @return PV1 - Specified PV1 Segment
	 */
	public PV1 getPatientVisitSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_PV1);
		if(objSingleCollection != null)
			return (PV1)objSingleCollection.elementAt(0);
		return null;
	}

	/**
	 * Sets value of Patient Visit segment for this message,overwrites if already present.
	 * @param objPV1 Specified PV1 Segment
	 */
	public void setPatientVisitSegment(PV1 objPV1)
	{
		setSegment(EnumSegments.HL7_SEG_PV1,objPV1);
	}

	/**
	 * Retrieves Patient Visit Additional Info(PV2) segment present in this message.
	 * @return PV2 - Specified Patient Visit Additional Info(PV2) Segment
	 */
	public PV2 getPatientVisitAdditionalInfoSegment()
	{
		ISingleCollection<ISegment> objSingleCollection = getSegment(EnumSegments.HL7_SEG_PV2);
		if(objSingleCollection != null)
			return (PV2)objSingleCollection.elementAt(0);
		return null;
	}
	/**
	 * Sets value of Patient Visit Additional Info(PV2) segment for this message,overwrites if already present.
	 * @param objPV2 Specified PV2 Segment
	 */
	public void setPatientVisitAdditionalInfoSegment(PV2 objPV2)
	{
		setSegment(EnumSegments.HL7_SEG_PV2,objPV2);
	}
	
	/**
	 * Adds Participation(PRT) to this message.
	 * @param objPRT Specified Participation Segment to be added in message.
	 */
	public void addParticipationForPatientSegment(PRT objPRT)
	{
		addSegment(EnumSegments.HL7_SEG_PRT, objPRT);
	}

	/**
	 * Adds collection of Participation(PRT) 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, (ISingleCollection<ISegment>)objSegmentCollection);
	}

	/**
	 * Retrieves Collection of Participation(PRT) 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);
		return (ISingleCollection<PRT>)objSegmentCollection;
	}

	//===================
	/**
	 * Retrieves Collection of Patient Visit Observation GROUP present in this message.
	 * @return ISingleCollection<Group> - Collection of Patient Visit Observation Group present 
	 */
	public ISingleCollection<IGroup> getPatientVisitObservationGroups()
	{
		return getGroup(EnumSegments.HL7_GROUP_PATIENT_VISIT_OBSERVATION);
	}

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

	/**
	 * Adds Patient Visit Observation GROUP to this message.
	 * @param objGroup Specified Patient Visit Observation GROUP. 
	 */
	public void addPatientVisitObservationGroup(IGroup objGroup)
	{
		addGroup(EnumSegments.HL7_GROUP_PATIENT_VISIT_OBSERVATION, objGroup);
	}
	//=====================
	/**
	 * Retrieves Collection of ACCESSION DETAIL GROUP present in this message.
	 * @return ISingleCollection<Group> - Collection of ACCESSION DETAIL Group present 
	 */
	public ISingleCollection<IGroup> getAccessionDetailsGroups()
	{
		return getGroup(EnumSegments.HL7_GROUP_ACCESSION_DETAIL);
	}

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

	/**
	 * Adds ACCESSION DETAILS GROUP to this message.
	 * @param objGroup Specified ACCESSION DETAILS GROUP. 
	 */
	public void addAccessionDetailsGroup(IGroup objGroup)
	{
		addGroup(EnumSegments.HL7_GROUP_ACCESSION_DETAIL, objGroup);
	}
}
