package com.agilex.healthcare.schedulingmanager.datalayer;

import static org.junit.Assert.assertEquals;
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.schedulingmanager.datalayer.vista.util.AuthenticationUtil;
import com.agilex.healthcare.schedulingmanager.datalayer.vista.util.TestUtil;
import com.agilex.healthcare.schedulingmanager.domain.WaitListEntries;
import com.agilex.healthcare.schedulingmanager.domain.WaitListEntry;
import com.agilex.healthcare.schedulingmanager.mdws.connection.MdwsConfiguration;
import com.agilex.healthcare.utility.DateHelper;

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

	@Resource
	MdwsConfiguration mdwsSchedulingConfiguration;

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

	@Test
	public void getWaitListForFacilityEwl() {
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws(mdwsSchedulingConfiguration);
		WaitListEntries entries = dl.getWaitListForFacility("17", "ewl"); //taggedEwlByFacilityArrays
		assertNotNull(entries);
		assertEquals(3, entries.size());

		WaitListEntry one = entries.get(0);

		assertNull(one.getAccessionno());
		assertNull(one.getAppointmentLength());
		assertNull(one.getAppointmentRequestDate());
		assertNull(one.getCellPhone());
		assertEquals("", one.getClinicId());
		assertEquals("", one.getClinicName());
		assertNull(one.getComment());
		TestUtil.assertNullDataIdentifier(one.getDataIdentifier());
		Date dateLastUpdated = DateHelper.parseVistaDefaultDateTIme("20140716");
		assertEquals(dateLastUpdated, one.getDateLastUpdated());
		assertNull(one.getDateReminderSent());
		assertNull(one.getDateRemovedFromEwl());
		assertNotNull(one.getDaysOnList());
		Date dateDesired = DateHelper.parseVistaDefaultDateTIme("20140203");
		assertNotNull(one.getDesiredDate());
		assertEquals("224", one.getDfn());
		assertNull(one.getEligibilityCodeExternal());
		assertNull(one.getEligibilityCodeInternal());
		assertEquals("ESTABLISHED", one.getEnrolleeStatus());
		assertEquals("29", one.getEwlIen());
		assertNull(one.getFacilityId());
		assertNull(one.getFastNonFasting());
		assertNull(one.getHomePhone());
		assertNull(one.getId());
		assertNull(one.getLastName());
		assertNull(one.getMessage());
		Date dateOriginating = DateHelper.parseVistaDefaultDateTIme("20140716");
		assertEquals(dateOriginating, one.getOriginatingDate());
		TestUtil.assertNullPatientIdentifier(one.getPatientIdentifier());
		assertEquals("ELEVEN,PATIENT", one.getPatientName());
		assertEquals("99998", one.getPatientZip());
		assertEquals("ASAP", one.getPriority());
		assertNull(one.getProvider());
		assertNull(one.getRecallDate());
		assertNull(one.getRecallDate1());
		assertNull(one.getSecondPrintDate());
		assertNull(one.getSourceSystem());
		assertEquals("666-00-0011", one.getSsn());
		assertEquals("", one.getStopCode());
		TestUtil.assertNullPatientIdentifier(one.getSurrogateIdentifier());
		assertNull(one.getUser());
		assertEquals("EWL", one.getWaitListType());
	}

	@Test
	public void getWaitListForFacilityNear() {
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws(mdwsSchedulingConfiguration);
		WaitListEntries entries = dl.getWaitListForFacility("17", "near"); //taggedNearListByFacilityArrays
		assertNotNull(entries);
		assertEquals(16, entries.size());

		WaitListEntry one = entries.get(0);

		assertNull(one.getAccessionno());
		assertNull(one.getAppointmentLength());
		Date aptRequestDt = DateHelper.parseVistaDefaultDateTIme("20140301.134943");
		assertEquals(aptRequestDt, one.getAppointmentRequestDate());
		assertEquals("", one.getCellPhone());
		assertNull(one.getClinicId());
		assertNull(one.getClinicName());
		assertNull(one.getComment());
		TestUtil.assertNullDataIdentifier(one.getDataIdentifier());
		assertNull(one.getDateLastUpdated());
		assertNull(one.getDateReminderSent());
		assertNull(one.getDateRemovedFromEwl());
		assertNull(one.getDaysOnList());
		assertNull(one.getDesiredDate());
		assertEquals("3", one.getDfn());
		assertEquals("SC LESS THAN 50%", one.getEligibilityCodeExternal());
		assertEquals("15", one.getEligibilityCodeInternal());
		assertNull(one.getEnrolleeStatus());
		assertNull(one.getEwlIen());
		assertEquals("500", one.getFacilityId());
		assertNull(one.getFastNonFasting());
		assertEquals("222-555-8235", one.getHomePhone());
		assertNull(one.getId());
		assertNull(one.getLastName());
		assertNull(one.getMessage());
		assertNull(one.getOriginatingDate());
		TestUtil.assertNullPatientIdentifier(one.getPatientIdentifier());
		assertEquals("EIGHT,PATIENT", one.getPatientName());
		assertNull(one.getPatientZip());
		assertNull(one.getPriority());
		assertNull(one.getProvider());
		assertNull(one.getRecallDate());
		assertNull(one.getRecallDate1());
		assertNull(one.getSecondPrintDate());
		assertNull(one.getServiceConnected());
		assertNull(one.getSourceSystem());
		assertEquals("666000008", one.getSsn());
		assertNull(one.getStopCode());
		TestUtil.assertNullPatientIdentifier(one.getSurrogateIdentifier());
		assertNull(one.getUser());
		assertEquals("NEAR", one.getWaitListType());
	}

	@Test
	public void getWaitListForFacilityRecall() {
		SchedulingDataLayerMdws dl = new SchedulingDataLayerMdws(mdwsSchedulingConfiguration);
		WaitListEntries entries = dl.getWaitListForFacility("17", "recall"); //taggedRecallListByFacilityArrays
		assertNotNull(entries);
		assertEquals(3, entries.size());

		WaitListEntry one = entries.get(0);

		assertEquals("", one.getAccessionno());
		assertEquals("15", one.getAppointmentLength());
		assertNull(one.getAppointmentRequestDate());
		assertNull(one.getCellPhone());
		assertEquals("195", one.getClinicId());
		assertEquals("CARDIOLOGY", one.getClinicName());
		assertEquals("SOME MORE LONG COMMENTS", one.getComment());
		TestUtil.assertNullDataIdentifier(one.getDataIdentifier());
		assertNull(one.getDateLastUpdated());
		assertNull(one.getDateReminderSent());
		assertNull(one.getDateRemovedFromEwl());
		assertNull(one.getDaysOnList());
		assertNull(one.getDesiredDate());
		assertEquals("100099", one.getDfn());
		assertNull(one.getEligibilityCodeExternal());
		assertNull(one.getEligibilityCodeInternal());
		assertNull(one.getEnrolleeStatus());
		assertNull(one.getEwlIen());
		assertNull(one.getFacilityId());
		assertEquals("", one.getFastNonFasting());
		assertNull(one.getHomePhone());
		assertNull(one.getId());
		assertNull(one.getLastName());
		assertNull(one.getMessage());
		assertNull(one.getOriginatingDate());
		TestUtil.assertNullPatientIdentifier(one.getPatientIdentifier());
		assertEquals("BCMA,EIGHTYFOUR-PATIENT", one.getPatientName());
		assertNull(one.getPatientZip());
		assertNull(one.getPriority());
		assertEquals("991", one.getProvider());
		Date dateRecall = DateHelper.parseVistaDefaultDateTIme("20140210");
		assertEquals(dateRecall, one.getRecallDate());
		assertNull(one.getRecallDate1());
		assertNull(one.getSecondPrintDate());
		assertNull(one.getServiceConnected());
		assertNull(one.getSourceSystem());
		assertEquals("666-33-0084", one.getSsn());
		assertNull(one.getStopCode());
		TestUtil.assertNullPatientIdentifier(one.getSurrogateIdentifier());
		assertEquals("1", one.getUser());
		assertEquals("RECALL", one.getWaitListType());
	}
}
