-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LABC-3 Added implementation for assigning the patients to the locatio…
…ns on registration Removed personAttribute creation Added fixes for PR comments PR Review fixes Added minor fix Added some fixes according to the PR reviews Minor fix Changed the locationCheck method structure minor fix Changed method name Added fixes for PR reviews Added fixes for PR reviews Changed method to compare Changed Compare method Minor improvements Minor modifications
- Loading branch information
Suthagar23
committed
Jun 25, 2018
1 parent
5fb6e2e
commit fec3b88
Showing
7 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
api/src/main/java/org/openmrs/module/locationbasedaccess/PatientSearchAdviser.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,77 @@ | ||
/** | ||
* 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.lang3.StringUtils; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.openmrs.*; | ||
import org.openmrs.api.context.Context; | ||
import org.springframework.aop.Advisor; | ||
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class PatientSearchAdviser extends StaticMethodMatcherPointcutAdvisor implements Advisor { | ||
|
||
private static final Log log = LogFactory.getLog(PatientSearchAdviser.class); | ||
public static final String LOCATION_ATTRIBUTE_GLOBAL_PROPERTY_NAME = "locationbasedaccess.locationAttributeUuid"; | ||
|
||
@Override | ||
public boolean matches(Method method, Class targetClass) { | ||
if (method.getName().equals("getPatients")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Advice getAdvice() { | ||
return new PatientSearchAdvise(); | ||
} | ||
|
||
private class PatientSearchAdvise implements MethodInterceptor { | ||
|
||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
Integer sessionLocationId = Context.getUserContext().getLocationId(); | ||
String locationAttributeUuid = Context.getAdministrationService().getGlobalProperty(LOCATION_ATTRIBUTE_GLOBAL_PROPERTY_NAME); | ||
List<Patient> patientList = (List<Patient>) invocation.proceed(); | ||
if (StringUtils.isNotBlank(locationAttributeUuid)) { | ||
final PersonAttributeType personAttributeType = Context.getPersonService().getPersonAttributeTypeByUuid(locationAttributeUuid); | ||
if (sessionLocationId != null) { | ||
String sessionLocationUuid = Context.getLocationService().getLocation(sessionLocationId).getUuid(); | ||
|
||
for (Iterator<Patient> iterator = patientList.iterator(); iterator.hasNext(); ) { | ||
Patient patient = iterator.next(); | ||
if (!compare(patient.getAttribute(personAttributeType).getValue(), sessionLocationUuid)) { | ||
iterator.remove(); | ||
} | ||
} | ||
} else { | ||
// If the sessionLocationId is null, then return a empty list | ||
log.debug("Search Patient : Null Session Location in the UserContext"); | ||
return new ArrayList<Patient>(); | ||
} | ||
} | ||
return patientList; | ||
} | ||
|
||
private Boolean compare(String value1, String value2) { | ||
return (StringUtils.isNotBlank(value1) && StringUtils.isNotBlank(value2)) && value1.equals(value2); | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...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,17 @@ | ||
package org.openmrs.module.locationbasedaccess.fragment.controller.field; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.ui.framework.fragment.FragmentModel; | ||
|
||
import org.openmrs.api.context.Context; | ||
import javax.servlet.http.HttpSession; | ||
import java.util.List; | ||
|
||
public class LocationsFragmentController { | ||
|
||
public void controller(FragmentModel model, | ||
HttpSession session) { | ||
List<Location> activeLocations = Context.getLocationService().getAllLocations(); | ||
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,16 @@ | ||
|
||
<div> | ||
<div> | ||
<p class="left"> | ||
<label> | ||
Please select the location | ||
</label> | ||
<select id="${config.formFieldName}" name="${config.formFieldName}"> | ||
<% 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