This screen is used to create/view/edit the Report Macro lookups. These are used to:

  • enable the accelerated entry of text in any text field by running a report.
  • generate email text.
  • generate text in documents using macro:eval. See below.

If you are having problems, see here.

The fields are the same as for normal Macros (see Lookups|Macros) but with a different usage for the Expression field and an additional Report field.

Description - it is sensible to use a description like the above to emphasise that the macro will generate a text version of the report (and not the actual fully formatted report)

Expression - this is used to pass the data source to the report and we need to access the thing that we are going to report on. This is done using of the JXPath Extension Functions - specifically one of the party:get*() series. As you can see in the above example the expression is getting the last visit for the current patient.
Note: You need to be careful with the syntax used in the Expression. Specifically, you can only use the $xxxx argument format ($patient in the above screen shot) if the ReportMacro is to be invoked directly by the user.  If the ReportMacro is to be invoked from say an Open Office document by using the macro:eval function, then you cannot use the $xxxx argument format. Instead, simply use a period - ie party:getPatientVisit(.) and in the Open Office document the user field should be like: [macro:eval('@referral',openvpms:get(.,'patient.entity'))] - here the second argument is passing the patient entity needed by the macro expression.

Report - the Report to run. See below.
The above macro runs the Referral Letter report, using the current patient's most recent Visit. Note that if there is no current patient, then the macro simply will not expand - i.e. the user will be left with the '@referral' that they typed.


Report macros can use:

  • OpenOffice documents
  • Microsoft Word documents
  • JasperReports templates

 OpenOffice and Word documents

If you are using OpenOffice or Word documents, you may want to do some conditional text handling (ie if sex=male use 'he', if female use 'she', else use 'it'.  This is possible - see here for OpenOffice, here for MS Word.

JasperReports templates

When using JasperReports templates, there are a number of issues to be aware of:

  • a fixed size font should be used
  • special properties need to be defined to indicate to JasperReports how to divide the report into a grid
  • fields should start on grid boundaries to avoid text being excluded

The easiest approach is to:

  • define all dimensions in pixels
  • set the character width and height to a round number
  • ensure the page height and width is divisible by the character size

To set the character size to 10x10 pixels in iReport:

  1. right click on the report in Report Inspector
  2. select Properties
  3. scroll down to Properties in the displayed table
  4. click on the elipsis; this will display a dialog containing the defined properties.
  5. add property net.sf.jasperreports.export.text.character.width with value 10
  6. add property net.sf.jasperreports.export.text.character.height with value 10

Set the page width and height to a multiple of the character width and height. E.g. 500x500. Note also:

  • The 'Stretch with overflow' setting is ignored with when using this Text Export facility, hence all the text needs to fit in the field.
  • With a character width of 10, and a page width of 500 the maximum number of characters in a field will be 500/10=50.  If you need more than this increase the page width to say 2000 and decrease the character width to 5 which will then allow 400 characters.
  • Set the height of your fields to the same as text.character.height setting - eg 10 px
  • Use a small font (say 5) so you can see the text in the fields

See also JasperReports - Text Export Sample

Using macro:eval

Report macros can be run in documents using the macro:eval function.

To access the document (e.g. Patient Letter or Form) that launched them:

  • use '.' without quotes as the Expression
  • use either:
    • macro:eval('<code>') or
    • macro:eval('<code>', /)

to run the macro, where <code> is the report macro code.

Syndicate content