<commit_before>'use strict';
var React = require('react');
var url = require('url');
var _ = require('underscore');
var moment = require('moment');
var panel = require('../libs/bootstrap/panel');
var form = require('../libs/bootstrap/form');
var globals = require('./globals');
var curator = require('./curator');
var RestMixin = require('./rest').RestMixin;
var methods = require('./methods');
var individual_curation = require('./individual_curation');
var Assessments = require('./assessment');

var CurationMixin = curator.CurationMixin;
var RecordHeader = curator.RecordHeader;
var CurationPalette = curator.CurationPalette;
var PmidSummary = curator.PmidSummary;
var PanelGroup = panel.PanelGroup;
var Panel = panel.Panel;
var AssessmentTracker = Assessments.AssessmentTracker;
var AssessmentPanel = Assessments.AssessmentPanel;
var AssessmentMixin = Assessments.AssessmentMixin;
var Form = form.Form;
var FormMixin = form.FormMixin;
var Input = form.Input;
var InputMixin = form.InputMixin;
var PmidDoiButtons = curator.PmidDoiButtons;
var queryKeyValue = globals.queryKeyValue;
var country_codes = globals.country_codes;
var makeStarterIndividual = individual_curation.makeStarterIndividual;
var updateProbandVariants = individual_curation.updateProbandVariants;

// Will be great to convert to 'const' when available
var MAX_VARIANTS = 5;

// Settings for this.state.varOption
var VAR_NONE = 0; // No variants entered in a panel
var VAR_SPEC = 1; // A specific variant (dbSNP, ClinVar, HGVS) entered in a panel
var VAR_OTHER = 2; // Other description entered in a panel


// Maps segregation field refs to schema properties
var formMapSegregation = {
    'SEGpedigreedesc': 'pedigreeDescription',
    'SEGpedigreesize': 'pedigreeSize',
    'SEGnogenerationsinpedigree': 'numberOfGenerationInPedigree',
    'SEGconsanguineous': 'consanguineousFamily',
    'SEGnocases': 'numberOfCases',
    'SEGdenovo': 'deNovoType',
    'SEGunaffectedcarriers': 'numberOfParentsUnaffectedCarriers',
    'SEGnoaffected': 'numberOfAffectedAlleles',
    'SEGnoaffected1': 'numberOfAffectedWithOneVariant',
    'SEGnoaffected2': 'numberOfAffectedWithTwoVariants',
    'SEGnounaffectedcarriers': 'numberOfUnaffectedCarriers',
    'SEGnounaffectedindividuals': 'numberOfUnaffectedIndividuals',
    'SEGbothvariants': 'probandAssociatedWithBoth',
    'SEGaddedsegregationinfo': 'additionalInformation'
};


var FamilyCuration = React.createClass({
    mixins: [FormMixin, RestMixin, CurationMixin, AssessmentMixin],

    contextTypes: {
        navigate: React.PropTypes.func
    },

    cv: {
        assessmentTracker: null, // Tracking object for a single assessment
        filledSegregations: {} // Tracks segregation fields with values filled in
    },

    // Keeps track of values from the query string
    queryValues: {},

    getInitialState: function() {
        return {
            gdm: null, // GDM object given in query string
            group: null, // Group object given in query string
            family: null, // If we're editing a group, this gets the fleshed-out group object we're editing
            annotation: null, // Annotation object given in query string
            extraFamilyCount: 0, // Number of extra families to create
            extraFamilyNames: [], // Names of extra families to create
            variantCount: 0, // Number of variants to display
            variantOption: [], // One variant panel, and nothing entered
            probandIndividual: null, //Proband individual if the family being edited has one
            familyName: '', // Currently entered family name
            addVariantDisabled: false, // True if Add Another Variant button enabled
            genotyping2Disabled: true, // True if genotyping method 2 dropdown disabled
            segregationFilled: false // True if at least one segregation field has a value
        };
    },

    // Handle value changes in various form fields
    handleChange: function(ref, e) {
        var clinvarid, othervariant;

        if (ref === 'genotypingmethod1' && this.refs[ref].getValue()) {
            // Disable the Genotyping Method 2 if Genotyping Method 1 has no value
            this.setState({genotyping2Disabled: this.refs[ref].getValue() === 'none'});
        } else if (ref === 'familyname') {
            this.setState({familyName: this.refs[ref].getValue()});
        } else if (ref.substring(0, 3) === 'VAR') {
            // Disable Add Another Variant if no variant fields have a value (variant fields all start with 'VAR')
            // First figure out the last variant panel’s ref suffix, then see if any values in that panel have changed
            var lastVariantSuffix = (this.state.variantCount - 1) + '';
            var refSuffix = ref.match(/\d+$/);
            refSuffix = refSuffix && refSuffix[0];
            if (refSuffix && (lastVariantSuffix === refSuffix)) {
                // The changed item is in the last variant panel. If any fields in the last field have a value, disable
                // the Add Another Variant button.
                clinvarid = this.refs['VARclinvarid' + lastVariantSuffix].getValue();
                othervariant = this.refs['VARothervariant' + lastVariantSuffix].getValue();
                this.setState({addVariantDisabled: !(clinvarid || othervariant)});
            }

            // Disable fields depending on what fields have values in them.
            clinvarid = this.refs['VARclinvarid' + refSuffix].getValue();
            othervariant = this.refs['VARothervariant' + refSuffix].getValue();
            var currVariantOption = this.state.variantOption;
            if (othervariant) {
                // Something entered in Other; clear the ClinVar ID and set the variantOption state to disable it.
                this.refs['VARclinvarid' + refSuffix].resetValue();
                currVariantOption[refSuffix] = VAR_OTHER;
            } else if (clinvarid) {
                // Something entered in ClinCar ID; clear the Other field and set the variantOption state to disable it.
                this.refs['VARothervariant' + refSuffix].resetValue();
                currVariantOption[refSuffix] = VAR_SPEC;
            } else {
                // Nothing entered anywhere; enable everything.
                currVariantOption[refSuffix] = VAR_NONE;
            }
            this.setState({variantOption: currVariantOption});
        } else if (ref.substring(0,3) === 'SEG') {
            // Handle segregation fields to see if we should enable or disable the assessment dropdown
            var value = this.refs[ref].getValue();
            if (this.refs[ref].props.type === 'select') {
                value = value === 'none' ? '' : value;
            }
            if (value !== '') {
                console.log('non-empty');
                // A segregation field has a value; remember this field
                this.cv.filledSegregations[ref] = true;
            } else {
                console.log('empty');
                // A segregation field lost its value; if we had remembered it, forget it
                if (this.cv.filledSegregations[ref]) {
                    delete this.cv.filledSegregations[ref];
                }
            }

            // Now change the state of the assessment dropdown if needed
            var filled = Object.keys(this.cv.filledSegregations).length > 0;
            if (this.state.segregationFilled !== filled) {
                this.setState({segregationFilled: filled});
            }
        }
    },

    // Handle a click on the copy orphanet button<commit_msg>Remove debugging code<commit_after>'use strict';
var React = require('react');
var url = require('url');
var _ = require('underscore');
var moment = require('moment');
var panel = require('../libs/bootstrap/panel');
var form = require('../libs/bootstrap/form');
var globals = require('./globals');
var curator = require('./curator');
var RestMixin = require('./rest').RestMixin;
var methods = require('./methods');
var individual_curation = require('./individual_curation');
var Assessments = require('./assessment');

var CurationMixin = curator.CurationMixin;
var RecordHeader = curator.RecordHeader;
var CurationPalette = curator.CurationPalette;
var PmidSummary = curator.PmidSummary;
var PanelGroup = panel.PanelGroup;
var Panel = panel.Panel;
var AssessmentTracker = Assessments.AssessmentTracker;
var AssessmentPanel = Assessments.AssessmentPanel;
var AssessmentMixin = Assessments.AssessmentMixin;
var Form = form.Form;
var FormMixin = form.FormMixin;
var Input = form.Input;
var InputMixin = form.InputMixin;
var PmidDoiButtons = curator.PmidDoiButtons;
var queryKeyValue = globals.queryKeyValue;
var country_codes = globals.country_codes;
var makeStarterIndividual = individual_curation.makeStarterIndividual;
var updateProbandVariants = individual_curation.updateProbandVariants;

// Will be great to convert to 'const' when available
var MAX_VARIANTS = 5;

// Settings for this.state.varOption
var VAR_NONE = 0; // No variants entered in a panel
var VAR_SPEC = 1; // A specific variant (dbSNP, ClinVar, HGVS) entered in a panel
var VAR_OTHER = 2; // Other description entered in a panel


// Maps segregation field refs to schema properties
var formMapSegregation = {
    'SEGpedigreedesc': 'pedigreeDescription',
    'SEGpedigreesize': 'pedigreeSize',
    'SEGnogenerationsinpedigree': 'numberOfGenerationInPedigree',
    'SEGconsanguineous': 'consanguineousFamily',
    'SEGnocases': 'numberOfCases',
    'SEGdenovo': 'deNovoType',
    'SEGunaffectedcarriers': 'numberOfParentsUnaffectedCarriers',
    'SEGnoaffected': 'numberOfAffectedAlleles',
    'SEGnoaffected1': 'numberOfAffectedWithOneVariant',
    'SEGnoaffected2': 'numberOfAffectedWithTwoVariants',
    'SEGnounaffectedcarriers': 'numberOfUnaffectedCarriers',
    'SEGnounaffectedindividuals': 'numberOfUnaffectedIndividuals',
    'SEGbothvariants': 'probandAssociatedWithBoth',
    'SEGaddedsegregationinfo': 'additionalInformation'
};


var FamilyCuration = React.createClass({
    mixins: [FormMixin, RestMixin, CurationMixin, AssessmentMixin],

    contextTypes: {
        navigate: React.PropTypes.func
    },

    cv: {
        assessmentTracker: null, // Tracking object for a single assessment
        filledSegregations: {} // Tracks segregation fields with values filled in
    },

    // Keeps track of values from the query string
    queryValues: {},

    getInitialState: function() {
        return {
            gdm: null, // GDM object given in query string
            group: null, // Group object given in query string
            family: null, // If we're editing a group, this gets the fleshed-out group object we're editing
            annotation: null, // Annotation object given in query string
            extraFamilyCount: 0, // Number of extra families to create
            extraFamilyNames: [], // Names of extra families to create
            variantCount: 0, // Number of variants to display
            variantOption: [], // One variant panel, and nothing entered
            probandIndividual: null, //Proband individual if the family being edited has one
            familyName: '', // Currently entered family name
            addVariantDisabled: false, // True if Add Another Variant button enabled
            genotyping2Disabled: true, // True if genotyping method 2 dropdown disabled
            segregationFilled: false // True if at least one segregation field has a value
        };
    },

    // Handle value changes in various form fields
    handleChange: function(ref, e) {
        var clinvarid, othervariant;

        if (ref === 'genotypingmethod1' && this.refs[ref].getValue()) {
            // Disable the Genotyping Method 2 if Genotyping Method 1 has no value
            this.setState({genotyping2Disabled: this.refs[ref].getValue() === 'none'});
        } else if (ref === 'familyname') {
            this.setState({familyName: this.refs[ref].getValue()});
        } else if (ref.substring(0, 3) === 'VAR') {
            // Disable Add Another Variant if no variant fields have a value (variant fields all start with 'VAR')
            // First figure out the last variant panel’s ref suffix, then see if any values in that panel have changed
            var lastVariantSuffix = (this.state.variantCount - 1) + '';
            var refSuffix = ref.match(/\d+$/);
            refSuffix = refSuffix && refSuffix[0];
            if (refSuffix && (lastVariantSuffix === refSuffix)) {
                // The changed item is in the last variant panel. If any fields in the last field have a value, disable
                // the Add Another Variant button.
                clinvarid = this.refs['VARclinvarid' + lastVariantSuffix].getValue();
                othervariant = this.refs['VARothervariant' + lastVariantSuffix].getValue();
                this.setState({addVariantDisabled: !(clinvarid || othervariant)});
            }

            // Disable fields depending on what fields have values in them.
            clinvarid = this.refs['VARclinvarid' + refSuffix].getValue();
            othervariant = this.refs['VARothervariant' + refSuffix].getValue();
            var currVariantOption = this.state.variantOption;
            if (othervariant) {
                // Something entered in Other; clear the ClinVar ID and set the variantOption state to disable it.
                this.refs['VARclinvarid' + refSuffix].resetValue();
                currVariantOption[refSuffix] = VAR_OTHER;
            } else if (clinvarid) {
                // Something entered in ClinCar ID; clear the Other field and set the variantOption state to disable it.
                this.refs['VARothervariant' + refSuffix].resetValue();
                currVariantOption[refSuffix] = VAR_SPEC;
            } else {
                // Nothing entered anywhere; enable everything.
                currVariantOption[refSuffix] = VAR_NONE;
            }
            this.setState({variantOption: currVariantOption});
        } else if (ref.substring(0,3) === 'SEG') {
            // Handle segregation fields to see if we should enable or disable the assessment dropdown
            var value = this.refs[ref].getValue();
            if (this.refs[ref].props.type === 'select') {
                value = value === 'none' ? '' : value;
            }
            if (value !== '') {
                // A segregation field has a value; remember this field
                this.cv.filledSegregations[ref] = true;
            } else {
                // A segregation field lost its value; if we had remembered it, forget it
                if (this.cv.filledSegregations[ref]) {
                    delete this.cv.filledSegregations[ref];
                }
            }

            // Now change the state of the assessment dropdown if needed
            var filled = Object.keys(this.cv.filledSegregations).length > 0;
            if (this.state.segregationFilled !== filled) {
                this.setState({segregationFilled: filled});
            }
        }
    },

    // Handle a click on the copy orphanet button
{'fraction_non_alphanumeric': 0.10043639248875959, 'fraction_numerical': 0.0027770431102882836, 'mean_word_length': 2.707107843137255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '249128', 'n_tokens_mistral': 4194, 'n_tokens_neox': 3950, 'n_words': 1235}