package com.agilex.healthcare.schedulingmanager.datalayer;

import static org.junit.Assert.* ;

import javax.annotation.Resource ;

import org.junit.AfterClass ;
import org.junit.BeforeClass ;
import org.junit.Test ;
import org.junit.runner.RunWith ;
import org.springframework.test.context.ContextConfiguration ;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner ;

import com.agilex.healthcare.schedulingmanager.datalayer.vista.util.AuthenticationUtil ;
import com.agilex.healthcare.schedulingmanager.domain.SchedulingClinic ;
import com.agilex.healthcare.schedulingmanager.domain.SchedulingClinics ;
import com.agilex.healthcare.schedulingmanager.domain.SchedulingSpecialties ;
import com.agilex.healthcare.schedulingmanager.domain.SchedulingSpecialty ;
import com.agilex.healthcare.schedulingmanager.mdws.connection.MdwsConfiguration ;

@ContextConfiguration( locations = { "classpath:integrationApplicationContext.xml" } )  
@RunWith( SpringJUnit4ClassRunner.class ) 
public class SchedulingDataLayerMdwsClinicSpecialtiesVistaTest {

	// Site members
	private static final String SITE_CODE = "777" ; 
	private static final String SITE_ACCESS_CODE = "cprs1234" ; 
	private static final String SITE_VERIFY_CODE = "cprs4321$" ; 
	
	// Clinic members
	private static final String CLINIC_NAME = "MEDICINE" ; 
	private static final String CLINIC_OBJECT_TYPE = "SchedulingSpecialty" ; 

	// Specialty Clinic members
	private static final String SPECIALTY_CLINIC_TYPE = "DERMATOLOGY" ; 
	private static final String SPECIALTY_CLINIC_ID = "62" ;  
	private static final String SPECIALTY_CLINIC_DEPT = null ; 
	private static final String SPECIALTY_CLINIC_DSSID = null ; 
	private static final String SPECIALTY_CLINIC_FACILITY = null ; 
	private static final boolean SPECIALTY_CLINIC_CHECKIN_PROMPT = Boolean.FALSE ;
	
	@Resource
	MdwsConfiguration mdwsSchedulingConfiguration ; 
	
	@BeforeClass
	public static void login( ) { 
		
		AuthenticationUtil.loginUser( SITE_CODE , SITE_ACCESS_CODE , SITE_VERIFY_CODE , "1" ) ; 
	}
	
	@AfterClass
	public static void logout( ) { 
		
		AuthenticationUtil.logoffUser( ) ;  
	}
	
	@Test
	public void getClinicsWithSpecialties( ) { 
	
		// ***** Scheduling Specialties *****
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws( mdwsSchedulingConfiguration ) ; 
		SchedulingSpecialties schedulingSpecialties = dl.getClinicsWithSpecialties( SITE_CODE ) ; 
		assertNotNull( "getClinicsWithSpecialities() returned null for site code " + SITE_CODE , schedulingSpecialties ) ; 
		
		// ***** Scheduling Specialty *****
		SchedulingSpecialty schedulingSpecialty = null ;
		schedulingSpecialtiesLoop : for( int i = 0 ; i < schedulingSpecialties.getSize( ) ; i++ ) { 
			
			if( schedulingSpecialties.get( i ).getName( ).equalsIgnoreCase( CLINIC_NAME ) ) { 
				
				schedulingSpecialty = schedulingSpecialties.get( i ) ;
				break schedulingSpecialtiesLoop ; 
			}; 
		}
		assertNotNull( "Clinic " + CLINIC_NAME + " was not found in site " + SITE_CODE , schedulingSpecialty ) ; 
		assertEquals( CLINIC_OBJECT_TYPE , schedulingSpecialty.getObjectType( )  ) ; 
		
		
		// ***** Specialty Clinic ******
		SchedulingClinic specialtyClinic = null ; 
		SchedulingClinics schedulingClinics = schedulingSpecialty.getSpecialtyClinics( ) ; 
		specialtyClinicsLoop : for( int i = 0 ; i < schedulingClinics.getSize( ) ; i++ ) { 
			
				if( schedulingClinics.get( i ).getName( ).equalsIgnoreCase( SPECIALTY_CLINIC_TYPE ) ) { 
					
					specialtyClinic =  schedulingClinics.get( i ) ; 
					break specialtyClinicsLoop ; 
				}
		}
		assertNotNull( SPECIALTY_CLINIC_TYPE + " was not found in clinic " + CLINIC_NAME  , specialtyClinic ) ; 
		assertEquals( SPECIALTY_CLINIC_CHECKIN_PROMPT , specialtyClinic.isAskForCheckIn( ) ) ; 
		assertEquals( SPECIALTY_CLINIC_ID , specialtyClinic.getId( ) ) ; 
		assertEquals( SITE_CODE , specialtyClinic.getFacilityCode( ) ) ; 
		assertEquals( SPECIALTY_CLINIC_TYPE  , specialtyClinic.getName( ) ) ; 
		assertEquals( SPECIALTY_CLINIC_DEPT , specialtyClinic.getDepartment( ) ) ; 
		assertEquals( SPECIALTY_CLINIC_DSSID , specialtyClinic.getDssId( ) ) ; 
		assertEquals( SPECIALTY_CLINIC_FACILITY , specialtyClinic.getFacility( ) ) ; 

	}
	


}

















