Search in sources :

Example 41 with EncounterType

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

the class EncounterServiceTest method getEncounterType_shouldReturnNullIfOnlyRetiredTypeFound.

/**
 * Make sure that the "Some Retired Type" type is not returned because it is retired in
 * {@link EncounterService#getEncounterType(String)}
 *
 * @see EncounterService#getEncounterType(String)
 */
@Test
public void getEncounterType_shouldReturnNullIfOnlyRetiredTypeFound() {
    EncounterService encounterService = Context.getEncounterService();
    // sanity check to make sure 'some retired type' is in the dataset
    assertTrue(encounterService.getEncounterType(4).getRetired());
    assertEquals("Some Retired Type", encounterService.getEncounterType(4).getName());
    // we should get a null here because this named type is retired
    EncounterType type = encounterService.getEncounterType("Some Retired Type");
    assertNull(type);
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 42 with EncounterType

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

the class EncounterServiceTest method purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWhenEncounterTypesAreLocked.

/**
 * @see EncounterService#purgeEncounterType(EncounterType)
 */
@Test(expected = EncounterTypeLockedException.class)
public void purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWhenEncounterTypesAreLocked() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterType = Context.getEncounterService().getEncounterType(1);
    Assert.assertNotNull(encounterType);
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED);
    gp.setPropertyValue("true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    encounterService.purgeEncounterType(encounterType);
}
Also used : EncounterType(org.openmrs.EncounterType) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 43 with EncounterType

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

the class EncounterServiceTest method canEditAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToEditEncounters.

/**
 * @see EncounterService#canEditAllEncounterTypes(User)
 */
@Test
public void canEditAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToEditEncounters() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterType = new EncounterType("testing", "desc");
    Privilege editPrivilege = Context.getUserService().getPrivilege("Some Privilege For Edit Encounter Types");
    encounterType.setEditPrivilege(editPrivilege);
    encounterService.saveEncounterType(encounterType);
    User user = Context.getUserService().getUserByUsername("test_user");
    assertNotNull(user);
    assertFalse(encounterService.canEditAllEncounterTypes(user));
    Role role = Context.getUserService().getRole("Provider");
    role.addPrivilege(editPrivilege);
    user.addRole(role);
    assertTrue(encounterService.canEditAllEncounterTypes(user));
}
Also used : Role(org.openmrs.Role) EncounterRole(org.openmrs.EncounterRole) User(org.openmrs.User) EncounterType(org.openmrs.EncounterType) Privilege(org.openmrs.Privilege) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 44 with EncounterType

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

the class EncounterServiceTest method findEncounterTypes_shouldIncludeRetiredTypesInTheResults.

/**
 * @see EncounterService#findEncounterTypes(String)
 */
@Test
public void findEncounterTypes_shouldIncludeRetiredTypesInTheResults() {
    EncounterService encounterService = Context.getEncounterService();
    List<EncounterType> types = encounterService.findEncounterTypes("Test Enc");
    assertEquals(3, types.size());
    // make sure at least one of the types was retired
    boolean foundRetired = false;
    for (EncounterType type : types) {
        if (type.getRetired())
            foundRetired = true;
    }
    assertTrue("Retired types should be returned as well", foundRetired);
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 45 with EncounterType

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

the class EncounterServiceTest method unretireEncounterType_shouldUnretireTypeAndUnmarkAttributes.

/**
 * @see EncounterService#unretireEncounterType(EncounterType)
 */
@Test
public void unretireEncounterType_shouldUnretireTypeAndUnmarkAttributes() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType type = encounterService.getEncounterType(3);
    assertTrue(type.getRetired());
    assertNotNull(type.getRetiredBy());
    assertNotNull(type.getRetireReason());
    assertNotNull(type.getDateRetired());
    EncounterType unretiredEncType = encounterService.unretireEncounterType(type);
    // make sure its still the same object
    assertEquals(unretiredEncType, type);
    // make sure that all the values were unfilled in
    assertFalse(unretiredEncType.getRetired());
    assertNull(unretiredEncType.getDateRetired());
    assertNull(unretiredEncType.getRetiredBy());
    assertNull(unretiredEncType.getRetireReason());
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

EncounterType (org.openmrs.EncounterType)60 Test (org.junit.Test)44 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)42 Encounter (org.openmrs.Encounter)19 Date (java.util.Date)17 Location (org.openmrs.Location)12 Patient (org.openmrs.Patient)10 User (org.openmrs.User)10 EncounterRole (org.openmrs.EncounterRole)9 Provider (org.openmrs.Provider)8 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)5 GlobalProperty (org.openmrs.GlobalProperty)5 List (java.util.List)4 Privilege (org.openmrs.Privilege)4 Concept (org.openmrs.Concept)3 Visit (org.openmrs.Visit)3 HashMap (java.util.HashMap)2 SQLQuery (org.hibernate.SQLQuery)2