use of org.openmrs.module.appframework.context.AppContextModel 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));
}
use of org.openmrs.module.appframework.context.AppContextModel 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;
}
use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-coreapps by openmrs.
the class PatientDashboardPageController method controller.
public Object controller(@RequestParam("patientId") Patient patient, @RequestParam(value = "visitId", required = false) Visit visit, @RequestParam(value = "tab", defaultValue = "visits") String selectedTab, PageModel model, @InjectBeans PatientDomainWrapper patientDomainWrapper, @SpringBean("orderService") OrderService orderService, @SpringBean("adtService") AdtService adtService, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @SpringBean("applicationEventService") ApplicationEventService applicationEventService, UiSessionContext sessionContext) {
if (!Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_PATIENT_VISITS)) {
return new Redirect("coreapps", "noAccess", "");
} else if (patient.isVoided() || patient.isPersonVoided()) {
return new Redirect("coreapps", "patientdashboard/deletedPatient", "patientId=" + patient.getId());
}
patientDomainWrapper.setPatient(patient);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("selectedTab", selectedTab);
model.addAttribute("selectedVisit", visit);
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);
List<Extension> encounterTemplateExtensions = appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION);
model.addAttribute("encounterTemplateExtensions", encounterTemplateExtensions);
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("patientDashboard.overallActions", contextModel);
Collections.sort(overallActions);
model.addAttribute("overallActions", overallActions);
List<Extension> includeFragments = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.includeFragments");
Collections.sort(includeFragments);
model.addAttribute("includeFragments", includeFragments);
List<Extension> visitActions = appFrameworkService.getExtensionsForCurrentUser("patientDashboard.visitActions");
Collections.sort(visitActions);
model.addAttribute("visitActions", visitActions);
model.addAttribute("patientTabs", appFrameworkService.getExtensionsForCurrentUser("patientDashboard.tabs"));
model.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
model.addAttribute("encounterCount", coreAppsProperties.getPatientDashboardEncounterCount());
applicationEventService.patientViewed(patient, sessionContext.getCurrentUser());
return null;
}
use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-coreapps by openmrs.
the class SummaryDashboardPageController method controller.
public Object controller(@RequestParam("app") AppDescriptor app, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, PageModel model, UiSessionContext sessionContext) {
if (!Context.hasPrivilege(CoreAppsConstants.PRIVILEGE_SUMMARY_DASHBOARD)) {
return new Redirect("coreapps", "noAccess", "");
}
model.addAttribute("app", app);
AppContextModel contextModel = sessionContext.generateAppContextModel();
model.addAttribute("appContextModel", contextModel);
List<Extension> actions = appFrameworkService.getExtensionsForCurrentUser(app.getId() + ".actions", contextModel);
Collections.sort(actions);
model.addAttribute("actions", actions);
List<Extension> includeFragments = appFrameworkService.getExtensionsForCurrentUser(app.getId() + ".includeFragments", contextModel);
Collections.sort(includeFragments);
model.addAttribute("includeFragments", includeFragments);
List<Extension> firstColumnFragments = appFrameworkService.getExtensionsForCurrentUser(app.getId() + ".firstColumnFragments", contextModel);
Collections.sort(firstColumnFragments);
model.addAttribute("firstColumnFragments", firstColumnFragments);
List<Extension> secondColumnFragments = appFrameworkService.getExtensionsForCurrentUser(app.getId() + ".secondColumnFragments", contextModel);
Collections.sort(secondColumnFragments);
model.addAttribute("secondColumnFragments", secondColumnFragments);
return null;
}
use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-coreapps by openmrs.
the class VisitsSectionFragmentController method controller.
public void controller(FragmentConfiguration config, PageModel pageModel, FragmentModel model, UiUtils ui, UiSessionContext sessionContext, @SpringBean("appframeworkTemplateFactory") TemplateFactory templateFactory, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @InjectBeans PatientDomainWrapper patientWrapper, @SpringBean("adtService") AdtService adtService, @SpringBean("visitTypeHelper") VisitTypeHelper visitTypeHelper) {
config.require("patient");
Object patient = config.get("patient");
if (patient instanceof Patient) {
patientWrapper.setPatient((Patient) patient);
config.addAttribute("patient", patientWrapper);
} else if (patient instanceof PatientDomainWrapper) {
patientWrapper = (PatientDomainWrapper) patient;
}
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patient", new PatientContextModel(patientWrapper.getPatient()));
// backwards-compatible for links that still specify patient uuid substitution with "{{patientId}}"
contextModel.put("patientId", patientWrapper.getPatient().getUuid());
AppDescriptor app = (AppDescriptor) pageModel.get("app");
String visitsPageWithSpecificVisitUrl = null;
String visitsPageUrl = null;
// see if the app specifies urls to use
if (app != null) {
try {
visitsPageWithSpecificVisitUrl = app.getConfig().get("visitUrl").getTextValue();
} catch (Exception ex) {
}
try {
visitsPageUrl = app.getConfig().get("visitsUrl").getTextValue();
} catch (Exception ex) {
}
}
if (visitsPageWithSpecificVisitUrl == null) {
visitsPageWithSpecificVisitUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
}
visitsPageWithSpecificVisitUrl = "/" + ui.contextPath() + "/" + visitsPageWithSpecificVisitUrl;
if (visitsPageUrl == null) {
visitsPageUrl = coreAppsProperties.getVisitsPageUrl();
}
// hack fix for RA-1002--if there is an active visit, and we are using the "regular" visit dashboard we actually want to link to the specific visit
Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation());
VisitDomainWrapper activeVisit = adtService.getActiveVisit(patientWrapper.getPatient(), visitLocation);
if (visitsPageUrl.contains("/coreapps/patientdashboard/patientDashboard.page?") && activeVisit != null) {
visitsPageUrl = coreAppsProperties.getVisitsPageWithSpecificVisitUrl();
contextModel.put("visit", activeVisit.getVisit());
}
visitsPageUrl = "/" + ui.contextPath() + "/" + visitsPageUrl;
model.addAttribute("visitsUrl", templateFactory.handlebars(visitsPageUrl, contextModel));
List<VisitDomainWrapper> recentVisits = patientWrapper.getAllVisitsUsingWrappers();
if (recentVisits.size() > 5) {
recentVisits = recentVisits.subList(0, 5);
}
Map<VisitDomainWrapper, String> recentVisitsWithLinks = new LinkedHashMap<VisitDomainWrapper, String>();
for (VisitDomainWrapper recentVisit : recentVisits) {
contextModel.put("visit", new VisitContextModel(recentVisit));
// since the "recentVisit" isn't part of the context module, we bind it first to the visit url, before doing the handlebars binding against the context
recentVisitsWithLinks.put(recentVisit, templateFactory.handlebars(ui.urlBind(visitsPageWithSpecificVisitUrl, recentVisit.getVisit()), contextModel));
}
Map<Integer, Map<String, Object>> recentVisitsWithAttr = visitTypeHelper.getVisitColorAndShortName(recentVisits);
model.addAttribute("recentVisitsWithAttr", recentVisitsWithAttr);
model.addAttribute("recentVisitsWithLinks", recentVisitsWithLinks);
config.addAttribute("showVisitTypeOnPatientHeaderSection", visitTypeHelper.showVisitTypeOnPatientHeaderSection());
}
Aggregations