2011-11-02 OpenMRS University

Recording: http://breeze.iu.edu/p8fs4qvf8ou/

Real-time notes: http://notes.openmrs.org/OpenMRS-University-2011-11-02

http://notes.openmrs.org/OpenMRS-University-2011-11-02Notes copied from etherpad for posterity:

OpenMRS University
2011/11/02
Topic: How to program a custom cohort query in the reporting module
Presenter: Mike Seaton
Recording: http://breeze.iu.edu/p8fs4qvf8ou/
Attendees

  • Janet
  • Ben
  • Burke
  • Suranga
  • Mike
  • Cosmin
  • Rafal
  • Darius

Notes
The reporting module comes with many prepackaged queries. Sometimes it doesn't cover your reporting need.
How to add custom reporting to your own module.
A simple reporting use case:
Find patients created by a certain user in a certain date range.
Whirlwind tour of report admin pages:
Existing cohort queries:   there are many existing classes/queries listed in the left of the cohort query
You could make a sql cohort query if you didn't want to make your own module
Creating a new cohort query: requires making two classes
1) definition class - a javabean that extends   BaseCohortDefinition. containing all the parameters you're going to pass into the module, and defines what kind of cohort will be returned.
recommended:  copy& paste an existing definition class from a module, such as the built-in defs in the reporting module (http://svn.openmrs.org/openmrs-modules/reporting/trunk)
Rename the copied class
Add your class members.
Set configuration properties - the members marked with the @ConfigurationProperty annotation.  These are important for caching.  Anything that should be evaluated or copied during a clone() should have the annotation. No limits on the datatype marked with @ConfigurationProperty.
2) Create an evaluator for the definition.
The evaluator must implement CohortDefinitionEvaluator .
Update the @Handler(supports={})  annotation
Write a unit test. :)
Save, compile, and upload your module to your test server.
3) Check your work. Go to cohort definition page and run your new query.  It should appear and run. 
Making a module versus using a SqlCohortQuery:
SqlCohortQueries can be used by implementers who are good at SQL but don't know how to write modules.
Modules can be unit tested, and can do things that are very difficult to do with SQL.  Unit testing is recommended for any complex or critical query.