Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added implementation for assigning the patients to the locations on r…
…egistration License headers updated Removed unused constants Implemented custom fragement for the location selection Implemented custom fragement for the location selection Added solution to fetch the session location property Changed Location global property to user context Removed AOP implementation Added accessLocation filter for PatientSearch
- Loading branch information
Suthagar23
committed
Jun 16, 2018
1 parent
6dbd5a2
commit e0deb09
Showing
9 changed files
with
249 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
api/src/main/java/org/openmrs/module/locationbasedaccess/PatientSearchAdvise.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* <p> | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
|
||
package org.openmrs.module.locationbasedaccess; | ||
|
||
|
||
import org.aopalliance.aop.Advice; | ||
import org.aopalliance.intercept.MethodInvocation; | ||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.openmrs.Location; | ||
import org.openmrs.Patient; | ||
import org.openmrs.Person; | ||
import org.openmrs.PersonAttribute; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.locationbasedaccess.common.Constants; | ||
import org.springframework.aop.Advisor; | ||
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; | ||
import java.lang.reflect.Method; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
/** | ||
* It will used to implement the AOP Methods for PatientServiceImpl class | ||
*/ | ||
public class PatientSearchAdvise extends StaticMethodMatcherPointcutAdvisor implements Advisor { | ||
|
||
protected static final Log log = LogFactory.getLog(PatientSearchAdvise.class); | ||
|
||
@Override | ||
public boolean matches(Method method, Class targetClass) { | ||
// For PatientServiceImpl.savePatient() | ||
if (method.getName().equals("getPatients")) { | ||
return true; | ||
} | ||
// For PatientServiceImpl.getPatient() | ||
else if (method.getName().equals("getPatient")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Advice getAdvice() { | ||
return new UserControlAdvice(); | ||
} | ||
|
||
/** | ||
* This inner class will be used to intercept the caught method using AOP | ||
*/ | ||
private class UserControlAdvice implements MethodInterceptor { | ||
|
||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
Object currentResult = invocation.proceed(); | ||
Integer sessionLocationId = Context.getUserContext().getLocationId(); | ||
|
||
if(sessionLocationId != null) { | ||
Location sessionLocation = Context.getLocationService().getLocation(sessionLocationId); | ||
// For PatientServiceImpl.getPatient() | ||
if(currentResult instanceof Patient) { | ||
Patient currentPatient = (Patient)currentResult; | ||
currentPatient = checkPatientForAccessLocation(currentPatient, sessionLocation); | ||
return currentPatient; | ||
} | ||
// For PatientServiceImpl.savePatient() | ||
else { | ||
List<Patient> currentPatientResults = (List<Patient>)currentResult; | ||
for (Iterator<Patient> iterator = currentPatientResults.iterator(); iterator.hasNext(); ) { | ||
Patient patient = iterator.next(); | ||
patient = checkPatientForAccessLocation(patient, sessionLocation); | ||
if(patient == null) { | ||
iterator.remove(); | ||
} | ||
} | ||
return currentPatientResults; | ||
} | ||
} | ||
else { | ||
// If session location doesn't available, return empty patient | ||
log.debug("Search Patient : Null Session Location in the UserContext"); | ||
return null; | ||
} | ||
} | ||
|
||
private Patient checkPatientForAccessLocation(Patient patient, Location sessionLocation) { | ||
Person person = patient.getPerson(); | ||
PersonAttribute personAttribute = person.getAttribute(Constants.ACCESS_LOCATION_PERSON_ATTRIBUTE_TYPE_NAME); | ||
if (personAttribute == null) { | ||
log.debug("Patient AccessLocation attribute missing for Patient - " + person.getGivenName()); | ||
String showPatientsWithoutAccessLocation = Context.getAdministrationService().getGlobalProperty(Constants.SHOW_PATIENTS_WHO_WITHOUT_ACCESS_LOCATION); | ||
if( showPatientsWithoutAccessLocation.equals("false")) { | ||
patient = null; | ||
} | ||
} | ||
else { | ||
if(!personAttribute.getValue().equals(sessionLocation.getUuid())) { | ||
patient = null; | ||
} | ||
} | ||
return patient; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/main/java/org/openmrs/module/locationbasedaccess/common/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
|
||
package org.openmrs.module.locationbasedaccess.common; | ||
|
||
public class Constants { | ||
|
||
public static final String ACCESS_LOCATION_PERSON_ATTRIBUTE_TYPE_NAME = "accessControlLocation"; | ||
public static final String SHOW_PATIENTS_WHO_WITHOUT_ACCESS_LOCATION = "showPatientsWithoutAccessLocation"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...mrs/module/locationbasedaccess/fragment/controller/field/LocationsFragmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.openmrs.module.locationbasedaccess.fragment.controller.field; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.appui.UiSessionContext; | ||
import org.openmrs.ui.framework.fragment.FragmentModel; | ||
import javax.servlet.http.HttpSession; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Fields and actions to provide registrationInfo view. | ||
* | ||
* @author Romain Buisson | ||
*/ | ||
public class LocationsFragmentController { | ||
|
||
public void controller(FragmentModel model, | ||
HttpSession session) { | ||
|
||
// Fetch the current logged in attribute from the session | ||
String LOCATION_SESSION_ATTRIBUTE = UiSessionContext.LOCATION_SESSION_ATTRIBUTE; | ||
Integer sessionLocationId = (Integer) session.getAttribute(LOCATION_SESSION_ATTRIBUTE); | ||
|
||
List<Location> activeLocations =new ArrayList<Location>(); | ||
activeLocations.add(Context.getLocationService().getLocation(sessionLocationId)); | ||
for(Location location : Context.getLocationService().getAllLocations(true)) { | ||
if(location.getLocationId() != sessionLocationId) { | ||
activeLocations.add(location); | ||
} | ||
} | ||
|
||
model.addAttribute("activeLocations", activeLocations); | ||
} | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<% | ||
ui.includeJavascript("uicommons", "angular.js") | ||
ui.includeJavascript("uicommons", "angular-common.js") | ||
ui.includeJavascript("uicommons", "angular-resource.min.js") | ||
ui.includeJavascript("uicommons", "angular-ui/ui-bootstrap-tpls-0.6.0.min.js") | ||
%> | ||
|
||
<div> | ||
<div> | ||
<p class="left"> | ||
<label> | ||
Please select the default access location | ||
</label> | ||
<select id="${config.formFieldName}" name="${config.formFieldName}" class="rel_type"> | ||
<% activeLocations.each { location -> %> | ||
<option value="${location.uuid}">${location.name}</option> | ||
<% } %> | ||
</select> | ||
</p> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters