Search in sources :

Example 1 with PersonAddress

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

the class PersonServiceTest method createTestPatient.

/*
	 * Helper to create patient that does not have any existing relationships. Returns created Patient.
	 */
private Patient createTestPatient() {
    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.setBirthdate(new Date());
    patient.setBirthdateEstimated(true);
    patient.setDeathDate(new Date());
    patient.setCauseOfDeath(new Concept(1));
    patient.setGender("male");
    List<PatientIdentifierType> patientIdTypes = ps.getAllPatientIdentifierTypes();
    assertNotNull(patientIdTypes);
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("123-0");
    patientIdentifier.setIdentifierType(patientIdTypes.get(0));
    patientIdentifier.setLocation(new Location(1));
    patientIdentifier.setPreferred(true);
    Set<PatientIdentifier> patientIdentifiers = new TreeSet<>();
    patientIdentifiers.add(patientIdentifier);
    patient.setIdentifiers(patientIdentifiers);
    ps.savePatient(patient);
    return patient;
}
Also used : Concept(org.openmrs.Concept) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) TreeSet(java.util.TreeSet) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location)

Example 2 with PersonAddress

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

the class PersonServiceTest method unvoidPersonAddress_shouldUnvoidVoidedpersonAddress.

/**
 * @see PersonService#unvoidPersonAddress(org.openmrs.PersonAddress)
 */
@Test
public void unvoidPersonAddress_shouldUnvoidVoidedpersonAddress() throws Exception {
    executeDataSet("org/openmrs/api/include/PersionServiceTest-voidUnvoidPersonAddress.xml");
    PersonAddress voidedPersonAddress = Context.getPersonService().getPersonAddressByUuid("33ghghb5-821c-4e5e-ad1d-a9bce331e777");
    assertTrue(voidedPersonAddress.getVoided());
    PersonAddress unvoidedPersonAddress = Context.getPersonService().unvoidPersonAddress(voidedPersonAddress);
    Assert.assertFalse(unvoidedPersonAddress.getVoided());
    Assert.assertNull(unvoidedPersonAddress.getVoidedBy());
    Assert.assertNull(unvoidedPersonAddress.getDateVoided());
    Assert.assertNull(unvoidedPersonAddress.getVoidReason());
}
Also used : PersonAddress(org.openmrs.PersonAddress) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with PersonAddress

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

the class PersonServiceTest method getPersonAddressByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see PersonService#getPersonAddressByUuid(String)
 */
@Test
public void getPersonAddressByUuid_shouldFindObjectGivenValidUuid() throws Exception {
    String uuid = "3350d0b5-821c-4e5e-ad1d-a9bce331e118";
    PersonAddress personAddress = Context.getPersonService().getPersonAddressByUuid(uuid);
    Assert.assertEquals(2, (int) personAddress.getPersonAddressId());
}
Also used : PersonAddress(org.openmrs.PersonAddress) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with PersonAddress

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

the class PersonServiceTest method savePerson_shouldSetThePreferredNameAndAddressIfNoneIsSpecified.

/**
 * @see PersonService#savePerson(Person)
 */
@Test
public void savePerson_shouldSetThePreferredNameAndAddressIfNoneIsSpecified() throws Exception {
    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);
    personService.savePerson(person);
    assertTrue(name.getPreferred());
    assertTrue(address.getPreferred());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with PersonAddress

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

the class PersonServiceTest method voidPersonAddress_shouldVoidPersonAddressWithTheGivenReason.

/**
 * @see PersonService#voidPersonAddress(org.openmrs.PersonAddress, String)
 */
@Test
public void voidPersonAddress_shouldVoidPersonAddressWithTheGivenReason() throws Exception {
    executeDataSet("org/openmrs/api/include/PersionServiceTest-voidUnvoidPersonAddress.xml");
    PersonAddress personAddress = Context.getPersonService().getPersonAddressByUuid("33ghd0b5-821c-4e5e-ad1d-a9bce331e118");
    Assert.assertFalse(personAddress.getVoided());
    PersonAddress voidedPersonAddress = Context.getPersonService().voidPersonAddress(personAddress, "Test Voiding PersonAddress");
    assertTrue(voidedPersonAddress.getVoided());
    Assert.assertNotNull(voidedPersonAddress.getVoidedBy());
    Assert.assertNotNull(voidedPersonAddress.getDateVoided());
    Assert.assertEquals(voidedPersonAddress.getVoidReason(), "Test Voiding PersonAddress");
}
Also used : PersonAddress(org.openmrs.PersonAddress) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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