Search in sources :

Example 41 with User

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

Example 42 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounter_shouldNotOverwriteDateCreatedIfNonNull.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldNotOverwriteDateCreatedIfNonNull() {
    EncounterService encounterService = Context.getEncounterService();
    // the encounter to save without a dateCreated
    Encounter encounter = buildEncounter();
    encounter.setCreator(new User(4));
    // make sure we
    Date date = new Date(System.currentTimeMillis() - 5000);
    // have a
    // date that
    // isn't
    // "right now"
    encounter.setDateCreated(date);
    encounterService.saveEncounter(encounter);
    // make sure the encounter creator is user 4 not user 1
    assertEquals(4, encounter.getCreator().getId().intValue());
    assertNotSame(encounter.getCreator(), Context.getAuthenticatedUser());
    // make sure the encounter date created wasn't overwritten
    assertEquals(DateUtil.truncateToSeconds(date), encounter.getDateCreated());
    // make sure we can fetch this new encounter
    // from the database and its values are the same as the passed in ones
    Encounter newEncounter = encounterService.getEncounter(encounter.getEncounterId());
    assertNotNull(newEncounter);
    assertEquals(DateUtil.truncateToSeconds(date), encounter.getDateCreated());
}
Also used : User(org.openmrs.User) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 43 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounter_shouldFailIfUserIsNotAllowedToViewEncounterByGivenId.

/**
 * @see EncounterService#getEncounter(Integer)
 */
@Test(expected = APIException.class)
public void getEncounter_shouldFailIfUserIsNotAllowedToViewEncounterByGivenId() {
    // get encounter that has type with view privilege set
    Encounter encounter = getEncounterWithViewPrivilege();
    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 getEncounter(Integer) method
    Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
    assertNull(Context.getEncounterService().getEncounter(encounter.getId()));
}
Also used : User(org.openmrs.User) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 44 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class EncounterServiceTest method purgeEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter.

/**
 * @see EncounterService#purgeEncounter(Encounter)
 */
@Test(expected = APIException.class)
public void purgeEncounter_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 purgeEncounter(Encounter) method
    Context.addProxyPrivilege(PrivilegeConstants.PURGE_ENCOUNTERS);
    Context.getEncounterService().purgeEncounter(encounter);
}
Also used : User(org.openmrs.User) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 45 with User

use of org.openmrs.User in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounterType_shouldNotOverwriteCreatorOrDateCreated.

/**
 * @see EncounterService#saveEncounterType(EncounterType)
 */
@Test
public void saveEncounterType_shouldNotOverwriteCreatorOrDateCreated() {
    EncounterService encounterService = Context.getEncounterService();
    // the encounter to save without a dateCreated
    EncounterType encounterType = new EncounterType("testing", "desc");
    encounterType.setCreator(new User(4));
    // make sure we have a date that isn't "right now"
    Date date = new Date(System.currentTimeMillis() - 5000);
    encounterType.setDateCreated(date);
    // make sure the logged in user isn't the user we're testing with
    assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
    encounterService.saveEncounterType(encounterType);
    // make sure the encounter type creator is user 4 not user 1
    assertNotSame(encounterType.getCreator().getId(), Context.getAuthenticatedUser().getId());
    // make sure the encounter type date created wasn't overwritten
    assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
    // make sure we can fetch this new encounter type
    // from the database and its values are the same as the passed in ones
    EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId());
    assertNotNull(newEncounterType);
    assertEquals(4, encounterType.getCreator().getId().intValue());
    assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser());
    assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
}
Also used : User(org.openmrs.User) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

User (org.openmrs.User)201 Test (org.junit.Test)150 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)132 Date (java.util.Date)38 Person (org.openmrs.Person)33 Encounter (org.openmrs.Encounter)21 Patient (org.openmrs.Patient)18 PersonName (org.openmrs.PersonName)17 Role (org.openmrs.Role)13 GlobalProperty (org.openmrs.GlobalProperty)11 Location (org.openmrs.Location)11 ArrayList (java.util.ArrayList)10 EncounterType (org.openmrs.EncounterType)10 Locale (java.util.Locale)7 UserService (org.openmrs.api.UserService)7 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 EncounterRole (org.openmrs.EncounterRole)6 PatientIdentifier (org.openmrs.PatientIdentifier)6