<commit_before>'use strict';

/**
 * @ngdoc service
 * @name oncokbApp.reportGeneratorWorker
 * @description
 * # reportGeneratorWorker
 * Service in the oncokbApp.
 */
angular.module('oncokbApp')
    .service('reportGeneratorWorker', function ($q, DatabaseConnector, GenerateReportDataService, reportGeneratorParseAnnotation,reportGenerator) {
        var worker = function(data, patientId){
            var self = this;
            self.parseAnnotation = function(data){
                self.annotation = reportGeneratorParseAnnotation.parse(data);
            };

            self.prepareReportParams = function(){
                self.reportParams.reportContent = GenerateReportDataService.init([{
                    geneName: self.gene,
                    alteration: self.alteration,
                    tumorType: self.tumorType,
                    annotation: self.annotation.annotation,
                    relevantCancerType: self.annotation.relevantCancerType
                }]);
                self.reportParams.reportContent.patientName = self.patientId || '';
                self.reportParams.reportContent.diagnosis = self.reportParams.reportContent.tumorTissueType = self.tumorType;
                self.reportParams.requestInfo.email = self.email;
                self.reportParams.requestInfo.folderName = self.folderName;
                self.reportParams.requestInfo.fileName = self.fileName;
                self.reportParams.requestInfo.userName = self.userName;
            };

            self.generateGoogleDoc = function(){
                var _deferred = $q.defer();
                reportGenerator.generateGoogleDoc(self.reportParams).then(function(){
                    _deferred.resolve();
                },function(){
                    _deferred.reject();
                });
                return _deferred.promise;
            };

            self.getData = function(){
                var params = {
                    'alterationType': 'MUTATION',
                    'hugoSymbol': self.gene,
                    'alteration': self.alteration,
                    'tumorType': self.tumorType
                };
                var deferred = $q.defer();
                DatabaseConnector.searchAnnotation(params, function(data){
                    self.parseAnnotation(data);
                    deferred.resolve();
                }, function(){
                    deferred.reject('Error": no annotation data returned', self);
                });

                return deferred.promise;
            };

            self.init = function() {
                self.id = '';
                self.status = {};
                self.status.generate = 0; //0: ungenerated, 1: successfully generated, -1: unsuccessfully generated, 2: initializing, 3: initialized, 4: generating
                self.email = '';
                self.folderName = '';
                self.fileName = '';
                self.userName = '';
                self.parent = {};
                self.annotation = {};
                self.parent.name = ''; // could be the entry name
                self.reportParams = {
                    requestInfo: {},
                    reportContent: {}
                };

                if(angular.isString(patientId)) {
                    self.patientId = patientId;
                }

                self.gene = data.gene;
                self.alteration = data.alteration;
                self.tumorType = data.tumorType;

                if(data.hasOwnProperty('patientId')) {
                    self.patientId = data.patientId;
                }
            };
            self.init();

        };

        return (worker);
    });

angular.module('oncokbApp')
    .factory('reportGeneratorWorkers', ['reportGeneratorWorker' , function (ReportGeneratorWorker) {<commit_msg>Sign a timestamp to worker if no patientId available<commit_after>'use strict';

/**
 * @ngdoc service
 * @name oncokbApp.reportGeneratorWorker
 * @description
 * # reportGeneratorWorker
 * Service in the oncokbApp.
 */
angular.module('oncokbApp')
    .service('reportGeneratorWorker', function ($q, DatabaseConnector, GenerateReportDataService, reportGeneratorParseAnnotation,reportGenerator) {
        var worker = function(data, patientId){
            var self = this;
            self.parseAnnotation = function(data){
                self.annotation = reportGeneratorParseAnnotation.parse(data);
            };

            self.prepareReportParams = function(){
                self.reportParams.reportContent = GenerateReportDataService.init([{
                    geneName: self.gene,
                    alteration: self.alteration,
                    tumorType: self.tumorType,
                    annotation: self.annotation.annotation,
                    relevantCancerType: self.annotation.relevantCancerType
                }]);
                self.reportParams.reportContent.patientName = self.patientId || '';
                self.reportParams.reportContent.diagnosis = self.reportParams.reportContent.tumorTissueType = self.tumorType;
                self.reportParams.requestInfo.email = self.email;
                self.reportParams.requestInfo.folderName = self.folderName;
                self.reportParams.requestInfo.fileName = self.fileName;
                self.reportParams.requestInfo.userName = self.userName;
            };

            self.generateGoogleDoc = function(){
                var _deferred = $q.defer();
                reportGenerator.generateGoogleDoc(self.reportParams).then(function(){
                    _deferred.resolve();
                },function(){
                    _deferred.reject();
                });
                return _deferred.promise;
            };

            self.getData = function(){
                var params = {
                    'alterationType': 'MUTATION',
                    'hugoSymbol': self.gene,
                    'alteration': self.alteration,
                    'tumorType': self.tumorType
                };
                var deferred = $q.defer();
                DatabaseConnector.searchAnnotation(params, function(data){
                    self.parseAnnotation(data);
                    deferred.resolve();
                }, function(){
                    deferred.reject('Error": no annotation data returned', self);
                });

                return deferred.promise;
            };

            self.init = function() {
                self.id = '';
                self.status = {};
                self.status.generate = 0; //0: ungenerated, 1: successfully generated, -1: unsuccessfully generated, 2: initializing, 3: initialized, 4: generating
                self.email = '';
                self.folderName = '';
                self.fileName = '';
                self.userName = '';
                self.parent = {};
                self.annotation = {};
                self.parent.name = ''; // could be the entry name
                self.reportParams = {
                    requestInfo: {},
                    reportContent: {}
                };

                if(angular.isString(patientId)) {
                    self.patientId = patientId;
                }else{
                    self.patientId =- new Date().getTime();
                }

                self.gene = data.gene;
                self.alteration = data.alteration;
                self.tumorType = data.tumorType;

                if(data.hasOwnProperty('patientId')) {
                    self.patientId = data.patientId;
                }
            };
            self.init();

        };

        return (worker);
    });

angular.module('oncokbApp')
    .factory('reportGeneratorWorkers', ['reportGeneratorWorker' , function (ReportGeneratorWorker) {
{'fraction_non_alphanumeric': 0.10307298335467349, 'fraction_numerical': 0.001792573623559539, 'mean_word_length': 1.5156199677938809, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2647254', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1748, 'n_words': 314}