<commit_before>Trisano.CmrsModifiedTabs = {

    initialTabHtml : {},

    initialHasFollowupElements : {},

    init : function() {
        var self = this;

        $j("div.tab").each(function(t) {
            var id = $j(this).attr('id');
            var tab_key = '';

            $j(this).find('*').each(function(c) {
                var value = $j(this).val();
                var name = $j(this).attr('name');
                tab_key += value;

                if (self.hasFollowupElement(name)) {
                    self.initialHasFollowupElements[name] = value;
                }
                else if (name == "morbidity_event[disease_event_attributes][disease_id]") {
                    self.initialHasFollowupElements[name] = value;
                }
            });

            $j(this).find(':checked').each(function() {
                tab_key += $j(this).attr('name') + '1';
            });

            self.initialTabHtml[id] = tab_key;
        });

        this.prefetchShow();
    },

    /**
     * Prefetch the show page to ensure it is in the cache
     */
    prefetchShow : function() {
        var url = window.location.pathname;
        url = url.replace(/\/edit/, '');

        $j.ajax({
          url: url,
          complete: function() {
            // Do nothing
          }
        });
    },

    setChangedTabs : function() {
        var self = this;

        $j("div.tab").each(function(t) {
            var id = $j(this).attr('id');
            var initial = self.initialTabHtml[id];
            var current = '';

            $j(this).find('*').each(function(c) {
                var name = $j(this).attr('name');
                var value = $j(this).val();
                current += value;
                if (self.initialHasFollowupElements[name] != undefined && self.initialHasFollowupElements[name] != value) {
                    self.expireAll();
                }
            });

            $j(this).find(':checked').each(function() {
                current += $j(this).attr('name') + '1';
            });

            if (current != initial) {
                var form = $j(".edit_morbidity_event").first();
                $j('<input>').attr({
                    type: 'hidden',
                    name: 'expire_cache[' + id + ']',
                    value: true
                }).appendTo(form);
            }
        });
    },

    hasFollowupElement : function(name) {
        return (Trisano.FollowupCorePaths[name]) ? true : false;
    },

    expireAll : function() {
        var form = $j(".edit_morbidity_event").first();
        $j('<input>').attr({
            type: 'hidden',
            name: 'expire_cache_all',
            value: true
        }).appendTo(form);
    }

};


$j(document).ready(function() {
    Trisano.CmrsModifiedTabs.init();
});<commit_msg>Always invalidate tab caches that include investigation questions/answers<commit_after>Trisano.CmrsModifiedTabs = {

    initialTabHtml : {},

    initialHasFollowupElements : {},

    init : function() {
        var self = this;

        $j("div.tab").each(function(t) {
            var tab_key = '';
            var tab_id = $j(this).attr('id');

            $j(this).find('*').each(function(c) {
                var value = $j(this).val();
                var name = $j(this).attr('name');
                var id = $j(this).attr('id');
                tab_key += value;

                if (self.hasFollowupElement(name)) {
                    self.initialHasFollowupElements[name] = value;
                }
                else if (name == "morbidity_event[disease_event_attributes][disease_id]") {
                    self.initialHasFollowupElements[name] = value;
                }

                if (id && id.match(/investigat/)) {
                    tab_key = "INVALIDATE"; // always invalidate tab caches that include investigation questions/answers
                }
            });

            $j(this).find(':checked').each(function() {
                tab_key += $j(this).attr('name') + '1';
            });

            self.initialTabHtml[tab_id] = tab_key;
        });

        this.prefetchShow();
    },


    /**
     * Prefetch the show page to ensure it is in the cache
     */
    prefetchShow : function() {
        var url = window.location.pathname;
        url = url.replace(/\/edit/, '');

        $j.ajax({
          url: url,
          complete: function() {
            // Do nothing
          }
        });
    },

    setChangedTabs : function() {
        var self = this;

        $j("div.tab").each(function(t) {
            var id = $j(this).attr('id');
            var initial = self.initialTabHtml[id];
            var current = '';

            $j(this).find('*').each(function(c) {
                var name = $j(this).attr('name');
                var value = $j(this).val();
                current += value;
                if (self.initialHasFollowupElements[name] != undefined && self.initialHasFollowupElements[name] != value) {
                    self.expireAll();
                }
            });

            $j(this).find(':checked').each(function() {
                current += $j(this).attr('name') + '1';
            });

            if (current != initial) {
                var form = $j(".edit_morbidity_event").first();
                $j('<input>').attr({
                    type: 'hidden',
                    name: 'expire_cache[' + id + ']',
                    value: true
                }).appendTo(form);
            }
        });
    },

    hasFollowupElement : function(name) {
        return (Trisano.FollowupCorePaths[name]) ? true : false;
    },

    expireAll : function() {
        var form = $j(".edit_morbidity_event").first();
        $j('<input>').attr({
            type: 'hidden',
            name: 'expire_cache_all',
            value: true
        }).appendTo(form);
    }

};


$j(document).ready(function() {
    Trisano.CmrsModifiedTabs.init();
});
{'fraction_non_alphanumeric': 0.15620291310899045, 'fraction_numerical': 0.0006696802276912774, 'mean_word_length': 1.493322203672788, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1212682', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1663, 'n_words': 291}