Skip to content

Commit

Permalink
BAH-3049| Samridhi | Put default dates in Report screen to save time
Browse files Browse the repository at this point in the history
* BAH-3049| Samridhi | Put default dates in Report screen to save time

* BAH-3049| Samridhi | Add test default dates in Report screen to save time

* BAH-3049| Samridhi | Fix typo in quarter

* BAH-3049| Samridhi | Fix uglify error

* BAH-3049| Samridhi | Fix uglify error

* BAH-3049| Samridhi | Fix uglify error

* BAH-3049| Samridhi | Fix uglify error
  • Loading branch information
Samridhi-98 authored Aug 17, 2023
1 parent adb0b99 commit 66212db
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 34 deletions.
39 changes: 20 additions & 19 deletions ui/app/i18n/reports/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,44 @@
"login": "Login",
"selectLocation": "Select Location",
"clinical_key": "Clinical",
"REPORTS_NAME_HEADER_KEY":"Name",
"REPORTS_NAME_HEADER_KEY": "Name",
"REPORTS_START_DATE_HEADER_KEY": "Start Date",
"REPORTS_END_DATE_HEADER_KEY": "End Date",
"RUN_NOW_BUTTON_KEY": "Run Now",
"RUN_REPORT_BUTTON_KEY": "Run Report",
"QUEUE_BUTTON_KEY": "Queue",
"REPORT_FORMAT_KEY": "Format",
"REPORTS_TITLE_KEY":"Reports",
"REPORTS_TITLE_WITHOUT_DATE_RANGE_KEY":"Reports without Date Range",
"REPORTS_MISSING_WARNING_MESSAGE_KEY":"New reports can be configured in a json file within openmrs/apps/reports/reports.json. Please consult the documentation for more information on configuring canned reports",
"MESSAGE_DIALOG_OPTION_COPY" : "Copy Error",
"REPORTS_TITLE_KEY": "Reports",
"REPORTS_TITLE_WITHOUT_DATE_RANGE_KEY": "Reports without Date Range",
"REPORTS_MISSING_WARNING_MESSAGE_KEY": "New reports can be configured in a json file within openmrs/apps/reports/reports.json. Please consult the documentation for more information on configuring canned reports",
"MESSAGE_DIALOG_OPTION_COPY": "Copy Error",
"MESSAGE_DIALOG_OPTION_OKAY": "OK",
"REPORTS_QUEUE": "Reports Queue",
"REPORTS_SEARCH_PLACEHOLDER" : "Search By Report Name",
"REPORT_STATUS" : "Status",
"REPORT_REQUEST_TIME" : "Request time",
"REPORT_DELETE_SUCCESSFUL" : "Successfully deleted report",
"REPORT_DELETE_ERROR" : "Error in deleting report",
"REPORT_DELETE_DIALOG" : "Do you want to delete the report?",
"REPORT_DOWNLOAD" : "Download",
"REPORTS_SEARCH_PLACEHOLDER": "Search By Report Name",
"REPORT_STATUS": "Status",
"REPORT_REQUEST_TIME": "Request time",
"REPORT_DELETE_SUCCESSFUL": "Successfully deleted report",
"REPORT_DELETE_ERROR": "Error in deleting report",
"REPORT_DELETE_DIALOG": "Do you want to delete the report?",
"REPORT_DOWNLOAD": "Download",
"REPORT_ERROR": "Error",
"REPORT_DELETE" : "Delete",
"REPORTS_HEADER_REPORTS" : "Reports",
"REPORTS_HEADER_MY_REPORTS" : "My Reports",
"REPORT_DELETE": "Delete",
"REPORTS_HEADER_REPORTS": "Reports",
"REPORTS_HEADER_MY_REPORTS": "My Reports",
"NO_RESULTS_FOUND": "No results found",
"PRIVILEGE_REQUIRED": "User is logged in but doesn't have the relevant privilege",
"NO_FULFILMENT_MESSAGE": "No observations captured for this order.",
"NO_NAVIGATION_LINKS_AVAILABLE_MESSAGE": "No navigation links available.",
"CHOOSE_REPORT_FORMAT": "Choose Format",
"ACCEPT":"Accept",
"ACCEPT": "Accept",
"SELECT_VALUE_FROM_AUTOCOMPLETE_DEFAULT_MESSAGE": "Please select a value from auto complete",
"CONCEPT_NOT_FOUND_MESSAGE": "concept not found.",
"TIME_OF_BIRTH_LABEL": "Time of Birth",
"PATIENT_PROFILE_RELATIONSHIPS_LABEL": "Relationships",
"BROWSER_DOES_NOT_SUPPORT_VIDEO_TAG_MESSAGE":"Your browser does not support the video tag.",
"BROWSER_DOES_NOT_SUPPORT_VIDEO_TAG_MESSAGE": "Your browser does not support the video tag.",
"YEARS_LABEL": "Years",
"CHOOSE_ANSWER_FROM_DROPDOWN_LABEL": "Choose Answer",
"DELETE_LABEL": "Delete",
"EDIT_LABEL": "Edit"
}
"EDIT_LABEL": "Edit",
"REPORT_DATE_RANGE": "Select Date Range"
}
45 changes: 39 additions & 6 deletions ui/app/reports/controllers/reportsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,56 @@

angular.module('bahmni.reports')
.controller('ReportsController', ['$scope', 'appService', 'reportService', 'FileUploader', 'messagingService', 'spinner', '$rootScope', 'auditLogService', function ($scope, appService, reportService, FileUploader, messagingService, spinner, $rootScope, auditLogService) {
const format = _.values(reportService.getAvailableFormats());
const dateRange = _.values(reportService.getAvailableDateRange());

$scope.uploader = new FileUploader({
url: Bahmni.Common.Constants.uploadReportTemplateUrl,
removeAfterUpload: true,
autoUpload: true
});

$scope.uploader.onSuccessItem = function (fileItem, response) {
fileItem.report.reportTemplateLocation = response;
};

$rootScope.default = _.isUndefined($rootScope.default) ? {reportsRequiringDateRange: {}, reportsNotRequiringDateRange: {}} : $rootScope.default;
$rootScope.default = _.isUndefined($rootScope.default) ? {
reportsRequiringDateRange: {
responseType: format[1],
dateRangeType: dateRange[0],
startDate: dateRange[0],
stopDate: dateRange[0],
report: {
responseType: format[1]
}
},
reportsNotRequiringDateRange: {}
} : $rootScope.default;
$scope.reportsDefined = true;
$scope.enableReportQueue = appService.getAppDescriptor().getConfigValue("enableReportQueue");

$scope.setDefault = function (item, header) {
var setToChange = header === 'reportsRequiringDateRange' ? $rootScope.reportsRequiringDateRange : $rootScope.reportsNotRequiringDateRange;
setToChange.forEach(function (report) {
report[item] = $rootScope.default[header][item];
if (item == 'dateRangeType') {
$rootScope.default.reportsRequiringDateRange.startDate = $rootScope.default[header][item];
$rootScope.default.reportsRequiringDateRange.stopDate = dateRange[0];
report['startDate'] = $rootScope.default[header][item];
report['stopDate'] = dateRange[0];
}
else if ($rootScope.default[header][item] === undefined) {
$rootScope.reportsRequiringDateRange.forEach(function (report) {
report.startDate = dateRange[0];
report.stopDate = dateRange[0];
report.responseType = format[1];
});
}
else {
report[item] = $rootScope.default[header][item];
}
});
};

var isDateRangeRequiredFor = function (report) {
return _.find($rootScope.reportsRequiringDateRange, {name: report.name});
return _.find($rootScope.reportsRequiringDateRange, { name: report.name });
};

var validateReport = function (report) {
Expand Down Expand Up @@ -71,7 +98,7 @@ angular.module('bahmni.reports')
};

var log = function (reportName) {
auditLogService.log(undefined, 'RUN_REPORT', {reportName: reportName}, "MODULE_LABEL_REPORTS_KEY");
auditLogService.log(undefined, 'RUN_REPORT', { reportName: reportName }, "MODULE_LABEL_REPORTS_KEY");
};

$scope.scheduleReport = function (report) {
Expand All @@ -97,6 +124,11 @@ angular.module('bahmni.reports')
$scope.formats = _.pick(reportService.getAvailableFormats(), supportedFormats);
};

var initializeDateRange = function () {
var supportedDateRange = appService.getAppDescriptor().getConfigValue("supportedDateRange") || _.keys(reportService.getAvailableDateRange());
$scope.dateRange = _.pick(reportService.getAvailableDateRange(), supportedDateRange);
};

var initialization = function () {
var reportList = appService.getAppDescriptor().getConfigForPage("reports");
$rootScope.reportsRequiringDateRange = _.isUndefined($rootScope.reportsRequiringDateRange) ? _.values(reportList).filter(function (report) {
Expand All @@ -108,6 +140,7 @@ angular.module('bahmni.reports')
$scope.reportsDefined = _.values(reportList).length > 0;

initializeFormats();
initializeDateRange();
};

initialization();
Expand Down
13 changes: 13 additions & 0 deletions ui/app/reports/services/reportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ angular.module('bahmni.reports')
.service('reportService', ['appService', '$bahmniCookieStore', '$http', function (appService, $bahmniCookieStore, $http) {
var paperSize = appService.getAppDescriptor().getConfigValue("paperSize");
var appName = appService.getAppName() ? appService.getAppName() : "reports";
var currentDate = new Date();
var availableFormats = {
"CSV": "text/csv",
"HTML": "text/html",
Expand All @@ -12,6 +13,14 @@ angular.module('bahmni.reports')
"CUSTOM EXCEL": "application/vnd.ms-excel-custom",
"ODS": "application/vnd.oasis.opendocument.spreadsheet"
};
var avaialbleDateRange = {
"Today": currentDate,
"This Month": new Date(currentDate.getFullYear(), currentDate.getMonth(), 1),
"This Quarter": new Date(currentDate.getFullYear(), Math.floor(currentDate.getMonth() / 3) * 3, 1),
"This Year": new Date(currentDate.getFullYear(), 0, 1),
"Previous Week": new Date(new Date().setDate(currentDate.getDate() - 6)),
"Previous Month": new Date(new Date().setDate(currentDate.getDate() - 30))
};

var scheduleReport = function (report) {
var url = Bahmni.Common.Constants.reportsUrl + "/schedule";
Expand Down Expand Up @@ -44,6 +53,9 @@ angular.module('bahmni.reports')
}
});
};
var getAvailableDateRange = function () {
return avaialbleDateRange;
};
var deleteReport = function (id) {
var url = Bahmni.Common.Constants.reportsUrl + "/delete/{0}";
url = url.format(id);
Expand All @@ -63,6 +75,7 @@ angular.module('bahmni.reports')
getFormatForMimeType: getFormatForMimeType,
getMimeTypeForFormat: getMimeTypeForFormat,
getAvailableFormats: getAvailableFormats,
getAvailableDateRange: getAvailableDateRange,
scheduleReport: scheduleReport,
getScheduledReports: getScheduledReports,
deleteReport: deleteReport,
Expand Down
14 changes: 12 additions & 2 deletions ui/app/reports/views/reports.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ <h2 class="section-title">{{::'REPORTS_TITLE_KEY' | translate}}</h2>
<table class="alt-row form">
<thead>
<tr>
<th>{{::'REPORTS_NAME_HEADER_KEY' | translate}}</th>
<th style="display: flex; justify-content: space-between;">
<div>{{::'REPORTS_NAME_HEADER_KEY' | translate}}</div>
<div style="width: 170px; margin-right: 25px;">
{{::'REPORT_DATE_RANGE' | translate}}
<span class="asterick">*</span>
<select ng-model="default.reportsRequiringDateRange.dateRangeType"
ng-options="type as label for (label , type) in ::dateRange"
ng-change="setDefault('dateRangeType', 'reportsRequiringDateRange')">
</select>
</div>
</th>
<th class="reports-start-date">{{::'REPORTS_START_DATE_HEADER_KEY ' |translate}}
<span class="asterick">*</span>
<input ng-model="default.reportsRequiringDateRange.startDate" date-converter
class="form-field start-date" type="date" max="{{default.reportsRequiringDateRange.stopDate | date:'yyyy-MM-dd'}}"
ng-change="setDefault('startDate', 'reportsRequiringDateRange')">
ng-change="setDefault('startDate', 'reportsRequiringDateRange')">
</th>
<th class="reports-stop-date">{{::'REPORTS_END_DATE_HEADER_KEY' |translate}}
<span class="asterick">*</span>
Expand Down
33 changes: 26 additions & 7 deletions ui/test/unit/reports/controllers/reportsController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ describe("ReportsController", function () {
mockAppDescriptor.getConfigForPage.and.returnValue(typicalReportConfig);
appServiceMock.getAppDescriptor.and.returnValue(mockAppDescriptor);

reportServiceMock = jasmine.createSpyObj('reportService', ['scheduleReport', 'getAvailableFormats', 'getMimeTypeForFormat']);
reportServiceMock = jasmine.createSpyObj('reportService', ['scheduleReport', 'getAvailableFormats', 'getAvailableDateRange', 'getMimeTypeForFormat']);
scheduleReportPromise = specUtil.createServicePromise('scheduleReport');
reportServiceMock.scheduleReport.and.returnValue(scheduleReportPromise);
reportServiceMock.getAvailableFormats.and.returnValue({
"CSV": "text/csv",
"HTML": "text/html"
});

reportServiceMock.getAvailableDateRange.and.returnValue({
"Today": new Date(),
"This Month": new Date(new Date().getFullYear(), new Date().getMonth(), 1)
});
controller = $controller;
controller('ReportsController', {
$scope: scope,
Expand All @@ -63,7 +66,7 @@ describe("ReportsController", function () {
messagingService: messagingServiceMock,
spinner: spinnerMock,
$rootScope: rootScope,
FileUploader: function () {}
FileUploader: function () { }
});
}));

Expand All @@ -81,14 +84,30 @@ describe("ReportsController", function () {
reportService: reportServiceMock,
messagingService: messagingServiceMock,
$rootScope: rootScope,
FileUploader: function () {}
FileUploader: function () { }
});

expect(_.keys(scope.formats).length).toBe(2);
expect(scope.formats['CSV']).toBe('text/csv');
expect(scope.formats['HTML']).toBe('text/html');
});

it('should initialise date range with supportedDateRange config', function () {
rootScope.default.reportsRequiringDateRange = {
dateRangeType: new Date(),
startDate: new Date(),
stopDate: new Date(),
};
scope.setDefault('dateRangeType', 'reportsRequiringDateRange');
scope.setDefault('startDate', 'reportsRequiringDateRange');
scope.setDefault('stopDate', 'reportsRequiringDateRange');

expect(_.keys(rootScope.default.reportsRequiringDateRange).length).toBe(3);
expect((rootScope.default.reportsRequiringDateRange.dateRangeType).getDate()).toBe(new Date().getDate());
expect(rootScope.reportsRequiringDateRange[0].startDate).toBe(rootScope.default.reportsRequiringDateRange.startDate);
expect(rootScope.reportsRequiringDateRange[0].stopDate).toBe(rootScope.default.reportsRequiringDateRange.stopDate);
});

it('should initialise all available formats when supportedFormats config is not specified', function () {
mockAppDescriptor.getConfigValue.and.returnValue(undefined);

Expand Down Expand Up @@ -351,7 +370,7 @@ describe("ReportsController", function () {
messagingService: messagingServiceMock,
spinner: spinnerMock,
$rootScope: rootScope,
FileUploader: function () {}
FileUploader: function () { }
});
}));

Expand Down Expand Up @@ -379,7 +398,7 @@ describe("ReportsController", function () {
messagingService: messagingServiceMock,
spinner: spinnerMock,
$rootScope: rootScope,
FileUploader: function () {}
FileUploader: function () { }
});
}));

Expand All @@ -397,7 +416,7 @@ describe("ReportsController", function () {
responseType: 'text/html'
});

var messageParams = {reportName: 'Vitals'};
var messageParams = { reportName: 'Vitals' };
expect(mockAuditLogService.log).toHaveBeenCalledWith(undefined, 'RUN_REPORT', messageParams, 'MODULE_LABEL_REPORTS_KEY');
});

Expand Down

0 comments on commit 66212db

Please sign in to comment.