Search in sources :

Example 16 with PersonAddress

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

the class PersonAddressValidatorTest method validate_shouldPassIfEndDateIsNull.

/**
 * @see PersonAddressValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfEndDateIsNull() {
    PersonAddress personAddress = new PersonAddress();
    Calendar c = Calendar.getInstance();
    personAddress.setStartDate(c.getTime());
    personAddress.setEndDate(null);
    Errors errors = new BindException(personAddress, "personAddress");
    validator.validate(personAddress, errors);
    Assert.assertEquals(false, errors.hasFieldErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonAddress(org.openmrs.PersonAddress) Calendar(java.util.Calendar) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 17 with PersonAddress

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

the class PersonAddressValidatorTest method validate_shouldPassIfStartDateAndEndDateAreBothNull.

/**
 * @see PersonAddressValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfStartDateAndEndDateAreBothNull() {
    PersonAddress personAddress = new PersonAddress();
    personAddress.setStartDate(null);
    personAddress.setEndDate(null);
    Errors errors = new BindException(personAddress, "personAddress");
    validator.validate(personAddress, errors);
    Assert.assertEquals(false, errors.hasFieldErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonAddress(org.openmrs.PersonAddress) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 18 with PersonAddress

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

the class PersonServiceImpl method setPreferredPersonAddress.

private void setPreferredPersonAddress(Person person) {
    PersonAddress preferredAddress = null;
    PersonAddress possiblePreferredAddress = person.getPersonAddress();
    if (possiblePreferredAddress != null && possiblePreferredAddress.getPreferred() && !possiblePreferredAddress.getVoided()) {
        preferredAddress = possiblePreferredAddress;
    }
    for (PersonAddress address : person.getAddresses()) {
        if (preferredAddress == null && !address.getVoided()) {
            address.setPreferred(true);
            preferredAddress = address;
            continue;
        }
        if (!address.equals(preferredAddress)) {
            address.setPreferred(false);
        }
    }
}
Also used : PersonAddress(org.openmrs.PersonAddress)

Example 19 with PersonAddress

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

the class PatientServiceTest method savePatient_shouldNotSetAVoidedNameOrAddressOrIdentifierAsPreferred.

/**
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotSetAVoidedNameOrAddressOrIdentifierAsPreferred() throws Exception {
    Patient patient = new Patient();
    patient.setGender("M");
    PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
    PatientIdentifier preferredIdentifier = new PatientIdentifier("QWERTY2", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
    preferredIdentifier.setPreferred(true);
    preferredIdentifier.setVoided(true);
    patient.addIdentifier(identifier);
    patient.addIdentifier(preferredIdentifier);
    PersonName name = new PersonName("givenName", "middleName", "familyName");
    PersonName preferredName = new PersonName("givenName", "middleName", "familyName");
    preferredName.setPreferred(true);
    preferredName.setVoided(true);
    patient.addName(name);
    patient.addName(preferredName);
    PersonAddress address = new PersonAddress();
    address.setAddress1("some address");
    PersonAddress preferredAddress = new PersonAddress();
    preferredAddress.setAddress1("another address");
    preferredAddress.setPreferred(true);
    preferredAddress.setVoided(true);
    patient.addAddress(address);
    patient.addAddress(preferredAddress);
    patientService.savePatient(patient);
    Assert.assertFalse(preferredIdentifier.getPreferred());
    Assert.assertFalse(preferredName.getPreferred());
    Assert.assertFalse(preferredAddress.getPreferred());
    Assert.assertTrue(identifier.getPreferred());
    Assert.assertTrue(name.getPreferred());
    Assert.assertTrue(address.getPreferred());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 20 with PersonAddress

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

the class PatientServiceTest method savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified.

/**
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified() throws Exception {
    Patient patient = new Patient();
    patient.setGender("M");
    PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
    patient.addIdentifier(identifier);
    PersonName name = new PersonName("givenName", "middleName", "familyName");
    patient.addName(name);
    PersonAddress address = new PersonAddress();
    address.setAddress1("some address");
    patient.addAddress(address);
    Context.getPatientService().savePatient(patient);
    Assert.assertTrue(identifier.getPreferred());
    Assert.assertTrue(name.getPreferred());
    Assert.assertTrue(address.getPreferred());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PersonAddress (org.openmrs.PersonAddress)49 Test (org.junit.Test)32 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 PersonName (org.openmrs.PersonName)20 Patient (org.openmrs.Patient)18 BindException (org.springframework.validation.BindException)13 Errors (org.springframework.validation.Errors)13 Date (java.util.Date)12 PatientIdentifier (org.openmrs.PatientIdentifier)12 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)9 Person (org.openmrs.Person)6 Calendar (java.util.Calendar)5 Location (org.openmrs.Location)5 PatientIdentifierType (org.openmrs.PatientIdentifierType)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 DateTime (org.joda.time.DateTime)3 Concept (org.openmrs.Concept)3 PersonAttribute (org.openmrs.PersonAttribute)3 DateFormat (java.text.DateFormat)2