package com.agilex.healthcare.schedulingmanager.mdws.translator;

import static org.junit.Assert.* ;

import org.junit.BeforeClass ;
import org.junit.Test ;

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.generatedwsdl.schedulingservice.ArrayOfHospitalLocationTO ;
import com.agilex.healthcare.schedulingmanager.mdws.generatedwsdl.schedulingservice.HospitalLocationTO ;
import com.agilex.healthcare.schedulingmanager.mdws.generatedwsdl.schedulingservice.TaggedHospitalLocationArray ;
import com.agilex.healthcare.schedulingmanager.mdws.generatedwsdl.schedulingservice.TaggedText ;
import com.agilex.healthcare.schedulingmanager.mdws.generatedwsdl.schedulingservice.TimeSlotArray ;

public class SpecialtyWithClinicTranslatorTest {
	
	private static final String SITE_CODE = "777" ; 
	
	// Clinic members
	private static final String CLINIC_NAME = "MEDICINE" ; 
	private static final String CLINIC_OBJECT_TYPE = "SchedulingSpecialty" ; 
	private static TaggedHospitalLocationArray taggedHospitalLocationArray ; 
	
	// 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 ;
	
	@BeforeClass
	public static void setupTaggedHospitalLocationArray( ) { 

		HospitalLocationTO audiologyHospitalTO = createHosptialLocationTO( "64" , "AUDIOLOGY" , "M" , "MEDICINE" ) ;
		HospitalLocationTO cardiologyHospitalTO = createHosptialLocationTO( "195" , "CARDIOLOGY" , "M" , "MEDICINE" ) ;
		HospitalLocationTO dermatologyHospitalTO = createHosptialLocationTO( "62" , "DERMATOLOGY" , "M" , "MEDICINE" ) ;
		
		ArrayOfHospitalLocationTO arrayOfHospitalLocationTo = new ArrayOfHospitalLocationTO( ) ; 
		arrayOfHospitalLocationTo.getHospitalLocationTO( ).add( audiologyHospitalTO ) ; 
		arrayOfHospitalLocationTo.getHospitalLocationTO( ).add( cardiologyHospitalTO ) ; 
		arrayOfHospitalLocationTo.getHospitalLocationTO( ).add( dermatologyHospitalTO ) ; 
			
		taggedHospitalLocationArray = new TaggedHospitalLocationArray( ) ; 
		taggedHospitalLocationArray.setLocations( arrayOfHospitalLocationTo ) ;
	}

	@Test
	public void testTranslate( ) {

		SpecialtyWithClinicTranslator specWithClinicTrans = new SpecialtyWithClinicTranslator( ) ; 
		SchedulingSpecialties schedulingSpecialties = specWithClinicTrans.translate( taggedHospitalLocationArray , SITE_CODE ) ; 
		assertNotNull( "schedulingSpecialties is null for site code " + SITE_CODE , schedulingSpecialties ) ; 
		assertTrue( "No scheduling specialities found." , schedulingSpecialties.getSize( ) > 0 ) ;
		
		// ***** Test 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( )  ) ; 
		
		// ***** Test 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( ) ) ; 
	}
	
	
	private static HospitalLocationTO createHosptialLocationTO( String ID , String name , String serviceTag , String serviceText ) { 
		
		HospitalLocationTO hospitalLocationTo = new HospitalLocationTO( ) ; 
		
		hospitalLocationTo.setAbbreviation( null );
		hospitalLocationTo.setAppointmentLength( null );
		hospitalLocationTo.setAppointmentTimestamp( null );
		hospitalLocationTo.setAskForCheckIn( false );
		
		TimeSlotArray availabilityTimeSlotArray = new TimeSlotArray( ) ;  
		hospitalLocationTo.setAvailability( availabilityTimeSlotArray );
		
		hospitalLocationTo.setBed( null ); 
		hospitalLocationTo.setBuilding( null );
		hospitalLocationTo.setClinicDisplayStartTime( null ); 
		
		TaggedText creditStopCodeTaggedText = new TaggedText( ) ; 
		hospitalLocationTo.setCreditStopCode( creditStopCodeTaggedText ); 
		
		TaggedText departmentTaggedText = new TaggedText( ) ; 
		hospitalLocationTo.setDepartment( departmentTaggedText ); 
		hospitalLocationTo.setDisplayIncrements( null ); 
		hospitalLocationTo.setFacility( null );
		hospitalLocationTo.setFault( null ) ; 
		hospitalLocationTo.setFloor( null ) ;  
		hospitalLocationTo.setId( ID ) ;
		hospitalLocationTo.setMaxOverbooksPerDay( null ) ;  
		hospitalLocationTo.setName( name ) ; 
		hospitalLocationTo.setPhone( null ) ; 
		hospitalLocationTo.setPhysicalLocation( null ) ;  
		hospitalLocationTo.setProhibitAccessToClinic( null ) ;  
		hospitalLocationTo.setRoom( null ) ;  

		TaggedText serviceTaggedText = new TaggedText( ) ; 
		serviceTaggedText.setTag( serviceTag ) ; 
		serviceTaggedText.setText( serviceText ) ; 
		hospitalLocationTo.setService( serviceTaggedText ) ; 
		
		TaggedText specialtyTaggedText = new TaggedText( ) ; 
		specialtyTaggedText.setText( serviceText ) ; 
		hospitalLocationTo.setSpecialty( specialtyTaggedText ) ;  
		hospitalLocationTo.setStatus( null ) ; 
		
		TaggedText stopCodeTaggedText = new TaggedText( ) ; 
		hospitalLocationTo.setStopCode( stopCodeTaggedText ) ; 
		hospitalLocationTo.setType( null ) ; 
		hospitalLocationTo.setVisitLocation( null ) ; 
		
		return( hospitalLocationTo ) ; 
	}

}
