Report Time Monitoring with ReportTimerController - hmislk/hmis GitHub Wiki
The ReportTimerController
utility class has been introduced to track and monitor the time taken for report generation in the system. This allows automatic logging of report execution metrics for audit, performance optimization, and debugging purposes.
- โฐ Start time - When report generation begins
- โฐ End time - When report generation completes
- ๐ค Executing user - Who initiated the report
- ๐ Report type and name - What report was generated
All captured data is saved in the ReportLog
entity for future analysis.
com.divudi.bean.common.ReportTimerController
The ReportTimerController encapsulates the logic required to:
- Log the start time of a report
- Execute the report generation logic
- Log the end time and calculate report duration
- Save execution metrics to the database
Follow this step-by-step guide to integrate report time tracking into your existing report methods:
Find the XHTML file where your report exists (e.g., /pharmacy/bin_card.xhtml
)
Navigate to the processing button and identify the method in the action
attribute:
action="#{pharmacyErrorChecking.processBinCard()}"
Wrap your existing report processing logic inside the trackReportExecution
method:
reportTimerController.trackReportExecution(() -> {
// Your existing report processing code goes here
}, YourReportEnum.REPORT_NAME, sessionController.getLoggedUser());
public void processBinCard() {
binCardEntries = stockHistoryController.findBinCardDTOs(fromDate, toDate, null, department, item);
if (configOptionApplicationController.getBooleanValueByKey("Pharmacy Bin Card - Hide Adjustment Bills in Bin Card", true)) {
List<BillType> bts = new ArrayList<>();
bts.add(BillType.PharmacyAdjustmentSaleRate);
Iterator<PharmacyBinCardDTO> iterator = binCardEntries.iterator();
while (iterator.hasNext()) {
PharmacyBinCardDTO dto = iterator.next();
if (dto.getBillType() != null && bts.contains(dto.getBillType())) {
iterator.remove();
}
}
}
}
public void processBinCard() {
reportTimerController.trackReportExecution(() -> {
binCardEntries = stockHistoryController.findBinCardDTOs(fromDate, toDate, null, department, item);
if (configOptionApplicationController.getBooleanValueByKey("Pharmacy Bin Card - Hide Adjustment Bills in Bin Card", true)) {
List<BillType> bts = new ArrayList<>();
bts.add(BillType.PharmacyAdjustmentSaleRate);
Iterator<PharmacyBinCardDTO> iterator = binCardEntries.iterator();
while (iterator.hasNext()) {
PharmacyBinCardDTO dto = iterator.next();
if (dto.getBillType() != null && bts.contains(dto.getBillType())) {
iterator.remove();
}
}
}
}, PharmacyReports.PHARMACY_BIN_CARD, sessionController.getLoggedUser());
}
To enable proper identification of report types, ensure your report type is declared in the appropriate module enum. Use the module-specific enum file based on your report's domain.
Example: PharmacyReports.java
package com.divudi.core.data.reports;
public enum PharmacyReports implements IReportType {
PHARMACY_BIN_CARD("Pharmacy Bin Card"),
PHARMACY_STOCK_SUMMARY("Pharmacy Stock Summary"),
PHARMACY_SALES_REPORT("Pharmacy Sales Report");
private final String displayName;
PharmacyReports(String displayName) {
this.displayName = displayName;
}
@Override
public String getDisplayName() {
return displayName;
}
@Override
public String getReportType() {
return this.getClass().getSimpleName();
}
@Override
public String getReportName() {
return this.name();
}
}