Skip to content

Commit

Permalink
LABC-3 Added implementation for assigning the patients to the locatio…
Browse files Browse the repository at this point in the history
…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

Minor fix
  • Loading branch information
Suthagar23 committed Jun 25, 2018
1 parent 5fb6e2e commit 4a57e1c
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 3 deletions.
@@ -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.Patient;
import org.openmrs.PersonAttributeType;
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);
}
}
}
6 changes: 6 additions & 0 deletions omod/pom.xml
Expand Up @@ -19,6 +19,12 @@
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>appui-omod</artifactId>
<version>${appuiVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
@@ -0,0 +1,16 @@
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);
}
}
8 changes: 7 additions & 1 deletion omod/src/main/resources/config.xml
Expand Up @@ -18,7 +18,7 @@

<!-- Required Modules -->
<require_modules>

<require_module version="${uiframeworkVersion}">org.openmrs.module.uiframework</require_module>
</require_modules>
<!-- / Required Modules -->

Expand Down Expand Up @@ -46,5 +46,11 @@
<file>messages_es.properties</file>
</messages>
<!-- /Internationalization -->

<advice>
<point>org.openmrs.api.PatientService</point>
<class>org.openmrs.module.locationbasedaccess.PatientSearchAdviser</class>
</advice>

</module>

4 changes: 3 additions & 1 deletion omod/src/main/resources/webModuleApplicationContext.xml
Expand Up @@ -5,6 +5,8 @@
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!-- Add here beans related to the web context -->

<bean class="org.openmrs.ui.framework.StandardModuleUiConfiguration">
<property name="moduleId" value="${project.parent.artifactId}"/>
</bean>

</beans>
16 changes: 16 additions & 0 deletions omod/src/main/webapp/fragments/field/locations.gsp
@@ -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>

30 changes: 29 additions & 1 deletion pom.xml
Expand Up @@ -22,6 +22,10 @@

<properties>
<openMRSVersion>2.0.5</openMRSVersion>
<uiframeworkVersion>3.9</uiframeworkVersion>
<uicommonsVersion>2.4.0</uicommonsVersion>
<appframeworkVersion>2.9</appframeworkVersion>
<appuiVersion>1.7</appuiVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -64,7 +68,31 @@
<scope>provided</scope>
</dependency>


<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>uiframework-api</artifactId>
<version>${uiframeworkVersion}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>uicommons-api</artifactId>
<version>${uicommonsVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>appframework-api</artifactId>
<version>${appframeworkVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>appui-omod</artifactId>
<version>${appuiVersion}</version>
<scope>provided</scope>
</dependency>
<!-- For testing -->
<dependency>
<groupId>org.openmrs.test</groupId>
Expand Down

0 comments on commit 4a57e1c

Please sign in to comment.