Skip to content

Commit

Permalink
EA-184 - Move reporting module to an aware_of dependency (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton authored May 29, 2024
1 parent 651fd6a commit 0789713
Show file tree
Hide file tree
Showing 38 changed files with 548 additions and 896 deletions.
111 changes: 111 additions & 0 deletions api-reporting/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>emrapi</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>emrapi-api-reporting</artifactId>
<packaging>jar</packaging>
<name>EMR API Reporting API</name>

<properties>
<reportingVersion>1.25.0</reportingVersion>
<serialization.xstreamVersion>0.2.16</serialization.xstreamVersion>
<calculationVersion>1.3.0</calculationVersion>
</properties>

<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-api</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api</artifactId>
<version>${reportingVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api-1.10</artifactId>
<version>${reportingVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api-2.0</artifactId>
<version>${reportingVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>reporting-api-2.2</artifactId>
<version>${reportingVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api</artifactId>
<version>${serialization.xstreamVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api-1.10</artifactId>
<version>${serialization.xstreamVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>serialization.xstream-api-2.0</artifactId>
<version>${serialization.xstreamVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openmrs.module</groupId>
<artifactId>calculation-api</artifactId>
<version>${calculationVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</testResource>
<testResource>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
<filtering>false</filtering>
</testResource>
</testResources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.openmrs.module.emrapi.adt.reporting.evaluator;

import org.openmrs.Location;
import org.openmrs.Visit;
import org.openmrs.annotation.Handler;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.emrapi.adt.AdtService;
import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery;
import org.openmrs.module.reporting.evaluation.EvaluationContext;
import org.openmrs.module.reporting.evaluation.EvaluationException;
import org.openmrs.module.reporting.evaluation.context.VisitEvaluationContext;
import org.openmrs.module.reporting.query.visit.VisitQueryResult;
import org.openmrs.module.reporting.query.visit.definition.VisitQuery;
import org.openmrs.module.reporting.query.visit.evaluator.VisitQueryEvaluator;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;
import java.util.List;

@Handler(supports = AwaitingAdmissionVisitQuery.class)
@OpenmrsProfile(modules = { "reporting:*" })
public class AwaitingAdmissionVisitQueryEvaluator implements VisitQueryEvaluator {

@Autowired
AdtService adtService;

@Override
public VisitQueryResult evaluate(VisitQuery visitQuery, EvaluationContext evaluationContext) throws EvaluationException {
AwaitingAdmissionVisitQuery eq = (AwaitingAdmissionVisitQuery) visitQuery;
Location location = eq.getLocation();
Collection<Integer> patientIds = null;
Collection<Integer> visitIds = null;
if (evaluationContext.getBaseCohort() != null) {
patientIds = evaluationContext.getBaseCohort().getMemberIds();
}
if (evaluationContext instanceof VisitEvaluationContext) {
VisitEvaluationContext visitEvaluationContext = (VisitEvaluationContext) evaluationContext;
if (visitEvaluationContext.getBaseVisits() != null) {
visitIds = visitEvaluationContext.getBaseVisits().getMemberIds();
}
}
List<Visit> results = adtService.getVisitsAwaitingAdmission(location, patientIds, visitIds);
VisitQueryResult result = new VisitQueryResult(visitQuery, evaluationContext);
for (Visit v : results) {
result.add(v.getVisitId());
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.openmrs.Obs;
import org.openmrs.Provider;
import org.openmrs.annotation.Handler;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.api.LocationService;
import org.openmrs.api.context.Context;
import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition;
import org.openmrs.module.emrapi.adt.util.AdtUtil;
import org.openmrs.module.emrapi.concept.EmrConceptService;
Expand All @@ -31,7 +31,8 @@
/**
* Evaluates a MostRecentAdmissionRequestVisitDataDefinition to produce a VisitData
*/
@Handler(supports=MostRecentAdmissionRequestVisitDataDefinition.class, order=50)
@Handler(supports= MostRecentAdmissionRequestVisitDataDefinition.class, order=50)
@OpenmrsProfile(modules = { "reporting:*" })
public class MostRecentAdmissionRequestVisitDataEvaluator implements VisitDataEvaluator {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.openmrs.module.emrapi.patient.reporting.library;

import org.openmrs.PatientIdentifier;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.emrapi.EmrApiProperties;
import org.openmrs.module.reporting.data.converter.PropertyConverter;
import org.openmrs.module.reporting.data.patient.definition.ConvertedPatientDataDefinition;
Expand All @@ -27,7 +28,7 @@
/**
* Basic patient data columns provided by emr-api module
*/
@Component
@OpenmrsProfile(modules = { "reporting:*" })
public class EmrApiPatientDataLibrary extends BaseDefinitionLibrary<PatientDataDefinition> {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openmrs.module.emrapi.visit.reporting.library;

import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition;
import org.openmrs.module.reporting.data.visit.definition.VisitDataDefinition;
import org.openmrs.module.reporting.definition.library.BaseDefinitionLibrary;
Expand All @@ -9,7 +10,7 @@
/**
* Basic visit data columns provided by module
*/
@Component
@OpenmrsProfile(modules = { "reporting:*" })
public class EmrApiVisitDataLibrary extends BaseDefinitionLibrary<VisitDataDefinition> {


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openmrs.module.emrapi;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openmrs.module.Module;
import org.openmrs.module.ModuleFactory;
import org.openmrs.test.BaseModuleContextSensitiveTest;

import java.io.File;

public abstract class BaseReportingTest extends BaseModuleContextSensitiveTest {

@BeforeClass
public static void beforeClass() {
Module mod = new Module("", "reporting", "", "", "", "1.25.0");
mod.setFile(new File(""));
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
}

@AfterClass
public static void afterClass() {
ModuleFactory.getStartedModulesMap().remove("reporting");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.openmrs.api.ConceptService;
import org.openmrs.contrib.testdata.TestDataManager;
import org.openmrs.contrib.testdata.builder.ObsBuilder;
import org.openmrs.module.emrapi.BaseReportingTest;
import org.openmrs.module.emrapi.EmrApiConstants;
import org.openmrs.module.emrapi.EmrApiProperties;
import org.openmrs.module.emrapi.adt.reporting.query.AwaitingAdmissionVisitQuery;
Expand All @@ -25,16 +26,16 @@
import org.openmrs.module.reporting.query.visit.VisitIdSet;
import org.openmrs.module.reporting.query.visit.VisitQueryResult;
import org.openmrs.module.reporting.query.visit.service.VisitQueryService;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.Collections;
import java.util.Date;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseModuleContextSensitiveTest {
public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseReportingTest {

@Autowired
private ConceptService conceptService;
Expand All @@ -45,6 +46,7 @@ public class AwaitingAdmissionVisitQueryEvaluatorTest extends BaseModuleContextS
@Autowired
private DispositionService dispositionService;

@Qualifier("reportingVisitQueryService")
@Autowired
private VisitQueryService visitQueryService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.openmrs.api.ConceptService;
import org.openmrs.api.context.Context;
import org.openmrs.contrib.testdata.TestDataManager;
import org.openmrs.module.emrapi.BaseReportingTest;
import org.openmrs.module.emrapi.EmrApiConstants;
import org.openmrs.module.emrapi.EmrApiProperties;
import org.openmrs.module.emrapi.adt.reporting.definition.MostRecentAdmissionRequestVisitDataDefinition;
Expand All @@ -26,7 +27,6 @@
import org.openmrs.module.reporting.data.visit.service.VisitDataService;
import org.openmrs.module.reporting.evaluation.context.VisitEvaluationContext;
import org.openmrs.module.reporting.query.visit.VisitIdSet;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
Expand All @@ -36,7 +36,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class MostRecentAdmissionRequestVisitDataEvaluatorTest extends BaseModuleContextSensitiveTest {
public class MostRecentAdmissionRequestVisitDataEvaluatorTest extends BaseReportingTest {

@Autowired
private VisitDataService visitDataService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
import org.junit.Test;
import org.openmrs.Cohort;
import org.openmrs.api.PatientService;
import org.openmrs.module.emrapi.BaseReportingTest;
import org.openmrs.module.emrapi.patient.reporting.library.EmrApiPatientDataLibrary;
import org.openmrs.module.reporting.common.DateUtil;
import org.openmrs.module.reporting.data.patient.EvaluatedPatientData;
import org.openmrs.module.reporting.data.patient.definition.PatientDataDefinition;
import org.openmrs.module.reporting.data.patient.service.PatientDataService;
import org.openmrs.module.reporting.evaluation.EvaluationContext;
import org.openmrs.module.reporting.evaluation.EvaluationException;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class EmrApiPatientDataLibraryComponentTest extends BaseModuleContextSensitiveTest {
public class EmrApiPatientDataLibraryComponentTest extends BaseReportingTest {

@Autowired
private PatientDataService pds;
Expand Down
29 changes: 29 additions & 0 deletions api-reporting/src/test/resources/TestingApplicationContext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<!--
From applicationContext-service.xml in openmrs-api
Needed to override and add hibernate mappings to the classpath since omod is not packaged yet
-->
<bean id="sessionFactory" class="org.openmrs.api.db.hibernate.HibernateSessionFactoryBean">
<property name="configLocations">
<list>
<value>classpath:hibernate.cfg.xml</value>
<value>classpath:test-hibernate.cfg.xml</value>
</list>
</property>
<property name="mappingJarLocations">
<ref bean="mappingJarResources"/>
</property>
<property name="packagesToScan">
<list>
<value>org.openmrs</value>
</list>
</property>
<!-- default properties must be set in the hibernate.default.properties -->
</bean>
</beans>

19 changes: 19 additions & 0 deletions api-reporting/src/test/resources/test-hibernate.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<mapping resource="Provider.hbm.xml"/>
<mapping resource="ProviderRole.hbm.xml"/>
<mapping resource="ExportedPackage.hbm.xml" />
<mapping resource="ImportedPackage.hbm.xml" />
<mapping resource="ImportedItem.hbm.xml" />
<mapping resource="ReportDesign.hbm.xml" />
<mapping resource="MetadataSource.hbm.xml"/>
<mapping resource="MetadataTermMapping.hbm.xml"/>
<mapping resource="MetadataSet.hbm.xml"/>
<mapping resource="MetadataSetMember.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Loading

0 comments on commit 0789713

Please sign in to comment.