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);
}
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());
}
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());
}
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);
}
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");
}
Aggregations