Search in sources :

Example 16 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.

the class RequireUtilTest method shouldReturnFalseIfLocationHasTagButVisitNotActive.

@Test
public void shouldReturnFalseIfLocationHasTagButVisitNotActive() {
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
    when(visit.isActive()).thenReturn(false);
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.ADMISSION_LOCATION), patientHasActiveVisit())), appContextModel), is(false));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.

the class HomePageController method controller.

public void controller(PageModel model, UiSessionContext sessionContext, @SpringBean("config") Config config, @SpringBean("featureToggles") FeatureToggleProperties featureToggleProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService) {
    sessionContext.requireAuthentication();
    AppContextModel appContextModel = sessionContext.generateAppContextModel();
    List<Extension> extensions = appFrameworkService.getExtensionsForCurrentUser(HOME_PAGE_EXTENSION_POINT, appContextModel);
    for (int i = 0; i < extensions.size(); i++) {
        Extension extension = extensions.get(i);
        if (extensionFeatureToggledOff(extension, featureToggleProperties)) {
            extensions.remove(i);
            i--;
        }
    }
    Collections.sort(extensions);
    model.addAttribute("extensions", extensions);
    model.addAttribute("privilegeSearchForPatients", Privileges.APP_COREAPPS_FIND_PATIENT.privilege());
    if (Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_DASHBOARD)) {
        if (StringUtils.isNotBlank(config.getDashboardUrl())) {
            model.addAttribute("dashboardUrl", config.getDashboardUrl());
        } else {
            model.addAttribute("dashboardUrl", "/coreapps/patientdashboard/patientDashboard.page?patientId={{patientId}}");
        }
    } else // if the user doesn't have permission to view patient dashboard, we redirect to registration dashboard
    {
        model.addAttribute("dashboardUrl", "/registrationapp/registrationSummary.page?patientId={{patientId}}&appId=" + CustomAppLoaderConstants.Apps.PATIENT_REGISTRATION);
    }
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) AppContextModel(org.openmrs.module.appframework.context.AppContextModel)

Example 18 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-pihcore by PIH.

the class HomePageController method controller.

public void controller(PageModel model, UiSessionContext sessionContext, @SpringBean("config") Config config, @SpringBean("featureToggles") FeatureToggleProperties featureToggleProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService) {
    sessionContext.requireAuthentication();
    AppContextModel appContextModel = sessionContext.generateAppContextModel();
    String findPatientColumnConfigJson = null;
    try {
        ArrayNode findPatientColumnConfig = config.getFindPatientColumnConfig();
        if (findPatientColumnConfig != null) {
            findPatientColumnConfigJson = new ObjectMapper().writeValueAsString(findPatientColumnConfig);
        }
    } catch (Exception e) {
        log.warn("Error parsing find patient column configuration", e);
    }
    model.addAttribute("findPatientColumnConfig", findPatientColumnConfigJson);
    List<Extension> extensions = appFrameworkService.getExtensionsForCurrentUser(HOME_PAGE_EXTENSION_POINT, appContextModel);
    for (int i = 0; i < extensions.size(); i++) {
        Extension extension = extensions.get(i);
        if (extensionFeatureToggledOff(extension, featureToggleProperties)) {
            extensions.remove(i);
            i--;
        }
    }
    Collections.sort(extensions);
    model.addAttribute("extensions", extensions);
    model.addAttribute("privilegeSearchForPatients", PihEmrConfigConstants.PRIVILEGE_APP_COREAPPS_FIND_PATIENT);
    if (Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_DASHBOARD)) {
        if (StringUtils.isNotBlank(config.getDashboardUrl())) {
            model.addAttribute("dashboardUrl", config.getDashboardUrl());
        } else {
            model.addAttribute("dashboardUrl", "/coreapps/patientdashboard/patientDashboard.page?patientId={{patientId}}");
        }
    } else // if the user doesn't have permission to view patient dashboard, we redirect to registration dashboard
    {
        model.addAttribute("dashboardUrl", "/registrationapp/registrationSummary.page?patientId={{patientId}}&appId=" + CustomAppLoaderConstants.Apps.PATIENT_REGISTRATION);
    }
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) ArrayNode(org.codehaus.jackson.node.ArrayNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 19 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-pihcore by PIH.

the class RequireUtilTest method shouldReturnFalseIfNotProperLocationTagAndUserHasRetroPrivilege.

@Test
public void shouldReturnFalseIfNotProperLocationTagAndUserHasRetroPrivilege() {
    user.addRole(admin);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", "Admission Location");
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(new DateTime(2014, 1, 1, 1, 1).getMillis());
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    Config config = mock(Config.class);
    when(config.isComponentEnabled("visitNote")).thenReturn(false);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag("Consult Note Location"), or(and(userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_ENTER_CONSULT_NOTE), patientHasActiveVisit()), userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_RETRO_CLINICAL_NOTE), and(userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY), patientVisitWithinPastThirtyDays(config))))), appContextModel), is(false));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with AppContextModel

use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-pihcore by PIH.

the class RequireUtilTest method shouldReturnFalseIfProperLocationTagAndUserHasConsultPrivilegeButNoActiveVisit.

@Test
public void shouldReturnFalseIfProperLocationTagAndUserHasConsultPrivilegeButNoActiveVisit() {
    user.addRole(doctor);
    Location sessionLocation = new Location();
    SimpleObject sessionLocationRestRep = new SimpleObject();
    sessionLocationRestRep.put("uuid", "123abc");
    SimpleObject admitTag = new SimpleObject();
    admitTag.put("display", "Consult Note Location");
    sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
    PowerMockito.mockStatic(ConversionUtil.class);
    when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
    VisitContextModel visit = mock(VisitContextModel.class);
    when(visit.getStopDatetimeInMilliseconds()).thenReturn(null);
    when(visit.isActive()).thenReturn(false);
    uiSessionContext.setSessionLocation(sessionLocation);
    AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
    appContextModel.put("visit", visit);
    Config config = mock(Config.class);
    when(config.isComponentEnabled("visitNote")).thenReturn(false);
    assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag("Consult Note Location"), or(and(userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_ENTER_CONSULT_NOTE), patientHasActiveVisit()), userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_RETRO_CLINICAL_NOTE), and(userHasPrivilege(PihEmrConfigConstants.PRIVILEGE_TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY), patientVisitWithinPastThirtyDays(config))))), appContextModel), is(false));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Config(org.openmrs.module.pihcore.config.Config) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AppContextModel (org.openmrs.module.appframework.context.AppContextModel)48 Test (org.junit.Test)39 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 Location (org.openmrs.Location)28 SimpleObject (org.openmrs.ui.framework.SimpleObject)27 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)20 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)16 Config (org.openmrs.module.pihcore.config.Config)16 DateTime (org.joda.time.DateTime)8 Extension (org.openmrs.module.appframework.domain.Extension)7 PatientContextModel (org.openmrs.module.coreapps.contextmodel.PatientContextModel)5 Date (java.util.Date)4 Patient (org.openmrs.Patient)4 Redirect (org.openmrs.ui.framework.page.Redirect)3 ArrayList (java.util.ArrayList)2 User (org.openmrs.User)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1