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

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

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

	@Test
	public void getPatient() {
		SMPatientDataLayerMdws dl = new SMPatientDataLayerMdws(mdwsSchedulingConfiguration);
		Patient pat = dl.getPatient(fourPatient);
		
		Date dob = DateHelper.parseVistaDefaultDateTIme("19350407");
		assertNotNull(pat);
		assertNull(pat.getAdmittedDateTime());
		assertNull(pat.getAge());
		assertEquals("CAD", pat.getCwad());
		assertNotNull(pat.getDateOfBirth());
		assertEquals(dob, pat.getDateOfBirth().getDate());
		assertEquals("FOUR,PATIENT", pat.getDisplayName());
		assertNull(pat.getEnterpriseId());
		assertEquals("PATIENT", pat.getFirstName());
		assertEquals("M", pat.getGender());
		assertEquals("10104", pat.getIcn());
		assertFalse(pat.isInpatient());
		assertEquals("FOUR", pat.getLastName());
		assertNull(pat.getLocationIEN());
		assertNull(pat.getMiddleInitial());
		assertNull(pat.getMiddleName());
		TestUtil.assertPatientIdentifier(pat.getPatientIdentifier(), "default", "229");
		assertNull(pat.getRoombed());
		assertFalse(pat.isSensitive());
		assertTrue(pat.isServiceConnected());
		assertEquals("10", pat.getServiceConnectedPercent());
		assertEquals("666000004", pat.getSsn());
		assertFalse(pat.isTextMessagingAllowed());
		assertNull(pat.getTextMessagingPhoneNumber());
		assertNull(pat.getWardLocation());
	}
}
