Search in sources :

Example 81 with Encounter

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());
}
Also used : Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 82 with Encounter

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");
}
Also used : User(org.openmrs.User) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 83 with Encounter

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());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 84 with Encounter

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));
}
Also used : Role(org.openmrs.Role) EncounterRole(org.openmrs.EncounterRole) User(org.openmrs.User) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 85 with Encounter

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;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Privilege(org.openmrs.Privilege)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19