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