From 1ec74ab00b9bf806e7d82311b7c356800068c6bc Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Tue, 15 Oct 2024 16:08:33 -0400 Subject: [PATCH] RA-2055 - Overall actions on registration summary should support visit in the context model --- ...RegistrationSummaryFragmentController.java | 22 ++++++++++++++++++- ...strationSummaryFragmentControllerTest.java | 14 +++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/summary/RegistrationSummaryFragmentController.java b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/summary/RegistrationSummaryFragmentController.java index 82e35052..950ca7f4 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/summary/RegistrationSummaryFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/summary/RegistrationSummaryFragmentController.java @@ -2,6 +2,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.Predicate; +import org.openmrs.Location; import org.openmrs.Patient; import org.openmrs.api.AdministrationService; import org.openmrs.module.appframework.context.AppContextModel; @@ -10,7 +11,10 @@ import org.openmrs.module.appframework.service.AppFrameworkService; import org.openmrs.module.appui.UiSessionContext; import org.openmrs.module.coreapps.contextmodel.PatientContextModel; +import org.openmrs.module.coreapps.contextmodel.VisitContextModel; +import org.openmrs.module.emrapi.adt.AdtService; import org.openmrs.module.emrapi.patient.PatientDomainWrapper; +import org.openmrs.module.emrapi.visit.VisitDomainWrapper; import org.openmrs.module.registrationapp.RegistrationAppConstants; import org.openmrs.module.registrationapp.converter.RegistrationSummaryExtensionsGenerator; import org.openmrs.ui.framework.annotation.InjectBeans; @@ -29,6 +33,7 @@ public void controller(FragmentConfiguration config, FragmentModel model, @SpringBean AppFrameworkService appFrameworkService, @SpringBean("adminService") AdministrationService administrationService, + @SpringBean("adtService") AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper, @RequestParam(value = "search", required = false) String search, // context for going back to registration landing page UiSessionContext sessionContext @@ -45,8 +50,23 @@ public void controller(FragmentConfiguration config, patientDomainWrapper = (PatientDomainWrapper) patient; appContextModel.put("patient", new PatientContextModel(((PatientDomainWrapper) patient).getPatient())); } + appContextModel.put("search", search); // TODO consider putting all request params in the module in some structured way - appContextModel.put("patientId", patientDomainWrapper != null ? patientDomainWrapper.getPatient().getUuid() : null); // support legacy substitution methods that use "{{patientId}}" as a template and expect a uuid substitution + appContextModel.put("patientId", patientDomainWrapper != null ? patientDomainWrapper.getPatient().getUuid() : null); // support legacy substitution methods that use "{{patientId}}" as a template and expect a uuid substitution + appContextModel.put("visit", null); + + try { + Location visitLocation = adtService.getLocationThatSupportsVisits(sessionContext.getSessionLocation()); + if (visitLocation != null && patientDomainWrapper != null) { + VisitDomainWrapper activeVisit = adtService.getActiveVisit(patientDomainWrapper.getPatient(), visitLocation); + if (activeVisit != null) { + appContextModel.put("visit", new VisitContextModel(activeVisit)); + } + } + } + catch (IllegalArgumentException ex) { + // location does not support visits + } model.addAttribute("patient", patientDomainWrapper); model.addAttribute("appContextModel", appContextModel); diff --git a/omod/src/test/java/org/openmrs/module/registrationapp/fragment/controller/RegistrationSummaryFragmentControllerTest.java b/omod/src/test/java/org/openmrs/module/registrationapp/fragment/controller/RegistrationSummaryFragmentControllerTest.java index f0313272..c3656fe6 100644 --- a/omod/src/test/java/org/openmrs/module/registrationapp/fragment/controller/RegistrationSummaryFragmentControllerTest.java +++ b/omod/src/test/java/org/openmrs/module/registrationapp/fragment/controller/RegistrationSummaryFragmentControllerTest.java @@ -22,6 +22,7 @@ import org.openmrs.module.appframework.domain.Extension; import org.openmrs.module.appframework.service.AppFrameworkService; import org.openmrs.module.appui.UiSessionContext; +import org.openmrs.module.emrapi.adt.AdtService; import org.openmrs.module.emrapi.patient.PatientDomainWrapper; import org.openmrs.module.registrationapp.RegistrationAppConstants; import org.openmrs.module.registrationapp.fragment.controller.summary.RegistrationSummaryFragmentController; @@ -45,6 +46,8 @@ public class RegistrationSummaryFragmentControllerTest { private PatientDomainWrapper patientDomainWrapper; private AppFrameworkService appFrameworkService; + + private AdtService adtService; private List firstColFragments; @@ -73,6 +76,7 @@ public void setUp() throws Exception { when(appFrameworkService.getApp(eq((String) fragmentConfig.get("appId")))).thenReturn(appDescriptor); administrationService = mock(AdministrationService.class); + adtService = mock(AdtService.class); sessionContext = mock(UiSessionContext.class); when(sessionContext.generateAppContextModel()).thenReturn(new AppContextModel()); @@ -85,7 +89,7 @@ public void controller_shouldAutoGenerateSummaryWidgetsOnDefaultColumnWhenNoneCo when(administrationService.getGlobalProperty(eq(RegistrationAppConstants.DISTRIBUTE_SUMMARY_WIDGETS), eq("false"))).thenReturn("false"); // replay - regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService + regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService, adtService ,patientDomainWrapper ,null, sessionContext); List firstColumnFragments = (ArrayList) fragmentModel.getAttribute("firstColumnFragments"); @@ -107,7 +111,7 @@ public void controller_shouldAutoGenerateDistributedSummaryWidgetsWhenNoneConfig when(administrationService.getGlobalProperty(eq(RegistrationAppConstants.DISTRIBUTE_SUMMARY_WIDGETS), eq("false"))).thenReturn("true"); // replay - regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService + regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService, adtService ,patientDomainWrapper ,null, sessionContext); List firstColumnFragments = (ArrayList) fragmentModel.getAttribute("firstColumnFragments"); @@ -131,7 +135,7 @@ public void controller_shouldNotAutoGenerateDistributedSummaryWidgetsWhenConfigu when(administrationService.getGlobalProperty(eq(RegistrationAppConstants.DISTRIBUTE_SUMMARY_WIDGETS), eq("false"))).thenReturn("false"); //replay - regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService + regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService, adtService ,patientDomainWrapper ,null, sessionContext); List firstColumnFragments = (ArrayList) fragmentModel.getAttribute("firstColumnFragments"); @@ -153,7 +157,7 @@ public void controller_shouldNotAutoGenerateDistributedSummaryWidgetsWhenConfigu when(administrationService.getGlobalProperty(eq(RegistrationAppConstants.DISTRIBUTE_SUMMARY_WIDGETS), eq("false"))).thenReturn("false"); //replay - regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService + regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService, adtService ,patientDomainWrapper ,null, sessionContext); List firstColumnFragments = (ArrayList) fragmentModel.getAttribute("firstColumnFragments"); @@ -180,7 +184,7 @@ public void controller_shouldNotAutoGenerateDistributedSummaryWidgetsWhenConfigu when(administrationService.getGlobalProperty(eq(RegistrationAppConstants.DISTRIBUTE_SUMMARY_WIDGETS), eq("false"))).thenReturn("false"); //replay - regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService + regSummaryFragmentcontroller.controller(fragmentConfig, fragmentModel, appFrameworkService, administrationService, adtService ,patientDomainWrapper ,null, sessionContext); List firstColumnFragments = (ArrayList) fragmentModel.getAttribute("firstColumnFragments");