<commit_before>module ElementsHelper
  include ElementsRouteMaps
  include PagesRouteMaps
  include QuestionnaireRouteMaps
  include ReadonlyHelper

  INITIALLY_REQUIRED = {
    :appln_person => { :first_name => true, :last_name => true, :gender => true, :email => true},
    :emerg => {}
  }

  def custom_element_text_field(txt, m, c)
    custom_element_item(txt, m, c) do |m, c, classes| 
      text_field m, c, :class => classes
    end
  end

  MAP_ID = { 
#    :person_local_province_id => :local_province,
#    :person_local_country_id => :local_country,
#    :person_province_id => :permanent_province,
#    :person_country_id => :permanent_country,
#    :gender_id => :gender,
#    :health_province_id => :health_province_longDesc,
#    :title_id => :title
  }

  def custom_element_visible(name, method = "header")
    return true if custom_element_edit_mode || custom_element_create_mode
    !@element.custom_element_hidden_sections.find_by_name(name, method).present?
  end

  def custom_element_item(txt, m, c)
    if @element.custom_element_hidden_sections.detect{ |s| s.name == m.to_s && s.attribute == c.to_s }
      return ""
    end

    if @readonly
      if MAP_ID[c] then c = MAP_ID[c] end

      return %|
<span class="readonly_question_text">#{txt}</span><br />
<span class="blue">#{instance_variable_get("@#{m}").send(c)}</span><br />
|
    end

    reqd_section = @element && <commit_msg>handle case where element is nil<commit_after>module ElementsHelper
  include ElementsRouteMaps
  include PagesRouteMaps
  include QuestionnaireRouteMaps
  include ReadonlyHelper

  INITIALLY_REQUIRED = {
    :appln_person => { :first_name => true, :last_name => true, :gender => true, :email => true},
    :emerg => {}
  }

  def custom_element_text_field(txt, m, c)
    custom_element_item(txt, m, c) do |m, c, classes| 
      text_field m, c, :class => classes
    end
  end

  MAP_ID = { 
#    :person_local_province_id => :local_province,
#    :person_local_country_id => :local_country,
#    :person_province_id => :permanent_province,
#    :person_country_id => :permanent_country,
#    :gender_id => :gender,
#    :health_province_id => :health_province_longDesc,
#    :title_id => :title
  }

  def custom_element_visible(name, method = "header")
    return true if custom_element_edit_mode || custom_element_create_mode
    return true if @element.nil?
    !@element.custom_element_hidden_sections.find_by_name(name, method).present?
  end

  def custom_element_item(txt, m, c)
    if @element.nil? || @element.custom_element_hidden_sections.detect{ |s| s.name == m.to_s && s.attribute == c.to_s }
      return ""
    end

    if @readonly
      if MAP_ID[c] then c = MAP_ID[c] end

      return %|
<span class="readonly_question_text">#{txt}</span><br />
<span class="blue">#{instance_variable_get("@#{m}").send(c)}</span><br />
|
    end

    reqd_section = @element && 
{'fraction_non_alphanumeric': 0.1305699481865285, 'fraction_numerical': 0.0, 'mean_word_length': 4.062937062937063, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 43, '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': '3602660', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1006, 'n_words': 200}