<commit_before>import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actions as uiActions } from 'redux/modules/ui';
import { actions as patientActions } from 'redux/modules/patient';
import { actions as advancedSearchActions } from 'redux/modules/advancedSearch';
import GlobalSearchFilters from 'components/GlobalSearchFilters';
import SearchResultRow from 'components/SearchResultRow';
import styles from './HomeView.scss';
// import MultiGraph from '../components/MultiGraph';
// import CreatePatient from '../components/CreatePatient';

// We define mapStateToProps where we'd normally use
// the @connect decorator so the data requirements are clear upfront, but then
// export the decorated component after the main class definition so
// the component can be tested w/ and w/o being connected.
// See: http://rackt.github.io/redux/docs/recipes/WritingTests.html
const mapStateToProps = (state) => ({
  graphs: state.graphs,
  patients: state.patients.searchResults,
  tumorFilter: state.ui.tumorFilter,
  mrn: state.advancedSearch.mrn,
  firstname: state.advancedSearch.firstname,
  surname: state.advancedSearch.surname
});

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

export class HomeView extends React.Component {

  componentWillMount () {
    this.props.uiActions.hideSearchResults();
    this.props.advancedSearchActions.resetSearchFields();
  }

  filterPatients = (value) => {
    var searchMRN = this.props.mrn ? this.props.mrn.toUpperCase() : '';
    var searchFirstname = this.props.firstname ? this.props.firstname.toUpperCase() : '';
    var searchSurname = this.props.surname ? this.props.surname.toUpperCase() : '';
    var firstname = value.firstname.toUpperCase();
    var surname = value.surname.toUpperCase();
    var mrn = value.mrn.toString();
    return (
      (searchMRN === '' || mrn.indexOf(searchMRN) >= 0) &&
      (searchFirstname === '' || firstname.indexOf(searchFirstname) >= 0) &&
      (searchSurname === '' || surname.indexOf(searchSurname) >= 0) &&
      (this.props.tumorFilter === undefined || this.props.tumorFilter === '' || value.tumorType === this.props.tumorFilter)
    );
  };

  render () {
    var patientResults;
    if (this.props.mrn || this.props.firstname || this.props.surname) {
      patientResults = this.props.patients.filter(this.filterPatients);
    } else {
      patientResults = this.props.patients;
    }<commit_msg>fixed advanced search filter bug<commit_after>import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actions as uiActions } from 'redux/modules/ui';
import { actions as patientActions } from 'redux/modules/patient';
import { actions as advancedSearchActions } from 'redux/modules/advancedSearch';
import GlobalSearchFilters from 'components/GlobalSearchFilters';
import SearchResultRow from 'components/SearchResultRow';
import styles from './HomeView.scss';
// import MultiGraph from '../components/MultiGraph';
// import CreatePatient from '../components/CreatePatient';

// We define mapStateToProps where we'd normally use
// the @connect decorator so the data requirements are clear upfront, but then
// export the decorated component after the main class definition so
// the component can be tested w/ and w/o being connected.
// See: http://rackt.github.io/redux/docs/recipes/WritingTests.html
const mapStateToProps = (state) => ({
  graphs: state.graphs,
  patients: state.patients.searchResults,
  tumorFilter: state.ui.tumorFilter,
  mrn: state.advancedSearch.mrn,
  firstname: state.advancedSearch.firstname,
  surname: state.advancedSearch.surname
});

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

export class HomeView extends React.Component {

  componentWillMount () {
    this.props.uiActions.hideSearchResults();
    this.props.advancedSearchActions.resetSearchFields();
  }

  filterPatients = (value) => {
    var searchMRN = this.props.mrn ? this.props.mrn.toUpperCase() : '';
    var searchFirstname = this.props.firstname ? this.props.firstname.toUpperCase() : '';
    var searchSurname = this.props.surname ? this.props.surname.toUpperCase() : '';
    var firstname = value.firstname.toUpperCase();
    var surname = value.surname.toUpperCase();
    var mrn = value.mrn.toString();
    return (
      (searchMRN === '' || mrn.indexOf(searchMRN) >= 0) &&
      (searchFirstname === '' || firstname.indexOf(searchFirstname) >= 0) &&
      (searchSurname === '' || surname.indexOf(searchSurname) >= 0) &&
      (this.props.tumorFilter === undefined || this.props.tumorFilter === '' || value.tumorType === this.props.tumorFilter)
    );
  };

  render () {
    var patientResults;
    if (this.props.mrn || this.props.firstname || this.props.surname || this.props.tumorFilter) {
      patientResults = this.props.patients.filter(this.filterPatients);
    } else {
      patientResults = this.props.patients;
    }
{'fraction_non_alphanumeric': 0.12873307364125394, 'fraction_numerical': 0.0011129660545353367, 'mean_word_length': 4.3228035538005924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4473682', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1520, 'n_words': 359}