use of org.openmrs.Encounter in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterByUuid_shouldFindObjectGivenValidUuid.
/**
* @see EncounterService#getEncounterByUuid(String)
*/
@Test
public void getEncounterByUuid_shouldFindObjectGivenValidUuid() {
String uuid = "6519d653-393b-4118-9c83-a3715b82d4ac";
Encounter encounter = Context.getEncounterService().getEncounterByUuid(uuid);
Assert.assertEquals(3, (int) encounter.getEncounterId());
}
use of org.openmrs.Encounter 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.Encounter in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounters_shouldGetEncountersByType.
/**
* @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
* java.util.Collection, java.util.Collection, boolean)
*/
@Test
public void getEncounters_shouldGetEncountersByType() {
List<EncounterType> types = new ArrayList<>();
types.add(new EncounterType(1));
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setEncounterTypes(types).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
assertEquals(7, encounters.size());
}
use of org.openmrs.Encounter 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.Encounter in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterWithViewPrivilege.
/**
* Gets encounter and adds view privilege to it
*
* @return encounter with type having non null view privilege
*/
private Encounter getEncounterWithViewPrivilege() {
// create service to be used for encounter manipulations
EncounterService encounterService = Context.getEncounterService();
Encounter encounter = encounterService.getEncounter(1);
EncounterType encounterType = encounter.getEncounterType();
// make sure that encounter type is not null
assertNotNull(encounterType);
// set view privilege on this encounter type
Privilege viewPrivilege = Context.getUserService().getPrivilege("Some Privilege For View Encounter Types");
encounterType.setViewPrivilege(viewPrivilege);
encounter.setEncounterType(encounterType);
// update encounter
encounter = encounterService.saveEncounter(encounter);
// make sure that encounter was updated successfully
assertNotNull(encounter);
return encounter;
}
Aggregations