Search in sources :

Example 6 with EncounterRole

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

the class EncounterServiceTest method filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters.

/**
 * @see EncounterService#filterEncountersByViewPermissions(List, User)
 */
@Test
public void filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters() {
    EncounterService encounterService = Context.getEncounterService();
    int expectedSize = encounterService.getEncountersByPatientId(3).size();
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(Context.getPatientService().getPatient(3));
    EncounterType encounterType = new EncounterType(1);
    encounterType.setViewPrivilege(Context.getUserService().getPrivilege("Some Privilege For View Encounter Types"));
    encounter.setEncounterType(encounterType);
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = encounterService.saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    encounter.addProvider(role, provider);
    encounterService.saveEncounter(encounter);
    List<Encounter> patientEncounters = encounterService.getEncountersByPatientId(3);
    assertEquals(expectedSize + 1, patientEncounters.size());
    if (Context.isAuthenticated()) {
        Context.logout();
    }
    Context.authenticate("test_user", "test");
    Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
    patientEncounters = encounterService.getEncountersByPatientId(3);
    int actualSize = patientEncounters.size();
    Context.removeProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
    Context.logout();
    assertEquals(actualSize, expectedSize);
    assertTrue(!patientEncounters.contains(encounter));
}
Also used : Encounter(org.openmrs.Encounter) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 7 with EncounterRole

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

the class EncounterServiceTest method getEncounterRoleByName_shouldFindEncounterRoleByName.

/**
 * @see EncounterService#getEncounterRoleByName(String)
 */
@Test
public void getEncounterRoleByName_shouldFindEncounterRoleByName() {
    EncounterService encounterService = Context.getEncounterService();
    EncounterRole encounterRole = new EncounterRole();
    String name = "surgeon role";
    encounterRole.setDescription("The surgeon");
    encounterRole.setName(name);
    encounterRole = encounterService.saveEncounterRole(encounterRole);
    EncounterRole retrievedEncounterRole = encounterService.getEncounterRoleByName(name);
    assertNotNull("valid EncounterRole object should be returned", retrievedEncounterRole);
    assertEquals(encounterRole.getUuid(), retrievedEncounterRole.getUuid());
}
Also used : EncounterRole(org.openmrs.EncounterRole) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 8 with EncounterRole

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

the class EncounterServiceTest method voidEncounter_shouldNotVoidProviders.

/**
 * @see EncounterService#voidEncounter(Encounter, String)
 */
@Test
public void voidEncounter_shouldNotVoidProviders() {
    EncounterService encounterService = Context.getEncounterService();
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(1));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(3));
    EncounterRole role = new EncounterRole();
    role.setName("role");
    role = encounterService.saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    encounter.addProvider(role, provider);
    encounterService.saveEncounter(encounter);
    assertEquals(1, encounter.getProvidersByRoles().size());
    encounterService.voidEncounter(encounter, "reason");
    encounter = encounterService.getEncounter(encounter.getEncounterId());
    assertEquals(1, encounter.getProvidersByRoles().size());
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 9 with EncounterRole

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

the class RequireNameValidatorTest method validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace.

/**
 * @see RequireNameValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfNameIsNullOrEmptyOrWhitespace() {
    EncounterRole role = new EncounterRole();
    role.setName(null);
    role.setDescription(":(");
    Errors errors = new BindException(role, "type");
    new RequireNameValidator().validate(role, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    role.setName("");
    errors = new BindException(role, "type");
    new RequireNameValidator().validate(role, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    role.setName(" ");
    errors = new BindException(role, "type");
    new RequireNameValidator().validate(role, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
}
Also used : Errors(org.springframework.validation.Errors) EncounterRole(org.openmrs.EncounterRole) BindException(org.springframework.validation.BindException) Test(org.junit.Test)

Example 10 with EncounterRole

use of org.openmrs.EncounterRole in project openmrs-module-coreapps by openmrs.

the class VisitDetailsFragmentControllerTest method shouldReturnEncountersForVisit.

@Test
public void shouldReturnEncountersForVisit() throws ParseException {
    CoreAppsProperties coreAppsProperties = mock(CoreAppsProperties.class);
    when(coreAppsProperties.getPatientDashboardEncounterCount()).thenReturn(100);
    UiSessionContext sessionContext = mock(UiSessionContext.class);
    User authenticatedUser = new User();
    when(sessionContext.getCurrentUser()).thenReturn(authenticatedUser);
    AppContextModel appContextModel = new AppContextModel();
    when(sessionContext.generateAppContextModel()).thenReturn(appContextModel);
    authenticatedUser.addRole(createRoleForUser());
    AdministrationService administrationService = mock(AdministrationService.class);
    when(administrationService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATETIME_FORMAT)).thenReturn("dd.MMM.yyyy, HH:mm:ss");
    AppFrameworkService appFrameworkService = mock(AppFrameworkService.class);
    when(appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION)).thenReturn(generateMockEncounterTemplateExtensions());
    EncounterService encounterService = mock(EncounterService.class);
    Patient patient = mock(Patient.class);
    when(patient.getPatientId()).thenReturn(1);
    when(patient.isDead()).thenReturn(false);
    Visit visit = new Visit();
    Location visitLocation = new Location();
    visitLocation.setName("Visit Location");
    visit.setVisitId(1);
    visit.setLocation(visitLocation);
    visit.setStartDatetime(new Date());
    visit.setStopDatetime(new Date());
    visit.setCreator(authenticatedUser);
    visit.setPatient(patient);
    Location encounterLocation = new Location();
    encounterLocation.setName("Location");
    EncounterType encounterType = new EncounterType();
    encounterType.setName("Encounter Type");
    encounterType.setUuid(encounterTypeUuid);
    Provider primaryProvider = new Provider();
    primaryProvider.setName("Primary Provider");
    EncounterProvider primaryEncounterProvider = new EncounterProvider();
    primaryEncounterProvider.setProvider(primaryProvider);
    EncounterRole primaryEncounterRole = new EncounterRole();
    primaryEncounterRole.setUuid(primaryEncounterRoleUuid);
    primaryEncounterProvider.setEncounterRole(primaryEncounterRole);
    when(encounterService.getEncounterRoleByUuid(primaryEncounterRoleUuid)).thenReturn(primaryEncounterRole);
    Provider secondaryProvider = new Provider();
    secondaryProvider.setName("Secondary Provider");
    EncounterProvider secondaryEncounterProvider = new EncounterProvider();
    secondaryEncounterProvider.setProvider(secondaryProvider);
    secondaryEncounterProvider.setEncounterRole(new EncounterRole());
    Encounter encounter = new Encounter();
    encounter.setEncounterId(7);
    encounter.setEncounterDatetime(new Date());
    encounter.setLocation(encounterLocation);
    encounter.setEncounterType(encounterType);
    encounter.setEncounterProviders(new LinkedHashSet<EncounterProvider>());
    // add secondary provider so that it is the one that is "arbitrarily" returned first
    encounter.getEncounterProviders().add(secondaryEncounterProvider);
    encounter.getEncounterProviders().add(primaryEncounterProvider);
    encounter.setCreator(authenticatedUser);
    encounter.setDateCreated(new Date());
    visit.addEncounter(encounter);
    UiUtils uiUtils = new TestUiUtils(administrationService);
    VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
    SimpleObject response = controller.getVisitDetails(mock(EmrApiProperties.class), coreAppsProperties, appFrameworkService, encounterService, visit, null, null, uiUtils, sessionContext);
    List<SimpleObject> actualEncounters = (List<SimpleObject>) response.get("encounters");
    SimpleObject actualEncounter = actualEncounters.get(0);
    assertThat(response.get("startDatetime"), notNullValue());
    assertThat(response.get("stopDatetime"), notNullValue());
    assertThat((String) response.get("location"), is("Visit Location"));
    assertThat(actualEncounters.size(), is(1));
    assertThat((Integer) actualEncounter.get("encounterId"), is(7));
    assertThat((String) actualEncounter.get("location"), is("Location"));
    assertThat((SimpleObject) actualEncounter.get("encounterType"), isSimpleObjectWith("uuid", encounterType.getUuid(), "name", encounterType.getName()));
    assertThat(actualEncounter.get("encounterDatetime"), notNullValue());
    assertThat(actualEncounter.get("encounterDate"), notNullValue());
    assertThat(actualEncounter.get("encounterTime"), notNullValue());
    assertTrue((Boolean) actualEncounter.get("canEdit"));
    assertThat((String) actualEncounter.get("primaryProvider"), is("Primary Provider"));
    List<SimpleObject> actualProviders = (List<SimpleObject>) actualEncounter.get("encounterProviders");
    assertThat(actualProviders.size(), is(2));
}
Also used : UiSessionContext(org.openmrs.module.appui.UiSessionContext) EncounterProvider(org.openmrs.EncounterProvider) User(org.openmrs.User) SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) TestUiUtils(org.openmrs.module.appui.TestUiUtils) Patient(org.openmrs.Patient) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) EncounterService(org.openmrs.api.EncounterService) Date(java.util.Date) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) AdministrationService(org.openmrs.api.AdministrationService) CoreAppsProperties(org.openmrs.module.coreapps.CoreAppsProperties) EncounterRole(org.openmrs.EncounterRole) Encounter(org.openmrs.Encounter) AppFrameworkService(org.openmrs.module.appframework.service.AppFrameworkService) ArrayList(java.util.ArrayList) List(java.util.List) EncounterType(org.openmrs.EncounterType) Location(org.openmrs.Location) TestUiUtils(org.openmrs.module.appui.TestUiUtils) UiUtils(org.openmrs.ui.framework.UiUtils) Test(org.junit.Test)

Aggregations

EncounterRole (org.openmrs.EncounterRole)22 Test (org.junit.Test)20 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)17 EncounterType (org.openmrs.EncounterType)7 Provider (org.openmrs.Provider)7 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 Date (java.util.Date)6 Encounter (org.openmrs.Encounter)6 Location (org.openmrs.Location)6 Patient (org.openmrs.Patient)4 EncounterProvider (org.openmrs.EncounterProvider)2 SimpleObject (org.openmrs.ui.framework.SimpleObject)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 User (org.openmrs.User)1 Visit (org.openmrs.Visit)1 AdministrationService (org.openmrs.api.AdministrationService)1 EncounterService (org.openmrs.api.EncounterService)1 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)1