use of org.openmrs.module.coreapps.contextmodel.VisitContextModel 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.coreapps.contextmodel.VisitContextModel 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));
}
use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-pihcore by PIH.
the class RequireUtilTest method shouldReturnTrueIfProperLocationTagAndUserHasConsultPrivilegeAndActiveVisit.
@Test
public void shouldReturnTrueIfProperLocationTagAndUserHasConsultPrivilegeAndActiveVisit() {
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(true);
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(true));
}
use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-pihcore by PIH.
the class RequireUtilTest method shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilegeThisProviderOnlyAndVisitInLastThirtyDays.
@Test
public void shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilegeThisProviderOnlyAndVisitInLastThirtyDays() {
// doctor has last thirty days privilege
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(new DateTime().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(true));
}
use of org.openmrs.module.coreapps.contextmodel.VisitContextModel in project openmrs-module-coreapps by openmrs.
the class PatientPageController method controller.
public Object controller(@RequestParam("patientId") Patient patient, PageModel model, @RequestParam(required = false, value = "app") AppDescriptor app, @RequestParam(required = false, value = "dashboard") String dashboard, @InjectBeans PatientDomainWrapper patientDomainWrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitService") VisitService visitService, @SpringBean("encounterService") EncounterService encounterService, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("applicationEventService") ApplicationEventService applicationEventService, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, UiSessionContext sessionContext) {
if (!Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_DASHBOARD)) {
return new Redirect("coreapps", "noAccess", "");
} else if (patient.isVoided() || patient.isPersonVoided()) {
return new Redirect("coreapps", "patientdashboard/deletedPatient", "patientId=" + patient.getId());
}
if (StringUtils.isEmpty(dashboard)) {
dashboard = "patientDashboard";
}
patientDomainWrapper.setPatient(patient);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("app", app);
Location visitLocation = null;
try {
visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
} catch (IllegalArgumentException ex) {
// location does not support visits
}
VisitDomainWrapper activeVisit = null;
if (visitLocation != null) {
activeVisit = adtService.getActiveVisit(patient, visitLocation);
}
model.addAttribute("activeVisit", activeVisit);
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patient", new PatientContextModel(patient));
contextModel.put("visit", activeVisit == null ? null : new VisitContextModel(activeVisit));
model.addAttribute("appContextModel", contextModel);
List<Extension> overallActions = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".overallActions", contextModel);
Collections.sort(overallActions);
model.addAttribute("overallActions", overallActions);
List<Extension> visitActions;
if (activeVisit == null) {
visitActions = new ArrayList<Extension>();
} else {
visitActions = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".visitActions", contextModel);
Collections.sort(visitActions);
}
model.addAttribute("visitActions", visitActions);
List<Extension> includeFragments = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".includeFragments", contextModel);
Collections.sort(includeFragments);
model.addAttribute("includeFragments", includeFragments);
List<Extension> firstColumnFragments = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".firstColumnFragments", contextModel);
Collections.sort(firstColumnFragments);
model.addAttribute("firstColumnFragments", firstColumnFragments);
List<Extension> secondColumnFragments = appFrameworkService.getExtensionsForCurrentUser(dashboard + ".secondColumnFragments", contextModel);
Collections.sort(secondColumnFragments);
model.addAttribute("secondColumnFragments", secondColumnFragments);
List<Extension> otherActions = appFrameworkService.getExtensionsForCurrentUser((dashboard == "patientDashboard" ? "clinicianFacingPatientDashboard" : dashboard) + ".otherActions", contextModel);
Collections.sort(otherActions);
model.addAttribute("otherActions", otherActions);
// used for breadcrumbs to link back to the base dashboard in the case when this is used to render a context-specific dashboard
model.addAttribute("baseDashboardUrl", coreAppsProperties.getDashboardUrl());
model.addAttribute("dashboard", dashboard);
applicationEventService.patientViewed(patient, sessionContext.getCurrentUser());
return null;
}
Aggregations