📄 TestReport.cshtml Documentation

File Path: IrbyImaging/Views/HRImaging/TestReport.cshtml
Purpose: Razor View to render HR imaging test reports using BoldReports viewer.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. File Structure
  5. View Model & Data Context
  6. Main Components & Code Breakdown
  7. API Endpoints Overview
  8. Third‑party Integrations
  9. Sample Code Blocks & Usage Examples
  10. UML Component Diagram
  11. Error Handling & Return Types
  12. Conclusion

1. Overview & Purpose 🚀

The TestReport.cshtml is a Razor view in the HRImaging area of the IrbyImaging web application. It embeds a rich, interactive report viewer to display HR-related test results.

  • Key Goals:
    • Dynamically load different report definitions via ViewBag.ReportType.
    • Provide a consistent layout using a shared _reportLayout.cshtml.
    • Offer interactive toolbar features (export, print, navigation).

2. Dependencies & Technologies ⚙️

Category Details
Framework ASP.NET Core MVC (Razor Views)
Reporting BoldReports JavaScript Report Viewer
Front‑end HTML5, CSS, JavaScript (for event callbacks)
Layout Master _reportLayout.cshtml (Shared layout for reports)
API /api/ReportViewer (Back‑end report engine)

3. Key Functional Areas 🗂️

Functional Area Description
Layout Integration Uses a shared Razor layout for consistent styling and scripts.
Report Viewer Host Embeds <bold-report-viewer> tag to host the report UI.
Dynamic Report Path Reads ViewBag.ReportType to decide which report to fetch and display.
Toolbar Event Binding Hooks into viewer events: onToolbarRendering, onToolBarItemClick, etc.
Export Handling Captures export actions to customize formats or download behavior.

4. File Structure 📁

IrbyImaging/
└─ Views/
   └─ HRImaging/
      └─ TestReport.cshtml    ← This file
Shared/
└─ _reportLayout.cshtml      ← Master layout for report pages

5. View Model & Data Context 📝

This view does not bind to a strongly‑typed model. Instead, it uses:

  • ViewBag.ReportType
    • Type: string
    • Purpose: Specifies the path or key of the report definition (e.g., .rdl file) to render.

Controller Example:

public IActionResult TestReport()
{
    // Could be set based on user choice or business logic
    ViewBag.ReportType = "HRImaging/PatientLabResults";
    return View();
}

6. Main Components & Code Breakdown 🔍

@{
    Layout = "~/Views/Shared/_reportLayout.cshtml";
}

<div style="min-height: 800px; width: 100%;">
  <bold-report-viewer
      id="viewer"
      report-path="@ViewBag.ReportType"
      report-service-url="/api/ReportViewer"
      toolbar-rendering="onToolbarRendering"
      tool-bar-item-click="onToolBarItemClick"
      export-item-click="onExportItemClick">
  </bold-report-viewer>
</div>
Line(s) Description
Layout = ... Applies the shared report layout for consistent header, footer, CSS, JS.
<div> container Ensures the viewer occupies full width and a minimum height of 800px.
<bold-report-viewer> Core component. Renders the interactive report.
report-path Binds @ViewBag.ReportType to instruct which report design to load.
report-service-url Points to the back‑end API that serves report definitions and data (/api/ReportViewer).
toolbar-rendering, tool-bar-item-click, export-item-click JavaScript callbacks for toolbar events.

7. API Endpoints Overview 🛣️

Endpoint HTTP Verb Purpose
/api/ReportViewer POST Serves report definition & data to the viewer.
/api/ReportViewer/export POST Handles export requests (PDF, Excel, etc.).

👉 The viewer will internally call these endpoints. Ensure CORS, authentication, and routing are configured.


8. Third‑party Integrations 🔗

  • BoldReports
    • Provides <bold-report-viewer> web component.
    • Offers built‑in toolbar, pagination, export, print, zoom, search.
    • Requires registering scripts/styles in the shared layout (_reportLayout.cshtml).

9. Sample Code Blocks & Usage Examples 📓

Controller Setup

public class HRImagingController : Controller
{
    public IActionResult TestReport(string reportName)
    {
        // reportName could be "EmployeePerformance" or "LabResults"
        ViewBag.ReportType = $"HRImaging/{reportName}.rdl";
        return View();
    }
}

Shared Layout Snippet (_reportLayout.cshtml)

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>@ViewData["Title"] - IrbyImaging Reports</title>
  <link href="~/lib/boldreports/styles/bold.min.css" rel="stylesheet" />
  <script src="~/lib/boldreports/scripts/bold.min.js"></script>
</head>
<body>
  <div class="report-container">
    @RenderBody()
  </div>
  <script>
    function onToolbarRendering(args) { /* customize toolbar */ }
    function onToolBarItemClick(args) { /* handle clicks */ }
    function onExportItemClick(args) { /* post‑process exports */ }
  </script>
</body>
</html>

10. UML Component Diagram 📊

graph LR
  Browser(Client) --> ViewerComponent["<bold-report-viewer>"]
  ViewerComponent --> |"POST /api/ReportViewer"| ReportAPI[/ReportViewer Controller/]
  ReportAPI --> ReportEngine[(BoldReports Engine)]
  ReportEngine --> DataSource[(Database / RDLC files)]
  • Browser hosts the Razor view.
  • ViewerComponent sends/receives data to/from the ReportAPI.
  • ReportEngine processes the .rdl/.rdlc and fetches data.
  • DataSource holds the actual report definitions & business data.

11. Error Handling & Return Types ❗

  • On Viewer Errors:
    • The BoldReports viewer exposes events like on-report-load-failed.
    • You can hook into these in the layout scripts to show friendly messages.
  • API Errors:
    • Return HTTP 4xx/5xx with JSON error object:
      { "status": "error", "message": "Report not found" }
      

12. Conclusion 🎉

The TestReport.cshtml is a lightweight, reusable Razor view designed to render dynamic HR test reports using the BoldReports viewer. By centralizing layout and wiring up key event callbacks, it provides a flexible foundation for:

  • Switching report definitions on the fly
  • Handling toolbar and export customizations
  • Integrating with your back‑end report service

Use this template across the HRImaging area to maintain consistency and reduce boilerplate when adding new report types.

Happy Reporting! 🖥️📈