use of org.openmrs.Location 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.Location 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.Location in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method testParsingDispositionWithAdmissionLocation.
@Test
public void testParsingDispositionWithAdmissionLocation() throws Exception {
Concept admit = new ConceptBuilder(null, conceptService.getConceptDatatypeByName("N/A"), conceptService.getConceptClassByName("Misc")).addName("Admit").get();
when(emrConceptService.getConcept("test:admit")).thenReturn(admit);
Obs dispositionObs = dispositionDescriptor.buildObsGroup(new Disposition("emrapi.admit", "Admit", "test:admit", Collections.<String>emptyList(), Collections.<DispositionObs>emptyList()), emrConceptService);
Obs admissionLocationObs = new Obs();
admissionLocationObs.setObsId(100);
admissionLocationObs.setConcept(dispositionDescriptor.getAdmissionLocationConcept());
admissionLocationObs.setValueText("3");
dispositionObs.addGroupMember(admissionLocationObs);
Location admissionLocation = new Location();
admissionLocation.setName("Outpatient clinic");
when(locationService.getLocation(3)).thenReturn(admissionLocation);
encounter.addObs(doNotGoToServiceToFormatMembers(dispositionObs));
ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
SimpleObject expectedAdmissionLocationObject = SimpleObject.create("obsId", admissionLocationObs.getObsId());
expectedAdmissionLocationObject.put("question", "Admission location");
expectedAdmissionLocationObject.put("answer", "Outpatient clinic");
List<SimpleObject> expectedAdditionalObsList = new ArrayList<SimpleObject>();
expectedAdditionalObsList.add(expectedAdmissionLocationObject);
assertThat(parsed.getDiagnoses().size(), is(0));
assertThat(parsed.getDispositions().size(), is(1));
assertThat(parsed.getObs().size(), is(0));
assertThat(path(parsed.getDispositions(), 0, "disposition"), is((Object) "Admit"));
assertThat(path(parsed.getDispositions(), 0, "additionalObs"), is((Object) expectedAdditionalObsList));
}
use of org.openmrs.Location in project openmrs-module-coreapps by openmrs.
the class RetrospectiveVisitFragmentControllerTest method test_shouldCreateNewRetrospectiveVisit_whenNoStopDateSpecified.
@Test
public void test_shouldCreateNewRetrospectiveVisit_whenNoStopDateSpecified() throws Exception {
when(ui.message("coreapps.retrospectiveVisit.addedVisitMessage")).thenReturn("success message");
Patient patient = createPatient();
Location location = new Location();
Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();
// should round to the time components to the start and end of the days, respectively
Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
Date expectedStopDate = new DateTime(2012, 1, 1, 23, 59, 59, 999).toDate();
Visit visit = createVisit();
when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenReturn(new VisitDomainWrapper(visit));
SimpleObject result = (SimpleObject) controller.create(adtService, patient, location, startDate, null, request, ui);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
assertTrue((Boolean) result.get("success"));
assertThat((String) result.get("id"), is(visit.getId().toString()));
assertThat((String) result.get("uuid"), is(visit.getUuid()));
}
use of org.openmrs.Location in project openmrs-module-coreapps by openmrs.
the class RetrospectiveVisitFragmentControllerTest method test_shouldCreateNewRetrospectiveVisit.
@Test
public void test_shouldCreateNewRetrospectiveVisit() throws Exception {
when(ui.message("coreapps.retrospectiveVisit.addedVisitMessage")).thenReturn("success message");
Patient patient = createPatient();
Location location = new Location();
Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();
Date stopDate = new DateTime(2012, 1, 2, 13, 13, 13).toDate();
// should round to the time components to the start and end of the days, respectively
Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
Date expectedStopDate = new DateTime(2012, 1, 2, 23, 59, 59, 999).toDate();
Visit visit = createVisit();
when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenReturn(new VisitDomainWrapper(visit));
SimpleObject result = (SimpleObject) controller.create(adtService, patient, location, startDate, stopDate, request, ui);
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, ui.message("coreapps.retrospectiveVisit.addedVisitMessage"));
verify(session).setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
assertTrue((Boolean) result.get("success"));
assertThat((String) result.get("id"), is(visit.getId().toString()));
assertThat((String) result.get("uuid"), is(visit.getUuid()));
}
Aggregations