Search in sources :

Example 36 with User

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

Example 37 with User

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

Example 38 with User

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

Example 40 with 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());
}
Also used : User(org.openmrs.User) Calendar(java.util.Calendar) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) GlobalProperty(org.openmrs.GlobalProperty) 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