use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesEditPrivilegeColumnIsNull.
/**
* @see EncounterService#canEditAllEncounterTypes(User)
*/
@Test
public void canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesEditPrivilegeColumnIsNull() {
EncounterService encounterService = Context.getEncounterService();
// set editPrivilege on each encounter type to null
for (EncounterType encounterType : encounterService.getAllEncounterTypes()) {
encounterType.setEditPrivilege(null);
encounterService.saveEncounterType(encounterType);
}
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
assertTrue(encounterService.canEditAllEncounterTypes(user));
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered.
/**
* @see EncounterService#saveEncounter(Encounter)
*/
@Test
public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered() {
Encounter encounter = new Encounter();
encounter.setLocation(new Location(2));
encounter.setEncounterType(new EncounterType(1));
encounter.setEncounterDatetime(new Date());
encounter.setPatient(new Patient(2));
encounter.setCreator(new User(4));
// We should have no visit
assertNull(encounter.getVisit());
GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER);
gp.setPropertyValue("org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler");
Context.getAdministrationService().saveGlobalProperty(gp);
Calendar calendar = Calendar.getInstance();
calendar.setTime(encounter.getEncounterDatetime());
calendar.set(Calendar.YEAR, 1900);
encounter.setEncounterDatetime(calendar.getTime());
Context.getEncounterService().saveEncounter(encounter);
// We should have a visit.
assertNotNull(encounter.getVisit());
// The visit should be persisted.
assertNotNull(encounter.getVisit().getVisitId());
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesViewPrivilegeColumnIsNull.
/**
* @see EncounterService#canViewAllEncounterTypes(User)
*/
@Test
public void canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesViewPrivilegeColumnIsNull() {
EncounterService encounterService = Context.getEncounterService();
// set viewPrivilege on each encounter type to null
for (EncounterType encounterType : encounterService.getAllEncounterTypes()) {
encounterType.setViewPrivilege(null);
encounterService.saveEncounterType(encounterType);
}
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
assertTrue(encounterService.canViewAllEncounterTypes(user));
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters.
/**
* @see EncounterService#filterEncountersByViewPermissions(List, User)
*/
@Test
public void filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters() {
EncounterService encounterService = Context.getEncounterService();
int expectedSize = 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);
encounterType.setViewPrivilege(Context.getUserService().getPrivilege("Some Privilege For View Encounter Types"));
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);
assertEquals(expectedSize + 1, patientEncounters.size());
if (Context.isAuthenticated()) {
Context.logout();
}
Context.authenticate("test_user", "test");
Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
patientEncounters = encounterService.getEncountersByPatientId(3);
int actualSize = patientEncounters.size();
Context.removeProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
Context.logout();
assertEquals(actualSize, expectedSize);
assertTrue(!patientEncounters.contains(encounter));
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method retireEncounterType_shouldThrowErrorIfGivenNullReasonParameter.
/**
* @see EncounterService#retireEncounterType(EncounterType,String)
*/
@Test(expected = IllegalArgumentException.class)
public void retireEncounterType_shouldThrowErrorIfGivenNullReasonParameter() {
EncounterService encounterService = Context.getEncounterService();
EncounterType type = encounterService.getEncounterType(1);
encounterService.retireEncounterType(type, null);
}
Aggregations