<commit_before>import React, { Component } from 'react';
import Panel from './Panel';
import Loading from './Loading';
import { DateTimeInput, Select, TextInput, InlineWidgetGroup } from './widgets';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { actions as patientActions } from 'redux/modules/patient';
import styles from './FollowUpDiagnosis.scss';

const mapStateToProps = (state) => ({
  activePatient: state.patients.activePatient
});

const mapDispatchToProps = (dispatch) => {
  return {
    patientActions: bindActionCreators(patientActions, dispatch),
  };
};

export default class FollowUpDiagnosis extends Component {
  constructor () {
    super();
    this.state = {
      gsPatternOne: NaN,
      gsPatternTwo: NaN,
      gleasonScore: null,
    };
  }

  setGSPatternOne = (e) => {
    const gsPattern1Val = parseInt(e.target.value, 10);
    const gsResult = this.calculateGS(gsPattern1Val, this.state.gsPatternTwo);
    this.setState({
      ...this.state,
      gsPatternOne: gsPattern1Val,
      gleasonScore: gsResult,
    });
  };

  setGSPatternTwo = (e) => {
    const gsPattern2Val = parseInt(e.target.value, 10);
    const gsResult = this.calculateGS(this.state.gsPatternOne, gsPattern2Val);
    this.setState({
      ...this.state,
      gsPatternTwo: gsPattern2Val,
      gleasonScore: gsResult,
    });
  };

  calculateGS = (patternOne, patternTwo) => {
    let gleasonScore;
    if (!isNaN(patternOne) && !isNaN(patternTwo)) {
      gleasonScore = patternOne + patternTwo;
    } else {
      gleasonScore = null;
    }

    return gleasonScore;
  };

  componentWillMount () {
    this.props.patientActions.fetchDiagnosis(this.props.activePatient.ehrId);
  };

  componentWillUnmount () {
    this.props.patientActions.saveDiagnosis(
      this.props.activePatient.ehrId,
      this.props.activePatient.diagnosis.primary_tumour_pt,
      this.props.activePatient.diagnosis.regional_lymph_node_pn,
      this.props.activePatient.diagnosis.distant_metastasis_pm);
  };

  handleChangePrimaryTumorPt = (e) => {
    const newVal = e.target.value;
    const diagnosis = {
      primary_tumour_pt: newVal,
      regional_lymph_node_pn: this.props.activePatient.diagnosis.regional_lymph_node_pn,
      distant_metastasis_pm: this.props.activePatient.diagnosis.distant_metastasis_pm
    };
    this.props.patientActions.updateDiagnosis(diagnosis);
  };

  handleChangeRegionalLymphNode = (e) => {
    const newVal = e.target.value;
    const diagnosis = {
      primary_tumour_pt: this.props.activePatient.diagnosis.primary_tumour_pt,
      regional_lymph_node_pn: newVal,
      distant_metastasis_pm: this.props.activePatient.diagnosis.distant_metastasis_pm
    };
    this.props.patientActions.updateDiagnosis(diagnosis);
  };

  handleChangeDistantMetastasis = (e) => {
    const newVal = e.target.value;<commit_msg>Dont save followup changes unless they've been retrieived.<commit_after>import React, { Component } from 'react';
import Panel from './Panel';
import Loading from './Loading';
import { DateTimeInput, Select, TextInput, InlineWidgetGroup } from './widgets';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { actions as patientActions } from 'redux/modules/patient';
import styles from './FollowUpDiagnosis.scss';

const mapStateToProps = (state) => ({
  activePatient: state.patients.activePatient
});

const mapDispatchToProps = (dispatch) => {
  return {
    patientActions: bindActionCreators(patientActions, dispatch),
  };
};

export default class FollowUpDiagnosis extends Component {
  constructor () {
    super();
    this.state = {
      gsPatternOne: NaN,
      gsPatternTwo: NaN,
      gleasonScore: null,
    };
  }

  setGSPatternOne = (e) => {
    const gsPattern1Val = parseInt(e.target.value, 10);
    const gsResult = this.calculateGS(gsPattern1Val, this.state.gsPatternTwo);
    this.setState({
      ...this.state,
      gsPatternOne: gsPattern1Val,
      gleasonScore: gsResult,
    });
  };

  setGSPatternTwo = (e) => {
    const gsPattern2Val = parseInt(e.target.value, 10);
    const gsResult = this.calculateGS(this.state.gsPatternOne, gsPattern2Val);
    this.setState({
      ...this.state,
      gsPatternTwo: gsPattern2Val,
      gleasonScore: gsResult,
    });
  };

  calculateGS = (patternOne, patternTwo) => {
    let gleasonScore;
    if (!isNaN(patternOne) && !isNaN(patternTwo)) {
      gleasonScore = patternOne + patternTwo;
    } else {
      gleasonScore = null;
    }

    return gleasonScore;
  };

  componentWillMount () {
    this.props.patientActions.fetchDiagnosis(this.props.activePatient.ehrId);
  };

  componentWillUnmount () {
    if (this.props.activePatient.diagnosis) {
      this.props.patientActions.saveDiagnosis(
        this.props.activePatient.ehrId,
        this.props.activePatient.diagnosis.primary_tumour_pt,
        this.props.activePatient.diagnosis.regional_lymph_node_pn,
        this.props.activePatient.diagnosis.distant_metastasis_pm
      );
    }
  };

  handleChangePrimaryTumorPt = (e) => {
    const newVal = e.target.value;
    const diagnosis = {
      primary_tumour_pt: newVal,
      regional_lymph_node_pn: this.props.activePatient.diagnosis.regional_lymph_node_pn,
      distant_metastasis_pm: this.props.activePatient.diagnosis.distant_metastasis_pm
    };
    this.props.patientActions.updateDiagnosis(diagnosis);
  };

  handleChangeRegionalLymphNode = (e) => {
    const newVal = e.target.value;
    const diagnosis = {
      primary_tumour_pt: this.props.activePatient.diagnosis.primary_tumour_pt,
      regional_lymph_node_pn: newVal,
      distant_metastasis_pm: this.props.activePatient.diagnosis.distant_metastasis_pm
    };
    this.props.patientActions.updateDiagnosis(diagnosis);
  };

  handleChangeDistantMetastasis = (e) => {
    const newVal = e.target.value;
{'fraction_non_alphanumeric': 0.11365953109072376, 'fraction_numerical': 0.0033978933061501867, 'mean_word_length': 3.6759332803812548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5377777', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1871, 'n_words': 316}