use of org.openmrs.PersonAttribute in project openmrs-module-pihcore by PIH.
the class PihPatientMergeActionsTest method shouldRemoveNonPreferredPhoneNumberButNotMothersName.
@Test
public void shouldRemoveNonPreferredPhoneNumberButNotMothersName() {
Patient preferred = new Patient();
Patient nonPreferred = new Patient();
PersonAttribute preferredPhoneNumber = new PersonAttribute(phoneNumber, "preferred");
preferred.addAttribute(preferredPhoneNumber);
PersonAttribute nonPreferredPhoneNumber = new PersonAttribute(phoneNumber, "non-preferred");
PersonAttribute nonPreferredMothersName = new PersonAttribute(mothersName, "non-preferred");
nonPreferred.addAttribute(nonPreferredPhoneNumber);
nonPreferred.addAttribute(nonPreferredMothersName);
// sanity check
assertThat(preferred.getActiveAttributes().size(), is(1));
assertThat(nonPreferred.getActiveAttributes().size(), is(2));
pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
assertThat(preferred.getActiveAttributes().size(), is(1));
assertThat(nonPreferred.getActiveAttributes().size(), is(1));
assertThat(nonPreferred.getActiveAttributes(), contains(nonPreferredMothersName));
}
use of org.openmrs.PersonAttribute in project openmrs-module-pihcore by PIH.
the class PihPatientMergeActionsTest method shouldNotRemoveNonPreferredPhoneNumberAndMothersNameIfNotPresentOnPreferredPatient.
@Test
public void shouldNotRemoveNonPreferredPhoneNumberAndMothersNameIfNotPresentOnPreferredPatient() {
Patient preferred = new Patient();
Patient nonPreferred = new Patient();
PersonAttribute nonPreferredPhoneNumber = new PersonAttribute(phoneNumber, "non-preferred");
PersonAttribute nonPreferredMothersName = new PersonAttribute(mothersName, "non-preferred");
nonPreferred.addAttribute(nonPreferredPhoneNumber);
nonPreferred.addAttribute(nonPreferredMothersName);
// sanity check
assertThat(preferred.getActiveAttributes().size(), is(0));
assertThat(nonPreferred.getActiveAttributes().size(), is(2));
pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
assertThat(preferred.getActiveAttributes().size(), is(0));
assertThat(nonPreferred.getActiveAttributes().size(), is(2));
}
use of org.openmrs.PersonAttribute in project openmrs-module-pihcore by PIH.
the class PihPatientSearchAlgorithmTest method exactPersonAttributeFieldMatchShouldIncreaseScore.
@Test
public void exactPersonAttributeFieldMatchShouldIncreaseScore() {
// first get the base score for this patient
Patient patient = new Patient();
PersonName name = new PersonName();
patient.addName(name);
name.setGivenName("Jarusz");
name.setFamilyName("Rapondee");
patient.setBirthdate(new Date());
patient.setGender("M");
List<PatientAndMatchQuality> results = searchAlgorithm.findSimilarPatients(patient, null, null, 10);
double scoreWithoutAddress = results.get(0).getScore();
// now add in address and recalculate
PersonAttribute attribute = new PersonAttribute();
attribute.setAttributeType(personService.getPersonAttributeTypeByName("Birthplace"));
attribute.setValue("boston");
patient.addAttribute(attribute);
results = searchAlgorithm.findSimilarPatients(patient, null, null, 10);
double scoreWithAddress = results.get(0).getScore();
// in our test config we've weighed birthplace at 1 point
assertThat(scoreWithAddress - scoreWithoutAddress, is(1.0));
assertTrue(results.get(0).getMatchedFields().contains("attributes.Birthplace"));
}
use of org.openmrs.PersonAttribute in project openmrs-module-pihcore by PIH.
the class PihPatientMergeActions method voidNonPreferredAttribute.
private void voidNonPreferredAttribute(PersonAttributeType type, Patient preferred, Patient nonPreferred) {
if (preferred.getAttribute(type) != null) {
PersonAttribute attr = nonPreferred.getAttribute(type);
if (attr != null) {
attr.setVoided(true);
attr.setDateVoided(new Date());
attr.setVoidReason("Merging into patient " + preferred.getId());
attr.setVoidedBy(Context.getAuthenticatedUser());
}
// dont need to save, because it will be committed as part of the merge?
}
}
use of org.openmrs.PersonAttribute in project openmrs-core by openmrs.
the class HibernatePersonDAO method getPeople.
/**
* @see org.openmrs.api.db.PersonDAO#getPeople(java.lang.String, java.lang.Boolean)
* @should get no one by null
* @should get every one by empty string
* @should get no one by non-existing attribute
* @should get no one by non-searchable attribute
* @should get no one by voided attribute
* @should get one person by attribute
* @should get one person by random case attribute
* @should get one person by searching for a mix of attribute and voided attribute
* @should get multiple people by single attribute
* @should get multiple people by multiple attributes
* @should get no one by non-existing name
* @should get one person by name
* @should get one person by random case name
* @should get multiple people by single name
* @should get multiple people by multiple names
* @should get no one by non-existing name and non-existing attribute
* @should get no one by non-existing name and non-searchable attribute
* @should get no one by non-existing name and voided attribute
* @should get one person by name and attribute
* @should get one person by name and voided attribute
* @should get multiple people by name and attribute
* @should get one person by given name
* @should get multiple people by given name
* @should get one person by middle name
* @should get multiple people by middle name
* @should get one person by family name
* @should get multiple people by family name
* @should get one person by family name2
* @should get multiple people by family name2
* @should get one person by multiple name parts
* @should get multiple people by multiple name parts
* @should get no one by voided name
* @should not get voided person
* @should not get dead person
* @should get single dead person
* @should get multiple dead people
*/
@Override
@SuppressWarnings("unchecked")
public List<Person> getPeople(String searchString, Boolean dead, Boolean voided) {
if (searchString == null) {
return new ArrayList<>();
}
int maxResults = HibernatePersonDAO.getMaximumSearchResults();
boolean includeVoided = (voided != null) ? voided : false;
if (StringUtils.isBlank(searchString)) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Person.class);
if (dead != null) {
criteria.add(Restrictions.eq("dead", dead));
}
if (!includeVoided) {
criteria.add(Restrictions.eq("personVoided", false));
}
criteria.setMaxResults(maxResults);
return criteria.list();
}
String query = LuceneQuery.escapeQuery(searchString);
PersonLuceneQuery personLuceneQuery = new PersonLuceneQuery(sessionFactory);
LuceneQuery<PersonName> nameQuery = personLuceneQuery.getPersonNameQueryWithOrParser(query, includeVoided);
if (dead != null) {
nameQuery.include("person.dead", dead);
}
List<Person> people = new ArrayList<>();
ListPart<Object[]> names = nameQuery.listPartProjection(0, maxResults, "person.personId");
names.getList().forEach(name -> people.add(getPerson((Integer) name[0])));
LuceneQuery<PersonAttribute> attributeQuery = personLuceneQuery.getPersonAttributeQueryWithOrParser(query, includeVoided, nameQuery);
ListPart<Object[]> attributes = attributeQuery.listPartProjection(0, maxResults, "person.personId");
attributes.getList().forEach(attribute -> people.add(getPerson((Integer) attribute[0])));
return people;
}
Aggregations