<commit_before>package gov.nih.nci.eagle.query.dto;

import gov.nih.nci.caintegrator.application.dtobuilder.QueryDTOBuilder;
import gov.nih.nci.caintegrator.application.lists.UserListBeanHelper;
import gov.nih.nci.caintegrator.dto.query.QueryDTO;
import gov.nih.nci.caintegrator.studyQueryService.dto.epi.*;
import gov.nih.nci.eagle.web.struts.EpiForm;
import org.apache.log4j.Logger;


import java.util.*;


/**

 * User: <NAME>
 * Date: Apr 16, 2007
 * Time: 11:31:50 AM

 */
public class EPIQueryDTOBuilder implements QueryDTOBuilder {
    private static Logger logger = Logger.getLogger(EPIQueryDTOBuilder.class);
    
    public EPIQueryDTOBuilder() {}

    public QueryDTO buildQueryDTO(Object form, String cacheId) {
        EpiForm epiForm = (EpiForm) form;            // test

        EPIQueryDTO  epiQueryDTO = new EPIQueryDTO();

        if(epiForm.getQueryName() != null)
            epiQueryDTO.setQueryName(epiForm.getQueryName());

        // this contains most of StudyPart and Lifestyle
        PatientCharacteristicsCriterion patCharacterCrit = new PatientCharacteristicsCriterion();
        populatePatientCharactersticsCrit(epiForm, patCharacterCrit);
        epiQueryDTO.setPatientCharacteristicsCriterion(patCharacterCrit);

//	this is only for depression and anxiety, fagerstrom was done seperately below (dont know why)        
//        BehavioralCriterion behaveCrit = new BehavioralCriterion();
//        populateBehaviorCrit(epiForm, behaveCrit);
//        epiQueryDTO.setBehavioralCriterion(behaveCrit);
		
        TobaccoConsumptionCriterion tobaccoCrit = new TobaccoConsumptionCriterion();
        populateTobaccoCrit(epiForm, tobaccoCrit);
        epiQueryDTO.setTobaccoConsumptionCriterion(tobaccoCrit);

        BehavioralCriterion behaviorCrit = new BehavioralCriterion();
        if (epiForm.getFagerstromScore() != null && epiForm.getFagerstromScore().length()>0)
            behaviorCrit.setFagerstromScore(Integer.parseInt(epiForm.getFagerstromScore()));
        epiQueryDTO.setBehavioralCriterion(behaviorCrit);

        EnvironmentalTobaccoSmokeCriterion environCrit = new EnvironmentalTobaccoSmokeCriterion();
        pupulateEnvironmentalTobaccoCrit(epiForm, environCrit);
        epiQueryDTO.setEnvironmentalTobaccoSmokeCriterion(environCrit);

        FamilyHistoryCriterion familyHistCrit = new FamilyHistoryCriterion();
        populateFamilyHistoryCrit(epiForm, familyHistCrit);
        epiQueryDTO.setFamilyHistoryCriterion(familyHistCrit);

        //Populate the patient group
        UserListBeanHelper ulbh = new UserListBeanHelper(cacheId);

        String myGroupName = epiForm.getPatientGroup();
        if(myGroupName != null && !"".equals(myGroupName)) {
            List myGroupValues = ulbh.getItemsFromList(myGroupName);
            epiQueryDTO.setPatientIds(myGroupValues);
        }

        return epiQueryDTO;
    }

    private void populateFamilyHistoryCrit(EpiForm epiForm, FamilyHistoryCriterion familyHistCrit) {

        /*  1. handle Smoking Relatives */
        String[] smokingRelatives = epiForm.getRelativesWhoSmoked();
        if (smokingRelatives != null && smokingRelatives.length > 0) {
            final Collection<Relative> smokingRelativeCol = new ArrayList<Relative>();
            for (int i = 0; i < smokingRelatives.length; i++) {
                Relative  smokingRelative = Enum.valueOf(Relative.class, smokingRelatives[i]);
                smokingRelativeCol.add(smokingRelative);
            }
            familyHistCrit.setSmokingRelativeCollection(smokingRelativeCol);
        }
<commit_msg>added patient group query functionality<commit_after>package gov.nih.nci.eagle.query.dto;

import gov.nih.nci.caintegrator.application.dtobuilder.QueryDTOBuilder;
import gov.nih.nci.caintegrator.application.lists.UserListBeanHelper;
import gov.nih.nci.caintegrator.dto.query.QueryDTO;
import gov.nih.nci.caintegrator.studyQueryService.dto.epi.*;
import gov.nih.nci.eagle.web.struts.EpiForm;
import org.apache.log4j.Logger;


import java.util.*;


/**

 * User: <NAME>
 * Date: Apr 16, 2007
 * Time: 11:31:50 AM

 */
public class EPIQueryDTOBuilder implements QueryDTOBuilder {
    private static Logger logger = Logger.getLogger(EPIQueryDTOBuilder.class);
    
    public EPIQueryDTOBuilder() {}

    public QueryDTO buildQueryDTO(Object form, String cacheId) {
        EpiForm epiForm = (EpiForm) form;            // test

        EPIQueryDTO  epiQueryDTO = new EPIQueryDTO();

        if(epiForm.getQueryName() != null)
            epiQueryDTO.setQueryName(epiForm.getQueryName());

        // this contains most of StudyPart and Lifestyle
        PatientCharacteristicsCriterion patCharacterCrit = new PatientCharacteristicsCriterion();
        populatePatientCharactersticsCrit(epiForm, patCharacterCrit);
        epiQueryDTO.setPatientCharacteristicsCriterion(patCharacterCrit);

//	this is only for depression and anxiety, fagerstrom was done seperately below (dont know why)        
//        BehavioralCriterion behaveCrit = new BehavioralCriterion();
//        populateBehaviorCrit(epiForm, behaveCrit);
//        epiQueryDTO.setBehavioralCriterion(behaveCrit);
		
        TobaccoConsumptionCriterion tobaccoCrit = new TobaccoConsumptionCriterion();
        populateTobaccoCrit(epiForm, tobaccoCrit);
        epiQueryDTO.setTobaccoConsumptionCriterion(tobaccoCrit);

        BehavioralCriterion behaviorCrit = new BehavioralCriterion();
        if (epiForm.getFagerstromScore() != null && epiForm.getFagerstromScore().length()>0)
            behaviorCrit.setFagerstromScore(Integer.parseInt(epiForm.getFagerstromScore()));
        epiQueryDTO.setBehavioralCriterion(behaviorCrit);

        EnvironmentalTobaccoSmokeCriterion environCrit = new EnvironmentalTobaccoSmokeCriterion();
        pupulateEnvironmentalTobaccoCrit(epiForm, environCrit);
        epiQueryDTO.setEnvironmentalTobaccoSmokeCriterion(environCrit);

        FamilyHistoryCriterion familyHistCrit = new FamilyHistoryCriterion();
        populateFamilyHistoryCrit(epiForm, familyHistCrit);
        epiQueryDTO.setFamilyHistoryCriterion(familyHistCrit);

        //Populate the patient group
        UserListBeanHelper ulbh = new UserListBeanHelper(cacheId);

        String myGroupName = epiForm.getPatientGroup();
        if(myGroupName != null && !"".equals(myGroupName)) {
            List myGroupValues = ulbh.getItemsFromList(myGroupName);
            epiQueryDTO.setPatientIds(myGroupValues);
            epiQueryDTO.setPatientGroupName(myGroupName);
        }

        return epiQueryDTO;
    }

    private void populateFamilyHistoryCrit(EpiForm epiForm, FamilyHistoryCriterion familyHistCrit) {

        /*  1. handle Smoking Relatives */
        String[] smokingRelatives = epiForm.getRelativesWhoSmoked();
        if (smokingRelatives != null && smokingRelatives.length > 0) {
            final Collection<Relative> smokingRelativeCol = new ArrayList<Relative>();
            for (int i = 0; i < smokingRelatives.length; i++) {
                Relative  smokingRelative = Enum.valueOf(Relative.class, smokingRelatives[i]);
                smokingRelativeCol.add(smokingRelative);
            }
            familyHistCrit.setSmokingRelativeCollection(smokingRelativeCol);
        }

{'fraction_non_alphanumeric': 0.08717241379310345, 'fraction_numerical': 0.004689655172413793, 'mean_word_length': 3.651058370750481, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '4040098', 'n_tokens_mistral': 2138, 'n_tokens_neox': 2038, 'n_words': 361}