Hacking OpenMRS-Core for learning purposes

Hi there,

I installed OpenMRS to use as part of a demo app for a new tool I am developing. I am editing OpenMRS-Core to suit the demo requirements.

As part of the demo I would like to send Database requests to my external API. I need three pieces of information from OpenMRS

  • The SQL query
  • The username of the person making the request
  • The number of returned rows

Can anyone advise the best strategy for collecting this information? I’ve been looking at the ChainingInterceptor class as a place to gather this for every data request from the DB.

Does that make sense? If so, how can I get the App User information when making the request. Also, how can I find the SQL statement from hibernate on the onLoad() function.

Thoughts and feedback are welcome. :slight_smile:

1 Like

could you have a look at this https://wiki.openmrs.org/display/docs/REST+Web+Services+API+For+Clients

1 Like

Thanks @herbert24, I installed the REST module. I’m not entirely sure how that helps get the information that I need. Perhaps you can explain?

I tried changing the following code on org.openmrs.api.db.hibernate.ChainingInterceptor

	public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
		boolean objectChanged = false;

		System.out.println("Entity: "+entity.getClass().getSimpleName()+
			" user: "+Context.getAuthenticatedUser()+
			" timestamp: "+new Date());

		for (String prop:propertyNames)
			System.out.println("Property Names: "+prop);		

		for (Interceptor i : interceptors) {
			// must be in this order so that java doesn't skip the method call for optimizations
			objectChanged = i.onLoad(entity, id, state, propertyNames, types) || objectChanged;
		return objectChanged;

This still doesn’t get me the Rows returned or the SQL statement that I am looking for.