package com.agilex.healthcare.schedulingmanager.datalayer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.util.Date;

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.mobilehealthplatform.domain.PatientIdentifier;
import com.agilex.healthcare.schedulingmanager.datalayer.vista.util.AuthenticationUtil;
import com.agilex.healthcare.schedulingmanager.domain.AppointmentSlotFilter;
import com.agilex.healthcare.schedulingmanager.domain.BookedAppointment;
import com.agilex.healthcare.schedulingmanager.domain.BookedAppointments;
import com.agilex.healthcare.schedulingmanager.mdws.connection.MdwsConfiguration;
import com.agilex.healthcare.utility.DateHelper;

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

	@Resource
	MdwsConfiguration mdwsSchedulingConfiguration;

	@BeforeClass
	public static void login() {
		AuthenticationUtil.loginUser("777", "clerk3434", "clerk4343$", "1");
	}
	@AfterClass
	public static void logoff() {
		AuthenticationUtil.logoffUser();
	}

	@Test
	public void getCancelReasonList() {
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws(mdwsSchedulingConfiguration);
		Date startDate = DateHelper.parseVistaDefaultDateTIme("19900101.0000");
		Date endDate = DateHelper.parseVistaDefaultDateTIme("20131230.5959");
		AppointmentSlotFilter filter = new AppointmentSlotFilter();
		filter.setClinicId("23");
        filter.setSiteCode("777");
        filter.setStartDate(startDate);
        filter.setEndDate(endDate);
        PatientIdentifier patId = new PatientIdentifier("dfn-777", "237");
		filter.setPatientIdentifier(patId);
		BookedAppointments appts = dl.getPatientBookedAppointments(filter);
		assertNotNull(appts);

		Date aptTime = DateHelper.parseVistaDefaultDateTIme("19971120.090000");
		BookedAppointment appt = appts.get(0);
		assertEquals("120", appt.getAppointmentLength());
		assertEquals(aptTime, appt.getAppointmentTime());
		assertEquals("", appt.getBookingNote());
		assertNotNull(appt.getClinic());
		assertFalse(appt.getClinic().isAskForCheckIn());
		assertNull(appt.getClinic().getDepartment());
		assertNull(appt.getClinic().getDssId());
		assertNull(appt.getClinic().getFacility());
		assertNull(appt.getClinic().getFacilityCode());
		assertEquals("207", appt.getClinic().getId());
		assertEquals("LINDA'S CLINIC", appt.getClinic().getName());
		assertNull(appt.getClinic().getService());
		assertNull(appt.getClinic().getSpecialty());
		assertNull(appt.getClinic().getStopCode());
		assertEquals("INPATIENT/FUTURE", appt.getCurrentStatus());
		assertNull(appt.getEkgDateTime());
		assertNull(appt.getLabDateTime());
		assertNull(appt.getPatientId());
		assertEquals("", appt.getPurpose());
		assertNull(appt.getStatus());
		assertEquals("REGULAR", appt.getType());
		assertNull(appt.getXrayDateTime());
	}
}