Search in sources :

Example 71 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PatientServiceTest method shouldFetchAddressesForPersonsThatWereFirstFetchedAsPatients.

/**
 * This test verifies that {@link PersonAddress}es are fetched correctly from the hibernate
 * cache. (Or really, not fetched from the cache but instead are mapped with lazy=false. For
 * some reason Hibernate isn't able to find objects in the cache if a parent object was the one
 * that loaded them)
 *
 * @throws Exception
 */
@Test
public void shouldFetchAddressesForPersonsThatWereFirstFetchedAsPatients() throws Exception {
    Person person = Context.getPersonService().getPerson(2);
    Patient patient = Context.getPatientService().getPatient(2);
    patient.getAddresses().size();
    person.getAddresses().size();
}
Also used : Patient(org.openmrs.Patient) Person(org.openmrs.Person) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 72 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PatientServiceTest method shouldFetchPersonAttributesForPersonsThatWereFirstFetchedAsPatients.

/**
 * This test verifies that {@link PersonAttribute}s are fetched correctly from the hibernate
 * cache. (Or really, not fetched from the cache but instead are mapped with lazy=false. For
 * some reason Hibernate isn't able to find objects in the cache if a parent object was the one
 * that loaded them)
 *
 * @throws Exception
 */
@Test
public void shouldFetchPersonAttributesForPersonsThatWereFirstFetchedAsPatients() throws Exception {
    Person person = Context.getPersonService().getPerson(2);
    Patient patient = Context.getPatientService().getPatient(2);
    patient.getAttributes().size();
    person.getAttributes().size();
}
Also used : Patient(org.openmrs.Patient) Person(org.openmrs.Person) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 73 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class PatientServiceTest method savePatient_shouldNotThrowNonUniqueObjectExceptionWhenCalledWithPersonPromotedToPatient.

/**
 * https://tickets.openmrs.org/browse/TRUNK-3728
 *
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotThrowNonUniqueObjectExceptionWhenCalledWithPersonPromotedToPatient() throws Exception {
    Person person = personService.getPerson(1);
    Patient patient = patientService.getPatientOrPromotePerson(person.getPersonId());
    PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", new PatientIdentifierType(2), new Location(1));
    patientIdentifier.setPreferred(true);
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
}
Also used : Patient(org.openmrs.Patient) Person(org.openmrs.Person) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 74 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class UserDAOTest method getUsers_shouldEscapeSqlWildcardsInSearchPhrase.

@Test
public void getUsers_shouldEscapeSqlWildcardsInSearchPhrase() {
    User u = new User();
    u.setPerson(new Person());
    u.getPerson().setGender("M");
    // we used to also test %, but UserValidator actually doesn't allow that in usernames. TODO: remove the loop
    String[] wildcards = new String[] { "_" };
    // with the wildcards and carry out a search for that user
    for (String wildcard : wildcards) {
        PersonName name = new PersonName(wildcard + "cats", wildcard + "and", wildcard + "dogs");
        name.setDateCreated(new Date());
        u.addName(name);
        u.setUsername(wildcard + "test" + wildcard);
        Context.getUserService().createUser(u, "Openmr5xy");
        // we expect only one matching name or or systemId  to be returned
        int size = dao.getUsers(wildcard + "ca", null, false, null, null).size();
        assertEquals(1, size);
        // if actually the search returned the matching name or system id
        String userName = (dao.getUsers(wildcard + "ca", null, false, null, null).get(0).getUsername());
        assertEquals("Test failed since no user containing the character " + wildcard + " was found, ", wildcard + "test" + wildcard, userName);
    }
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 75 with Person

use of org.openmrs.Person in project openmrs-core by openmrs.

the class AuditableInterceptorTest method onFlushDirty_shouldAddPersonChangedByForPerson.

@Test
public void onFlushDirty_shouldAddPersonChangedByForPerson() {
    AuditableInterceptor interceptor = new AuditableInterceptor();
    Person person = new Person();
    String[] propertyNames = new String[] { "personChangedBy" };
    Object[] currentState = new Object[] { null };
    interceptor.onFlushDirty(person, null, currentState, null, propertyNames, null);
    Assert.assertNotNull(currentState[0]);
}
Also used : Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Person (org.openmrs.Person)172 Test (org.junit.Test)140 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)107 PersonName (org.openmrs.PersonName)41 User (org.openmrs.User)36 Date (java.util.Date)33 Relationship (org.openmrs.Relationship)19 Obs (org.openmrs.Obs)16 Patient (org.openmrs.Patient)15 BindException (org.springframework.validation.BindException)15 Message (ca.uhn.hl7v2.model.Message)14 Concept (org.openmrs.Concept)14 Provider (org.openmrs.Provider)14 Voidable (org.openmrs.Voidable)14 Errors (org.springframework.validation.Errors)14 ArrayList (java.util.ArrayList)10 PersonMergeLog (org.openmrs.person.PersonMergeLog)9 RelationshipType (org.openmrs.RelationshipType)8 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)7 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)7