Search in sources :

Example 36 with PersonAddress

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

the class PatientServiceTest method createBasicPatient.

/**
 * Convenience method to have a Patient object with all required values filled in
 *
 * @return a mock Patient object that can be saved
 */
private Patient createBasicPatient() {
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    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);
    // patient.removeAddress(pAddress);
    patient.setBirthdate(new Date());
    patient.setBirthdateEstimated(true);
    patient.setDeathDate(new Date());
    patient.setCauseOfDeath(new Concept());
    patient.setGender("male");
    patient.setDeathdateEstimated(true);
    return patient;
}
Also used : Concept(org.openmrs.Concept) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) Date(java.util.Date)

Example 37 with PersonAddress

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

the class PatientServiceTest method mergePatients_shouldMaintainSimilarButDifferentAddresses.

@Test
public void mergePatients_shouldMaintainSimilarButDifferentAddresses() throws Exception {
    executeDataSet(PATIENT_MERGE_XML);
    Patient preferredPatient = patientService.getPatient(10000);
    Patient nonPreferredPatient = patientService.getPatient(10001);
    patientService.mergePatients(preferredPatient, nonPreferredPatient);
    Set<PersonAddress> addresses = preferredPatient.getAddresses();
    assertThat(addresses, containsAddress("a1:Apartment ABC, a2:123 fake st, cv:Faketown, sp:null, c:null, cd:null, nc:null, pc:1234, lat:null, long:null"));
    assertThat(addresses, containsAddress("a1:Apartment ABC, a2:123 fake st, cv:Faketown, sp:Fakeland, c:null, cd:null, nc:null, pc:null, lat:null, long:null"));
}
Also used : PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 38 with PersonAddress

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

the class AuditableInterceptorTest method createPersonWithNameAndAddress.

private Person createPersonWithNameAndAddress() {
    Person person = new Person();
    person.setGender("M");
    PersonName name = new PersonName("givenName", "middleName", "familyName");
    person.addName(name);
    PersonAddress address = new PersonAddress();
    address.setAddress1("some address");
    person.addAddress(address);
    return person;
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person)

Example 39 with PersonAddress

use of org.openmrs.PersonAddress 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 40 with PersonAddress

use of org.openmrs.PersonAddress 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)

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