<commit_before># last menstrual period calculator methods
module LastMenstrualPeriodHelper
  def last_menstrual_period_display
    return nil unless last_menstrual_period_now
    display_as_weeks last_menstrual_period_now
  end

  def last_menstrual_period_display_short
    return nil unless last_menstrual_period_now
    last_menstrual_period_display.to_s.gsub(' weeks,', 'w').gsub(' days', 'd')
  end

  def last_menstrual_period_at_appt
    return nil unless last_menstrual_period_now && patient.appointment_date
    lmp = last_menstrual_period_on_date patient.appointment_date
    display_as_weeks lmp
  end

  private

  def last_menstrual_period_now
    if patient.appointment_date && patient.appointment_date < Time.zone.today
      last_menstrual_period_on_date patient.appointment_date
    else
      last_menstrual_period_on_date Time.zone.today
    end
  end

  def last_menstrual_period_on_date(date)
    return nil unless patient.initial_call_date && last_menstrual_period_weeks
    weeks = 7 * (last_menstrual_period_weeks || 0)
    days = (last_menstrual_period_days || 0)
    (date - patient.initial_call_date) + weeks + days
  end

  def display_as_weeks(num)
    "#{(num / 7).floor} weeks, " \
    "#{(num % 7).to_i} days"
  end
end<commit_msg>Added case handling to last_menstrual_period_on_date method to prevent pregnancies from incrementing over 40 weeks<commit_after># last menstrual period calculator methods
module LastMenstrualPeriodHelper
  def last_menstrual_period_display
    return nil unless last_menstrual_period_now
    display_as_weeks last_menstrual_period_now
  end

  def last_menstrual_period_display_short
    return nil unless last_menstrual_period_now
    last_menstrual_period_display.to_s.gsub(' weeks,', 'w').gsub(' days', 'd')
  end

  def last_menstrual_period_at_appt
    return nil unless last_menstrual_period_now && patient.appointment_date
    lmp = last_menstrual_period_on_date patient.appointment_date
    display_as_weeks lmp
  end

  private

  def last_menstrual_period_now
    if patient.appointment_date && patient.appointment_date < Time.zone.today
      last_menstrual_period_on_date patient.appointment_date
    else
      last_menstrual_period_on_date Time.zone.today
    end
  end

  def last_menstrual_period_on_date(date)
    return nil unless patient.initial_call_date && last_menstrual_period_weeks
    weeks = 7 * (last_menstrual_period_weeks || 0)
    days = (last_menstrual_period_days || 0)
    if (date - patient.initial_call_date) + weeks + days > 280
      return 280
    else
      (date - patient.initial_call_date) + weeks + days
    end
  end

  def display_as_weeks(num)
    "#{(num / 7).floor} weeks, " \
    "#{(num % 7).to_i} days"
  end
end
{'fraction_non_alphanumeric': 0.061995597945708, 'fraction_numerical': 0.006603081438004402, 'mean_word_length': 4.3893280632411065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '3214628', 'n_tokens_mistral': 952, 'n_tokens_neox': 904, 'n_words': 192}