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

import gov.nih.nci.cabig.caaers.dao.CtcDao;
import gov.nih.nci.cabig.caaers.dao.MeddraVersionDao;
import gov.nih.nci.cabig.caaers.domain.*;
import gov.nih.nci.cabig.caaers.web.fields.DefaultInputFieldGroup;
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.InputFieldFactory;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroup;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroupMap;
import gov.nih.nci.cabig.caaers.web.utils.WebUtils;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

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

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class DetailsTab extends StudyTab {

    private CtcDao ctcDao;
    private MeddraVersionDao meddraVersionDao;


    public DetailsTab() {
        super("Details", "Details", "study/study_details");
        setAutoPopulateHelpKey(true);
        /*addHelpKeyExclusion("multiInstitutionIndicator", "adeersReporting", "term", "ctcVersion", "meddraVersion", "diseaseCodeTerm");*/
    }

    @Override
    public Map<String, Object> referenceData(HttpServletRequest request, StudyCommand command) {
        Map<String, Object> refdata = super.referenceData(request, command);
        // TODO : to be removed from reference data, as they are no longer used.
        refdata.put("ctcVersion", ctcDao.getAll()); // remove
        if (command.getStudy().getAeTerminology() != null && command.getStudy().getAeTerminology().getTerm() == null) {
            command.getStudy().getAeTerminology().setTerm(Term.CTC);
        };

        if (command.getStudy().getAeTerminology() != null && command.getStudy().getDiseaseTerminology().getDiseaseCodeTerm() == null) {
            command.getStudy().getDiseaseTerminology().setDiseaseCodeTerm(DiseaseCodeTerm.CTEP);
            // diseaseTerminology.diseaseCodeTerm
        }
        return refdata;
    }

    @Override
    public Map<String, InputFieldGroup> createFieldGroups(final StudyCommand command) {


        // TODO: Add validation for when terminology.term = Term.CTC
        List<Ctc> ctcList = ctcDao.getAll();
        for(Ctc ctc : ctcList){
        	ctc.getCategories().size();
        }

        InputFieldGroup fieldGroup = null,
                reportFormatFieldGroup = null,
                fundSponsorFieldGroup = null,
                coordinatingCenterFieldGroup = null,
                dcpCodeFieldGroup = null;

        if (fieldGroup == null) {
            // set up the fields
            fieldGroup = new DefaultInputFieldGroup("studyDetails");
            List<InputField> fields = fieldGroup.getFields();
            InputField shortTitleField = InputFieldFactory.createTextField("study.shortTitle", "Short title", true);
            InputFieldAttributes.setSize(shortTitleField, 50);
            fields.add(shortTitleField);
            InputField longTitleField = InputFieldFactory.createTextArea("study.longTitle", "Long title", true);
            InputFieldAttributes.setColumns(longTitleField, 70);
            fields.add(longTitleField);
            InputField precisField = InputFieldFactory.createTextArea("study.precis", "Precis", false);
            InputFieldAttributes.setColumns(precisField, 70);
            fields.add(precisField);
            InputField descField = InputFieldFactory.createTextArea("study.description", "Description", false);
            InputFieldAttributes.setColumns(descField, 70);

            fields.add(descField);
            fields.add(InputFieldFactory.createSelectField("study.phaseCode", "Phase", true, collectOptionsFromConfig("phaseCodeRefData", "desc", "desc")));
            fields.add(InputFieldFactory.createSelectField("study.status", "Status", true, collectOptionsFromConfig("statusRefData", "code", "desc")));

            Map<Object, Object> options = new LinkedHashMap<Object, Object>();
            options.put("", "Please select");
            options.put(Boolean.FALSE, "No");
            options.put(Boolean.TRUE, "Yes");

            Map<Object, Object> verbatimFirstOptions = new LinkedHashMap<Object, Object>();
            verbatimFirstOptions.put(Boolean.FALSE, "No");
            verbatimFirstOptions.put(Boolean.TRUE, "Yes");

            fields.add(InputFieldFactory.createSelectField("study.multiInstitutionIndicator", "Multi Institutional", true, options));
            fields.add(InputFieldFactory.createSelectField("study.adeersReporting", "AdEERS  reporting required", true, options));
            fields.add(InputFieldFactory.createSelectField("study.verbatimFirst", "verbatimFirst", false, verbatimFirstOptions));
            fields.add(InputFieldFactory.createLabelField("dataEntryStatus", "Data Entry Status", false));

        }

        if (reportFormatFieldGroup == null) {
            reportFormatFieldGroup = new DefaultInputFieldGroup("rfFieldGroup");
            List<InputField> fields = reportFormatFieldGroup.getFields();

            InputField caaersXMLTypeField = InputFieldFactory.createCheckboxField("study.caaersXMLType", "caAERS XML");
            InputFieldAttributes.setSize(caaersXMLTypeField, 50);
            fields.add(caaersXMLTypeField);

            InputField adeersPDFTypeField = InputFieldFactory.createCheckboxField("study.adeersPDFType", "AdEERS PDF");
            InputFieldAttributes.setSize(adeersPDFTypeField, 50);
            fields.add(adeersPDFTypeField);

            InputField ciomsPDFTypeField = InputFieldFactory.createCheckboxField("study.ciomsPDFType", "CIOMS Form");
            InputFieldAttributes.setSize(ciomsPDFTypeField, 50);
            fields.add(ciomsPDFTypeField);

            InputField ciomsSaePDFTypeField = InputFieldFactory.createCheckboxField("study.ciomsSaePDFType", "CIOMS SAE Form");
            InputFieldAttributes.setSize(ciomsSaePDFTypeField, 50);
            fields.add(ciomsSaePDFTypeField);

            InputField dcpSAEPDFTypeField = InputFieldFactory.createCheckboxField("study.dcpSAEPDFType", "DCP SAE Form");
            InputFieldAttributes.setSize(dcpSAEPDFTypeField, 50);
            fields.add(dcpSAEPDFTypeField);

            InputField medwatchPDFTypeField = InputFieldFactory.createCheckboxField("study.medwatchPDFType", "MedWatch PDF");
            InputFieldAttributes.setSize(medwatchPDFTypeField, 50);
            fields.add(medwatchPDFTypeField);
        }

        if (fundSponsorFieldGroup == null) {
            fundSponsorFieldGroup = new DefaultInputFieldGroup("fsFieldGroup");
            List<InputField> fields = fundSponsorFieldGroup.getFields();
            InputField sponsorField = InputFieldFactory.createAutocompleterField("study.primaryFundingSponsorOrganization", "Funding sponsor", true);
            // sponsorField.getAttributes().put(InputField.DETAILS,"Enter a portion of the sponsor
            // name you are looking for");
            fields.add(sponsorField);
            InputField sponsorIdentiferField = InputFieldFactory.createTextField("study.identifiersLazy[0].value", "Funding sponsor study identifier", true);
            fields.add(sponsorIdentiferField);

        }

        if (coordinatingCenterFieldGroup == null) {
            coordinatingCenterFieldGroup = new DefaultInputFieldGroup("ccFieldGroup");
            List<InputField> fields = coordinatingCenterFieldGroup.getFields();
            fields.add(InputFieldFactory.createAutocompleterField("study.studyCoordinatingCenter.organization", "Coordinating center", true));
            fields.add(InputFieldFactory.createTextField("study.identifiersLazy[1].value", "Coordinating center study identifier", true));

        }
        
        // Create fieldGroup for AeTerminology
        InputFieldGroup studyCodeFieldGroup = new DefaultInputFieldGroup("scFieldGroup");
        List<InputField> scFields = studyCodeFieldGroup.getFields();
        scFields.add(InputFieldFactory.createSelectField("study.aeTerminology.term", "Terminology", true, WebUtils.collectOptions(Arrays.asList(Term.values()), null, "displayName")));


        scFields.add(InputFieldFactory.createSelectField("study.aeTerminology.ctcVersion", "CTC version", false, collectOptions(ctcList, "id", "name")));
        scFields.add(InputFieldFactory.createSelectField("study.aeTerminology.meddraVersion", "MedDRA version", false, collectOptions(meddraVersionDao.getAll(), "id", "name")));
        scFields.add(InputFieldFactory.createSelectField("study.otherMeddra", "Other MedDRA Version", false, collectOptions(meddraVersionDao.getAll(),"id", "name")));
        
        // Create fieldGroup for DiseaseTerminology
        InputFieldGroup studyDiseaseCodeFieldGroup = new DefaultInputFieldGroup("sdcFieldGroup");
        List<InputField> sdFields = studyDiseaseCodeFieldGroup.getFields();
        sdFields.add(InputFieldFactory.createSelectField("study.diseaseTerminology.diseaseCodeTerm", "Terminology", true, WebUtils.collectOptions(Arrays.asList(DiseaseCodeTerm.values(),"Please select"), null, "displayName")));
        sdFields.add(InputFieldFactory.createSelectField("study.diseaseTerminology.meddraVersion", "MedDRA version", false, collectOptions(meddraVersionDao.getAll(), "id", "name")));

        if (dcpCodeFieldGroup == null) {
            dcpCodeFieldGroup = new DefaultInputFieldGroup("dcpFieldGroup");
            List<InputField> fields = dcpCodeFieldGroup.getFields();
            Map<Object, Object> designOpts = new LinkedHashMap<Object, Object>();
            designOpts.put("", "Please select");
            designOpts.putAll(collectOptions(Arrays.asList(Design.values()), null, "displayName"));
            fields.add(InputFieldFactory.createSelectField("study.design", "Study design", false, designOpts));
        }
<commit_msg> CAAERS-4321 - Please select for disease terminology<commit_after>package gov.nih.nci.cabig.caaers.web.study;

import gov.nih.nci.cabig.caaers.dao.CtcDao;
import gov.nih.nci.cabig.caaers.dao.MeddraVersionDao;
import gov.nih.nci.cabig.caaers.domain.*;
import gov.nih.nci.cabig.caaers.web.fields.DefaultInputFieldGroup;
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.InputFieldFactory;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroup;
import gov.nih.nci.cabig.caaers.web.fields.InputFieldGroupMap;
import gov.nih.nci.cabig.caaers.web.utils.WebUtils;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

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

/**
 * @author <NAME>
 * @author <NAME>
 * @author <NAME>
 */
public class DetailsTab extends StudyTab {

    private CtcDao ctcDao;
    private MeddraVersionDao meddraVersionDao;


    public DetailsTab() {
        super("Details", "Details", "study/study_details");
        setAutoPopulateHelpKey(true);
        /*addHelpKeyExclusion("multiInstitutionIndicator", "adeersReporting", "term", "ctcVersion", "meddraVersion", "diseaseCodeTerm");*/
    }

    @Override
    public Map<String, Object> referenceData(HttpServletRequest request, StudyCommand command) {
        Map<String, Object> refdata = super.referenceData(request, command);
        // TODO : to be removed from reference data, as they are no longer used.
        refdata.put("ctcVersion", ctcDao.getAll()); // remove
        if (command.getStudy().getAeTerminology() != null && command.getStudy().getAeTerminology().getTerm() == null) {
            command.getStudy().getAeTerminology().setTerm(Term.CTC);
        };

        if (command.getStudy().getAeTerminology() != null && command.getStudy().getDiseaseTerminology().getDiseaseCodeTerm() == null) {
            command.getStudy().getDiseaseTerminology().setDiseaseCodeTerm(DiseaseCodeTerm.CTEP);
            // diseaseTerminology.diseaseCodeTerm
        }
        return refdata;
    }

    @Override
    public Map<String, InputFieldGroup> createFieldGroups(final StudyCommand command) {


        // TODO: Add validation for when terminology.term = Term.CTC
        List<Ctc> ctcList = ctcDao.getAll();
        for(Ctc ctc : ctcList){
        	ctc.getCategories().size();
        }

        InputFieldGroup fieldGroup = null,
                reportFormatFieldGroup = null,
                fundSponsorFieldGroup = null,
                coordinatingCenterFieldGroup = null,
                dcpCodeFieldGroup = null;

        if (fieldGroup == null) {
            // set up the fields
            fieldGroup = new DefaultInputFieldGroup("studyDetails");
            List<InputField> fields = fieldGroup.getFields();
            InputField shortTitleField = InputFieldFactory.createTextField("study.shortTitle", "Short title", true);
            InputFieldAttributes.setSize(shortTitleField, 50);
            fields.add(shortTitleField);
            InputField longTitleField = InputFieldFactory.createTextArea("study.longTitle", "Long title", true);
            InputFieldAttributes.setColumns(longTitleField, 70);
            fields.add(longTitleField);
            InputField precisField = InputFieldFactory.createTextArea("study.precis", "Precis", false);
            InputFieldAttributes.setColumns(precisField, 70);
            fields.add(precisField);
            InputField descField = InputFieldFactory.createTextArea("study.description", "Description", false);
            InputFieldAttributes.setColumns(descField, 70);

            fields.add(descField);
            fields.add(InputFieldFactory.createSelectField("study.phaseCode", "Phase", true, collectOptionsFromConfig("phaseCodeRefData", "desc", "desc")));
            fields.add(InputFieldFactory.createSelectField("study.status", "Status", true, collectOptionsFromConfig("statusRefData", "code", "desc")));

            Map<Object, Object> options = new LinkedHashMap<Object, Object>();
            options.put("", "Please select");
            options.put(Boolean.FALSE, "No");
            options.put(Boolean.TRUE, "Yes");

            Map<Object, Object> verbatimFirstOptions = new LinkedHashMap<Object, Object>();
            verbatimFirstOptions.put(Boolean.FALSE, "No");
            verbatimFirstOptions.put(Boolean.TRUE, "Yes");

            fields.add(InputFieldFactory.createSelectField("study.multiInstitutionIndicator", "Multi Institutional", true, options));
            fields.add(InputFieldFactory.createSelectField("study.adeersReporting", "AdEERS  reporting required", true, options));
            fields.add(InputFieldFactory.createSelectField("study.verbatimFirst", "verbatimFirst", false, verbatimFirstOptions));
            fields.add(InputFieldFactory.createLabelField("dataEntryStatus", "Data Entry Status", false));

        }

        if (reportFormatFieldGroup == null) {
            reportFormatFieldGroup = new DefaultInputFieldGroup("rfFieldGroup");
            List<InputField> fields = reportFormatFieldGroup.getFields();

            InputField caaersXMLTypeField = InputFieldFactory.createCheckboxField("study.caaersXMLType", "caAERS XML");
            InputFieldAttributes.setSize(caaersXMLTypeField, 50);
            fields.add(caaersXMLTypeField);

            InputField adeersPDFTypeField = InputFieldFactory.createCheckboxField("study.adeersPDFType", "AdEERS PDF");
            InputFieldAttributes.setSize(adeersPDFTypeField, 50);
            fields.add(adeersPDFTypeField);

            InputField ciomsPDFTypeField = InputFieldFactory.createCheckboxField("study.ciomsPDFType", "CIOMS Form");
            InputFieldAttributes.setSize(ciomsPDFTypeField, 50);
            fields.add(ciomsPDFTypeField);

            InputField ciomsSaePDFTypeField = InputFieldFactory.createCheckboxField("study.ciomsSaePDFType", "CIOMS SAE Form");
            InputFieldAttributes.setSize(ciomsSaePDFTypeField, 50);
            fields.add(ciomsSaePDFTypeField);

            InputField dcpSAEPDFTypeField = InputFieldFactory.createCheckboxField("study.dcpSAEPDFType", "DCP SAE Form");
            InputFieldAttributes.setSize(dcpSAEPDFTypeField, 50);
            fields.add(dcpSAEPDFTypeField);

            InputField medwatchPDFTypeField = InputFieldFactory.createCheckboxField("study.medwatchPDFType", "MedWatch PDF");
            InputFieldAttributes.setSize(medwatchPDFTypeField, 50);
            fields.add(medwatchPDFTypeField);
        }

        if (fundSponsorFieldGroup == null) {
            fundSponsorFieldGroup = new DefaultInputFieldGroup("fsFieldGroup");
            List<InputField> fields = fundSponsorFieldGroup.getFields();
            InputField sponsorField = InputFieldFactory.createAutocompleterField("study.primaryFundingSponsorOrganization", "Funding sponsor", true);
            // sponsorField.getAttributes().put(InputField.DETAILS,"Enter a portion of the sponsor
            // name you are looking for");
            fields.add(sponsorField);
            InputField sponsorIdentiferField = InputFieldFactory.createTextField("study.identifiersLazy[0].value", "Funding sponsor study identifier", true);
            fields.add(sponsorIdentiferField);

        }

        if (coordinatingCenterFieldGroup == null) {
            coordinatingCenterFieldGroup = new DefaultInputFieldGroup("ccFieldGroup");
            List<InputField> fields = coordinatingCenterFieldGroup.getFields();
            fields.add(InputFieldFactory.createAutocompleterField("study.studyCoordinatingCenter.organization", "Coordinating center", true));
            fields.add(InputFieldFactory.createTextField("study.identifiersLazy[1].value", "Coordinating center study identifier", true));

        }
        
        // Create fieldGroup for AeTerminology
        InputFieldGroup studyCodeFieldGroup = new DefaultInputFieldGroup("scFieldGroup");
        List<InputField> scFields = studyCodeFieldGroup.getFields();
        scFields.add(InputFieldFactory.createSelectField("study.aeTerminology.term", "Terminology", true, WebUtils.collectOptions(Arrays.asList(Term.values()), null, "displayName")));


        scFields.add(InputFieldFactory.createSelectField("study.aeTerminology.ctcVersion", "CTC version", false, collectOptions(ctcList, "id", "name")));
        scFields.add(InputFieldFactory.createSelectField("study.aeTerminology.meddraVersion", "MedDRA version", false, collectOptions(meddraVersionDao.getAll(), "id", "name")));
        scFields.add(InputFieldFactory.createSelectField("study.otherMeddra", "Other MedDRA Version", false, collectOptions(meddraVersionDao.getAll(),"id", "name")));
        
        // Create fieldGroup for DiseaseTerminology
        InputFieldGroup studyDiseaseCodeFieldGroup = new DefaultInputFieldGroup("sdcFieldGroup");
        List<InputField> sdFields = studyDiseaseCodeFieldGroup.getFields();
        Map<Object, Object> diseaseOpt = new LinkedHashMap<Object, Object>();
        diseaseOpt.put("", "Please select");
        diseaseOpt.putAll(WebUtils.collectOptions(Arrays.asList(DiseaseCodeTerm.values()), null, "displayName"));
        sdFields.add(InputFieldFactory.createSelectField("study.diseaseTerminology.diseaseCodeTerm", "Terminology", true,  diseaseOpt));
        sdFields.add(InputFieldFactory.createSelectField("study.diseaseTerminology.meddraVersion", "MedDRA version", false, collectOptions(meddraVersionDao.getAll(), "id", "name")));

        if (dcpCodeFieldGroup == null) {
            dcpCodeFieldGroup = new DefaultInputFieldGroup("dcpFieldGroup");
            List<InputField> fields = dcpCodeFieldGroup.getFields();
            Map<Object, Object> designOpts = new LinkedHashMap<Object, Object>();
            designOpts.put("", "Please select");
            designOpts.putAll(collectOptions(Arrays.asList(Design.values()), null, "displayName"));
            fields.add(InputFieldFactory.createSelectField("study.design", "Study design", false, designOpts));
        }

{'fraction_non_alphanumeric': 0.1128760051623151, 'fraction_numerical': 0.0023826069691253848, 'mean_word_length': 3.7438191664704497, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '6081897', 'n_tokens_mistral': 5748, 'n_tokens_neox': 5535, 'n_words': 907}