use of org.openmrs.Location in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldFindPatientsEfficiently.
@Test
@Ignore("Designated for manual runs")
public void getPatients_shouldFindPatientsEfficiently() throws IOException, URISyntaxException {
URL givenNamesIn = getClass().getResource("/org/openmrs/api/db/givenNames.csv");
List<String> givenNames = FileUtils.readLines(new File(givenNamesIn.toURI()));
URL familyNamesIn = getClass().getResource("/org/openmrs/api/db/familyNames.csv");
List<String> familyNames = FileUtils.readLines(new File(familyNamesIn.toURI()));
List<String> attributes = Arrays.asList("London", "Berlin", "Warsaw", "Paris", "Zurich", "Singapore");
PatientIdentifierType idType = patientService.getPatientIdentifierTypeByName("Old Identification Number");
PersonAttributeType attributeType = personService.getPersonAttributeTypeByName("Birthplace");
attributeType.setSearchable(true);
Context.getPersonService().savePersonAttributeType(attributeType);
Location location = locationService.getLocation(1);
// set the seed to have repeatable results
Random random = new Random(100);
List<String> generatedPatients = new ArrayList<>();
for (int i = 0; i < 20000; i++) {
int given = random.nextInt(givenNames.size());
int family = random.nextInt(familyNames.size());
int attribute = random.nextInt(attributes.size());
generatedPatients.add((i + 1000) + " " + givenNames.get(given) + " " + familyNames.get(family) + " " + attributes.get(attribute));
PersonName personName = new PersonName(givenNames.get(given), null, familyNames.get(family));
Patient patient = new Patient();
patient.setGender("m");
patient.addIdentifier(new PatientIdentifier("" + (i + 1000), idType, location));
patient.addName(personName);
PersonAttribute personAttribute = new PersonAttribute();
personAttribute.setAttributeType(attributeType);
personAttribute.setValue(attributes.get(attribute));
patient.addAttribute(personAttribute);
patientService.savePatient(patient);
if (i % 100 == 0) {
System.out.println("Created " + i + " patients!");
Context.flushSession();
Context.clearSession();
}
}
File file = File.createTempFile("generated-patients-", ".csv");
FileUtils.writeLines(file, generatedPatients);
System.out.println("Dumped generated patients to " + file.getAbsolutePath());
long time = System.currentTimeMillis();
updateSearchIndex();
time = System.currentTimeMillis() - time;
System.out.println("Indexing took " + time + " ms.");
// get Lucene up to speed...
patientService.getPatients("Aaaaa");
time = System.currentTimeMillis();
List<Patient> results = patientService.getPatients("Al");
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Al' name returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Al", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Al' name limited to 15 results returned in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Al Dem");
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Al Dem' name returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Al Dem", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Al Dem' name limited to 15 results returned in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Jack");
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Jack' name returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Jack", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Jack' name limited to 15 results returned in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Jack Sehgal");
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Jack Sehgal' name returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("Jack Sehgal", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Starts with search for 'Jack Sehgal' name limited to 15 results returned in " + time + " ms");
Context.getAdministrationService().setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_ANYWHERE);
time = System.currentTimeMillis();
results = patientService.getPatients("aso");
time = System.currentTimeMillis() - time;
System.out.println("Anywhere search for 'aso' name returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("aso", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Anywhere search for 'aso' name limited to 15 results returned in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("aso os");
time = System.currentTimeMillis() - time;
System.out.println("Anywhere search for 'aso os' name returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("aso os", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Anywhere search for 'aso os' limited to 15 results returned in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("9243");
time = System.currentTimeMillis() - time;
System.out.println("Exact search for '9243' identifier returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("London");
time = System.currentTimeMillis() - time;
System.out.println("Exact search for 'London' attribute returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("London", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Exact search for 'London' attribute limited to 15 results returned in " + time + " ms");
Context.getAdministrationService().setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATTRIBUTE_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATTRIBUTE_SEARCH_MATCH_ANYWHERE);
time = System.currentTimeMillis();
results = patientService.getPatients("uric");
time = System.currentTimeMillis() - time;
System.out.println("Anywhere search for 'uric' attribute returned " + results.size() + " in " + time + " ms");
time = System.currentTimeMillis();
results = patientService.getPatients("uric", 0, 15);
time = System.currentTimeMillis() - time;
System.out.println("Anywhere search for 'uric' attribute limited to 15 results returned in " + time + " ms");
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists.
/**
* You should be able to add a transient tag with an existing tag name.
*
* @see LocationService#saveLocation(Location)
*/
@Test
public void saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists() {
LocationService ls = Context.getLocationService();
// First, create a new Location
Location location = new Location();
location.setName("name");
location.setDescription("is a location");
// Add a transient tag with an existing name
location.addTag(new LocationTag("General Hospital", null));
ls.saveLocation(location);
Location newSavedLocation = ls.getLocation(location.getLocationId());
// Saved parent location should have exactly 1 tag
assertEquals(1, newSavedLocation.getTags().size());
// Tag must be overwritten with tag with locationTagId == 1
assertNotNull("Location tag should have an ID now", newSavedLocation.getTags().iterator().next().getLocationTagId());
assertEquals(1, newSavedLocation.getTags().iterator().next().getLocationTagId().intValue());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationServiceTest method purgeLocation_shouldDeleteLocationSuccessfully.
/**
* Make sure that purging a location removes the row from the database
*
* @see LocationService#purgeLocation(Location)
*/
@Test
public void purgeLocation_shouldDeleteLocationSuccessfully() {
LocationService ls = Context.getLocationService();
// fetch the encounter to delete from the db
Location locationToDelete = ls.getLocation(4);
ls.purgeLocation(locationToDelete);
// try to refetch the location. should get a null object
Location l = ls.getLocation(locationToDelete.getLocationId());
assertNull("We shouldn't find the location after deletion", l);
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound.
/**
* @see LocationService#saveLocation(Location)
*/
@Test(expected = APIException.class)
public void saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound() {
LocationTag tagWithoutName = new LocationTag("some random tag name", "a nonexistant tag");
Location location = new Location();
location.setName("Some name");
location.setDescription("Some description");
location.addTag(tagWithoutName);
Context.getLocationService().saveLocation(location);
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldCreateLocationSuccessfully.
/**
* Test to make sure that a simple save to a new location gets persisted to the database
*
* @see LocationService#saveLocation(Location)
*/
@Test
public void saveLocation_shouldCreateLocationSuccessfully() {
Location location = new Location();
location.setName("testing");
location.setDescription("desc");
location.setAddress1("123");
location.setAddress1("456");
location.setCityVillage("city");
location.setStateProvince("state");
location.setCountry("country");
location.setPostalCode("post");
location.setLatitude("lat");
location.setLongitude("lon");
LocationService ls = Context.getLocationService();
ls.saveLocation(location);
Location newSavedLocation = ls.getLocation(location.getLocationId());
assertNotNull("The saved location should have an id now", location.getLocationId());
assertNotNull("We should get back a location", newSavedLocation);
assertTrue("The created location needs to equal the pojo location", location.equals(newSavedLocation));
}
Aggregations