<commit_before>/*
* ADR Reporting
* Copyright (C) 2017 <NAME>
* GNU Affero General Public License 3.0 (https://github.com/divayprakash/adr/blob/master/LICENSE)
*/
$(document).ready(function(){
  $('.button-collapse').sideNav();
  var helpOpen = false;
  $('#help-fab').click(function(e) {
    if (helpOpen) {
      $('#help-tap-target').tapTarget('close');
      helpOpen = false;
    }
    else {
      $('#help-tap-target').tapTarget('open');
      helpOpen = true;
    }
  });
  $('.chips').material_chip();
  $('.datepicker').pickadate({
    format: 'dd/mm/yyyy',
    selectMonths: true
  });
  $('.datepicker-year').pickadate({
    format: 'dd/mm/yyyy',
    selectMonths: true,
    selectYears: 7
  });
  $('#medication-add').modal();
  enableSpecFieldOnRadio('stop','#stop-reduced');
  enableSpecFieldOnRadio('reintro','#reintro-reduced');
});

function enableSpecFieldOnRadio(radioId, fieldSelector) {
  $('input[type=radio][name=' + radioId + ']').on('change', function() {
    switch($(this).val()) {
      case 'yes':
        $(fieldSelector).prop('disabled', false);
        break;
      case 'no':
      case 'unknown':
      case 'na':
        $(fieldSelector).val("");
        $(fieldSelector).removeClass('valid');
        $(fieldSelector).removeClass('invalid');
        $(fieldSelector).prop('disabled', true);
        break;
    }
  });
}

var medicationCount = 0;
function medicationAdd() {
  var name = $('#medication-name').val();
  var manufacturer = $('#manufacturer').val();
  var batch = $('#batch').val();
  var expiry = $('#expiry').pickadate().pickadate('picker').get();
  var dose = $('#dose').val();
  var route = $("input[type='radio'][name='route']:checked").val();
  var frequency = $('#freq').val();
  var therapyStart = $('#therapy-start').pickadate().pickadate('picker').get();
  var therapyEnd = $('#therapy-end').pickadate().pickadate('picker').get();
  var duration = $('#duration').val();
  var reason = $('#reason').val();
  var stop = $("input[type='radio'][name='stop']:checked").val();
  var stopReduced = 0;
  if (stop == "yes") stopReduced = $('#stop-reduced').val();
  var reintro = $("input[type='radio'][name='reintro']:checked").val();
  var reintroReduced = 0;
  if (reintro == "yes")  reintroReduced = $('reintro-reduced').val();
  $('#medication-add').modal('close');
}
<commit_msg>WIP: Add medication div on form submit<commit_after>/*
* ADR Reporting
* Copyright (C) 2017 <NAME>
* GNU Affero General Public License 3.0 (https://github.com/divayprakash/adr/blob/master/LICENSE)
*/
$(document).ready(function(){
  $('.button-collapse').sideNav();
  var helpOpen = false;
  $('#help-fab').click(function(e) {
    if (helpOpen) {
      $('#help-tap-target').tapTarget('close');
      helpOpen = false;
    }
    else {
      $('#help-tap-target').tapTarget('open');
      helpOpen = true;
    }
  });
  $('.chips').material_chip();
  $('.datepicker').pickadate({
    format: 'dd/mm/yyyy',
    selectMonths: true
  });
  $('.datepicker-year').pickadate({
    format: 'dd/mm/yyyy',
    selectMonths: true,
    selectYears: 7
  });
  $('#medication-add').modal();
  enableSpecFieldOnRadio('stop','#stop-reduced');
  enableSpecFieldOnRadio('reintro','#reintro-reduced');
});

function enableSpecFieldOnRadio(radioId, fieldSelector) {
  $('input[type=radio][name=' + radioId + ']').on('change', function() {
    switch($(this).val()) {
      case 'yes':
        $(fieldSelector).prop('disabled', false);
        break;
      case 'no':
      case 'unknown':
      case 'na':
        $(fieldSelector).val("");
        $(fieldSelector).removeClass('valid');
        $(fieldSelector).removeClass('invalid');
        $(fieldSelector).prop('disabled', true);
        break;
    }
  });
}

var medicationCount = 0;
function medicationAdd() {
  var name = $('#medication-name').val();
  var manufacturer = $('#manufacturer').val();
  var batch = $('#batch').val();
  var expiry = $('#expiry').pickadate().pickadate('picker').get();
  var dose = $('#dose').val();
  var route = $("input[type='radio'][name='route']:checked").val();
  var frequency = $('#freq').val();
  var therapyStart = $('#therapy-start').pickadate().pickadate('picker').get();
  var therapyEnd = $('#therapy-end').pickadate().pickadate('picker').get();
  var duration = $('#duration').val();
  var reason = $('#reason').val();
  var stop = $("input[type='radio'][name='stop']:checked").val();
  var stopReduced = 0;
  if (stop == "yes") stopReduced = $('#stop-reduced').val();
  var reintro = $("input[type='radio'][name='reintro']:checked").val();
  var reintroReduced = 0;
  if (reintro == "yes")  reintroReduced = $('reintro-reduced').val();
  $('#medication-add').modal('close');
  var divToAdd = "<div class='card blue lighten-4'><div class='card-content'><span class='card-title'>"+ name +"</span><p>"+ manufacturer + " / " + expiry + "</p></div><div class='card-action'><button class='waves-effect waves-light btn'><i class='material-icons right'>mode_edit</i>Edit</button><button class='waves-effect waves-light btn'><i class='material-icons right'>delete</i>Delete</button></div></div>";
  $("#insert").before(divToAdd);
}

{'fraction_non_alphanumeric': 0.23283407897296246, 'fraction_numerical': 0.004084808403034429, 'mean_word_length': 4.173038229376258, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '1483362', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1643, 'n_words': 293}