Groovy Scripts are used as extension scripts that can be executed when a particular event is triggered.
Some of the events can be
Displaying Display controls
Observation Save
What should be configured for groovy scripts?
For any groovy script the following are configurable
What is the script to execute on trigger of an event
What should be implemented in the script
Types of Groovy Scripts
Different types of groovy scripts that can be configured are
Standard Extensions
Custom Extensions
Standard Extensions
The standard extension file names cannot be changed. The reason for referring them standard is that they need not be explicitly configured. Names are standard. Only implementation of the script can be customised.
If the file is present, by default it will be executed when the respective event is triggered.
Some of those extensions are
BahmniObsValueCalcuator
TreatmentRegimenExtension
File Name
Location and Example File
Note
BahmniObsValueCalculator.groovy
Location of the file is /var/www/bahmni_config/openmrs/obscalculator/
This file should extend BaseTableExtension<PivotTable>.
Override the update() method according to the requirement.
Developer Tips
One way to debug groovy scripts during development is to write statements to a temporary file, e.g., in BahmniObsValueCalculator.groovy, use the snippet below. groovy_debug.txt should be writable. Make sure to remove debugging statements and temporary file before deployment.
def file1 = new File(OpenmrsUtil.getApplicationDataDirectory() + "obscalculator/groovy_debug.txt")
file1.append 'debugging statement\n'