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());
}
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));
}
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));
}
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());
}
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));
}
Aggregations