<commit_before>/**
 * 
 */
package edu.duke.cabig.c3pr.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import edu.duke.cabig.c3pr.dao.ProtocolDao;
import edu.duke.cabig.c3pr.domain.Protocol;
import edu.duke.cabig.c3pr.domain.ProtocolType;
import edu.duke.cabig.c3pr.service.ProtocolService;
import edu.duke.cabig.c3pr.utils.propertyeditors.CustomProtocolPhaseCodeEditor;

/**
 * @author Priyatam
 *
 */
public class CreateProtocolController extends SimpleFormController {
    private static Log log = LogFactory.getLog(CreateProtocolController.class);

	private ProtocolService protocolService;
	private ProtocolDao protocolDao;
	
    public CreateProtocolController() {
        setCommandClass(CreateProtocolController.class);
    }

    protected void initBinder(HttpServletRequest request,
            ServletRequestDataBinder binder) throws Exception {
    		binder.registerCustomEditor(Date.class, ControllerTools.getDateEditor(true));
           // ControllerTools.registerDomainObjectEditor(binder, "protocolType", protocolDao);
            binder.registerCustomEditor(edu.duke.cabig.c3pr.domain.ProtocolPhase.class, "protocolPhase", new CustomProtocolPhaseCodeEditor());
            
            super.initBinder(request, binder);
        }
    
    protected Map<String, Object> referenceData(HttpServletRequest httpServletRequest) throws Exception {
    	//String userName = ApplicationSecurityManager.getUser(httpServletRequest);
    	
    	Map<String, Object> refdata = new HashMap<String, Object>();
    	
    	refdata.put("protocoltypecode", getProtocolTypeCode());
        refdata.put("multiInstitutional", getMultiInstitutionalList());
        return refdata;
    }

    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object oCommand, BindException errors) throws Exception {
    	Protocol protocol = (Protocol) oCommand;
    	protocolService.saveProtocol(protocol);      
    	 	
    	return new ModelAndView(getSuccessView());
    }

	/**
	 * @return the protocolService
	 */
	public ProtocolService getProtocolService() {
		return protocolService;
	}

	/**
	 * @param protocolService the protocolService to set
	 */
	public void setProtocolService(ProtocolService protocolService) {
		this.protocolService = protocolService;
	}
	
	private List <ProtocolType> getProtocolTypeCode(){
		List <ProtocolType> protocolTypeCode = new ArrayList<ProtocolType>();
		ProtocolType pt = new ProtocolType();
		pt.setId(new Integer(1));
		pt.setCode("D");
		pt.setDescription("Diagnostic");
		ProtocolType pt2 = new ProtocolType();
		pt2.setId(new Integer(2));
		pt2.setCode("GN");
		pt2.setDescription("Genetic Non Therapeutic");
		
		protocolTypeCode.add(pt);
		protocolTypeCode.add(pt2);
		
		String str = new String();
		
    	return protocolTypeCode;
	}
	
	private List<StringBean> getMultiInstitutionalList(){
		List<StringBean> multiInstitutional = new ArrayList<StringBean>();
		StringBean str1 = new StringBean();
		str1.setStr("YES");
		StringBean str2 = new StringBean();
		str1.setStr("NO");		
    	multiInstitutional.add(str1);
    	multiInstitutional.add(str2);
    	return multiInstitutional;
	}
	
	public class StringBean {
		
		private String str;

		public String getStr() {
			return str;
		}

		public void setStr(String str) {
			this.str = str;
		}
	}

	public ProtocolDao getProtocolDao() {
		return protocolDao;
	}

	public void setProtocolDao(ProtocolDao protocolDao) {
		this.protocolDao = protocolDao;
	}
	
}<commit_msg>updated for create protocol screen<commit_after>/**
 * 
 */
package edu.duke.cabig.c3pr.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import edu.duke.cabig.c3pr.dao.ProtocolDao;
import edu.duke.cabig.c3pr.domain.Study;
import edu.duke.cabig.c3pr.service.ProtocolService;

/**
 * @author Priyatam
 *
 */
public class CreateProtocolController extends SimpleFormController {
    private static Log log = LogFactory.getLog(CreateProtocolController.class);

	private ProtocolService protocolService;
	private ProtocolDao protocolDao;
	
    public CreateProtocolController() {
        setCommandClass(CreateProtocolController.class);
    }

//    protected void initBinder(HttpServletRequest request,
//            ServletRequestDataBinder binder) throws Exception {
//    		binder.registerCustomEditor(Date.class, ControllerTools.getDateEditor(true));
//            ControllerTools.registerDomainObjectEditor(binder, "protocolType", protocolDao);
//            binder.registerCustomEditor(edu.duke.cabig.c3pr.domain.ProtocolPhase.class, "protocolPhase", new CustomProtocolPhaseCodeEditor());            
//            super.initBinder(request, binder);
//        }
//    
    protected Map<String, Object> referenceData(HttpServletRequest httpServletRequest) throws Exception {
    	// Currently the referenceData is a hack, once DB design is approved for an LOV this will be
    	// replaced with LOVDao to get the static data 
    	Map<String, Object> refdata = new HashMap<String, Object>();
    	
    	refdata.put("diseaseCode", getDiseaseCodeList());
        refdata.put("monitorCode", getMonitorCodeList());
        refdata.put("phaseCode", getDiseaseCodeList());
        refdata.put("sponsorCode", getSponsorCodeList() );
        refdata.put("status", getStatusList());
        refdata.put("type", getTypeList() );
        refdata.put("multiInstitutionIndicator", getMultinstitutionList());
        refdata.put("randomizedIndicator", getRandomizedList());
        refdata.put("blindedIndicator", getBlindedIndicator());
        refdata.put("nciIdentifier", getNciIdentifier());
        return refdata;
    }

    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object oCommand, BindException errors) throws Exception {
    	Study study = (Study) oCommand;
    	protocolService.saveStudy(study);   
    	ModelAndView modelAndView= new ModelAndView(getSuccessView());
    	modelAndView.addAllObjects(errors.getModel());
    	return modelAndView;
    }

  
	/**
	 * @return the protocolService
	 */
	public ProtocolService getProtocolService() {
		return protocolService;
	}

	/**
	 * @param protocolService the protocolService to set
	 */
	public void setProtocolService(ProtocolService protocolService) {
		this.protocolService = protocolService;
	}

	
	private List<LOV> getDiseaseCodeList(){
		List<LOV> col = new ArrayList<LOV>();
		LOV lov1 = new LOV("10028534", "Myelodysplastic syndrome NOS");
		LOV lov2 = new LOV("10038272", "Refractory anemia with ringed sideroblasts");
		LOV lov3 = new LOV("10024536", "Lip and/or oral cavity cancer stage 0");
		LOV lov4 = new LOV("10031098", "Oropharyngeal cancer recurrent");
		
		col.add(lov1);
    	col.add(lov2);
    	col.add(lov3);
    	col.add(lov4);
    	
    	return col;
	}
	
	private List<LOV> getMonitorCodeList(){
		List<LOV> col = new ArrayList<LOV>();
		LOV lov1 = new LOV("10028534", "Monitor Code 1");
		LOV lov2 = new LOV("10038272", "Monitor Code 2");
		LOV lov3 = new LOV("10024536", "Monitor Code 3");
		LOV lov4 = new LOV("10031098", "Monitor Code List 4");
		
		col.add(lov1);
    	col.add(lov2);
    	col.add(lov3);
    	col.add(lov4);
    	
    	return col;
	}
	
	private List<LOV> getPhaseCodeList(){
		List<LOV> col = new ArrayList<LOV>();
		LOV lov1 = new LOV("100", "Phase I");
		LOV lov2 = new LOV("101", "Phase I/II");
		LOV lov3 = new LOV("102", "Phase III");
		LOV lov4 = new LOV("103", "NOT APPLICABLE");
		
		col.add(lov1);
    	col.add(lov2);
    	col.add(lov3);
    	col.add(lov4);
    	
    	return col;
	}
	
	
	private List<LOV> getSponsorCodeList(){
		List<LOV> col = new ArrayList<LOV>();
		LOV lov1 = new LOV("200", "Sponsor 1 - Duke");
		LOV lov2 = new LOV("201", "Sponsor 2 - Nci");
		LOV lov3 = new LOV("202", "Sponsor 3 - FDA");
		
		col.add(lov1);
    	col.add(lov2);
    	col.add(lov3);
    		
    	return col;
	}
	
	private List<LOV> getStatusList(){
		List<LOV> col = new ArrayList<LOV>();
		LOV lov1 = new LOV("C", "Closed");
		LOV lov2 = new LOV("O", "Open");
		LOV lov3 = new LOV("S", "Suspended");
		LOV lov4 = new LOV("T", "Terminated");
		LOV lov5 = new LOV("I", "IRB Approved");
		
		col.add(lov1);
    	col.add(lov2);
    	col.add(lov3);
    	col.add(lov4);
    	col.add(lov5);
    	
    	return col;
	}

	private List<LOV> getTypeList(){
		List<LOV> col = new ArrayList<LOV>();
		LOV lov1 = new LOV("C", "Diagnostic");
		LOV lov2 = new LOV("GN", "Genetic Non-therapeutic");
		LOV lov3 = new LOV("GT", "Genetic Non-therapeutic");
		LOV lov4 = new LOV("N", "Non-therapeutic");
		LOV lov5 = new LOV("P", "Primary Treatment");
		LOV lov6 = new LOV("S", "Supportive");
		LOV lov7 = new LOV("P", "Preventive'");
		
		col.add(lov1);
    	col.add(lov2);
    	col.add(lov3);
    	col.add(lov4);
    	col.add(lov5);
    	col.add(lov6);
    	col.add(lov7);
    	
    	return col;
	}
	
	private List<StringBean> getMultinstitutionList(){
		List<StringBean> col = new ArrayList<StringBean>();		
    	col.add(new StringBean("Y"));
    	col.add(new StringBean("N"));
    	return col;
	}
	private List<StringBean> getRandomizedList(){
		List<StringBean> col = new ArrayList<StringBean>();		
    	col.add(new StringBean("Y"));
    	col.add(new StringBean("N"));
    	return col;
	}
	
	private List<StringBean> getBlindedIndicator(){
		List<StringBean> col = new ArrayList<StringBean>();		
    	col.add(new StringBean("Y"));
    	col.add(new StringBean("N"));
    	return col;
	}
	
	private List<StringBean> getNciIdentifier(){
		List<StringBean> col = new ArrayList<StringBean>();		
    	col.add(new StringBean("Y"));
    	col.add(new StringBean("N"));
    	return col;
	}	
	
	public class LOV {
		
		private String code;
		private String desc;
		
		LOV(String code, String desc)
		{
			this.code=code;
			this.desc=desc;
			
		}
		
		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}
		
		public String getDesc(){
			return desc;
		}
			
		public void setDesc(String desc){
			this.desc=desc;
		}
	}

	public ProtocolDao getProtocolDao() {
		return protocolDao;
	}

	public void setProtocolDao(ProtocolDao protocolDao) {
		this.protocolDao = protocolDao;
	}
	
	public class StringBean {
	
		String str;
		
		StringBean(String str)
		{
			this.str=str;
		}
		
		public void setStr(String str){
			this.str=str;
		}
		
		public String getStr(){
			return str;
		}
		
	}
	
	
}
{'fraction_non_alphanumeric': 0.12218078494050791, 'fraction_numerical': 0.015272598117563489, 'mean_word_length': 3.7866553336166597, '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': '7252889', 'n_tokens_mistral': 3901, 'n_tokens_neox': 3599, 'n_words': 774}