Search in sources :

Example 31 with PersonAttributeType

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

the class PersonServiceTest method purgePersonAttributeType_shouldDeletePersonAttributeTypeFromDatabase.

/**
 * @see PersonService#purgePersonAttributeType(PersonAttributeType)
 */
@Test
public void purgePersonAttributeType_shouldDeletePersonAttributeTypeFromDatabase() throws Exception {
    PersonService service = Context.getPersonService();
    PersonAttributeType pat = new PersonAttributeType();
    pat.setName("attr type name");
    pat.setDescription("attr type desc");
    pat.setFormat("java.lang.String");
    service.savePersonAttributeType(pat);
    assertNotNull(pat.getId());
    service.purgePersonAttributeType(pat);
    PersonAttributeType deletedPersonAttributeType = service.getPersonAttributeType(pat.getId());
    Assert.assertNull(deletedPersonAttributeType);
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 32 with PersonAttributeType

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

the class PersonServiceTest method shouldRetirePersonAttributeType.

@Test
public void shouldRetirePersonAttributeType() {
    PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE);
    assertFalse("need an unretired PersonAttributeType", pat.getRetired());
    String retireReason = "reason";
    personService.retirePersonAttributeType(pat, retireReason);
    PersonAttributeType retiredPat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE);
    assertTrue(retiredPat.getRetired());
    assertThat(retiredPat.getRetiredBy(), is(Context.getAuthenticatedUser()));
    assertThat(retiredPat.getRetireReason(), is(retireReason));
    assertNotNull(retiredPat.getDateRetired());
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 33 with PersonAttributeType

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

the class PersonServiceTest method shouldFailToRetirePersonAttributeTypeIfGivenReasonIsEmpty.

@Test(expected = APIException.class)
public void shouldFailToRetirePersonAttributeTypeIfGivenReasonIsEmpty() {
    PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE);
    personService.retirePersonAttributeType(pat, "");
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 34 with PersonAttributeType

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

the class PersonServiceTest method getPersonAttributeTypeByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see PersonService#getPersonAttributeTypeByUuid(String)
 */
@Test
public void getPersonAttributeTypeByUuid_shouldFindObjectGivenValidUuid() throws Exception {
    String uuid = "b3b6d540-a32e-44c7-91b3-292d97667518";
    PersonAttributeType personAttributeType = Context.getPersonService().getPersonAttributeTypeByUuid(uuid);
    Assert.assertEquals(1, (int) personAttributeType.getPersonAttributeTypeId());
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 35 with PersonAttributeType

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

the class PersonServiceTest method getAllPersonAttributeTypes_shouldReturnAllPersonAttributeTypesIncludingRetiredWhenIncludeRetiredIsTrue.

/**
 * @see PersonService#getAllPersonAttributeTypes(null)
 */
@Test
public void getAllPersonAttributeTypes_shouldReturnAllPersonAttributeTypesIncludingRetiredWhenIncludeRetiredIsTrue() throws Exception {
    executeDataSet("org/openmrs/api/include/PersonServiceTest-createRetiredPersonAttributeType.xml");
    // TODO: is this the correct way? or should we loop to find a retired type and then perform the following?
    List<PersonAttributeType> attributeTypes = Context.getPersonService().getAllPersonAttributeTypes(true);
    assertTrue("At least one element, otherwise no checking for retired will take place", attributeTypes.size() > 0);
    boolean foundRetired = false;
    for (PersonAttributeType personAttributeType : attributeTypes) {
        if (personAttributeType.getRetired()) {
            foundRetired = true;
            break;
        }
    }
    assertTrue("There should be at least one retired person attribute type found in the list", foundRetired);
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PersonAttributeType (org.openmrs.PersonAttributeType)40 Test (org.junit.Test)33 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 PersonAttribute (org.openmrs.PersonAttribute)4 Location (org.openmrs.Location)3 PatientIdentifierType (org.openmrs.PatientIdentifierType)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Patient (org.openmrs.Patient)2 ImportPatientFromWebService (org.openmrs.module.importpatientfromws.api.ImportPatientFromWebService)2 RemoteServerConfiguration (org.openmrs.module.importpatientfromws.api.RemoteServerConfiguration)2 DLD (ca.uhn.hl7v2.model.v25.datatype.DLD)1 IS (ca.uhn.hl7v2.model.v25.datatype.IS)1 File (java.io.File)1 URL (java.net.URL)1 Random (java.util.Random)1 Ignore (org.junit.Ignore)1 GlobalProperty (org.openmrs.GlobalProperty)1