Search in sources :

Example 21 with Provider

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

the class ProviderServiceTest method unretireProvider_shouldUnretireAProvider.

/**
 * @see ProviderService#unretireProvider(Provider)
 */
@Test
public void unretireProvider_shouldUnretireAProvider() {
    Provider provider = service.getProvider(2);
    service.unretireProvider(provider);
    assertFalse(provider.getRetired());
    assertNull(provider.getRetireReason());
}
Also used : Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with Provider

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

the class ProviderServiceTest method getProvidersByPerson_shouldReturnProvidersForGivenPerson.

/**
 * @see ProviderService#getProvidersByPerson(Person)
 */
@Test
public void getProvidersByPerson_shouldReturnProvidersForGivenPerson() {
    // given
    Person person = Context.getPersonService().getPerson(999);
    Provider provider = new Provider();
    provider.setIdentifier("unique");
    provider.setPerson(person);
    provider = service.saveProvider(provider);
    // when
    Collection<Provider> providers = service.getProvidersByPerson(person);
    // then
    Assert.assertEquals(1, providers.size());
    Assert.assertTrue(providers.contains(provider));
}
Also used : Person(org.openmrs.Person) Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with Provider

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

the class ProviderServiceTest method getProviderByUuid_shouldGetProviderGivenUuid.

/**
 * @see ProviderService#getProviderByUuid(String)
 */
@Test
public void getProviderByUuid_shouldGetProviderGivenUuid() {
    Provider provider = service.getProviderByUuid("ba4781f4-6b94-11e0-93c3-18a905e044dc");
    assertEquals("Collet Test Chebaskwony", provider.getName());
    assertNotNull(provider);
}
Also used : Provider(org.openmrs.Provider) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with Provider

use of org.openmrs.Provider 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)

Example 25 with Provider

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

the class ParseEncounterToJson method createEncounterJSON.

public SimpleObject createEncounterJSON(User authenticatedUser, Encounter encounter) {
    boolean canDelete = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_ENCOUNTER);
    boolean canEdit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_EDIT_ENCOUNTER);
    SimpleObject simpleEncounter = SimpleObject.fromObject(new EncounterDomainWrapper(encounter), uiUtils, "encounterId", "location", "encounterDatetime", "encounterProviders.provider", "voided", "form");
    // UUID is not provided by EncounterDomainWrapper, adding it here.
    simpleEncounter.put("uuid", encounter.getUuid());
    // manually set the date and time components so we can control how we format them
    simpleEncounter.put("encounterDate", DateFormatUtils.format(encounter.getEncounterDatetime(), "dd MMM yyyy", Context.getLocale()));
    simpleEncounter.put("encounterTime", DateFormatUtils.format(encounter.getEncounterDatetime(), "hh:mm a", Context.getLocale()));
    // do the same for other date fields
    simpleEncounter.put("dateCreated", DateFormatUtils.format(encounter.getDateCreated(), "dd MMM yyyy", Context.getLocale()));
    simpleEncounter.put("creator", uiUtils.format(encounter.getCreator()));
    if (encounter.getDateChanged() != null) {
        simpleEncounter.put("dateChanged", DateFormatUtils.format(encounter.getDateChanged(), "dd MMM yyyy", Context.getLocale()));
    }
    if (encounter.getChangedBy() != null) {
        simpleEncounter.put("changedBy", uiUtils.format(encounter.getChangedBy()));
    }
    EncounterType encounterType = encounter.getEncounterType();
    simpleEncounter.put("encounterType", SimpleObject.create("uuid", encounterType.getUuid(), "name", uiUtils.format(encounterType)));
    // determine the provider
    Provider primaryProvider = null;
    // if a primary encounter role has been specified, get the provider for that role
    EncounterRole primaryEncounterRole = getPrimaryEncounterRoleForEncounter(encounter);
    if (primaryEncounterRole != null) {
        Set<Provider> providers = encounter.getProvidersByRole(primaryEncounterRole);
        if (providers != null && !providers.isEmpty()) {
            // for now, if there are multiple providers with this role, return an arbitrary one
            primaryProvider = providers.iterator().next();
        }
    }
    // otherwise, just pick an arbitrary (non-voided) provider
    if (primaryProvider == null) {
        primaryProvider = getFirstNonVoidedProvider(encounter);
    }
    simpleEncounter.put("primaryProvider", uiUtils.format(primaryProvider));
    if (verifyIfUserHasPermissionToDeleteAnEncounter(encounter, authenticatedUser, canDelete)) {
        simpleEncounter.put("canDelete", true);
    }
    if (verifyIfUserHasPermissionToEditAnEncounter(encounter, authenticatedUser, canEdit)) {
        simpleEncounter.put("canEdit", true);
    } else {
        simpleEncounter.put("canEdit", false);
    }
    if (encounter.getVisit() != null) {
        simpleEncounter.put("visitId", encounter.getVisit().getId());
    }
    return simpleEncounter;
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper) SimpleObject(org.openmrs.ui.framework.SimpleObject) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider)

Aggregations

Provider (org.openmrs.Provider)49 Test (org.junit.Test)40 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 Encounter (org.openmrs.Encounter)16 Date (java.util.Date)12 Person (org.openmrs.Person)10 Patient (org.openmrs.Patient)9 EncounterType (org.openmrs.EncounterType)8 EncounterRole (org.openmrs.EncounterRole)7 Location (org.openmrs.Location)7 PersonName (org.openmrs.PersonName)6 TestOrder (org.openmrs.TestOrder)5 Message (ca.uhn.hl7v2.model.Message)4 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)4 DrugOrder (org.openmrs.DrugOrder)4 Order (org.openmrs.Order)4 OrderUtilTest (org.openmrs.order.OrderUtilTest)4 Criteria (org.hibernate.Criteria)3 Concept (org.openmrs.Concept)3 User (org.openmrs.User)3