Search in sources :

Example 56 with Location

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;
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Redirect(org.openmrs.ui.framework.page.Redirect) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel)

Example 57 with Location

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;
}
Also used : Extension(org.openmrs.module.appframework.domain.Extension) PatientContextModel(org.openmrs.module.coreapps.contextmodel.PatientContextModel) AppContextModel(org.openmrs.module.appframework.context.AppContextModel) Redirect(org.openmrs.ui.framework.page.Redirect) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location) VisitContextModel(org.openmrs.module.coreapps.contextmodel.VisitContextModel)

Example 58 with Location

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));
}
Also used : Concept(org.openmrs.Concept) DispositionObs(org.openmrs.module.emrapi.disposition.DispositionObs) Obs(org.openmrs.Obs) ConceptBuilder(org.openmrs.module.emrapi.test.builder.ConceptBuilder) SimpleObject(org.openmrs.ui.framework.SimpleObject) Disposition(org.openmrs.module.emrapi.disposition.Disposition) ArrayList(java.util.ArrayList) DispositionObs(org.openmrs.module.emrapi.disposition.DispositionObs) SimpleObject(org.openmrs.ui.framework.SimpleObject) Location(org.openmrs.Location) Test(org.junit.Test)

Example 59 with Location

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()));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) Test(org.junit.Test)

Example 60 with Location

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()));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) Test(org.junit.Test)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15