{"size": 3496, "ext": "js", "max_stars_repo_path": "root/webapp/app/scripts/controllers/modal/exportcsv.js", "max_stars_repo_name": "SolidStateGroup/patientview", "max_stars_repo_stars_event_min_datetime": "2015-06-03T10:18:35.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-30T09:04:42.000Z", "max_issues_repo_path": "root/webapp/app/scripts/controllers/modal/exportcsv.js", "max_issues_repo_name": "SolidStateGroup/patientview", "max_issues_repo_issues_event_min_datetime": "2015-07-31T14:34:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T03:20:53.000Z", "max_forks_repo_path": "root/webapp/app/scripts/controllers/modal/exportcsv.js", "max_forks_repo_name": "SolidStateGroup/patientview", "max_forks_repo_forks_event_min_datetime": "2015-06-03T10:19:02.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-01T07:06:50.000Z"}
{"max_stars_count": 7, "max_issues_count": 10, "max_forks_count": 3, "avg_line_length": 39.2808988764, "max_line_length": 113, "alphanum_fraction": 0.5715102975}
angular.module('patientviewApp').controller('ExportInfoModalInstanceCtrl',
['$scope','$modalInstance', '$location', 'ExportService', 'ObservationHeadingService', 'UtilService', 'result',
    function ($scope, $modalInstance, $location, ExportService, ObservationHeadingService, UtilService, result) {
        $scope.selectedGroup = [];
        $scope.filterString = "";
        /**
         * Setup the default period to export
         * @type {Date}
         */
        var today = new Date();
        var todayDay = ("0" + today.getDate().toString()).slice(-2);
        var todayMonth = (today.getMonth()+1 < 10 ? "0" : "") + (today.getMonth()+1).toString().slice(-2);

        var currentDateTo = {};
        currentDateTo['day'] = todayDay;
        currentDateTo['month'] = todayMonth;
        currentDateTo['year']= today.getFullYear().toString();
        $scope.to = currentDateTo;

        var currentDateFrom = {};
        currentDateFrom['day']   = todayDay;
        currentDateFrom['month'] = todayMonth;
        currentDateFrom['year']  = (today.getFullYear()-3).toString();
        $scope.from = currentDateFrom;

        // Add to scope, remove blank values so date will always be selected
        $scope.months =  _.without(UtilService.generateMonths(), '');
        $scope.years = _.without(UtilService.generateYears1990(), '');
        $scope.days =  _.without(UtilService.generateDays(), '');

        // Add the referrer (used for the end point)
        $scope.referrer = $location.$$path.toString();
        $scope.showResults = false;

        // Setup the title
        if ($scope.referrer == ("/results") || $scope.referrer == ("/resultstable")) {
            $scope.referrer = "/results";
            $scope.showResults = true;
            $scope.pgtitle = "Results";
        } else if ($scope.referrer == "/letters"){
            $scope.pgtitle = "Letters";
        } else if ($scope.referrer == "/medicines") {
            $scope.pgtitle = "Medicines";
        }

        $scope.loadingMessage = "Loading";

        $scope.init = function(){
            $scope.loading = true;

            ObservationHeadingService.getAvailableObservationHeadings($scope.loggedInUser.id)
                .then(function(observationHeadings) {
                $scope.observationHeadings = observationHeadings;
                $scope.loading = false;
            }, function() {
                alert('Error retrieving result types');
            });
        };

        $scope.isResultTypeChecked = function (observationHeading) {
            if (_.contains($scope.selectedGroup, observationHeading)) {
                return 'glyphicon glyphicon-ok pull-right';
            }
            return false;
        };

        $scope.setSelected = function(observationHeading){
            $scope.loading = true;
            if (!_.contains($scope.selectedGroup, observationHeading)) {
                $scope.selectedGroup.push(observationHeading);
                $scope.filterString = $scope.selectedGroup.toString();
            } else{
                $scope.selectedGroup = _.without($scope.selectedGroup, observationHeading);
                $scope.filterString = $scope.selectedGroup.toString();

            }
            $scope.loading = false;
        };

        $scope.removeAllSelectedGroup = function(){
            $scope.selectedGroup = [];
        };

        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };

        $scope.init();
}]);