From fa392657333f3e9fc91a5148d355fa47079bd0d3 Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Mon, 11 May 2026 15:32:15 -0400 Subject: [PATCH 1/3] RA-2107: AppContextModel: add new "hasAnyActiveVisit" to model --- ...AppContextModelGeneratorComponentTest.java | 158 ++++++++++++++++ .../AppContextModelGeneratorTest.java | 171 ++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100644 omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java create mode 100644 omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java diff --git a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java new file mode 100644 index 000000000..c20462fdf --- /dev/null +++ b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java @@ -0,0 +1,158 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.coreapps.contextmodel; + +import org.junit.Before; +import org.junit.Test; +import org.openmrs.Location; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.VisitType; +import org.openmrs.api.LocationService; +import org.openmrs.api.PatientService; +import org.openmrs.api.VisitService; +import org.openmrs.api.context.Context; +import org.openmrs.module.appframework.context.AppContextModel; +import org.openmrs.module.appui.UiSessionContext; +import org.openmrs.module.emrapi.test.ContextSensitiveMetadataTestUtils; +import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.core.IsNull.nullValue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AppContextModelGeneratorComponentTest extends BaseModuleWebContextSensitiveTest { + + @Autowired + private AppContextModelGenerator generator; + + @Autowired + private LocationService locationService; + + @Autowired + private PatientService patientService; + + @Autowired + private VisitService visitService; + + private Location visitSupportingLocation; + private Patient patient; + + @Before + public void setUp() throws Exception { + ContextSensitiveMetadataTestUtils.setupSupportsVisitLocationTag(locationService); + + // location_id=2 ("Xanadu") from the standard test dataset; we add the Supports Visits tag to it + visitSupportingLocation = locationService.getLocation(2); + visitSupportingLocation.addTag(locationService.getLocationTagByName("Visit Location")); + locationService.saveLocation(visitSupportingLocation); + + // patient 6 has no encounters or programs — keeps tests focused on visit/patient behavior + patient = patientService.getPatient(6); + } + + @Test + public void generateAppContextModel_shouldPopulateActiveVisitWhenOneExists() { + Visit activeVisit = createActiveVisit(patient, visitSupportingLocation); + + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + VisitContextModel visitModel = (VisitContextModel) contextModel.get("visit"); + assertThat(visitModel, notNullValue()); + assertThat(visitModel.getUuid(), is(activeVisit.getUuid())); + assertThat(visitModel.isActive(), is(true)); + } + + @Test + public void generateAppContextModel_shouldSetVisitNullWhenNoActiveVisitExists() { + // patient 7 has only a closed visit in baseTestDataset + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("visit"), nullValue()); + } + + @Test + public void generateAppContextModel_shouldSetVisitNullWhenSessionLocationDoesNotSupportVisits() { + Location nonVisitLocation = locationService.getLocation(1); // "Unknown Location" — no Supports Visits tag + + UiSessionContext sessionContext = mockSessionContext(nonVisitLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("visit"), nullValue()); + } + + @Test + public void generateAppContextModel_shouldUseExplicitVisitInsteadOfLookingUpActiveVisit() { + // Create both an active visit and a closed visit; pass the closed one explicitly + createActiveVisit(patient, visitSupportingLocation); + Visit closedVisit = createClosedVisit(patient, visitSupportingLocation); + + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient, closedVisit); + + VisitContextModel visitModel = (VisitContextModel) contextModel.get("visit"); + assertThat(visitModel, notNullValue()); + assertThat(visitModel.getUuid(), is(closedVisit.getUuid())); + assertThat(visitModel.isActive(), is(false)); + } + + @Test + public void generateAppContextModel_shouldSetPatientAndPatientIdOnContextModel() { + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("patient"), notNullValue()); + assertThat(contextModel.get("patientId"), is(patient.getUuid())); + } + + @Test + public void generateAppContextModel_shouldPopulateEncountersAndProgramsOnContextModel() { + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("encounters"), notNullValue()); + assertThat(contextModel.get("programs"), notNullValue()); + assertThat(contextModel.get("activePrograms"), notNullValue()); + } + + private Visit createActiveVisit(Patient patient, Location location) { + VisitType visitType = visitService.getAllVisitTypes().get(0); + Visit visit = new Visit(patient, visitType, new Date()); + visit.setLocation(location); + return visitService.saveVisit(visit); + } + + private Visit createClosedVisit(Patient patient, Location location) { + VisitType visitType = visitService.getAllVisitTypes().get(0); + Visit visit = new Visit(patient, visitType, new Date()); + visit.setLocation(location); + visit.setStopDatetime(new Date()); + return visitService.saveVisit(visit); + } + + private UiSessionContext mockSessionContext(Location sessionLocation) { + UiSessionContext sessionContext = mock(UiSessionContext.class); + when(sessionContext.generateAppContextModel()).thenReturn(new AppContextModel()); + when(sessionContext.getSessionLocation()).thenReturn(sessionLocation); + return sessionContext; + } +} \ No newline at end of file diff --git a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java new file mode 100644 index 000000000..c4080d476 --- /dev/null +++ b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java @@ -0,0 +1,171 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.coreapps.contextmodel; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.openmrs.Location; +import org.openmrs.Patient; +import org.openmrs.Visit; +import org.openmrs.api.EncounterService; +import org.openmrs.api.ProgramWorkflowService; +import org.openmrs.module.appframework.context.AppContextModel; +import org.openmrs.module.appui.UiSessionContext; +import org.openmrs.module.emrapi.adt.AdtService; +import org.openmrs.module.emrapi.visit.VisitDomainWrapper; + +import java.util.Collections; +import java.util.Date; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.core.IsNull.nullValue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class AppContextModelGeneratorTest { + + @InjectMocks + private AppContextModelGenerator generator; + + @Mock + private AdtService adtService; + + @Mock + private EncounterService encounterService; + + @Mock + private ProgramWorkflowService programWorkflowService; + + private UiSessionContext sessionContext; + private Patient patient; + private Location sessionLocation; + private Location visitSupportingLocation; + + @Before + public void setUp() { + sessionContext = mock(UiSessionContext.class); + patient = new Patient(); + patient.setUuid("patient-uuid"); + + sessionLocation = new Location(); + visitSupportingLocation = new Location(); + + when(sessionContext.generateAppContextModel()).thenReturn(new AppContextModel()); + when(sessionContext.getSessionLocation()).thenReturn(sessionLocation); + when(encounterService.getEncountersByPatient(patient)).thenReturn(Collections.emptyList()); + when(programWorkflowService.getPatientPrograms( + any(Patient.class), any(), any(), any(), any(), any(), anyBoolean() + )).thenReturn(Collections.emptyList()); + } + + @Test + public void generateAppContextModel_shouldSetActiveVisitWhenOneExists() { + VisitDomainWrapper activeVisit = mockVisitDomainWrapper("visit-uuid"); + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenReturn(visitSupportingLocation); + when(adtService.getActiveVisit(patient, visitSupportingLocation)).thenReturn(activeVisit); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + VisitContextModel visit = (VisitContextModel) contextModel.get("visit"); + assertThat(visit, notNullValue()); + assertThat(visit.getUuid(), is("visit-uuid")); + assertThat(visit.isActive(), is(true)); + } + + @Test + public void generateAppContextModel_shouldSetVisitToNullWhenNoActiveVisitExists() { + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenReturn(visitSupportingLocation); + when(adtService.getActiveVisit(patient, visitSupportingLocation)).thenReturn(null); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("visit"), nullValue()); + } + + @Test + public void generateAppContextModel_shouldSetVisitToNullWhenLocationDoesNotSupportVisits() { + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenThrow(new IllegalArgumentException("location does not support visits")); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("visit"), nullValue()); + verify(adtService, never()).getActiveVisit(any(Patient.class), any(Location.class)); + } + + @Test + public void generateAppContextModel_shouldUseProvidedVisitWithoutLookingUpActiveVisit() { + Visit visit = new Visit(); + visit.setStartDatetime(new Date()); + visit.setPatient(patient); + + VisitDomainWrapper wrappedVisit = mockVisitDomainWrapper("explicit-visit-uuid"); + when(adtService.wrap(visit)).thenReturn(wrappedVisit); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient, visit); + + VisitContextModel visitModel = (VisitContextModel) contextModel.get("visit"); + assertThat(visitModel, notNullValue()); + assertThat(visitModel.getUuid(), is("explicit-visit-uuid")); + verify(adtService, never()).getLocationThatSupportsVisits(any(Location.class)); + verify(adtService, never()).getActiveVisit(any(Patient.class), any(Location.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void generateAppContextModel_shouldThrowIfPatientAndVisitPatientMismatch() { + Patient otherPatient = new Patient(); + otherPatient.setUuid("other-patient-uuid"); + + Visit visit = new Visit(); + visit.setPatient(otherPatient); + + generator.generateAppContextModel(sessionContext, patient, visit); + } + + @Test + public void generateAppContextModel_shouldSetPatientAndPatientIdOnContextModel() { + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenReturn(visitSupportingLocation); + when(adtService.getActiveVisit(patient, visitSupportingLocation)).thenReturn(null); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("patient"), notNullValue()); + assertThat(contextModel.get("patientId"), is("patient-uuid")); + } + + private VisitDomainWrapper mockVisitDomainWrapper(String uuid) { + VisitDomainWrapper wrapper = mock(VisitDomainWrapper.class); + Visit visit = new Visit(); + visit.setUuid(uuid); + visit.setStartDatetime(new Date()); + when(wrapper.getVisit()).thenReturn(visit); + when(wrapper.getVisitId()).thenReturn(1); + when(wrapper.isOpen()).thenReturn(true); + when(wrapper.isAdmitted()).thenReturn(false); + when(wrapper.getStartDatetime()).thenReturn(new Date()); + when(wrapper.getStopDatetime()).thenReturn(null); + when(wrapper.getSortedEncounters()).thenReturn(Collections.emptyList()); + return wrapper; + } +} \ No newline at end of file From 9035a983d73d3744c62a6ccadb551168e59e084b Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Mon, 11 May 2026 17:00:52 -0400 Subject: [PATCH 2/3] RA-2107: AppContextModel: add new "hasAnyActiveVisit" to model --- .../AppContextModelGenerator.java | 7 ++++ ...AppContextModelGeneratorComponentTest.java | 21 ++++++++++ .../AppContextModelGeneratorTest.java | 39 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/omod/src/main/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGenerator.java b/omod/src/main/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGenerator.java index 975e1e86a..aaeb6af95 100644 --- a/omod/src/main/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGenerator.java +++ b/omod/src/main/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGenerator.java @@ -23,6 +23,7 @@ import org.openmrs.Visit; import org.openmrs.api.EncounterService; import org.openmrs.api.ProgramWorkflowService; +import org.openmrs.api.VisitService; import org.openmrs.module.appframework.context.AppContextModel; import org.openmrs.module.appui.UiSessionContext; import org.openmrs.module.emrapi.adt.AdtService; @@ -48,6 +49,9 @@ public class AppContextModelGenerator { @Autowired ProgramWorkflowService programWorkflowService; + @Autowired + VisitService visitService; + /** * Generates an AppContextModel for the given patient */ @@ -86,6 +90,9 @@ public AppContextModel generateAppContextModel(UiSessionContext sessionContext, contextModel.put("patient", new PatientContextModel(patient)); contextModel.put("patientId", patient != null ? patient.getUuid() : null); // support legacy substitution methods that use "{{patientId}}" as a template and expect a uuid substitution contextModel.put("visit", visitDomainWrapper == null ? null : new VisitContextModel(visitDomainWrapper)); + boolean hasAnyActiveVisit = visitDomainWrapper != null + || (patient != null && !visitService.getActiveVisitsByPatient(patient).isEmpty()); + contextModel.put("hasAnyActiveVisit", hasAnyActiveVisit); List encounterTypes = new ArrayList<>(); ArrayList encountersModel = new ArrayList<>(); diff --git a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java index c20462fdf..c915ed2bb 100644 --- a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java @@ -124,6 +124,27 @@ public void generateAppContextModel_shouldSetPatientAndPatientIdOnContextModel() assertThat(contextModel.get("patientId"), is(patient.getUuid())); } + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueWhenActiveVisitExistsAtAnyLocation() { + createActiveVisit(patient, locationService.getLocation(1)); // a location without the Supports Visits tag + + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("hasAnyActiveVisit"), is(true)); + } + + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitFalseWhenNoActiveVisitsExist() { + // patient 8 has no visits at all in the standard dataset + Patient patientWithNoVisits = patientService.getPatient(8); + + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patientWithNoVisits); + + assertThat(contextModel.get("hasAnyActiveVisit"), is(false)); + } + @Test public void generateAppContextModel_shouldPopulateEncountersAndProgramsOnContextModel() { UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); diff --git a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java index c4080d476..211889621 100644 --- a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java +++ b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorTest.java @@ -24,6 +24,7 @@ import org.openmrs.Visit; import org.openmrs.api.EncounterService; import org.openmrs.api.ProgramWorkflowService; +import org.openmrs.api.VisitService; import org.openmrs.module.appframework.context.AppContextModel; import org.openmrs.module.appui.UiSessionContext; import org.openmrs.module.emrapi.adt.AdtService; @@ -58,6 +59,9 @@ public class AppContextModelGeneratorTest { @Mock private ProgramWorkflowService programWorkflowService; + @Mock + private VisitService visitService; + private UiSessionContext sessionContext; private Patient patient; private Location sessionLocation; @@ -78,6 +82,7 @@ public void setUp() { when(programWorkflowService.getPatientPrograms( any(Patient.class), any(), any(), any(), any(), any(), anyBoolean() )).thenReturn(Collections.emptyList()); + when(visitService.getActiveVisitsByPatient(patient)).thenReturn(Collections.emptyList()); } @Test @@ -154,6 +159,40 @@ public void generateAppContextModel_shouldSetPatientAndPatientIdOnContextModel() assertThat(contextModel.get("patientId"), is("patient-uuid")); } + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueWithoutServiceCallWhenVisitDomainWrapperIsNotNull() { + VisitDomainWrapper activeVisit = mockVisitDomainWrapper("visit-uuid"); + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenReturn(visitSupportingLocation); + when(adtService.getActiveVisit(patient, visitSupportingLocation)).thenReturn(activeVisit); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("hasAnyActiveVisit"), is(true)); + verify(visitService, never()).getActiveVisitsByPatient(any(Patient.class)); + } + + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueViaServiceCallWhenActiveVisitExistsElsewhere() { + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenReturn(visitSupportingLocation); + when(adtService.getActiveVisit(patient, visitSupportingLocation)).thenReturn(null); + when(visitService.getActiveVisitsByPatient(patient)).thenReturn(Collections.singletonList(new Visit())); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("hasAnyActiveVisit"), is(true)); + } + + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitFalseWhenPatientHasNoActiveVisits() { + when(adtService.getLocationThatSupportsVisits(sessionLocation)).thenReturn(visitSupportingLocation); + when(adtService.getActiveVisit(patient, visitSupportingLocation)).thenReturn(null); + when(visitService.getActiveVisitsByPatient(patient)).thenReturn(Collections.emptyList()); + + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("hasAnyActiveVisit"), is(false)); + } + private VisitDomainWrapper mockVisitDomainWrapper(String uuid) { VisitDomainWrapper wrapper = mock(VisitDomainWrapper.class); Visit visit = new Visit(); From 1bc0001e85bbefe68338f29acec83e0e027926af Mon Sep 17 00:00:00 2001 From: mogoodrich Date: Mon, 11 May 2026 17:17:17 -0400 Subject: [PATCH 3/3] RA-2107: AppContextModel: add new "hasAnyActiveVisit" to model --- ...AppContextModelGeneratorComponentTest.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java index c915ed2bb..bb6c4b76f 100644 --- a/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java +++ b/omod/src/test/java/org/openmrs/module/coreapps/contextmodel/AppContextModelGeneratorComponentTest.java @@ -125,12 +125,37 @@ public void generateAppContextModel_shouldSetPatientAndPatientIdOnContextModel() } @Test - public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueWhenActiveVisitExistsAtAnyLocation() { - createActiveVisit(patient, locationService.getLocation(1)); // a location without the Supports Visits tag + public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueViaShortCircuitWhenActiveVisitFoundAtSessionLocation() { + // visitDomainWrapper is non-null from getActiveVisit — no service call needed + createActiveVisit(patient, visitSupportingLocation); + + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + + assertThat(contextModel.get("visit"), notNullValue()); + assertThat(contextModel.get("hasAnyActiveVisit"), is(true)); + } + + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueViaShortCircuitWhenExplicitVisitPassed() { + // visitDomainWrapper is non-null from wrap(visit) — no service call needed + Visit activeVisit = createActiveVisit(patient, visitSupportingLocation); + + UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); + AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient, activeVisit); + + assertThat(contextModel.get("hasAnyActiveVisit"), is(true)); + } + + @Test + public void generateAppContextModel_shouldSetHasAnyActiveVisitTrueWhenActiveVisitExistsAtNonSessionLocation() { + // visitDomainWrapper is null (no active visit at session location), falls back to service call + createActiveVisit(patient, locationService.getLocation(1)); // location without Visit Location tag UiSessionContext sessionContext = mockSessionContext(visitSupportingLocation); AppContextModel contextModel = generator.generateAppContextModel(sessionContext, patient); + assertThat(contextModel.get("visit"), nullValue()); assertThat(contextModel.get("hasAnyActiveVisit"), is(true)); }