Implement a report inside a .omod (Build Error)

Hi everyone!

I’m trying to implement a simple report inside the referenceapplication module. I have created a new class called VisitCountRegisterand. I have added the following line to the module activator class.

ReportManagerUtil.setupAllReports(ReportManager.class);


@Component
public class VisitCountRegister extends BaseReportManager {

	public VisitCountRegister() {
	}

	@Override
	public String getUuid() {
		return "eb6c9c1f-62f7-49fc-a8fd-748e77b9f906";
	}

	@Override
	public String getName() {
		return "JUDE DEMO DEMO DEMO";
	}

	@Override
	public String getDescription() {
		return "First reporting trying to implement through the reference module";
	}

	@Override
	public List<Parameter> getParameters() {
		List<Parameter> parameterArrayList = new ArrayList<Parameter>();
		parameterArrayList.add(ReportingConstants.START_DATE_PARAMETER);
		parameterArrayList.add(ReportingConstants.END_DATE_PARAMETER);
		return parameterArrayList;
	}

	@Override
	public ReportDefinition constructReportDefinition() {

		ReportDefinition numberOfVisits_ReportDefinition = new ReportDefinition();
		numberOfVisits_ReportDefinition.setUuid(getUuid());
		numberOfVisits_ReportDefinition.setName(getName());
		numberOfVisits_ReportDefinition.setDescription(getDescription());
		numberOfVisits_ReportDefinition.setParameters(getParameters());
		return numberOfVisits_ReportDefinition;
	}

	@Override
	public List<ReportDesign> constructReportDesigns(ReportDefinition reportDefinition) {
		List<ReportDesign> l = new ArrayList<ReportDesign>();
		l.add(ReportManagerUtil.createExcelDesign("ae928860-4a4e-48d4-bbc2-50902babcfc0", reportDefinition));
		return l;
	}

	@Override
	public String getVersion() {
		return "1.0";
	}
}

Note that I am only trying to configure the report. I haven’t connected a dataset to that report yet. When I try to build the referenceApplication module, it will gives me the following error.

java.lang.RuntimeException: failed to setup the required modules                                                                                                                                                                                     at org.openmrs.module.referenceapplication.ReferenceApplicationActivator.started(ReferenceApplicationActivator.java:116)                                                                                                                     at org.openmrs.module.referenceapplication.ReferenceApplicationActivatorComponentTest.testSetupOfProcessHL7Task(ReferenceApplicationActivatorComponentTest.java:124)                                                                                                                    ... 39 more`

 Caused by: org.hibernate.MappingException: Unknown entity: org.openmrs.module.reporting.report.ReportDesign     

BTW; I added the following to the moduleApplicationContext.xml file.

	&lt; context:component-scan base-package="org.openmrs.module.referenceapplication" / &gt;

Thanks.

1 Like

require reporting module as well as its depended upon modules within your referenceapplication module clone

@k.joseph Thanks for your reply. Actually the reporting module api dependency is already existing in the referenceApplication module.

Are you seeing this error in a unit test? When you refer to another module’s hibernate-managed classes in a unit test you need to refer to them, like is done here:

1 Like

Thank you @darius for your tip. :grinning: Yes, I just saw that I have missed to put those mappings in the test. That’s why those tests were failed.

    <mapping resource="ReportDesign.hbm.xml"/>
    <mapping resource="ReportRequest.hbm.xml"/>
    <mapping resource="HtmlFormEntryHtmlForm.hbm.xml"/>

But now I get very lengthy hibernate mapping exceptions when try to run those tests. For the moment I have skipped the tests and try to see whether my new code is working, and It does!!! :innocent:

1 Like

for unit tests, you could actually just choose to add api-tests dependency as;

<dependency>
  			<groupId>org.openmrs.module</groupId>
 			<artifactId>reporting-api-tests</artifactId>
 			<version>${reportingVersion}</version>
 			<scope>test</scope>
 			<type>test-jar</type>
 </dependency>

and then in your TestingApplicationContext.xml refer to reporting-hibernate.cfg.xml instead of adding each of those mapping files individually such as below;

1 Like

Appreciate all of your responses. I was able to resolve all problems right now. :smiley_cat:

Big thanks goes out @dkayiwa (:clap: :clap: :clap:) who identified the missing dependencies which caused the test failures. I had to add these new dependecies to referenceApplication module. Now it builds smoothly.

        <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.0</artifactId>
        </dependency>