use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited.
/**
* @see EncounterService#saveEncounterType(EncounterType)
*/
@Test
public void saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited() {
EncounterService es = Context.getEncounterService();
// Create encounter type, ensure creator/dateCreated are set, and changedBy and dateChanged are not setDateCreated.
EncounterType encounterType = es.saveEncounterType(new EncounterType("testing", "desc"));
User creator = encounterType.getCreator();
Date dateCreated = encounterType.getDateCreated();
assertNotNull("creator should be set after saving", creator);
assertNotNull("date creates should be set after saving", dateCreated);
assertNull("changed by should not be set after creation", encounterType.getChangedBy());
assertNull("date changed should not be set after creation", encounterType.getDateChanged());
// Edit encounter type.
encounterType.setDescription("This has been a test!");
EncounterType editedEt = es.saveEncounterType(encounterType);
Context.flushSession();
// Ensure creator/dateCreated remain unchanged, and changedBy and dateChanged are set.
assertTrue("creator should not change during edit", creator.equals(editedEt.getCreator()));
assertTrue("date created should not changed during edit", dateCreated.equals(editedEt.getDateCreated()));
assertNotNull("changed by should be set after edit", editedEt.getChangedBy());
assertNotNull("date changed should be set after edit", editedEt.getDateChanged());
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method voidEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter.
/**
* @see EncounterService#voidEncounter(Encounter, String)
*/
@Test(expected = APIException.class)
public void voidEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter() {
// get encounter that has type with edit privilege set
Encounter encounter = getEncounterWithEditPrivilege();
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
// left this user as is - i.e. without required privilege
// and authenticate under it's account
Context.becomeUser(user.getSystemId());
// have to add privilege in order to be able to call voidEncounter(Encounter,String) method
Context.addProxyPrivilege(PrivilegeConstants.EDIT_ENCOUNTERS);
Context.getEncounterService().voidEncounter(encounter, "test");
}
use of org.openmrs.User in project openmrs-core by openmrs.
the class EncounterServiceTest method canViewEncounter_shouldReturnTrueIfUserCanViewEncounter.
/**
* @see EncounterService#canViewEncounter(Encounter, User)
*/
@Test
public void canViewEncounter_shouldReturnTrueIfUserCanViewEncounter() {
// get encounter that has type with view privilege set
Encounter encounter = getEncounterWithViewPrivilege();
User user = Context.getUserService().getUserByUsername("test_user");
assertNotNull(user);
// add required privilege to role in which this user is
Role role = Context.getUserService().getRole("Provider");
role.addPrivilege(encounter.getEncounterType().getViewPrivilege());
user.addRole(role);
assertTrue(Context.getEncounterService().canViewEncounter(encounter, user));
}
use of org.openmrs.User 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.User 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());
}
Aggregations