Search in sources :

Example 46 with EncounterType

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

the class EncounterServiceTest method filterEncountersByViewPermissions_shouldNotFilterAllEncountersWhenTheEncounterTypesViewPrivilegeColumnIsNull.

/**
 * @see EncounterService#filterEncountersByViewPermissions(List, User)
 */
@Test
public void filterEncountersByViewPermissions_shouldNotFilterAllEncountersWhenTheEncounterTypesViewPrivilegeColumnIsNull() {
    EncounterService encounterService = Context.getEncounterService();
    int beforeSize = encounterService.getEncountersByPatientId(3).size();
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(Context.getPatientService().getPatient(3));
    EncounterType encounterType = new EncounterType(1);
    // viewPrivilege on encounter type intentionally left null
    encounter.setEncounterType(encounterType);
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = encounterService.saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    encounter.addProvider(role, provider);
    encounterService.saveEncounter(encounter);
    List<Encounter> patientEncounters = encounterService.getEncountersByPatientId(3);
    assertNotNull(patientEncounters);
    assertEquals(beforeSize + 1, patientEncounters.size());
}
Also used : Encounter(org.openmrs.Encounter) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 47 with EncounterType

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

the class EncounterServiceTest method purgeEncounterType_shouldPurgeType.

/**
 * @see EncounterService#purgeEncounterType(EncounterType)
 */
@Test
public void purgeEncounterType_shouldPurgeType() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterTypeToPurge = encounterService.getEncounterType(4);
    assertNotNull(encounterTypeToPurge);
    // check deletion
    encounterService.purgeEncounterType(encounterTypeToPurge);
    assertNull(encounterService.getEncounterType(4));
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 48 with EncounterType

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

the class EncounterServiceTest method saveEncounter_shouldCascadeSaveEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeSaveEncounterProviders() {
    // given
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(3));
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = Context.getEncounterService().saveEncounterRole(role);
    EncounterRole role2 = new EncounterRole();
    role2.setName("role2");
    role2 = Context.getEncounterService().saveEncounterRole(role2);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name1"));
    provider = Context.getProviderService().saveProvider(provider);
    Provider provider2 = new Provider();
    provider2.setIdentifier("id2");
    provider2.setPerson(newPerson("name2"));
    provider2 = Context.getProviderService().saveProvider(provider2);
    encounter.addProvider(role, provider);
    encounter.addProvider(role, provider2);
    encounter.addProvider(role2, provider2);
    // when
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(2, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).containsAll(Arrays.asList(provider, provider2)));
    Assert.assertEquals(1, encounter.getProvidersByRole(role2).size());
    Assert.assertTrue("Role2", encounter.getProvidersByRole(role2).contains(provider2));
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 49 with EncounterType

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

the class EncounterServiceTest method retireEncounterType_shouldRetireTypeAndSetAttributes.

/**
 * @see EncounterService#retireEncounterType(EncounterType,String)
 */
@Test
public void retireEncounterType_shouldRetireTypeAndSetAttributes() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType type = encounterService.getEncounterType(1);
    assertFalse(type.getRetired());
    assertNull(type.getRetiredBy());
    assertNull(type.getRetireReason());
    assertNull(type.getDateRetired());
    EncounterType retiredEncType = encounterService.retireEncounterType(type, "Just Testing");
    // make sure its still the same object
    assertEquals(retiredEncType, type);
    // make sure that all the values were filled in
    assertTrue(retiredEncType.getRetired());
    assertNotNull(retiredEncType.getDateRetired());
    assertEquals(Context.getAuthenticatedUser(), retiredEncType.getRetiredBy());
    assertEquals("Just Testing", retiredEncType.getRetireReason());
}
Also used : EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 50 with EncounterType

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

the class EncounterServiceTest method canViewAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToViewEncounters.

/**
 * @see EncounterService#canViewAllEncounterTypes(User)
 */
@Test
public void canViewAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToViewEncounters() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType encounterType = new EncounterType("testing", "desc");
    Privilege viewPrivilege = Context.getUserService().getPrivilege("Some Privilege For View Encounter Types");
    encounterType.setViewPrivilege(viewPrivilege);
    encounterService.saveEncounterType(encounterType);
    User user = Context.getUserService().getUserByUsername("test_user");
    assertNotNull(user);
    assertFalse(encounterService.canViewAllEncounterTypes(user));
    Role role = Context.getUserService().getRole("Provider");
    role.addPrivilege(viewPrivilege);
    user.addRole(role);
    assertTrue(encounterService.canViewAllEncounterTypes(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)

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