Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Context

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 NameLocation and Example FileNote

BahmniObsValueCalculator.groovy


  • This groovy script is executed on click of consultation save button.
  • This file should implement ObsValueCalculator.
  • Override the run() method according to the requirement.

TreatmentRegimenExtension.groovy


  • This groovy script is executed before displaying the "Chronic Treatment" Control.
  • This file should extend BaseTableExtension<TreatmentRegimen>.
  • Override the update() method according to the requirement.



Info

bahmni.executeGroovyObsValueCalculator - Groovy scripts to calculate obs during Encounter save can be disabled using this property. Under heavy load, Groovy scripts loading/compilation and execution can make the responses slower. This property if set to False, will not execute groovy scripts (BahmniObsValueCalculator.groovy).

If you do not use advanced calculations, it's better to turn this property to false. Note, for simple calculations while capturing observations, you may use JavaScript in Forms2 (e.g. BMI calculation).



Custom Extensions

  • Groovy extensions that can have custom files along with custom implementation.
  • Display controls such as Obs To Obs Flowsheet have flexibility to have custom extensions.
  • These scripts are triggered when displaying the display control under which the extension is configured.
Note
titleExample

If One Configures, DstExtension.groovy under Display Controls#ObsToObsFlowSheetObsToObsFlowSheet Control (Refer Sample Config), then the groovy is executed while the control (Display Controls#ObsToObsFlowSheetObsToObsFlowSheet Control) is displayed.


Obs To Obs Flowsheet

Configuration

Location and Example

Note

Add the groovy extension name as value of key "type" under the configuration section of Display Controls#ObsToObsFlowShee ObsToObsFlowSheet Control 



  • 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'



Tip
iconfalse
titleOn this Page

Table of Contents


Panel
titleColorWhite
titleBGColor#1FA5A0
titleRelated Links

Auto-Calculation of Observations