package org.mitre.synthea.world.agents;

import org.junit.Assert;
import org.junit.Test;
import org.mitre.synthea.world.geography.Location;

public class ProviderTest {

  @Test
  public void testLoadProvidersByAbbreviation() {
    Provider.loadProviders("MA");
    Assert.assertNotNull(Provider.getProviderList());
    Assert.assertFalse(Provider.getProviderList().isEmpty());
  }

  @Test
  public void testLoadProvidersByStateName() {
    Provider.loadProviders("Massachusetts");
    Assert.assertNotNull(Provider.getProviderList());
    Assert.assertFalse(Provider.getProviderList().isEmpty());
  }

  @Test
  public void testNearestInpatientInState() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", null);
    location.assignPoint(person, location.randomCityName(person.random));
    Provider provider = Provider.findClosestService(person, Provider.INPATIENT);
    Assert.assertNotNull(provider);
  }

  @Test
  public void testNearestAmbulatoryInState() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", null);
    location.assignPoint(person, location.randomCityName(person.random));
    Provider provider = Provider.findClosestService(person, Provider.AMBULATORY);
    Assert.assertNotNull(provider);
  }
  
  @Test
  public void testPatientCachesProvider() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", "Bedford");
    location.assignPoint(person, location.randomCityName(person.random));
    Provider p = person.getAmbulatoryProvider();
    Assert.assertTrue(person.attributes.containsKey(Person.PREFERREDAMBULATORYPROVIDER));
    Assert.assertNotNull(person.attributes.get(Person.PREFERREDAMBULATORYPROVIDER));
    Provider q = person.getAmbulatoryProvider();
    Assert.assertEquals(p, q);
  }

  @Test
  public void testNearestEmergencyInState() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", null);
    location.assignPoint(person, location.randomCityName(person.random));
    Provider provider = Provider.findClosestService(person, Provider.EMERGENCY);
    Assert.assertNotNull(provider);
  }
  
  @Test
  public void testNearestInpatientInCity() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", "Bedford");
    location.assignPoint(person, location.randomCityName(person.random));
    Provider provider = Provider.findClosestService(person, Provider.INPATIENT);
    Assert.assertNotNull(provider);
  }

  @Test
  public void testNearestAmbulatoryInCity() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", "Bedford");
    location.assignPoint(person, location.randomCityName(person.random));
    Provider provider = Provider.findClosestService(person, Provider.AMBULATORY);
    Assert.assertNotNull(provider);
  }

  @Test
  public void testNearestEmergencyInCity() {
    Provider.loadProviders("Massachusetts");
    Person person = new Person(0L);
    Location location = new Location("Massachusetts", "Bedford");
    location.assignPoint(person, location.randomCityName(person.random));
    Provider provider = Provider.findClosestService(person, Provider.EMERGENCY);
    Assert.assertNotNull(provider);
  }
}

@@ -1385,592 +1385,8 @@
 %0A  %7D
-%0A  %0A  @Test%0A  public void testPatientCachesProvider() %7B%0A    Provider.loadProviders(%22Massachusetts%22);%0A    Person person = new Person(0L);%0A    Location location = new Location(%22Massachusetts%22, %22Bedford%22);%0A    location.assignPoint(person, location.randomCityName(person.random));%0A    Provider p = person.getAmbulatoryProvider();%0A    Assert.assertTrue(person.attributes.containsKey(Person.PREFERREDAMBULATORYPROVIDER));%0A    Assert.assertNotNull(person.attributes.get(Person.PREFERREDAMBULATORYPROVIDER));%0A    Provider q = person.getAmbulatoryProvider();%0A    Assert.assertEquals(p, q);%0A  %7D
 %0A%0A  

Remove accidental test.