List of usage examples for java.sql Date getTime
public long getTime()
From source file:ips1ap101.lib.base.util.TimeUtils.java
public static Time newTime(java.util.Date date) { if (date == null) { return null; } else {/*from w w w. ja va 2 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:ips1ap101.lib.base.util.TimeUtils.java
public static Date newDate(java.util.Date date) { if (date == null) { return null; } else {/*from w w w. j a v a 2s. c o 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 new Date(c.getTimeInMillis()); } }
From source file:net.sf.farrago.namespace.sfdc.SfdcUdx.java
public static void getDeleted(String objectName, String start, String end, PreparedStatement resultInserter) throws SQLException { SoapBindingStub binding = (SoapBindingStub) FarragoUdrRuntime.getDataServerRuntimeSupport(null); if (((start == null) || start.equals("")) || ((end == null) || end.equals(""))) { throw SfdcResource.instance().InvalidRangeException.ex(); }/*from w ww. j a v a2 s . co m*/ Calendar startTime; Calendar endTime; Calendar thirtyDaysAgo; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); java.util.Date sd = sdf.parse(start, new ParsePosition(0)); startTime = Calendar.getInstance(); startTime.setTime(sd); java.util.Date now = new java.util.Date(); // 30 days == 30*24*60*60*1000 ms Long thirty = new Long("2592000000"); java.util.Date thirtyDate = new java.util.Date(now.getTime() - thirty.longValue()); thirtyDaysAgo = Calendar.getInstance(); thirtyDaysAgo.setTime(thirtyDate); java.util.Date ed = sdf.parse(end, new ParsePosition(0)); endTime = Calendar.getInstance(); endTime.setTime(ed); } catch (Exception ex) { ex.printStackTrace(); throw SfdcResource.instance().InvalidTimeException.ex(ex.getMessage()); } if (thirtyDaysAgo.compareTo(startTime) > 0) { throw SfdcResource.instance().InvalidStartTimeException.ex(startTime.getTime().toString()); } if (startTime.compareTo(endTime) > 0) { throw SfdcResource.instance().InvalidEndTimeException.ex(endTime.getTime().toString(), startTime.getTime().toString()); } SfdcDataServer server = (SfdcDataServer) FarragoUdrRuntime.getDataServerRuntimeSupport(new Object()); try { DescribeSObjectResult describeSObjectResult = (DescribeSObjectResult) server .getEntityDescribe(objectName); // check the name if ((describeSObjectResult != null) && describeSObjectResult.getName().equals(objectName)) { // check if data replication is allowed on object if (!describeSObjectResult.isReplicateable()) { throw SfdcResource.instance().ReplicationException.ex(objectName); } } else { throw SfdcResource.instance().InvalidObjectException.ex(objectName); } GetDeletedResult gdr = binding.getDeleted(objectName, startTime, endTime); if ((gdr.getDeletedRecords() != null) && (gdr.getDeletedRecords().length > 0)) { for (int i = 0; i < gdr.getDeletedRecords().length; i++) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); StringBuffer sbuf = new StringBuffer(); String idString = gdr.getDeletedRecords(i).getId(); int prec = 25 + server.getVarcharPrecision(); if (idString.length() > prec) { idString = idString.substring(0, prec); } resultInserter.setString(1, idString); String timeStr = sdf .format(gdr.getDeletedRecords(i).getDeletedDate().getTime(), sbuf, new FieldPosition(0)) .toString(); resultInserter.setTimestamp(2, java.sql.Timestamp.valueOf(timeStr)); resultInserter.executeUpdate(); } } } catch (AxisFault ae) { SQLException retryExcn = new SQLException(ae.getFaultString(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(ae.getFaultString(), chainedEx); } catch (RemoteException re) { SQLException retryExcn = new SQLException(re.getMessage(), null, 460150); Exception chainedEx = FarragoResource.instance().RetryableFailure.ex(retryExcn); throw SfdcResource.instance().BindingCallException.ex(re.getMessage(), chainedEx); } }
From source file:com.arm.connector.bridge.core.Utils.java
public static String dateToString(java.sql.Date date) { if (date != null) { return Utils.dateToString(new java.util.Date(date.getTime())); } else {/*from www.j a va2 s .co m*/ return "[no date]"; } }
From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java
private static EncounterData createApppointment(Connection conn, Long siteId, MshPatientMaster mshPatientMaster) throws NumberFormatException, Exception { Form formDef = null;//from w ww . j av a2 s.co m Long formId = (Long) DynaSiteObjects.getFormNameMap().get("Appointment"); formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId)); Appointment formData = new Appointment(); 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()); Integer dateOffset = mshPatientMaster.getDaysToNextAppointment(); Date dateVisit = null; Date initialvisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted()); Date dateNextAppt = DateUtils.toDateSql(mshPatientMaster.getDateOfNextAppointment()); if ((dateNextAppt != null) && (dateOffset != null)) { String datePastVisitStr = DateUtils.createFutureDate(dateNextAppt, 0 - dateOffset); Date datePastVisit = Date.valueOf(datePastVisitStr); if (datePastVisit.getTime() > initialvisit.getTime()) { dateVisit = datePastVisit; } else { dateVisit = initialvisit; } } else { dateVisit = initialvisit; } formData.setDateVisit(dateVisit); if (dateVisit != null) { Timestamp ts = new Timestamp(dateVisit.getTime()); formData.setCreated(ts); formData.setLastModified(ts); } formData.setAppointment_date(dateNextAppt); EncounterData enc = null; if (dateNextAppt != null) { enc = FormDAO.create(conn, formData, formData.getCreatedBy(), formData.getSiteId(), formDef, formData.getFlowId(), null); } return enc; }
From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java
/** * Creates Current Health Record.//from w ww . ja v a2 s. co m * @param conn * @param siteId * @param mshPatientMaster * @return * @throws NumberFormatException * @throws Exception */ private static EncounterData createCurrentHealthRecord(Connection conn, Long siteId, MshPatientMaster mshPatientMaster) throws NumberFormatException, Exception { Form formDef = null; Long formId = (Long) DynaSiteObjects.getFormNameMap().get("PatientCondition"); formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId)); PatientCondition formData = new PatientCondition(); 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()); Integer dateOffset = mshPatientMaster.getDaysToNextAppointment(); Date dateVisit = null; Date initialvisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted()); if ((mshPatientMaster.getDateOfNextAppointment() != null) && (dateOffset != null)) { Date dateNextAppt = DateUtils.toDateSql(mshPatientMaster.getDateOfNextAppointment()); String datePastVisitStr = DateUtils.createFutureDate(dateNextAppt, 0 - dateOffset); Date datePastVisit = Date.valueOf(datePastVisitStr); if (datePastVisit.getTime() > initialvisit.getTime()) { dateVisit = datePastVisit; } else { dateVisit = initialvisit; } } else { dateVisit = initialvisit; } formData.setDateVisit(dateVisit); if (dateVisit != null) { Timestamp ts = new Timestamp(dateVisit.getTime()); formData.setCreated(ts); formData.setLastModified(ts); } formData.setWeight(mshPatientMaster.getCurrentWeight()); formData.setHeight(mshPatientMaster.getCurrentHeight()); if (mshPatientMaster.getTB() == 1) { formData.setTb_status(3297); //Under treatment } else if (mshPatientMaster.getNoTB() == 1) { formData.setTb_status(3296); // None } StringBuffer sbuf = new StringBuffer(); if (mshPatientMaster.getCotrimoxazole() == 1) { sbuf.append("Taking Cotrimoxazole. "); } if (mshPatientMaster.getNoCotrimoxazole() == 1) { sbuf.append("Not taking Cotrimoxazole. "); } formData.setOi_indications(sbuf.toString()); EncounterData enc = FormDAO.create(conn, formData, formData.getCreatedBy(), formData.getSiteId(), formDef, formData.getFlowId(), null); return enc; }
From source file:ips1ap101.lib.core.util.STP.java
public static Object getObjeto(String string, TipoDatoParEnumeration tipo) { String cadena = StringUtils.trimToNull(string); if (cadena == null) { return null; }// ww w .j av a2 s .c o m Object objeto; switch (tipo) { case ALFANUMERICO: // objeto = new String(string); objeto = cadena; break; case NUMERICO: try { objeto = new BigDecimal(cadena); } catch (NumberFormatException e) { objeto = null; } break; case FECHA_HORA: try { java.util.Date dateTime = TimeUtils.parse(cadena); objeto = dateTime == null ? null : new Timestamp(dateTime.getTime()); } catch (RuntimeException e) { objeto = null; } break; case ENTERO: try { objeto = new Integer(new BigDecimal(cadena).intValue()); } catch (NumberFormatException e) { objeto = null; } break; case ENTERO_GRANDE: try { objeto = new Long(new BigDecimal(cadena).longValue()); } catch (NumberFormatException e) { objeto = null; } break; default: objeto = null; break; } return objeto; }
From source file:adalid.commons.util.TimeUtils.java
public static Timestamp newTimestamp(java.util.Date date) { return date == null ? null : new Timestamp(date.getTime()); }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Timestamp getTimestamp(Date date) { return date == null ? currentTimestamp() : new Timestamp(date.getTime()); }
From source file:org.rti.zcore.dar.transfer.access.ImportMshData.java
private static EncounterData createCurrentRegimen(Connection conn, Long siteId, MshPatientMaster mshPatientMaster) throws NumberFormatException, Exception { Form formDef = null;/*from ww w . java 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()); Integer dateOffset = mshPatientMaster.getDaysToNextAppointment(); Date dateVisit = null; Date initialvisit = DateUtils.toDateSql(mshPatientMaster.getDateTherapyStarted()); if ((mshPatientMaster.getDateOfNextAppointment() != null) && (dateOffset != null)) { Date dateNextAppt = DateUtils.toDateSql(mshPatientMaster.getDateOfNextAppointment()); String datePastVisitStr = DateUtils.createFutureDate(dateNextAppt, 0 - dateOffset); Date datePastVisit = Date.valueOf(datePastVisitStr); if (datePastVisit.getTime() > initialvisit.getTime()) { dateVisit = datePastVisit; } else { dateVisit = initialvisit; } } else { dateVisit = initialvisit; } 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.getCurrentRegimen(); 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("R12")) { //R12 7A 13 regimenCode = 13; } else if (regimen.equals("R13")) { //R13 7B 14 7B (TDF/FTC/EFV) regimenCode = 14; } 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); if ((mshPatientMaster.getReasonsforChanges() != null) && (!mshPatientMaster.getReasonsforChanges().equals(""))) { Integer reasonForChange = mshPatientMaster.getReasonsforChanges(); String reason = null; switch (reasonForChange) { case 1: reason = "Anemia"; break; case 2: reason = "TB"; break; case 3: reason = "Pregnancy"; break; case 4: reason = "Neuropathy"; break; case 5: reason = "Rash"; break; case 6: reason = "Lipodistrophy"; break; case 7: reason = "fluconazole treatment"; break; case 8: reason = "treatment failure"; break; case 9: reason = "Guideline change"; break; default: break; } formData.setRegimen_change_reason(reason); } EncounterData enc = null; if (importEncounter) { enc = FormDAO.create(conn, formData, formData.getCreatedBy(), formData.getSiteId(), formDef, formData.getFlowId(), null); } return enc; }