Codementor Events

Stimulsoft Monthly-Scheduler-View report

Published Apr 30, 2018

Introduction

In this article I will describe how to implement a Stimulsoft Asp.Net MVC report which looks like a monthly scheduler and has some custom filters.
Stimulsoft offers a wide variety of reports and a wide variety of export options, the UI it's also pretty nice so it was decided to use this option. For showing data in an Asp.Net MVC view, two main steps are required:

  1. Create a .mrt file which represents the template from which the report will be created.
  2. Provide data sources to be used by the previously created template.

What is our goal?

We have a list of patients and we want to show their appointments in a monthly-scheduler-like report. The report should have four filters in order to be able to narrow down by patient, patient’s office and the month in where the appointment are created. For every patient, we need to display his/her monthly scheduler on at least one page and if there are more appointments in a day, then the day slot should extend accordingly. The resulting report looks like in the image below:

P1.png

So in every day-slot we should present one ore more patient’s appointments with some information about them(like the time interval and with who the appointment would take place).

Create the designer file

The first step in creation of a Stimulsoft report is the creation of the .mrt file(I used Stimulsoft Designer version 2017.1.6). The designer has some specific tools which are used for rendering report’s data and I will explain what is the behavior for all used ones. This is how the .mrt file looks like:
P2.png

The main control here is the “Patient” data band which displays all patients who have visits in selected month. Data band controls are used for displaying a control template for every record in the related data source, so for every patient in the data source, the created template controls would be displayed.
For showing the patient info in the beginning of every page, we used a GroupHeaderBand which splits the data source by a certain condition and shows the controls which are declared inside it, for every created sub set of data.
In this case we didn’t specify any control in the “Patient” data band but we created another data band called “MonthCalendar” which doesn’t have any data source but it’s directly linked with it’s parent data band. This is how the data band configuration window looks like(double click on the data band control).
P3.png
P4.png

As you can see there is no specified Data Source but the Count Data is set for 6 and also the selected Master Component is the “Patient” data band. This construction tells the report to do the followings:

  1. Draw 6 times current data band – because Count Data is set to 6
  2. For every patient in the data source which is linked to “Patient” data band, draw 6 times current data band( - because Master Component is set to “Patient” data band and when this kind of construction is used, then the display is vertical, for parent item, all children items are displayed).
    As you can see, above the “MonthCaledar” data band exists also an header band in where days of week are shown. Since the header is placed above the “MonthCalendar”, then it is related to it.
    So what we have till now is:
  3. Get all patients which have appointments in specified month
  4. For every patient in the data source, create one header(the days header) and 6 rows (the Month Calendar is drawn 6 times) – which represents the month’s weeks.
    We have the weeks, so we need to add the days of week in the display. For displaying this, we used a “Cross Data” control which is embedded in the “MonthCalendar” data band – the “DaysInMonth” cross-data band. This type of control renders horizontally, so for every item in it’s related data source, specified controls are rendered. Since we need to display the days of week here, the following configuration have been used:
    P5.png

This template is translated like this: draw horizontally 7 times the controls which are placed in this cross-data band.
As you can see, the controls created at this level uses a variable called “dt” and another embedded data band which have only one Text element. The variable is used for showing the day of month and the embedded data band is used for showing the appointment(s) information.
The initialization and the usage of this “dt” variable is done in the “MonthCalendar” data band’s Begin Render event. This event is triggered once when the control is about to be rendered. The below image represents the “BeginRender” event editor code:
P6.png
The code is translated like this: every time a new month is about to be rendered, “dt” variable get the value of the first day of the current month then goes back until Sunday is reached, for starting all weeks from Sunday.
“dt” variable is incremented in the Rendering event of the cross-data band control called “DaysInMonth” and this is translated like this: every time a new day is rendered, increment the variable value.
Till now, we set up the scheduler-like report so if we try to test the report, it should show an empty monthly-scheduler with days of month properly rendered for every patient from data source.
It time now to display also the patient’s appointments in the monthly scheduler and this is accomplish using another data band which is embedded in the cross-data band and it’s called “PatientVisits”. This data band is linked to a data source which will get all appointments from selected month.
The configuration window is shown below:
P7.png
P8.png
P9.png
P10.png
So this data band is linked to a data source which gets all the patients which have appointments in selected month, has a Relation called PatientVisits, set it’s master component to Patient and has a filter which gets only those appointments which correspond to current day, so effectively for every day in the month, the visits list is queried.
For getting only the appointments for current patient a Relation was used and this tells that for a parent row, get only children rows which correspond to current parent row. In our case, the connection between “Patient” data band and “PatientVisits” data band is the patient’s id. The Relation works hand in hand with Master Component so in our case the Master Component for “PatientVisits” is the “Patient” data band and this works like this:

FOR every patient in “Patient” DO
BEGIN
SET currentPatient = GetCurrentPatient();
Var patientAppointments=IterateOverAllAppointmentsAndGetPatientAppointments();
Var filteredPatientAppointments = ExecuteDayFilter();
DisplayText(filteredPatientAppointments);
END
An important setting here is added in the “Begin Render” event of the “PatientsVisits” data band:

StiDataHelper.SetData(PatientVisits, true);

Another variable which is used just for display is the “Display Date” variable which gets initialize in the “Patient” data band’s “Begin Render” event:

DisplayDate = new DateTime(Year,Month,1).ToString("yyyy, MMMM");

Creation of data sources
For this report, two data sources are needed, one is linked with “Patient” data band and another one is linked with “PatientVisits” data band.
“Patient” data source gets all the patients which have appointments in selected month and retrieve patient information like the Id, Name, address…
“PatientVisits” data source gets all appointments for selected month and some needed information about them.

Specify the filters
For creating the filters, we need to create variables and set them accordingly. Stimulsoft reports provides this out of the box, we just need to create variables, link them to proper data source and select how them we want to behave.

Discover and read more posts from Vlad Daraban
get started