<commit_before>package gov.nih.nci.ess.ae;

import ess.caaers.nci.nih.gov.AdverseEvent;
import gov.nih.nci.cabig.caaers.dao.CtcTermDao;
import gov.nih.nci.cabig.caaers.dao.meddra.LowLevelTermDao;
import gov.nih.nci.cabig.caaers.domain.TimeValue;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

import _21090.org.iso.NullFlavor;
import _21090.org.iso.TSDateTime;

public class DomainToGridObjectConverter {

	private static final String TS_DATETIME_PATTERN = "yyyyMMddHHmmss";
	private static final ISO21090Helper h = null;

	private CtcTermDao ctcTermDao;
	private LowLevelTermDao lowLevelTermDao;

	private Date convert(TSDateTime tsDateTime) {
		try {
			if (tsDateTime != null && tsDateTime.getNullFlavor() == null) {
				String value = tsDateTime.getValue();
				if (value != null) {
					return DateUtils.parseDate(value,
							new String[] { TS_DATETIME_PATTERN });
				}
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	private TSDateTime convert(Date date) {
		TSDateTime tsDateTime = new TSDateTime();
		if (date != null) {
			tsDateTime.setValue(DateFormatUtils.format(date,
					TS_DATETIME_PATTERN));
		} else {
			tsDateTime.setNullFlavor(NullFlavor.NI);
		}
		return tsDateTime;

	}

	private TimeValue convertToTimeValue(TSDateTime tsDateTime) {
		TimeValue t = new TimeValue();
		try {
			if (tsDateTime != null && tsDateTime.getNullFlavor() == null) {
				String value = tsDateTime.getValue();
				String[] values = value.split(":");
				if (values.length == 3) {
					t.setHourString(values[0]);
					t.setMinuteString(values[1]);
					String type = values[2];
					if ("AM".equals(type)) {
						t.setType(0);
					} else {
						t.setType(1);
					}
					return t;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("test");
	}

	public void setCtcTermDao(CtcTermDao ctcTermDao) {
		this.ctcTermDao = ctcTermDao;
	}

	public void setLowLevelTermDao(LowLevelTermDao lowLevelTermDao) {
		this.lowLevelTermDao = lowLevelTermDao;
	}

	public AdverseEvent convertAdverseEvent(
			gov.nih.nci.cabig.caaers.domain.AdverseEvent ae) {
		AdverseEvent gridAE = new AdverseEvent();
		gridAE.setIdentifier(h.II(ae.getId().toString()));
		gridAE.setComment(h.ST(ae.getComments()));
		gridAE.setResolutionDate(convert(ae.getEndDate()));
		return gridAE;
	}

}<commit_msg>CAAERS-4517: implementation in progress.<commit_after>package gov.nih.nci.ess.ae;

import ess.caaers.nci.nih.gov.AdverseEvent;
import gov.nih.nci.cabig.caaers.dao.CtcTermDao;
import gov.nih.nci.cabig.caaers.dao.meddra.LowLevelTermDao;
import gov.nih.nci.cabig.caaers.domain.TimeValue;

import java.text.ParseException;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

import _21090.org.iso.NullFlavor;
import _21090.org.iso.TSDateTime;

public class DomainToGridObjectConverter {

	private static final String TS_DATETIME_PATTERN = "yyyyMMddHHmmss";
	private static final ISO21090Helper h = null;

	private CtcTermDao ctcTermDao;
	private LowLevelTermDao lowLevelTermDao;

	private Date convert(TSDateTime tsDateTime) {
		try {
			if (tsDateTime != null && tsDateTime.getNullFlavor() == null) {
				String value = tsDateTime.getValue();
				if (value != null) {
					return DateUtils.parseDate(value,
							new String[] { TS_DATETIME_PATTERN });
				}
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	private TSDateTime convert(Date date) {
		TSDateTime tsDateTime = new TSDateTime();
		if (date != null) {
			tsDateTime.setValue(DateFormatUtils.format(date,
					TS_DATETIME_PATTERN));
		} else {
			tsDateTime.setNullFlavor(NullFlavor.NI);
		}
		return tsDateTime;

	}

	private TimeValue convertToTimeValue(TSDateTime tsDateTime) {
		TimeValue t = new TimeValue();
		try {
			if (tsDateTime != null && tsDateTime.getNullFlavor() == null) {
				String value = tsDateTime.getValue();
				String[] values = value.split(":");
				if (values.length == 3) {
					t.setHourString(values[0]);
					t.setMinuteString(values[1]);
					String type = values[2];
					if ("AM".equals(type)) {
						t.setType(0);
					} else {
						t.setType(1);
					}
					return t;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("test");
	}

	public void setCtcTermDao(CtcTermDao ctcTermDao) {
		this.ctcTermDao = ctcTermDao;
	}

	public void setLowLevelTermDao(LowLevelTermDao lowLevelTermDao) {
		this.lowLevelTermDao = lowLevelTermDao;
	}

	public AdverseEvent convertAdverseEvent(
			gov.nih.nci.cabig.caaers.domain.AdverseEvent ae) {
		AdverseEvent gridAE = new AdverseEvent();
		gridAE.setIdentifier(h.II(ae.getId().toString()));
		gridAE.setComment(h.ST(ae.getComments()));
		gridAE.setResolutionDate(convert(ae.getEndDate()));
		gridAE.setOnsetDate(convert(ae.getEventApproximateTime()));
		return gridAE;
	}

	private TSDateTime convert(TimeValue time) {
		// A day is selected arbitrarily, since it will be ignored anyway. Only
		// hours and minutes matter.
		// My apologies for the complex expression below.
		return convert(DateUtils.setMinutes(DateUtils.setHours(new Date(0),
				time.isAM() ? (time.getHour() == 12 ? 0 : time.getHour())
						: (time.getHour() == 12 ? 12 : time.getHour() + 12)),
				time.getMinute()));
	}

}
{'fraction_non_alphanumeric': 0.12684989429175475, 'fraction_numerical': 0.009866102889358703, 'mean_word_length': 3.902417962003454, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '1094389', 'n_tokens_mistral': 2281, 'n_tokens_neox': 2019, 'n_words': 377}