use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified() throws Exception {
Patient patient = new Patient();
patient.setGender("M");
PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
patient.addIdentifier(identifier);
PersonName name = new PersonName("givenName", "middleName", "familyName");
patient.addName(name);
PersonAddress address = new PersonAddress();
address.setAddress1("some address");
patient.addAddress(address);
Context.getPatientService().savePatient(patient);
Assert.assertTrue(identifier.getPreferred());
Assert.assertTrue(name.getPreferred());
Assert.assertTrue(address.getPreferred());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method shouldCreatePatient.
@Test
public void shouldCreatePatient() throws Exception {
executeDataSet(CREATE_PATIENT_XML);
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
PersonAddress pAddress = new PersonAddress();
pAddress.setAddress1("123 My street");
pAddress.setAddress2("Apt 402");
pAddress.setCityVillage("Anywhere city");
pAddress.setCountry("Some Country");
Set<PersonAddress> pAddressList = patient.getAddresses();
pAddressList.add(pAddress);
patient.setAddresses(pAddressList);
patient.addAddress(pAddress);
// patient.removeAddress(pAddress);
patient.setBirthdateEstimated(true);
patient.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept());
patient.setGender("male");
List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes();
assertNotNull(patientIdTypes);
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("123-0");
patientIdentifier.setIdentifierType(patientIdTypes.get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setPreferred(true);
Set<PatientIdentifier> patientIdentifiers = new LinkedHashSet<>();
patientIdentifiers.add(patientIdentifier);
patient.setIdentifiers(patientIdentifiers);
patientService.savePatient(patient);
Patient createdPatient = patientService.getPatient(patient.getPatientId());
assertNotNull(createdPatient);
assertNotNull(createdPatient.getPatientId());
Patient createdPatientById = patientService.getPatient(createdPatient.getPatientId());
assertNotNull(createdPatientById);
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfBirthEstimated.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditPriorDateOfBirthEstimated() throws Exception {
// retrieve preferred patient and set a date of birth
GregorianCalendar cDate = new GregorianCalendar();
cDate.setTime(new Date());
Patient preferred = patientService.getPatient(999);
preferred.setBirthdate(cDate.getTime());
preferred.setBirthdateEstimated(true);
preferred.addName(new PersonName("givenName", "middleName", "familyName"));
patientService.savePatient(preferred);
Patient notPreferred = patientService.getPatient(7);
voidOrders(Collections.singleton(notPreferred));
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
Assert.assertTrue("prior estimated date of birth was not audited", audit.getPersonMergeLogData().isPriorDateOfBirthEstimated());
}
use of org.openmrs.PersonName in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldCopyNonvoidedNamesToPreferredPatient.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldCopyNonvoidedNamesToPreferredPatient() throws Exception {
Patient preferred = patientService.getPatient(7);
Patient notPreferred = patientService.getPatient(8);
patientService.mergePatients(preferred, notPreferred);
// make sure one of their addresses has the first name of "Anet"
boolean found = false;
for (PersonName pn : preferred.getNames()) {
if (pn.getGivenName().equals("Anet")) {
found = true;
}
}
Assert.assertTrue("odd, user 7 didn't get user 8's names", found);
}
use of org.openmrs.PersonName 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");
}
Aggregations