<commit_before>import React, {Component, PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {reduxForm} from 'redux-form';
import { connect } from 'react-redux';
import styles from './AddPatientView.scss';
import corestyles from '../styles/core.scss';
import { actions as patientActions } from 'redux/modules/patient';
export const fields = ['mrn', 'firstName', 'lastName', 'dob', 'email', 'phone', 'gender', 'tumorType', 'surgical', 'address'];
import Datetime from 'react-datetime';

const mapStateToProps = (state) => ({
  routerPath: state.router.path,
});

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

const validate = values => {
  const errors = {};
  if (!values.mrn) {
    errors.mrn = 'Required';
  }
  if (!values.firstName) {
    errors.firstName = 'Required';
  }
  if (!values.lastName) {
    errors.lastName = 'Required';
  }
  if (!values.dob) {
    errors.dob = 'Required';
  }
  if (!values.email) {
    errors.email = 'Required';
  } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
    errors.email = 'Invalid email address';
  }
  if (!values.phone) {
    errors.phone = 'Required';
  }
  if (!values.gender) {
    errors.gender = 'Required';
  }
  if (!values.tumorType) {
    errors.tumorType = 'Required';
  }
  if (!values.address) {
    errors.address = 'Required';
  }

  return errors;
};

export class AddPatientView extends Component {
  static propTypes = {
    fields: PropTypes.object.isRequired,
    handleSubmit: PropTypes.func.isRequired,
    resetForm: PropTypes.func.isRequired,
    submitting: PropTypes.bool.isRequired,
    patientActions: React.PropTypes.object,
  };
  static contextTypes = {
    router: React.PropTypes.object.isRequired
  };

  createToken = () => {
    var currentdate = new Date();
    return 'NEW<PASSWORD>-' + currentdate.getMonth().toString() + '-' + currentdate.getHours().toString() + '-' + currentdate.getMinutes().toString() + '-' + currentdate.getSeconds().toString();
  };

  submit = (values, dispatch) => {
    const body = {
      firstNames: values.firstName,
      lastNames: values.lastName,
      gender: values.gender,
      dateOfBirth: values.dob.toISOString(),
      address: values.address,
      mrn: values.mrn,
      tumorType: values.tumorType,
      isSurgical: (values.surgical) ? 'true' : 'false',
      phone: values.phone,
      email: values.email,
    };
    const newToken = this.createToken();
    const patient = {
      token: newToken,
      id: '',
      firstname: values.firstName,
      surname: values.lastName,
      gender: values.gender,
      dob: values.dob.toISOString(),
      address: values.address,
      mrn: values.mrn,
      tumorType: values.tumorType,
      surgical: (values.surgical) ? 'true' : 'false',
      phone: values.phone,
      email: values.email,
    };

    this.props.patientActions.createPatient(patient);

    const url = `${process.env.OPENEHR_URL}/patient/`;
    const options = {
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(body)
    };
    const thisAddPatientView = this;

    fetch(url, options)
    .then(function (response) {
      return response.json();
    }).then(function (json) {
      dispatch(thisAddPatientView.props.patientActions.updatePatient(json, newToken));
    }).catch(function (ex) {
      console.log('parsing failed', ex);<commit_msg>Fix a call to dispatch that wasn't dispatching a standard action... or in fact an action at all.<commit_after>import React, {Component, PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {reduxForm} from 'redux-form';
import { connect } from 'react-redux';
import styles from './AddPatientView.scss';
import corestyles from '../styles/core.scss';
import { actions as patientActions } from 'redux/modules/patient';
export const fields = ['mrn', 'firstName', 'lastName', 'dob', 'email', 'phone', 'gender', 'tumorType', 'surgical', 'address'];
import Datetime from 'react-datetime';

const mapStateToProps = (state) => ({
  routerPath: state.router.path,
});

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

const validate = values => {
  const errors = {};
  if (!values.mrn) {
    errors.mrn = 'Required';
  }
  if (!values.firstName) {
    errors.firstName = 'Required';
  }
  if (!values.lastName) {
    errors.lastName = 'Required';
  }
  if (!values.dob) {
    errors.dob = 'Required';
  }
  if (!values.email) {
    errors.email = 'Required';
  } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
    errors.email = 'Invalid email address';
  }
  if (!values.phone) {
    errors.phone = 'Required';
  }
  if (!values.gender) {
    errors.gender = 'Required';
  }
  if (!values.tumorType) {
    errors.tumorType = 'Required';
  }
  if (!values.address) {
    errors.address = 'Required';
  }

  return errors;
};

export class AddPatientView extends Component {
  static propTypes = {
    fields: PropTypes.object.isRequired,
    handleSubmit: PropTypes.func.isRequired,
    resetForm: PropTypes.func.isRequired,
    submitting: PropTypes.bool.isRequired,
    patientActions: React.PropTypes.object,
  };
  static contextTypes = {
    router: React.PropTypes.object.isRequired
  };

  createToken = () => {
    var currentdate = new Date();
    return 'NEWPATIENT-' + currentdate.getMonth().toString() + '-' + currentdate.getHours().toString() + '-' + currentdate.getMinutes().toString() + '-' + currentdate.getSeconds().toString();
  };

  submit = (values, dispatch) => {
    const body = {
      firstNames: values.firstName,
      lastNames: values.lastName,
      gender: values.gender,
      dateOfBirth: values.dob.toISOString(),
      address: values.address,
      mrn: values.mrn,
      tumorType: values.tumorType,
      isSurgical: (values.surgical) ? 'true' : 'false',
      phone: values.phone,
      email: values.email,
    };
    const newToken = this.createToken();
    const patient = {
      token: newToken,
      id: '',
      firstname: values.firstName,
      surname: values.lastName,
      gender: values.gender,
      dob: values.dob.toISOString(),
      address: values.address,
      mrn: values.mrn,
      tumorType: values.tumorType,
      surgical: (values.surgical) ? 'true' : 'false',
      phone: values.phone,
      email: values.email,
    };

    this.props.patientActions.createPatient(patient);

    const url = `${process.env.OPENEHR_URL}/patient/`;
    const options = {
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(body)
    };
    const thisAddPatientView = this;

    fetch(url, options)
    .then(function (response) {
      return response.json();
    }).then(function (json) {
      thisAddPatientView.props.patientActions.updatePatient(json, newToken);
    }).catch(function (ex) {
      console.log('parsing failed', ex);
{'fraction_non_alphanumeric': 0.1557029926595144, 'fraction_numerical': 0.0016939582156973462, 'mean_word_length': 3.212247324613555, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, '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': '7030011', 'n_tokens_mistral': 2293, 'n_tokens_neox': 2234, 'n_words': 478}