Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RA-2055 - Overall actions on registration summary should support visi… #148

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +46,8 @@ public class RegistrationSummaryFragmentControllerTest {
private PatientDomainWrapper patientDomainWrapper;

private AppFrameworkService appFrameworkService;

private AdtService adtService;

private List<Extension> firstColFragments;

Expand Down Expand Up @@ -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());
Expand All @@ -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<Extension> firstColumnFragments = (ArrayList<Extension>) fragmentModel.getAttribute("firstColumnFragments");
Expand All @@ -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<Extension> firstColumnFragments = (ArrayList<Extension>) fragmentModel.getAttribute("firstColumnFragments");
Expand All @@ -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<Extension> firstColumnFragments = (ArrayList<Extension>) fragmentModel.getAttribute("firstColumnFragments");
Expand All @@ -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<Extension> firstColumnFragments = (ArrayList<Extension>) fragmentModel.getAttribute("firstColumnFragments");
Expand All @@ -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<Extension> firstColumnFragments = (ArrayList<Extension>) fragmentModel.getAttribute("firstColumnFragments");
Expand Down
Loading