List of usage examples for java.sql Date getTime
public long getTime()
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSHistoryFileToSQL.java
/** * This method converts a date in string format to java.sql.Date Format. * /*from w w w .j a v a 2 s . c o m*/ * @param sDate * @param format * @return * @throws Exception */ public static Date convertStringToDate(String sDate, String format) throws Exception { java.util.Date dateUtil = null; SimpleDateFormat dateformat = new SimpleDateFormat(format); try { dateUtil = dateformat.parse(sDate); } catch (ParseException e) { throw new Exception("Exception while parsing the date: " + e.getMessage()); } return new Date(dateUtil.getTime()); }
From source file:adalid.commons.util.TimeUtils.java
public static Calendar newCalendar(java.util.Date date) { if (date == null) { return null; }/*from w w w. j a v a 2s .co m*/ Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); return c; }
From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java
/** * @param conn/*w ww . j av a 2 s .com*/ * @param siteId * @param mshPatientMaster * @param patientTransactions * @throws NumberFormatException * @throws Exception */ private static EncounterData createPatientRegistration(Connection conn, Long siteId, MshPatientMaster mshPatientMaster, ArrayList<MshPatientTransaction> patientTransactions) throws NumberFormatException, Exception { Form formDef = null; //String formName = className.replace(Constants.getDynasiteFormsPackage() + ".", ""); Long formId = (Long) DynaSiteObjects.getFormNameMap().get("PatientRegistration"); formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId)); // Patient patient = new Patient(); PatientRegistration pr = new PatientRegistration(); pr.setPatient_id_number(mshPatientMaster.getArtID()); pr.setFirstName(mshPatientMaster.getFirstname()); pr.setForenames(mshPatientMaster.getFirstname()); pr.setStreet_address_1(mshPatientMaster.getAddress()); if (mshPatientMaster.getSex().equals("Male")) { pr.setSex(2); } else { pr.setSex(1); } pr.setSurname(mshPatientMaster.getSurname()); pr.setAge_at_first_attendence(mshPatientMaster.getAge()); pr.setSiteId(siteId); pr.setCreatedBy("zepadmin"); //Person is a child when age is <= this number //child.age=14 String childAge = Constants.CHILD_AGE; Integer childAgeInt = Integer.valueOf(childAge); if (mshPatientMaster.getAge() <= childAgeInt) { pr.setAge_category(3284); } else { pr.setAge_category(3283); } if (patientTransactions != null) { StringBuffer sbuf = new StringBuffer(); sbuf.append("<p>Imported Transactions:</p>"); for (MshPatientTransaction mshPatientTransactions : patientTransactions) { sbuf.append("<p>"); String record = mshPatientTransactions.toString(); sbuf.append(record); sbuf.append("</p>"); sbuf.append(NL); } String notes = sbuf.toString(); int len = notes.length(); int max = 32700 - 30; if (len > max) { log.debug("Truncating record for patient id: " + mshPatientMaster.getArtID() + " len: " + len); String message = "<p>(Record truncated...)</p>"; String notesTruncated = notes.substring(0, max); pr.setNotes(notesTruncated + NL + message); } else { pr.setNotes(notes); } } /*patient.setPatientRegistration(pr); patient.setSiteId(siteId);*/ pr.setFlowId(formDef.getFlowId()); pr.setFormId(formId); Date dateVisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted()); pr.setDateVisit(dateVisit); if (dateVisit != null) { Timestamp ts = new Timestamp(dateVisit.getTime()); pr.setCreated(ts); pr.setLastModified(ts); } EncounterData enc = FormDAO.create(conn, pr, pr.getCreatedBy(), pr.getSiteId(), formDef, pr.getFlowId(), null); return enc; }
From source file:adalid.commons.util.TimeUtils.java
public static Calendar newTimeCalendar(java.util.Date date) { if (date == null) { return null; }//ww w .java 2 s.co m Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.YEAR, 1970); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DAY_OF_MONTH, 1); return c; }
From source file:adalid.commons.util.TimeUtils.java
public static Calendar newDateCalendar(java.util.Date date) { if (date == null) { return null; }//from w w w .j ava 2s. co m Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c; }
From source file:adalid.commons.util.TimeUtils.java
private static Timestamp merge(java.util.Date date, java.util.Date time) { Calendar d = Calendar.getInstance(); Calendar t = Calendar.getInstance(); d.setTimeInMillis(date.getTime()); t.setTimeInMillis(time.getTime());/*from ww w .j a v a 2s. com*/ d.set(Calendar.HOUR_OF_DAY, t.get(Calendar.HOUR_OF_DAY)); d.set(Calendar.MINUTE, t.get(Calendar.MINUTE)); d.set(Calendar.SECOND, t.get(Calendar.SECOND)); d.set(Calendar.MILLISECOND, t.get(Calendar.MILLISECOND)); return new Timestamp(d.getTimeInMillis()); }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Time getTime(java.util.Date date) { if (date == null) { return currentTime(); }//from w w w . ja va2 s . c o m Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.YEAR, 1970); c.set(Calendar.MONTH, Calendar.JANUARY); c.set(Calendar.DAY_OF_MONTH, 1); return new Time(c.getTimeInMillis()); }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Date getDate(java.util.Date date) { if (date == null) { return currentDate(); }/*from w ww . j ava2 s. c om*/ Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return new Date(c.getTimeInMillis()); }
From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java
private static EncounterData createInitialRegimen(Connection conn, Long siteId, MshPatientMaster mshPatientMaster) throws NumberFormatException, Exception { Form formDef = null;// w w w . j av a 2s .c o m Long formId = (Long) DynaSiteObjects.getFormNameMap().get("ArtRegimen"); formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId)); ArtRegimen formData = new ArtRegimen(); formData.setSiteId(siteId); formData.setCreatedBy("zepadmin"); formData.setFlowId(formDef.getFlowId()); formData.setFormId(formId); formData.setPatientId(mshPatientMaster.getPatientId()); formData.setSessionPatient(mshPatientMaster.getSessionPatient()); formData.setEvent(mshPatientMaster.getEvent()); formData.setEventId(mshPatientMaster.getEventId()); formData.setEventUuid(mshPatientMaster.getEventUuid()); Date dateVisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted()); formData.setDateVisit(dateVisit); if (dateVisit != null) { Timestamp ts = new Timestamp(dateVisit.getTime()); formData.setCreated(ts); formData.setLastModified(ts); } formData.setDate_started(dateVisit); String regimen = mshPatientMaster.getRegimenStarted(); Integer regimenCode = null; boolean importEncounter = true; if (regimen.equals("R01")) { importEncounter = false; } else if (regimen.equals("R02")) { //1A regimenCode = 1; } else if (regimen.equals("R03")) { //R03 2A 3 regimenCode = 3; } else if (regimen.equals("R04")) { //R04 3A 5 regimenCode = 5; } else if (regimen.equals("R05")) { //R05 3B 6 regimenCode = 6; } else if (regimen.equals("R06")) { //R06 4A 7 regimenCode = 7; } else if (regimen.equals("R07")) { //R07 5A 9 regimenCode = 9; } else if (regimen.equals("R08")) { //R08 5B 10 regimenCode = 10; } else if (regimen.equals("R09")) { //R09 6A 11 regimenCode = 11; } else if (regimen.equals("R10")) { //R10 6B 12 regimenCode = 12; } else if (regimen.equals("R12")) { //R12 7A 13 regimenCode = 13; } else if (regimen.equals("R21")) { //R21 PEP 1 21 PEP 1 (AZT/3TC) regimenCode = 21; } else if (regimen.equals("R23")) { //R23 PEP 3 24 regimenCode = 24; } else if (regimen.equals("R26")) { //R26 C1A 36 regimenCode = 36; } else if (regimen.equals("R27")) { //R27 C2A 40 regimenCode = 40; } else if (regimen.equals("R28")) { //R28 C3A 44 regimenCode = 44; } else if (regimen.equals("R29")) { //R29 C3B 45 regimenCode = 45; } else if (regimen.equals("R30")) { //R30 C4A 48 regimenCode = 48; } else if (regimen.equals("R31")) { //R31 C4B 49 regimenCode = 49; } else if (regimen.equals("R32")) { //R32 C4C 50 regimenCode = 50; } else { importEncounter = false; log.debug("Unable to import regimen for patient id" + mshPatientMaster.getPatientId() + " Regimen: " + regimen); } formData.setRegimen_1(regimenCode); EncounterData enc = null; if (importEncounter) { enc = FormDAO.create(conn, formData, formData.getCreatedBy(), formData.getSiteId(), formDef, formData.getFlowId(), null); } return enc; }
From source file:adalid.commons.util.TimeUtils.java
public static String jdbcTemporalString(Object object) { java.util.Date date = object instanceof java.util.Date ? (java.util.Date) object : null; if (date == null) { return null; }/* ww w. j av a2 s.c o m*/ Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); int dd = c.get(Calendar.YEAR); int MM = c.get(Calendar.MONTH); int yy = c.get(Calendar.DAY_OF_MONTH); int hh = c.get(Calendar.HOUR_OF_DAY); int mm = c.get(Calendar.MINUTE); int ss = c.get(Calendar.SECOND); int ms = c.get(Calendar.MILLISECOND); boolean dateless = dd == 1 && MM == Calendar.JANUARY && yy == 1970; boolean timeless = hh + mm + ss + ms == 0; return timeless ? jdbcDateString(date) : dateless ? jdbcTimeString(date) : jdbcTimestampString(date); }