<commit_before>package gov.nih.nci.cabig.caaers.web.ae;

import org.springframework.beans.BeanWrapper;
import org.springframework.validation.Errors;

import java.util.Map;
import java.util.ListIterator;

import gov.nih.nci.cabig.caaers.domain.AdverseEventPriorTherapy;
import gov.nih.nci.cabig.caaers.domain.expeditedfields.ExpeditedReportSection;
import gov.nih.nci.cabig.caaers.web.fields.InputField;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldAttributes;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroup;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldFactory;

/**
 * @author <NAME>
 */
public class PriorTherapyTab extends AeTab {

    public PriorTherapyTab() {
        super("Prior Therapies", ExpeditedReportSection.PRIOR_THERAPIES_SECTION.getDisplayName(), "ae/priorTherapies");
        setAutoPopulateHelpKey(true);
        addHelpKeyExclusion("other");
    }

    @Override
    protected void createFieldGroups(AeInputFieldCreator creator, ExpeditedAdverseEventInputCommand command) {
        InputField priorTherapyField = InputFieldFactory.createAutocompleterField("priorTherapy", "Prior therapy", false);
        /*InputFieldAttributes.setDetails(priorTherapyField, "If the appropriate therapy is not listed, type the therapy in the &quot;Comments(prior therapy)&quot; field below.");*/
        //TODO: change the name of other to "comment"
        InputField otherField = InputFieldFactory.createTextArea("other", "Comments (prior therapy)", false);
        InputFieldAttributes.setColumns(otherField, 65);
        InputField startDateField = InputFieldFactory.createDateField("startDate", "Therapy start Date", false);
        /*InputFieldAttributes.setDetails(startDateField, "If known, enter start date for prior therapy.");*/
        InputField endDateField = InputFieldFactory.createDateField("endDate", "Therapy end date", false);
        /*InputFieldAttributes.setDetails(endDateField, "If known, enter end date for prior therapy.");*/

        creator.createRepeatingFieldGroup("priorTherapy", "adverseEventPriorTherapies",
            new SimpleNumericDisplayNameCreator("Prior therapy"),
            priorTherapyField,
            otherField,
            startDateField,
            endDateField
            
        );

        creator.createRepeatingFieldGroup("ptAgent", "adverseEventPriorTherapies",
        		InputFieldFactory.createAutocompleterField("priorTherapyAgents.chemoAgent", "Agent", true)	
        );
    }

    @Override
    protected void validate(
        ExpeditedAdverseEventInputCommand command, BeanWrapper commandBean,
        Map<String, InputFieldGroup> fieldGroups, Errors errors
    ) {
        for (ListIterator<AdverseEventPriorTherapy> it = command.getAeReport().getAdverseEventPriorTherapies().listIterator(); it.hasNext();) {
            AdverseEventPriorTherapy aePriorTherapy = it.next();
            validatePriorTherapy(aePriorTherapy, it.previousIndex(), errors);
        }
    }

    private void validatePriorTherapy(AdverseEventPriorTherapy aePriorTherapy, int index, Errors errors) {
//        if (aePriorTherapy.getPriorTherapy() == null && aePriorTherapy.getOther() == null) {<commit_msg>Changed back to not required<commit_after>package gov.nih.nci.cabig.caaers.web.ae;

import org.springframework.beans.BeanWrapper;
import org.springframework.validation.Errors;

import java.util.Map;
import java.util.ListIterator;

import gov.nih.nci.cabig.caaers.domain.AdverseEventPriorTherapy;
import gov.nih.nci.cabig.caaers.domain.expeditedfields.ExpeditedReportSection;
import gov.nih.nci.cabig.caaers.web.fields.InputField;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldAttributes;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroup;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldFactory;

/**
 * @author <NAME>
 */
public class PriorTherapyTab extends AeTab {

    public PriorTherapyTab() {
        super("Prior Therapies", ExpeditedReportSection.PRIOR_THERAPIES_SECTION.getDisplayName(), "ae/priorTherapies");
        setAutoPopulateHelpKey(true);
        addHelpKeyExclusion("other");
    }

    @Override
    protected void createFieldGroups(AeInputFieldCreator creator, ExpeditedAdverseEventInputCommand command) {
        InputField priorTherapyField = InputFieldFactory.createAutocompleterField("priorTherapy", "Prior therapy", false);
        /*InputFieldAttributes.setDetails(priorTherapyField, "If the appropriate therapy is not listed, type the therapy in the &quot;Comments(prior therapy)&quot; field below.");*/
        //TODO: change the name of other to "comment"
        InputField otherField = InputFieldFactory.createTextArea("other", "Comments (prior therapy)", false);
        InputFieldAttributes.setColumns(otherField, 65);
        InputField startDateField = InputFieldFactory.createDateField("startDate", "Therapy start Date", false);
        /*InputFieldAttributes.setDetails(startDateField, "If known, enter start date for prior therapy.");*/
        InputField endDateField = InputFieldFactory.createDateField("endDate", "Therapy end date", false);
        /*InputFieldAttributes.setDetails(endDateField, "If known, enter end date for prior therapy.");*/

        creator.createRepeatingFieldGroup("priorTherapy", "adverseEventPriorTherapies",
            new SimpleNumericDisplayNameCreator("Prior therapy"),
            priorTherapyField,
            otherField,
            startDateField,
            endDateField
            
        );

        creator.createRepeatingFieldGroup("ptAgent", "adverseEventPriorTherapies",
        		InputFieldFactory.createAutocompleterField("priorTherapyAgents.chemoAgent", "Agent", false)	
        );
    }

    @Override
    protected void validate(
        ExpeditedAdverseEventInputCommand command, BeanWrapper commandBean,
        Map<String, InputFieldGroup> fieldGroups, Errors errors
    ) {
        for (ListIterator<AdverseEventPriorTherapy> it = command.getAeReport().getAdverseEventPriorTherapies().listIterator(); it.hasNext();) {
            AdverseEventPriorTherapy aePriorTherapy = it.next();
            validatePriorTherapy(aePriorTherapy, it.previousIndex(), errors);
        }
    }

    private void validatePriorTherapy(AdverseEventPriorTherapy aePriorTherapy, int index, Errors errors) {
//        if (aePriorTherapy.getPriorTherapy() == null && aePriorTherapy.getOther() == null) {
{'fraction_non_alphanumeric': 0.09996866186148542, 'fraction_numerical': 0.0006267627702914447, 'mean_word_length': 4.168421052631579, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5454814', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1812, 'n_words': 338}