<commit_before>Hippocrates.Autocomplete = {
  init: function() {
    var paths = {
      PATIENTS: '/api/patients',
      MEDICINES: '/api/medicines',
      DISEASES: '/api/diseases',
      USERS: '/api/users'
    };

    this.register(this.hasDiagnoses(), paths.DISEASES, { selector: '.disease', formatResult: this.formatDiseaseResult, onSelect: this.onSelectDiseases });
    this.register(this.hasPrescriptions(), paths.MEDICINES, { selector: '.inscription', formatResult: this.formatMedicineResult, onSelect: this.onSelectMedicines });
    this.register(this.patientsSearchEnabled(), paths.PATIENTS, { formatResult: this.formatPatientResult });
    this.register(this.medicinesSearchEnabled(), paths.MEDICINES, { formatResult: this.formatMedicineResult });
    this.register(this.diseasesSearchEnabled(), paths.DISEASES, { formatResult: this.formatDiseaseResult });
    this.register(this.usersSearchEnabled(), paths.USERS);
  },

  register: function(isEnabled, serviceUrl, opts) {
    opts = opts || {};

    if (!isEnabled) {
      return;
    }

    var defaults = {
      selector: "#query",
      onSelect: function (object) {
        window.location.href = object.path;
      }
    };

    var options = $.extend({}, defaults, opts)

    $(options.selector).autocomplete({
      minChars: 2,
      serviceUrl: serviceUrl,
      formatResult: options.formatResult,
      onSelect: options.onSelect
    });
  },

  onSelectMedicines: function (medicine) {
    var locked = $(this).closest("tr").find(".locked").is(':checked');
    if (!locked) {
      $(this).closest("tr").find("textarea.subscription").val(medicine.data);
    }
  },

  onSelectDiseases: function (suggestion) {
    $(this).closest("tr").find("input.code").val(suggestion.data);
  },

  formatDiseaseResult: function(suggestion, currentValue) {
    if (!currentValue) { return suggestion.value; }

    var pattern = '(' + currentValue.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&") + ')';

    var disease  = {
      name: Hippocrates.Autocomplete.sanitizeText(pattern, suggestion.value),
      code: Hippocrates.Autocomplete.sanitizeText(pattern, suggestion.data)
    };
<commit_msg>Do not trigger select on valid input (#107)<commit_after>Hippocrates.Autocomplete = {
  init: function() {
    var paths = {
      PATIENTS: '/api/patients',
      MEDICINES: '/api/medicines',
      DISEASES: '/api/diseases',
      USERS: '/api/users'
    };

    this.register(this.hasDiagnoses(), paths.DISEASES, { selector: '.disease', formatResult: this.formatDiseaseResult, onSelect: this.onSelectDiseases });
    this.register(this.hasPrescriptions(), paths.MEDICINES, { selector: '.inscription', formatResult: this.formatMedicineResult, onSelect: this.onSelectMedicines });
    this.register(this.patientsSearchEnabled(), paths.PATIENTS, { formatResult: this.formatPatientResult });
    this.register(this.medicinesSearchEnabled(), paths.MEDICINES, { formatResult: this.formatMedicineResult });
    this.register(this.diseasesSearchEnabled(), paths.DISEASES, { formatResult: this.formatDiseaseResult });
    this.register(this.usersSearchEnabled(), paths.USERS);
  },

  register: function(isEnabled, serviceUrl, opts) {
    opts = opts || {};

    if (!isEnabled) {
      return;
    }

    var defaults = {
      selector: "#query",
      onSelect: function (object) {
        window.location.href = object.path;
      }
    };

    var options = $.extend({}, defaults, opts)

    $(options.selector).autocomplete({
      minChars: 2,
      triggerSelectOnValidInput: false,
      serviceUrl: serviceUrl,
      formatResult: options.formatResult,
      onSelect: options.onSelect
    });
  },

  onSelectMedicines: function (medicine) {
    var locked = $(this).closest("tr").find(".locked").is(':checked');
    if (!locked) {
      $(this).closest("tr").find("textarea.subscription").val(medicine.data);
    }
  },

  onSelectDiseases: function (suggestion) {
    $(this).closest("tr").find("input.code").val(suggestion.data);
  },

  formatDiseaseResult: function(suggestion, currentValue) {
    if (!currentValue) { return suggestion.value; }

    var pattern = '(' + currentValue.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&") + ')';

    var disease  = {
      name: Hippocrates.Autocomplete.sanitizeText(pattern, suggestion.value),
      code: Hippocrates.Autocomplete.sanitizeText(pattern, suggestion.data)
    };

{'fraction_non_alphanumeric': 0.16072245084590764, 'fraction_numerical': 0.0011431184270690445, 'mean_word_length': 3.724622030237581, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4317209', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1336, 'n_words': 221}