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

BAH-4062 | Add Privilege Checks for Task Resource #66

Merged
merged 8 commits into from
Aug 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
@Repository
public class TaskDaoImpl implements TaskDao {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not very sure of the reasoning, the only thing I can see is that the extension class supports additional methods


@Autowired
private SessionFactory sessionFactory;

private Log log = LogFactory.getLog(this.getClass());

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

@Override
public List<Task> getTasksByVisitFilteredByTimeFrame(Visit visit, Date startTime, Date endTime) {
try {
Expand Down Expand Up @@ -99,11 +102,11 @@ public List<Task> getTasksByUuids(List<String> listOfUuids) {
CriteriaQuery<Task> criteriaQuery = criteriaBuilder.createQuery(Task.class);
Root<FhirTaskRequestedPeriod> fhirTaskRequestedPeriod = criteriaQuery.from(FhirTaskRequestedPeriod.class);
Join<FhirTask, FhirTaskRequestedPeriod> fhirTaskJoin = fhirTaskRequestedPeriod.join("task");

criteriaQuery.select(criteriaBuilder.construct(Task.class, fhirTaskJoin, fhirTaskRequestedPeriod)).where(
fhirTaskJoin.get("uuid").in(listOfUuids));
TypedQuery<Task> query = sessionFactory.getCurrentSession().createQuery(criteriaQuery);

return query.getResultList();
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
@Repository
public class TaskRequestedPeriodDaoImpl implements TaskRequestedPeriodDao {

@Autowired
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

@Override
public FhirTaskRequestedPeriod getTaskRequestedPeriodByTaskId(Integer taskId) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package org.openmrs.module.fhirExtension.service;

import org.openmrs.module.fhir2.model.FhirTask;
import org.openmrs.annotation.Authorized;
import org.openmrs.module.fhirExtension.model.Task;
import org.openmrs.module.fhirExtension.model.TaskSearchRequest;
import org.springframework.stereotype.Component;
import org.openmrs.module.fhirExtension.utils.PrivilegeConstants;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Component
@Transactional
public interface TaskService {

@Authorized({ PrivilegeConstants.ADD_TASKS, PrivilegeConstants.EDIT_TASKS })
Task saveTask(Task task);

@Authorized({ PrivilegeConstants.ADD_TASKS, PrivilegeConstants.EDIT_TASKS })
List<Task> saveTask(List<Task> tasks);

@Authorized({ PrivilegeConstants.GET_TASKS })
List<Task> getTasksByVisitFilteredByTimeFrame(String visitUuid, Date startTime, Date endTime);

@Authorized({ PrivilegeConstants.GET_TASKS })
List<Task> getTasksByPatientUuidsByTimeFrame(List<String> patientUuids, Date startTime, Date endTime);

@Authorized({ PrivilegeConstants.GET_TASKS })
List<Task> getTasksByUuids(List<String> listOdUuids);

@Authorized({ PrivilegeConstants.GET_TASKS })
List<Task> searchTasks(TaskSearchRequest taskSearchRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,21 @@
import org.openmrs.module.fhirExtension.model.Task;
import org.openmrs.module.fhirExtension.model.TaskSearchRequest;
import org.openmrs.module.fhirExtension.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.ArrayList;

@Transactional
@Component
public class TaskServiceImpl implements TaskService {

@Autowired
private FhirTaskDao fhirTaskDao;

@Autowired
private VisitService visitService;

@Autowired
private TaskDao taskDao;

@Autowired
private TaskRequestedPeriodDao taskRequestedPeriodDao;

@Override
Expand Down Expand Up @@ -78,4 +71,20 @@ public List<Task> getTasksByUuids(List<String> listOdUuids) {
public List<Task> searchTasks(TaskSearchRequest taskSearchRequest) {
return taskDao.searchTasks(taskSearchRequest);
}

public void setVisitService(VisitService visitService) {
this.visitService = visitService;
}

public void setFhirTaskDao(FhirTaskDao fhirTaskDao) {
this.fhirTaskDao = fhirTaskDao;
}

public void setTaskDao(TaskDao taskDao) {
this.taskDao = taskDao;
}

public void setTaskRequestedPeriodDao(TaskRequestedPeriodDao taskRequestedPeriodDao) {
this.taskRequestedPeriodDao = taskRequestedPeriodDao;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openmrs.module.fhirExtension.utils;

public class PrivilegeConstants {

private PrivilegeConstants() {
}

public static final String GET_TASKS = "Get Tasks";

public static final String EDIT_TASKS = "Edit Tasks";

public static final String ADD_TASKS = "Add Tasks";
}
40 changes: 26 additions & 14 deletions omod/src/main/resources/config.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<module configVersion="1.2">

<!-- Base Module Properties -->
<id>${project.parent.artifactId}</id>
<name>${project.parent.name}</name>
Expand All @@ -13,35 +13,35 @@
</description>

<activator>org.openmrs.module.fhirExtension.FhirExtensionModuleActivator</activator>

<!-- <updateURL>https://modules.openmrs.org/modules/download/@MODULE_ID@/update.rdf</updateURL> -->
<!-- /Base Module Properties -->

<require_version>${openmrsPlatformVersion}</require_version>

<!-- Extensions -->
<!-- <extension>-->
<!-- <point>org.openmrs.admin.list</point>-->
<!-- <class>${MODULE_PACKAGE}.extension.html.AdminList</class>-->
<!-- </extension>-->


<!-- AOP
<advice>
<point>org.openmrs.api.FormService</point>
<class>@[email protected]</class>
</advice>
/AOP -->
<!-- Required Privileges


<!-- Required Privileges
<privilege>
<name>Form Entry</name>
<description>Allows user to access Form Entry pages/functions</description>
</privilege>
/Required Privileges -->

<!-- Required Global Properties
<!-- Required Global Properties
<globalProperty>
<property>@[email protected]</property>
<defaultValue></defaultValue>
Expand All @@ -52,17 +52,17 @@
</description>
</globalProperty>
/Required Global Properties -->

<!-- Servlets -->
<!-- Accessed through the url /pageContext()/moduleServlet/<moduleId>/<servlet-name>
<!-- Accessed through the url /pageContext()/moduleServlet/<moduleId>/<servlet-name>
<servlet>
<servlet-name>formDownload</servlet-name>
<servlet-class>@[email protected]</servlet-class>
</servlet>
-->
<!-- /Servlets -->


<!-- Internationalization -->
<!-- All message codes should start with @MODULE_ID@.* -->
<aware_of_modules>
Expand Down Expand Up @@ -97,6 +97,18 @@
<name>Export Non Anonymised Patient Data</name>
<description>Ability to bulk-export patient data that has NOT been anonymised, in FHIR JSON format</description>
</privilege>
<privilege>
<name>Get Tasks</name>
<description>Ability to get FHIR Tasks</description>
</privilege>
<privilege>
<name>Add Tasks</name>
<description>Ability to create FHIR Tasks</description>
</privilege>
<privilege>
<name>Edit Tasks</name>
<description>Ability to edit FHIR Tasks</description>
</privilege>

<globalProperty>
<property>labEntry.visitType</property>
Expand Down
36 changes: 36 additions & 0 deletions omod/src/main/resources/webModuleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,42 @@
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>

<context:component-scan base-package="org.openmrs.module.fhirExtension" />
<bean id="taskServiceTarget" class="org.openmrs.module.fhirExtension.service.impl.TaskServiceImpl">
<property name="visitService" ref="visitService"/>
<property name="fhirTaskDao" ref="fhirTaskDaoImpl"/>
<property name="taskDao">
<bean class="org.openmrs.module.fhirExtension.dao.impl.TaskDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</property>
<property name="taskRequestedPeriodDao">
<bean class="org.openmrs.module.fhirExtension.dao.impl.TaskRequestedPeriodDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</property>
</bean>
<bean id="taskService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager" />
<property name="target" ref="taskServiceTarget"/>
<property name="preInterceptors" ref="serviceInterceptors" />
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
</property>
</bean>
<bean parent="serviceContext">
<property name="moduleService">
<list>
<value>org.openmrs.module.fhirExtension.service.TaskService</value>
<ref bean="taskService"/>
</list>
</property>
</bean>


</beans>
Loading