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));
}
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);
}
}
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);
}
}
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));
}
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));
}
Aggregations