Skip to content

ME-38:Added billing module domains - #41

Open
sudhanshu-raj wants to merge 8 commits into
openmrs:mainfrom
sudhanshu-raj:ME-38
Open

sudhanshu-raj wants to merge 8 commits into
openmrs:mainfrom
sudhanshu-raj:ME-38

Conversation

@sudhanshu-raj

@sudhanshu-raj sudhanshu-raj commented Sep 9, 2026

Copy link
Copy Markdown

Description of what I changed

Added billing module domains

Issue I worked on

see https://openmrs.atlassian.net/browse/ME-38

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@sudhanshu-raj

Copy link
Copy Markdown
Author

hi @wikumChamith let me know if this is what expected from billing module domains , and i will test cases, configs and readme update

@wikumChamith

Copy link
Copy Markdown
Member

@sudhanshu-raj have you noticed the build errors?

@Bawanthathilan

Copy link
Copy Markdown
Contributor

@sudhanshu-raj can you check these build errors ?

@sudhanshu-raj

Copy link
Copy Markdown
Author

Hey @wikumChamith , though I fixed the exact error which happening due to event api which needed for billing module.

But there is different issue which stopping the build and that is I think infinite recursive loop for the beans . The thing is its something wrong(which I assuming) with the how the beans are loading from the moduleApplicationContext.xml in the billing module because when I build with skipping the test it got build success but with including the test and the test classpath as we know BaseModuleContextSensitiveTest loads the all beans from the context and that part triggers the loop . I'm not sure exactly which things is causing the loop, though I tried some fixes in billing module which I though could help but it didn't . I'm dumping logs which could understand better, here is build logs that got stuck and here is the surefire test execution process logs.

@wikumChamith

Copy link
Copy Markdown
Member

@sudhanshu-raj what if we keep the jars for compilation but keep them out of the test JVM?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <classpathDependencyExcludes>
            <classpathDependencyExclude>org.openmrs.module:billing-api</classpathDependencyExclude>
            <classpathDependencyExclude>org.openmrs.module:stockmanagement-api</classpathDependencyExclude>
        </classpathDependencyExcludes>
    </configuration>
</plugin>

@sudhanshu-raj

Copy link
Copy Markdown
Author

@sudhanshu-raj what if we keep the jars for compilation but keep them out of the test JVM?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <classpathDependencyExcludes>
            <classpathDependencyExclude>org.openmrs.module:billing-api</classpathDependencyExclude>
            <classpathDependencyExclude>org.openmrs.module:stockmanagement-api</classpathDependencyExclude>
        </classpathDependencyExcludes>
    </configuration>
</plugin>

Will that not cause for the integration tests or calling the billing services methods, because those jar will be removed during the test classpath ?

@wikumChamith

Copy link
Copy Markdown
Member

@sudhanshu-raj what if we keep the jars for compilation but keep them out of the test JVM?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <classpathDependencyExcludes>
            <classpathDependencyExclude>org.openmrs.module:billing-api</classpathDependencyExclude>
            <classpathDependencyExclude>org.openmrs.module:stockmanagement-api</classpathDependencyExclude>
        </classpathDependencyExcludes>
    </configuration>
</plugin>

Will that not cause for the integration tests or calling the billing services methods, because those jar will be removed during the test classpath ?

Ohh yes. Let's keep the exclusion on the default Surefire execution but give the billing tests their own execution with the full classpath

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>
        <execution>
            <id>default-test</id>
            <configuration>
                <excludes>
                    <exclude>**/domain/billing/**</exclude>
                </excludes>
                <classpathDependencyExcludes>
                    <classpathDependencyExclude>org.openmrs.module:billing-api</classpathDependencyExclude>
                    <classpathDependencyExclude>org.openmrs.module:stockmanagement-api</classpathDependencyExclude>
                </classpathDependencyExcludes>
            </configuration>
        </execution>
        <execution>
            <id>billing-unit-tests</id>
            <goals><goal>test</goal></goals>
            <configuration>
                <includes>
                    <include>**/domain/billing/**/*Test.java</include>
                </includes>
            </configuration>
        </execution>
    </executions>
</plugin>

@sudhanshu-raj

Copy link
Copy Markdown
Author

ok, tested with one integration test for BillableServiceDomainExporter , seems like this test case got hung again and caught in same loop.

@wikumChamith

Copy link
Copy Markdown
Member

@sudhanshu-raj so I looked into this, and to fix it we need to make a few changes. I'll go through them one by one.

  • Billing's exemption evaluator needs GraalVM, which the platform supplies from 2.8.2 onward. So we should bump the platform version to 2.8.3.
  • Then we'll need to bump stockmanagementVersion from 1.4.0 to 3.0.0. This is because older stockmanagement releases reference LuceneQuery, which was removed from core in 2.8.0.
  • Then we need to add a sessionFactory override in TestingApplicationContext.xml plus a new test-hibernate.cfg.xml. Billing maps BillableService, CashPoint, PaymentMode and others in hbm files that only the running billing module registers. Without this, the integration test fails with "Unknown entity". Check the initializer module for an example.
<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="mappingJarResources"/>
	<property name="packagesToScan">
		<list>
			<value>org.openmrs</value>
		</list>
	</property>
</bean>

test-hibernate.cfg.xml:

<hibernate-configuration>
    <session-factory>
        <!-- Billing -->
        <mapping resource="Bill.hbm.xml"/>
        <mapping resource="Cashier.hbm.xml"/>
        <mapping resource="SequentialReceiptNumberGenerator.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

@sudhanshu-raj

Copy link
Copy Markdown
Author

@sudhanshu-raj so I looked into this, and to fix it we need to make a few changes. I'll go through them one by one.

  • Billing's exemption evaluator needs GraalVM, which the platform supplies from 2.8.2 onward. So we should bump the platform version to 2.8.3.
  • Then we'll need to bump stockmanagementVersion from 1.4.0 to 3.0.0. This is because older stockmanagement releases reference LuceneQuery, which was removed from core in 2.8.0.
  • Then we need to add a sessionFactory override in TestingApplicationContext.xml plus a new test-hibernate.cfg.xml. Billing maps BillableService, CashPoint, PaymentMode and others in hbm files that only the running billing module registers. Without this, the integration test fails with "Unknown entity". Check the initializer module for an example.
<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="mappingJarResources"/>
	<property name="packagesToScan">
		<list>
			<value>org.openmrs</value>
		</list>
	</property>
</bean>

test-hibernate.cfg.xml:

<hibernate-configuration>
    <session-factory>
        <!-- Billing -->
        <mapping resource="Bill.hbm.xml"/>
        <mapping resource="Cashier.hbm.xml"/>
        <mapping resource="SequentialReceiptNumberGenerator.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

It worked, thanks

@sudhanshu-raj

Copy link
Copy Markdown
Author

And I am curious how you came up with this ?

@wikumChamith

Copy link
Copy Markdown
Member

And I am curious how you came up with this ?

Just went through it one error at a time. Had some help from Claude too.

@wikumChamith

Copy link
Copy Markdown
Member

@sudhanshu-raj let's resolve these merge conflicts and make this ready for review.

@sudhanshu-raj

Copy link
Copy Markdown
Author

Ok so merged the conflicts and the new changes, then created test cases for BillableService domain , and while testing this I realized build got hung on same loop after merging the new changes because when I build after applying loop fix which is after this commit ME-38:Upgraded platform version and added configs 2211ed71ed978b3e1038cba9b2bc0599b7cc7e5a build got success.

@wikumChamith

Copy link
Copy Markdown
Member

@sudhanshu-raj have you tested this by trying to load the billing configs created by it using the initializer? The way to do it is to spin up a fresh OpenMRS O3 server and replace the billing configuration there with the exported one.

@sudhanshu-raj

sudhanshu-raj commented Sep 17, 2026

Copy link
Copy Markdown
Author

@sudhanshu-raj have you tested this by trying to load the billing configs created by it using the initializer? The way to do it is to spin up a fresh OpenMRS O3 server and replace the billing configuration there with the exported one.

Yes I tried loading all exported billing domain configs and matched it;s format too, it seems to worked after some small fixes. Yeah but i need to build without tests due to loop issue.

@wikumChamith

Copy link
Copy Markdown
Member

Let's drop or disable the breaking tests for now if they're giving too much trouble.

@sudhanshu-raj
sudhanshu-raj marked this pull request as ready for review September 17, 2026 21:10
@sudhanshu-raj

Copy link
Copy Markdown
Author

Let's drop or disable the breaking tests for now if they're giving too much trouble.

Ready for the review !

Comment on lines +36 to +43
if (instance.getServiceType() != null) {
Concept serviceType = instance.getServiceType();
String serviceTypeName = null;
if (serviceType.getNames() != null && !serviceType.getNames().isEmpty()) {
serviceTypeName = serviceType.getNames().iterator().next().getName();
}
line.put(HEADER_SERVICE_TYPE, serviceTypeName);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than exporting service type as an arbitrary concept name, we can just export the UUID. In the BillableServicesLineProcessor, this field is resolved with Utils.fetchConcept, which supports UUIDs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants