<commit_before>angular.module(
    'opal.services'
).factory(
    'Flow',
    function($q, $http, $modal, $cacheFactory){
        
        var flow_cache = $cacheFactory('flow-cache');

        // 
        // Return the correct flow object for the current
        // situation
        // 
        var flow_for_verb = function(verb, current_tags){
            var flow = flow_cache.get('flow');

            if(!current_tags){
                return flow['default'][verb];
            }
            if(current_tags.tag && current_tags.tag in flow){
                if(current_tags.subtag && current_tags.subtag in flow[current_tags.tag]){
                    if(verb in flow[current_tags.tag][current_tags.subtag]){
                        return flow[current_tags.tag][current_tags.subtag][verb];
                    }           // TODO: ELSE
                }else{
                    if(flow[current_tags.tag]['default'] && 
                       flow[current_tags.tag]['default'][verb]){
                        // The tag has this verb in it's default
                        return flow[current_tags.tag]['default'][verb];
                    }else {
                        return flow['default'][verb];
                    }
                    
                }
            }else{// Default
                return flow['default'][verb];
            }
        };

        var Flow = function(verb, schema, options, config){
            var deferred = $q.defer();
            var datadeferred = $q.defer();

            if(flow_cache.get('flow')){
                datadeferred.resolve()
            }else{
                $http.get('/flow/').then(
                    // Success
                    function(response){
                        flow_cache.put('flow', response.data);
                        datadeferred.resolve()
                    },
                    // Error
                    function(response){
                        alert('An error occurred - please inform someone!');
                    }
                )
            }            

            var verbs = {            
                // The patient is 'entering'. Do the right thing.
                //
                // Config params:
                //   hospital_number - the hospital number we're entering for
                //   current_tags - a tags object representing a current list
                //
                enter: function(schema, options, config){
                    datadeferred.promise.then(function(){
                        var flow = flow_for_verb('enter', config.current_tags);

		                result = $modal.open({
			                templateUrl: flow.template,
			                controller:  flow.controller,
                            resolve: {
                                schema:          function(){ return schema },
                                options:         function(){ return options },
                                tags:            function(){ return config.current_tags},
                                hospital_number: function(){ return config.hospital_number; }
                            }
		                }).result;
                        deferred.resolve(result);
                    })
                },

                // The patient is 'leaving'. Do the right thing.
                //
                // Config params:
                //   episode - the episode that is exiting
                //   current_tags - a tags object representing a current list
                //
                exit: function(schema, options, config){
                    datadeferred.promise.then(function(){
                        var flow = flow_for_verb('exit', config.current_tags);
                        
		                result = $modal.open({
			                templateUrl: flow.template,
			                controller:  flow.controller,
			                resolve: {
				                episode: function() { return config.episode; },
                                tags   : function() { return config.current_tags; },
                                options: function() { return options; },
                                schema : function() { return schema; }<commit_msg>Don't allow exit flow to be closed from the keyboard. refs openhealthcare/elcid#362<commit_after>angular.module(
    'opal.services'
).factory(
    'Flow',
    function($q, $http, $modal, $cacheFactory){
        
        var flow_cache = $cacheFactory('flow-cache');

        // 
        // Return the correct flow object for the current
        // situation
        // 
        var flow_for_verb = function(verb, current_tags){
            var flow = flow_cache.get('flow');

            if(!current_tags){
                return flow['default'][verb];
            }
            if(current_tags.tag && current_tags.tag in flow){
                if(current_tags.subtag && current_tags.subtag in flow[current_tags.tag]){
                    if(verb in flow[current_tags.tag][current_tags.subtag]){
                        return flow[current_tags.tag][current_tags.subtag][verb];
                    }           // TODO: ELSE
                }else{
                    if(flow[current_tags.tag]['default'] && 
                       flow[current_tags.tag]['default'][verb]){
                        // The tag has this verb in it's default
                        return flow[current_tags.tag]['default'][verb];
                    }else {
                        return flow['default'][verb];
                    }
                    
                }
            }else{// Default
                return flow['default'][verb];
            }
        };

        var Flow = function(verb, schema, options, config){
            var deferred = $q.defer();
            var datadeferred = $q.defer();

            if(flow_cache.get('flow')){
                datadeferred.resolve()
            }else{
                $http.get('/flow/').then(
                    // Success
                    function(response){
                        flow_cache.put('flow', response.data);
                        datadeferred.resolve()
                    },
                    // Error
                    function(response){
                        alert('An error occurred - please inform someone!');
                    }
                )
            }            

            var verbs = {            
                // The patient is 'entering'. Do the right thing.
                //
                // Config params:
                //   hospital_number - the hospital number we're entering for
                //   current_tags - a tags object representing a current list
                //
                enter: function(schema, options, config){
                    datadeferred.promise.then(function(){
                        var flow = flow_for_verb('enter', config.current_tags);

		                result = $modal.open({
			                templateUrl: flow.template,
			                controller:  flow.controller,
                            resolve: {
                                schema:          function(){ return schema },
                                options:         function(){ return options },
                                tags:            function(){ return config.current_tags},
                                hospital_number: function(){ return config.hospital_number; }
                            }
		                }).result;
                        deferred.resolve(result);
                    })
                },

                // The patient is 'leaving'. Do the right thing.
                //
                // Config params:
                //   episode - the episode that is exiting
                //   current_tags - a tags object representing a current list
                //
                exit: function(schema, options, config){
                    datadeferred.promise.then(function(){
                        var flow = flow_for_verb('exit', config.current_tags);
                        
		                result = $modal.open({
			                templateUrl: flow.template,
			                controller:  flow.controller,
                            keyboard: false,
			                resolve: {
				                episode: function() { return config.episode; },
                                tags   : function() { return config.current_tags; },
                                options: function() { return options; },
                                schema : function() { return schema; }
{'fraction_non_alphanumeric': 0.0970557430466659, 'fraction_numerical': 0.00034912137786570463, 'mean_word_length': 1.0297590930562117, 'pattern_counts': {'":': 0, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5508755', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1816, 'n_words': 435}