CSH Query - iReports stuff

As a result of struggling with iReports to get invoices to print the way I want them, I have realised that:

1) I need to beef up the Reference|Reporting CSH topic to better describe field names - ie that as well as 'simple' field names like customer.entity.companyName, one can also use expressions like
[date:format(openvpms:get(.,"target.startTime"),"yyyyMMdd")]

2) I do not understand the field names used in (for example) the invoice sub-report (where the field names appear have the format "target.xxxx" where xxxx would appear to be field name used in the main report)

3) I think I understand the function of the data source given to the subreport  - eg '$P{dataSource}.getDataSource("items", new String[]{"target.patient.entity.name", "target.startTime"})' - this sets things to provide the subreport with the data collection sorted by patientName/lineItemDateTime

4) I think that one can either sort the data via the above mechanism, or sort it in iReports - or do both. However, I suspect that where possible one should do it via the subreport data source expression - if for no other reason that iReports 3.7.6 appears to have a bug that leads to array bounds exceptions if a variable is used as a sort parameter but is not the first sort item.

5) I do not understand where the 'TOTAL_DISCOUNT' field in the invoice jrxml comes from - it is certainly not a field in act.customerAccountChargesInvoice - so it must have some special handling - but I cannot find 'TOTAL_DISOUNT' in the source.

6) Is it possible to use a function in the data source expression? I am getting:
Failed to generate report: Error evaluating expression :
Source text : $P{dataSource}.getDataSource("items", new String[]{"target.patient.entity.name","[date:format(openvpms:get(.,'target.startTime'),'yyyyMMdd')]","target.product.entity.type.source.sortOrder","target.startTime"})

ie I am trying to use [date:format(openvpms:get(.,"target.startTime"),"yyyyMMdd")] as one of 'sortNodes'.

 

Could someone please verify 1,3 & 4 above and fill in 2 & 5 to explain target. and TOTAL_DISCOUNT, and answer 6.

Regards, Tim G

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: CSH Query - iReports stuff

1). Correct. You can use simple archetype dot notation, and xpath expressions. The latter are denoted by the '[]'. E.g. $F{[party:getPartyFullName(.)]}

2). The invoice sub report is passed a collection of actRelationship.customerAccountInvoiceItem archetypes, via the following:

 $P{dataSource}.getDataSource("items", new String[]{"target.patient.entity.name", "target.startTime"} 

i.e. the objects from the "items" node are passed to the sub report.

To reference the invoice items themselves, you use the "target" node of actRelationship.customerAccountInvoiceItem.

So to get the invoice item, you use "target". To get the patient of the invoice item, you use "target.patient.entity" ("target.patient" returns the participation.patient archetype)

3). Yep.

4). The existing report templates do both. Theoretically the data source should sort faster, but this hasn't been optimised.

5). TOTAL_DISCOUNT is a variable. Its set from the SUM_target.discount variable from the sub-report. If you look at the jxrml you'll see:

 <subreport isUsingCache="true">
    <reportElement key="subreport-1" x="2" y="9" width="530" height="13"/>
    <dataSourceExpression><![CDATA[$P{dataSource}.getDataSource("items", new String[]{"target.patient.entity.name", "target.startTime"})]]></dataSourceExpression>
    <returnValue subreportVariable="SUM_target.discount" toVariable="TOTAL_DISCOUNT"/>
    <subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA["invoiceItems.jrxml"]]></subreportExpression>
</subreport> 

In the sub-report:

 <variable name="SUM_target.discount" class="java.math.BigDecimal" calculation="Sum">
    <variableExpression><![CDATA[$F{target.discount}]]></variableExpression>
</variable>

6). No - data source expressions only accept archetype dot notation. You might be able to declare an expression as a sortField.

That said, whats wrong with "target.startTime"?

-Tim A

Re: CSH Query - iReports stuff

Tim A  - thanks for this. I have started (but not completed) the beef up of the CSH reporting pages.

TOTAL_DISCOUNT - ahah - what confused me was that TOTAL_DISCOUNT is also a field (as well as a variable). I now understand that if you define a field that is not used, then no error is generated - so if I define a field named customer.abcd.efgh there would not be a problem unless I used a text field in the report with the Text Field Expression $F{customer.abcd.efgh}. Hence the field TOTAL_DISCOUNT can be deleted.
This also means that there is no penalty in defining fields that are not used - and one might want to do this to illustrate what is available if needed.

target.startTime - this contains the full date/time timestamp of the invoice line item (not just the date). Hence if you want to sort on patient/date/productTypeInvoiceOrder (so that for a multiday hospital stay, each day's charges are grouped together) then you need to sort by date and not date-time. 

 

Regards, Tim G

Syndicate content