<commit_before>@toolsReady = () ->
  $("[data-object~='submit-risk-assessment']").click (e) ->
    submitRiskAssessment()

@submitRiskAssessment = () ->
  #### Check answers using the following syntax ####
  # console.log document.getElementById('gender_male').checked
  # console.log document.getElementById('gender_female').checked
  # console.log document.getElementById('age').value
  # console.log document.getElementById('feet').value
  # console.log document.getElementById('inches').value
  # console.log document.getElementById('weight').value
  # console.log document.getElementById('systolic').value
  # console.log document.getElementById('diastolic').value
  # console.log document.getElementById('snoring_yes').checked
  # console.log document.getElementById('snoring_no').checked
  # console.log document.getElementById('tiredness_yes').checked
  # console.log document.getElementById('tiredness_no').checked
  # console.log document.getElementById('observation_yes').checked
  # console.log document.getElementById('observation_no').checked
  # console.log document.getElementById('neck_yes').checked
  # console.log document.getElementById('neck_no').checked

  highbloodpressure = (document.getElementById('systolic').value > 140) and (document.getElementById('diastolic').value > 90)
  height = (document.getElementById('feet').value * 12) + parseInt(document.getElementById('inches').value)
  weight = document.getElementById('weight').value
  bmi = ( weight / Math.pow(height,2) ) * 703

  stop = { "s": 0, "t": 0, "o" : 0, "p" : 0 }
  stop["s"] = 1 if document.getElementById('snoring_yes').checked
  stop["t"] = 1 if document.getElementById('tiredness_yes').checked
  stop["o"] = 1 if document.getElementById('observation_yes').checked
  stop["p"] = 1 if highbloodpressure

  stop_score = 0
  for k of stop
    stop_score += stop[k]

  stopbang = stop
  stopbang["b"] = if bmi > 35 then 1 else 0
  stopbang["a"] = if document.getElementById('age').value > 50 then 1 else 0
  stopbang["n"] = if document.getElementById('neck_yes').checked then 1 else 0
  stopbang["g"] = if document.getElementById('gender_male').checked then 1 else 0

  stopbang_score = 0
  for k of stopbang
    stopbang_score += stopbang[k]
<commit_msg>Added outcome logic for risk assessment tool for #479<commit_after>@toolsReady = () ->
  $("[data-object~='submit-risk-assessment']").click (e) ->
    submitRiskAssessment()

@submitRiskAssessment = () ->
  #### Check answers using the following syntax ####
  # console.log document.getElementById('gender_male').checked
  # console.log document.getElementById('gender_female').checked
  # console.log document.getElementById('age').value
  # console.log document.getElementById('feet').value
  # console.log document.getElementById('inches').value
  # console.log document.getElementById('weight').value
  # console.log document.getElementById('systolic').value
  # console.log document.getElementById('diastolic').value
  # console.log document.getElementById('snoring_yes').checked
  # console.log document.getElementById('snoring_no').checked
  # console.log document.getElementById('tiredness_yes').checked
  # console.log document.getElementById('tiredness_no').checked
  # console.log document.getElementById('observation_yes').checked
  # console.log document.getElementById('observation_no').checked
  # console.log document.getElementById('neck_yes').checked
  # console.log document.getElementById('neck_no').checked

  highbloodpressure = (document.getElementById('systolic').value > 140) and (document.getElementById('diastolic').value > 90)

  stop = { "s": 0, "t": 0, "o" : 0, "p" : 0 }
  stop["s"] = 1 if document.getElementById('snoring_yes').checked
  stop["t"] = 1 if document.getElementById('tiredness_yes').checked
  stop["o"] = 1 if document.getElementById('observation_yes').checked
  stop["p"] = 1 if highbloodpressure

  stop_score = 0
  for k of stop
    stop_score += stop[k]

  height = (document.getElementById('feet').value * 12) + parseInt(document.getElementById('inches').value)
  weight = document.getElementById('weight').value
  bmi = ( weight / Math.pow(height,2) ) * 703
  male = document.getElementById('gender_male').checked
  largeNeck = document.getElementById('neck_yes').checked

  stopbang = stop
  stopbang["b"] = if bmi > 35 then 1 else 0
  stopbang["a"] = if document.getElementById('age').value > 50 then 1 else 0
  stopbang["n"] = if largeNeck then 1 else 0
  stopbang["g"] = if male.checked then 1 else 0

  stopbang_score = 0
  for k of stopbang
    stopbang_score += stopbang[k]

  alert determineRisk(stop_score, stopbang_score, male, bmi > 35, largeNeck)

@determineRisk = (stop, stopbang, male, bmi, neck) ->
  if stopbang <= 2
    risk = "You're at low risk for OSA"
  else if stopbang <= 4
    risk = "You're at intermediate risk for OSA"
  else
    risk = "You're at high risk for OSA"
  if stop >= 2 and (male or bmi or neck)
    risk = "You're at high risk for OSA"
  return risk

{'fraction_non_alphanumeric': 0.14259927797833935, 'fraction_numerical': 0.014841556357801846, 'mean_word_length': 4.951073985680191, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 20, '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': '7468150', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1453, 'n_words': 336}