Search in sources :

Example 21 with Person

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

the class PersonServiceTest method getRelationships2_shouldFetchRelationshipsMatchingTheGivenToPerson.

/**
 * @see PersonService#getRelationships(Person,Person,RelationshipType,Date)
 */
@Test
public void getRelationships2_shouldFetchRelationshipsMatchingTheGivenToPerson() throws Exception {
    PersonService personService = Context.getPersonService();
    Person secondPerson = personService.getPerson(7);
    List<Relationship> relationships = personService.getRelationships(null, secondPerson, null, new Date());
    Assert.assertNotNull(relationships);
    assertTrue("There should be relationship found given the to person", relationships.size() > 0);
}
Also used : Relationship(org.openmrs.Relationship) Person(org.openmrs.Person) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with Person

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

the class PersonServiceTest method voidPerson_shouldRetireUsers.

/**
 * @see PersonService#voidPerson(Person,String)
 */
@Test
public void voidPerson_shouldRetireUsers() throws Exception {
    // given
    Person person = personService.getPerson(2);
    User user = new User(person);
    Context.getUserService().createUser(user, "Admin123");
    Assert.assertFalse(Context.getUserService().getUsersByPerson(person, false).isEmpty());
    // when
    personService.voidPerson(person, "reason");
    // then
    assertTrue(Context.getUserService().getUsersByPerson(person, false).isEmpty());
}
Also used : User(org.openmrs.User) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with Person

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

the class PersonServiceTest method savePerson_shouldNotSetThePreferredNameAndAddressIfTheyAlreadyExist.

/**
 * @see PersonService#savePerson(Person)
 */
@Test
public void savePerson_shouldNotSetThePreferredNameAndAddressIfTheyAlreadyExist() throws Exception {
    Person person = new Person();
    person.setGender("M");
    PersonName name = new PersonName("givenName", "middleName", "familyName");
    PersonName preferredName = new PersonName("givenName", "middleName", "familyName");
    preferredName.setPreferred(true);
    person.addName(name);
    person.addName(preferredName);
    PersonAddress address = new PersonAddress();
    address.setAddress1("some address");
    PersonAddress preferredAddress = new PersonAddress();
    preferredAddress.setAddress1("another address");
    preferredAddress.setPreferred(true);
    person.addAddress(address);
    person.addAddress(preferredAddress);
    personService.savePerson(person);
    assertTrue(preferredName.getPreferred());
    assertTrue(preferredAddress.getPreferred());
    Assert.assertFalse(name.getPreferred());
    Assert.assertFalse(address.getPreferred());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with Person

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

the class UserServiceTest method userWithValidPerson.

private User userWithValidPerson() {
    Person person = new Person();
    person.addName(new PersonName("jane", "sue", "doe"));
    person.setGender("F");
    return new User(person);
}
Also used : PersonName(org.openmrs.PersonName) User(org.openmrs.User) Person(org.openmrs.Person)

Example 25 with Person

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

the class PersonValidator method validate.

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object,
 *      org.springframework.validation.Errors)
 * @should fail validation if birthdate makes patient older that 120 years old
 * @should fail validation if birthdate is a future date
 * @should fail validation if deathdate is a future date
 * @should fail validation if birthdate is after death date
 * @should fail validation if voidReason is blank when patient is voided
 * @should fail validation if causeOfDeath is blank when patient is dead
 * @should pass validation if gender is blank for Persons
 * @should pass validation if field lengths are correct
 * @should fail validation if field lengths are not correct
 */
@Override
public void validate(Object target, Errors errors) {
    log.debug("{}.validate...", this.getClass().getName());
    if (target == null) {
        return;
    }
    Person person = (Person) target;
    int index = 0;
    boolean atLeastOneNonVoidPersonNameLeft = false;
    for (PersonName personName : person.getNames()) {
        errors.pushNestedPath("names[" + index + "]");
        personNameValidator.validate(personName, errors);
        if (!personName.getVoided()) {
            atLeastOneNonVoidPersonNameLeft = true;
        }
        errors.popNestedPath();
        index++;
    }
    if (!person.getVoided() && !atLeastOneNonVoidPersonNameLeft) {
        errors.rejectValue("names", "Person.shouldHaveAtleastOneNonVoidedName");
    }
    // validate the personAddress
    index = 0;
    for (PersonAddress address : person.getAddresses()) {
        try {
            errors.pushNestedPath("addresses[" + index + "]");
            ValidationUtils.invokeValidator(personAddressValidator, address, errors);
        } finally {
            errors.popNestedPath();
            index++;
        }
    }
    validateBirthDate(errors, person.getBirthdate());
    validateDeathDate(errors, person.getDeathDate(), person.getBirthdate());
    if (person.getVoided()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "voidReason", "error.null");
    }
    if (person.getDead()) {
        ValidationUtils.rejectIfEmpty(errors, "causeOfDeath", "Person.dead.causeOfDeathNull");
    }
    ValidateUtil.validateFieldLengths(errors, Person.class, "gender", "personVoidReason");
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person)

Aggregations

Person (org.openmrs.Person)167 Test (org.junit.Test)140 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)107 PersonName (org.openmrs.PersonName)39 Date (java.util.Date)33 User (org.openmrs.User)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 Voidable (org.openmrs.Voidable)14 Errors (org.springframework.validation.Errors)14 ArrayList (java.util.ArrayList)10 Provider (org.openmrs.Provider)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