Search in sources :

Example 1 with PersonAttribute

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));
}
Also used : Patient(org.openmrs.Patient) PersonAttribute(org.openmrs.PersonAttribute) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with PersonAttribute

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));
}
Also used : Patient(org.openmrs.Patient) PersonAttribute(org.openmrs.PersonAttribute) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with PersonAttribute

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"));
}
Also used : PersonName(org.openmrs.PersonName) PatientAndMatchQuality(org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality) Patient(org.openmrs.Patient) Date(java.util.Date) PersonAttribute(org.openmrs.PersonAttribute) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 4 with PersonAttribute

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?
    }
}
Also used : PersonAttribute(org.openmrs.PersonAttribute) Date(java.util.Date)

Example 5 with PersonAttribute

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;
}
Also used : PersonName(org.openmrs.PersonName) ArrayList(java.util.ArrayList) Criteria(org.hibernate.Criteria) PersonAttribute(org.openmrs.PersonAttribute) Person(org.openmrs.Person)

Aggregations

PersonAttribute (org.openmrs.PersonAttribute)20 Test (org.junit.Test)12 Patient (org.openmrs.Patient)9 PersonName (org.openmrs.PersonName)7 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)5 Date (java.util.Date)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 PersonAddress (org.openmrs.PersonAddress)3 PersonAttributeType (org.openmrs.PersonAttributeType)3 PatientAndMatchQuality (org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality)3 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)3 ArrayList (java.util.ArrayList)2 PersonMergeLog (org.openmrs.person.PersonMergeLog)2 DLD (ca.uhn.hl7v2.model.v25.datatype.DLD)1 IS (ca.uhn.hl7v2.model.v25.datatype.IS)1 File (java.io.File)1 URL (java.net.URL)1 Random (java.util.Random)1 Criteria (org.hibernate.Criteria)1 Ignore (org.junit.Ignore)1