//#############################################################################
//#                                                                           #
//#  Copyright (C) <2015>  <IMS MAXIMS>                                       #
//#                                                                           #
//#  This program is free software: you can redistribute it and/or modify     #
//#  it under the terms of the GNU Affero General Public License as           #
//#  published by the Free Software Foundation, either version 3 of the       #
//#  License, or (at your option) any later version.                          # 
//#                                                                           #
//#  This program is distributed in the hope that it will be useful,          #
//#  but WITHOUT ANY WARRANTY; without even the implied warranty of           #
//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
//#  GNU Affero General Public License for more details.                      #
//#                                                                           #
//#  You should have received a copy of the GNU Affero General Public License #
//#  along with this program.  If not, see <http://www.gnu.org/licenses/>.    #
//#                                                                           #
//#  IMS MAXIMS provides absolutely NO GUARANTEE OF THE CLINICAL SAFTEY of    #
//#  this program.  Users of this software do so entirely at their own risk.  #
//#  IMS MAXIMS only ensures the Clinical Safety of unaltered run-time        #
//#  software that it builds, deploys and maintains.                          #
//#                                                                           #
//#############################################################################
//#EOH
// This code was generated by Cristian Belciug using IMS Development Environment (version 1.80 build 5007.25751)
// Copyright (C) 1995-2013 IMS MAXIMS. All rights reserved.

package ims.clinical.domain.impl;

import java.util.Iterator;
import java.util.Set;

import ims.admin.domain.ElectronicPrescribingConfigForm;
import ims.admin.domain.impl.ElectronicPrescribingConfigFormImpl;
import ims.clinical.domain.base.impl.BaseElectronicPrescribingInPatientFormImpl;
import ims.core.vo.lookups.TaxonomyType;
import ims.domain.DomainFactory;
import ims.domain.lookups.LookupMapping;
import ims.vo.LookupMappingVo;
import ims.vo.LookupMappingVoCollection;

public class ElectronicPrescribingInPatientFormImpl extends BaseElectronicPrescribingInPatientFormImpl
{
	private static final long serialVersionUID = 1L;

	public ims.admin.vo.ElectronicPrescribingConfigVoCollection listElectronicPrescribing()
	{
		ElectronicPrescribingConfigForm impl = (ElectronicPrescribingConfigForm)getDomainImpl(ElectronicPrescribingConfigFormImpl.class);
		return impl.listElectronicPrescribing();
	}
	
	public String getPHARMACYExternalMappingValue(Integer specialtyID)
	{		
		if (specialtyID == null)
			return "";
		
		DomainFactory factory = getDomainFactory();
		
		ims.domain.lookups.LookupInstance doInst = factory.getLookupInstance(specialtyID);
		
		Set mappings = doInst.getMappings();
		
		LookupMappingVoCollection mapColl = new LookupMappingVoCollection();
		
		Iterator iter = mappings.iterator();
		LookupMapping doMapping;
		while (iter.hasNext())
		{
			doMapping = (LookupMapping) iter.next();
			mapColl.add(new LookupMappingVo(doMapping.getExtSystem(), doMapping.getExtCode()));
		}
		
		if (mapColl != null && mapColl.size() > 0)
		{
			for (int i = 0; i < mapColl.size(); i++)
				if (TaxonomyType.PHARMACY.getIItemText().equals(mapColl.get(i).getExtSystem()))
					return mapColl.get(i).getExtCode();
		}
		
		return "";
	}
}
