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 static org.junit.Assert.assertTrue;

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.SMConsult;
import com.agilex.healthcare.schedulingmanager.domain.SMConsults;
import com.agilex.healthcare.schedulingmanager.mdws.connection.MdwsConfiguration;
import com.agilex.healthcare.utility.DateHelper;

@ContextConfiguration(locations = {"classpath:integrationApplicationContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class EmrDataLayerMdwsVistaTest {
	private String site = "777";
	private PatientIdentifier fourPatient = new PatientIdentifier("dfn" + site, "229");
	
	@Resource
	MdwsConfiguration mdwsConfiguration;

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

	@Test
	public void getPatientConsults() {
		EmrDataLayerMdws dl = new EmrDataLayerMdws(mdwsConfiguration);
		SMConsults consults = dl.getPatientConsults(fourPatient);
		assertNotNull(consults);
		assertEquals(26, consults.size());
		
		Date requestDate = DateHelper.parseVistaDefaultDateTIme("20131230.123452");
		SMConsult consult = consults.get(0);
		assertEquals("639", consult.getConsultIen());
		assertNotNull(consult.getDaysOnList());
		assertNull(consult.getPatientDfn());
		assertNull(consult.getPatientName());
		assertEquals(requestDate, consult.getRequestDate());
		assertNull(consult.getSendingProviderDuz());
		assertNull(consult.getSendingProviderName());
		assertNull(consult.getServiceIen());
		assertEquals("GASTROENTEROLOGY Cons", consult.getServiceName());
		assertEquals("Pending", consult.getStatus());
		assertNotNull(consult.getText());
		assertTrue(consult.getText().length() > 0);
	}
}
