Search in sources :

Example 86 with PersonName

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

the class PersonSaveHandlerTest method handle_shouldIgnoreBlankAddresses.

/**
 * @see PersonSaveHandler#handle(Person,User, Date,String)
 */
@Test
public void handle_shouldIgnoreBlankAddresses() {
    PersonSaveHandler handler = new PersonSaveHandler();
    Person person = new Person();
    PersonName personName = new PersonName("John", "", "Smith");
    person.addName(personName);
    person.setGender("M");
    PersonAddress personAddress = new PersonAddress();
    personAddress.setAddress1("     ");
    person.addAddress(personAddress);
    handler.handle(person, null, null, null);
    Assert.assertEquals(0, person.getAddresses().size());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 87 with PersonName

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

the class PatientValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see PatientValidator#validate(Object,Errors)
 */
@Override
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    patient.setGender("male");
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setLocation(new Location(1));
    patientIdentifier1.setIdentifier("012345678");
    patientIdentifier1.setDateCreated(new Date());
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    patient.setVoidReason("voidReason");
    Errors errors = new BindException(patient, "patient");
    validator.validate(patient, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Example 88 with PersonName

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

the class PersonNameValidatorTest method setUp.

@Before
public void setUp() {
    validator = new PersonNameValidator();
    personName = new PersonName();
    errors = new BindException(personName, "personName");
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_NAME_REGEX, "^[a-zA-Z \\-]+$"));
}
Also used : PersonName(org.openmrs.PersonName) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Before(org.junit.Before)

Example 89 with PersonName

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

the class PersonByNameComparatorTest method comparePersonsByName_shouldNotBeCaseSensitive.

@Test
public void comparePersonsByName_shouldNotBeCaseSensitive() {
    Person person1 = new Person();
    person1.addName(new PersonName("GIVENNAME", "MIDDLENAME", "FAMILYNAME"));
    Person person2 = new Person();
    person2.addName(new PersonName("givenName", "middleName", "familyName"));
    int actualValue = PersonByNameComparator.comparePersonsByName(person1, person2);
    Assert.assertTrue("Expected zero but it was: " + actualValue, actualValue == 0);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Test(org.junit.Test)

Example 90 with PersonName

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

the class PersonByNameComparatorTest method comparePersonsByName_shouldReturnPositiveIfPersonNameForPerson1ComesAfterThatOfPerson2.

/**
 * @see PersonByNameComparator#comparePersonsByName(Person,Person)
 */
@Test
public void comparePersonsByName_shouldReturnPositiveIfPersonNameForPerson1ComesAfterThatOfPerson2() {
    Person person1 = new Person();
    person1.addName(new PersonName("givenName", "middleNamf", "familyName"));
    Person person2 = new Person();
    person2.addName(new PersonName("givenName", "middleName", "familyName"));
    int actualValue = PersonByNameComparator.comparePersonsByName(person1, person2);
    Assert.assertTrue("Expected a positive value but it was: " + actualValue, actualValue > 0);
}
Also used : PersonName(org.openmrs.PersonName) Person(org.openmrs.Person) Test(org.junit.Test)

Aggregations

PersonName (org.openmrs.PersonName)108 Test (org.junit.Test)81 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)57 Patient (org.openmrs.Patient)41 Person (org.openmrs.Person)39 Date (java.util.Date)26 PatientIdentifier (org.openmrs.PatientIdentifier)19 PersonAddress (org.openmrs.PersonAddress)19 User (org.openmrs.User)17 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)17 PatientIdentifierType (org.openmrs.PatientIdentifierType)13 Location (org.openmrs.Location)12 ArrayList (java.util.ArrayList)9 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)9 PersonMergeLog (org.openmrs.person.PersonMergeLog)8 PersonAttribute (org.openmrs.PersonAttribute)7 PatientAndMatchQuality (org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)6 Provider (org.openmrs.Provider)5