Example usage for org.joda.time DateTime DateTime

List of usage examples for org.joda.time DateTime DateTime

Introduction

In this page you can find the example usage for org.joda.time DateTime DateTime.

Prototype

public DateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:au.org.alfred.icu.pdf.services.factories.DischargeSummaryDataBuilder.java

public static String buildData(String icuVisitNumber, String visitNumber, String patientId, String userName,
        String userId, DischargeSummaryData data) {
    TblAdmission admHosp = new TblAdmission();
    TblAdmissionICU admICU = new TblAdmissionICU();
    TblAdmICUTransfer txICU = new TblAdmICUTransfer();
    TblAdmAccountClassTfer accntTx = new TblAdmAccountClassTfer();
    TblPMI demo = new TblPMI();
    TblSex sex = new TblSex();
    TblProvider doc = new TblProvider();
    TblPayClass pc = new TblPayClass();
    TblUnit unit = new TblUnit();
    TblWard ward = new TblWard();
    VwDiagnosis apache3 = new VwDiagnosis();
    List<TblMicroResults> micro = null;
    List<TblOtherResults> other = null;
    List<TblAntibiotic> antibiotics = null;
    List<TblNeurology> neuro = null;
    List<TblResusPlan> resus = null;
    List<TblNicotine> nic = null;
    List<VwSiss> procs = null;
    List<TblCarePlan> nursing = null;
    List<TblRefCarePlan> nursingRef = null;
    QryHospAdm destination = null;//from w w w.ja  v a 2s.  c  om
    Map nursingPlans = new HashMap();
    int age = 0;
    int los = 0;
    StringBuilder fileName = new StringBuilder();
    List res;

    //fileName.append("\\\\alfapps01\\apps\\ICUApps\\CernerDischarge");

    res = ModelFactory.getModelObject(TblAdmission.class, TblAdmission.ADMID_PROPERTY, visitNumber);

    if (res.size() == 1) {
        admHosp = (TblAdmission) res.get(0);
    }

    res = ModelFactory.getModelObject(TblAdmissionICU.class, TblAdmissionICU.I_CUADM_ID_PROPERTY,
            icuVisitNumber);
    //System.out.println("Size "+res.size()+ " ICUID "+icuVisitNumber);
    if (res.size() == 1) {
        admICU = (TblAdmissionICU) res.get(0);
    }

    res = ModelFactory.getModelObject(TblPMI.class, TblPMI.P_MIID_PROPERTY, patientId);

    if (res.size() == 1) {
        demo = (TblPMI) res.get(0);
        org.joda.time.DateTime dob = new DateTime(demo.getBirthDate());
        org.joda.time.DateTime now = new DateTime();
        age = org.joda.time.Years.yearsBetween(dob, now).getYears();
    }

    res = ModelFactory.getModelWithExpression(TblAdmICUTransfer.class,
            ExpressionFactory.matchExp(TblAdmICUTransfer.ADM_ID_PROPERTY, admICU.getAdmID())
                    .andExp(ExpressionFactory.matchExp(TblAdmICUTransfer.WARD_TFER_DATE_PROPERTY,
                            admICU.getWardTferDate())));

    if (res.size() > 0) {
        txICU = (TblAdmICUTransfer) res.get(0);
    }

    res = ModelFactory.getModelObject(TblSex.class, TblSex.SEX_ID_PROPERTY,
            demo.getSexId() == null ? 1 : demo.getSexId());

    if (res.size() == 1) {
        sex = (TblSex) res.get(0);
    }

    res = ModelFactory.getModelObject(TblProvider.class, TblProvider.PROVIDER_CODE_PROPERTY,
            admHosp.getAttendingDrCode());

    if (res.size() == 1) {
        doc = (TblProvider) res.get(0);
    }

    res = ModelFactory.getModelObject(TblUnit.class, TblUnit.UNIT_ID_PROPERTY, admHosp.getUnitId());

    if (res.size() == 1) {
        unit = (TblUnit) res.get(0);
    }

    res = ModelFactory.getModelObject(TblPayClass.class, TblPayClass.PAY_CLASS_ID_PROPERTY,
            admHosp.getPayClassId());

    if (res.size() == 1) {
        pc = (TblPayClass) res.get(0);
    }

    try {
        res = ModelFactory.getModelObject(VwDiagnosis.class, VwDiagnosis.I_CUADM_ID_PROPERTY,
                admICU.getICUAdmID());
        if (res.size() > 0) {
            //System.out.println("APACHEIII " + res.size());
            apache3 = (VwDiagnosis) res.get(0);
            //System.out.println("APACHEIII " + apache3.getA3DiagDesc());
        }
    } catch (CayenneRuntimeException ex) {
        //apache3 = null;
    }

    res = ModelFactory.getModelObject(TblMicroResults.class, TblMicroResults.ICU_ADM_ID_PROPERTY,
            admICU.getICUAdmID());
    if (res.size() > 0) {
        data.setMicro(res);
    }

    res = ModelFactory.getModelObject(TblOtherResults.class, TblOtherResults.ICU_ADM_ID_PROPERTY,
            admICU.getICUAdmID());
    if (res.size() > 0) {
        data.setOther(res);
    }

    res = ModelFactory.getModelObject(TblAntibiotic.class, TblAntibiotic.ICU_ADM_ID_PROPERTY,
            admICU.getICUAdmID());
    if (res.size() > 0) {
        data.setAntibiotics(res);
    }

    res = ModelFactory.getModelObject(TblNeurology.class, TblNeurology.ICU_ADM_ID_PROPERTY,
            admICU.getICUAdmID());
    if (res.size() > 0) {
        data.setNeuro(res.subList(0, 1));
    }

    res = ModelFactory.getModelObject(TblResusPlan.class, TblResusPlan.ICU_ADM_ID_PROPERTY,
            admICU.getICUAdmID());
    if (res.size() > 0) {
        data.setResus(res.subList(0, 1));
    }

    res = ModelFactory.getModelObject(TblNicotine.class, TblNicotine.ICU_ADM_ID_PROPERTY, admICU.getICUAdmID());
    if (res.size() > 0) {

        data.setNic(res.subList(res.size() - 1, res.size()));
    }

    res = ModelFactory.getModelObject(QryHospAdm.class, QryHospAdm.I_CUADM_ID_PROPERTY, admICU.getICUAdmID());
    if (res.size() > 0) {

        data.setDestination((QryHospAdm) res.get(0));
    }

    res = ModelFactory.getModelObject(TblRefCarePlan.class, TblRefCarePlan.END_DATE_PROPERTY, null);
    if (res.size() > 0) {
        data.setNursingPlanRef(res);
    }

    for (TblRefCarePlan plan : data.getNursingPlanRef()) {
        res = ModelFactory.getModelWithExpression(TblCarePlan.class, ExpressionFactory
                .matchExp(TblCarePlan.I_CUADM_ID_PROPERTY, admICU.getICUAdmID())
                .andExp(ExpressionFactory.matchExp(TblCarePlan.ARCHIVE_PROPERTY, 0))
                .andExp(ExpressionFactory.matchExp(TblCarePlan.CARE_PLAN_ID_PROPERTY, plan.getCarePlanId())));
        if (res.size() > 0) {
            nursingPlans.put(plan.getCarePlanDesc(), res);
        }
    }

    data.setNursingPlans((HashMap) nursingPlans);

    try {

        res = ModelFactory.getModelWithExpression(VwSiss.class,
                ExpressionFactory.matchExp(VwSiss.I_CUADM_ID_PROPERTY, admICU.getICUAdmID())
                        .andExp(ExpressionFactory.matchExp(VwSiss.SISS_END_DATE_PROPERTY, null)));
        //System.out.println("Siss "+res.size());
        if (res.size() > 0) {
            data.setProcs(res);
        }
    } catch (CayenneRuntimeException ex) {
        //ex.printStackTrace(System.out);
        data.setProcs(new ArrayList<VwSiss>());
    }

    StringBuilder diag = new StringBuilder();
    if (null != apache3.getAdmID()) {
        if (apache3.getA3SubCodeDesc() != null) {
            diag.append(apache3.getA3SubCodeDesc());
        } else if (apache3.getA3DiagDesc() != null) {
            diag.append(apache3.getA3DiagDesc());
        } else {
            diag.append("No APACHE III");
        }
    } else {
        diag.append("No APACHE Diag Found");
    }
    //diag.append("1902: PostOperative - Musculoskeletal/Skin - Orthopedic surgery - Orthopedic surgery, other");

    String delayed = "Unknown";
    if (txICU.getWardExitDate() != null && admICU.getExpectDischarge() != null) {
        delayed = "No";
        if (org.joda.time.Hours.hoursBetween(new org.joda.time.DateTime(admICU.getExpectDischarge()),
                new org.joda.time.DateTime(txICU.getWardExitDate())).getHours() > 6) {
            delayed = "Yes";
        }
    }
    String early = "unknown";
    if (admICU.getEarlyDischarge() != null) {
        if (admICU.getEarlyDischarge().intValue() == 1) {
            early = "Yes";
        } else if (admICU.getEarlyDischarge().intValue() == 2) {
            early = "No";
        }
    }
    if (txICU.getWardExitDate() != null) {
        los = org.joda.time.Hours.hoursBetween(new org.joda.time.DateTime(txICU.getWardAdmDate()),
                new org.joda.time.DateTime(txICU.getWardExitDate())).getHours();
    } else {
        los = org.joda.time.Hours.hoursBetween(new org.joda.time.DateTime(txICU.getWardAdmDate()),
                new org.joda.time.DateTime(Calendar.getInstance().getTime())).getHours();
    }

    fileName.append(demo.getPatientId()).append("_").append(admHosp.getVisitNumber()).append("_")
            .append(new SimpleDateFormat("yyyyMMddHHmm")
                    .format(txICU.getWardExitDate() == null ? Calendar.getInstance().getTime()
                            : txICU.getWardExitDate()))
            .append("_ICU DISCHARGE SUMMARY.pdf");

    if (data.getDestination() != null) {
        if (data.getDestination().getDispositionDesc() == null
                || data.getDestination().getDispositionDesc().equals((""))) {
            res = ModelFactory.getModelObject(TblWard.class, TblWard.WARD_ID_PROPERTY, admHosp.getWardId());
            if (res.size() > 0) {
                ward = (TblWard) res.get(0);
                data.setCurrentLocation(data.getDestination().getAPDOutcomeDesc() + " " + ward.getWardCode());
            } else {
                data.setCurrentLocation(data.getDestination().getAPDOutcomeDesc());
            }
        } else {
            data.setCurrentLocation(data.getDestination().getAPDOutcomeDesc() + " - "
                    + (data.getDestination().getDestinationDesc() == null
                            ? data.getDestination().getDispositionDesc()
                            : data.getDestination().getDestinationDesc()));
        }
    }

    data.setActiveProblems(admICU.getActiveProblems() == null ? " - " : admICU.getActiveProblems());
    data.setFinalDiagnosis(admICU.getFinalDiagnosis() == null ? " - " : admICU.getFinalDiagnosis());
    //System.out.println("Transfer "+admICU.getPmiid());
    data.setAdmDate(txICU.getWardAdmDate() == null ? "N/A"
            : new SimpleDateFormat("dd/MM/yyyy HH:mm").format(txICU.getWardAdmDate()));
    data.setAdmID(admHosp.getAdmid() == null ? "N/A" : admHosp.getAdmid());
    data.setAdmNumber(String.valueOf(ModelFactory
            .getModelObject(TblAdmissionICU.class, TblAdmissionICU.ADM_ID_PROPERTY, admHosp.getAdmid())
            .size()));
    data.setAge(String.valueOf(age));
    data.setApacheIII(diag.toString());
    data.setBirthDate(demo.getBirthDate() == null ? "N/A"
            : new SimpleDateFormat("dd/MM/yyyy").format(demo.getBirthDate()));
    data.setConsultant(doc == null ? "" : (doc.getSurname() == null ? "" : doc.getSurname()));
    data.setDelayed(delayed);
    data.setDisSumm(admICU.getICUDisSumm() == null ? "N/A" : admICU.getICUDisSumm());
    data.setEarlyDischarge(early);
    data.setExpectDischarge(admICU.getExpectDischarge() == null ? "N/A"
            : new SimpleDateFormat("dd/MM/yyyy HH:mm").format(admICU.getExpectDischarge()));
    data.setLOSDays(String.valueOf(los / 24));
    data.setLOSHours(String.valueOf(los));
    data.setNotForCPR(
            admICU.getNotForCPR() == null ? "N/A" : admICU.getNotForCPR().intValue() == 1 ? "Yes" : "No");
    data.setNotForReadmit(admICU.getNotForReadmit() == null ? "N/A"
            : admICU.getNotForReadmit().intValue() == 1 ? "Yes" : "No");
    data.setPMIID(demo.getPMIid() == null ? "N/A" : demo.getPMIid());
    data.setPastHx(admICU.getPastHx() == null ? "N/A" : admICU.getPastHx());
    data.setPatientAddress(
            new String().concat(demo.getPatientAddress1() == null ? "" : demo.getPatientAddress1()).concat(" ")
                    .concat(demo.getPatientSuburb() == null ? "" : demo.getPatientSuburb()));
    data.setPatientFamilyName(demo.getPatientFamilyName() == null ? "N/A" : demo.getPatientFamilyName());
    data.setPatientGivenName(demo.getPatientGivenName() == null ? " N/A" : demo.getPatientGivenName());
    data.setPatientId(demo.getPatientId() == null ? "N/A" : demo.getPatientId());
    data.setPatientMiddleName(demo.getPatientMiddleName() == null ? "" : demo.getPatientMiddleName());
    data.setPayClass(pc == null ? "" : (pc.getPayClassCode() == null ? "" : pc.getPayClassCode()));
    data.setPendingInvestigations(
            admICU.getPendingInvestigations() == null ? " - " : admICU.getPendingInvestigations());
    data.setPresentingHx(admICU.getPresentingHx() == null ? "N/A" : admICU.getPresentingHx());
    data.setSexDesc(sex == null ? "N/A" : sex.getSexDesc());
    data.setStrFileName(fileName.toString());
    data.setUnitCode(unit.getUnitCode() == null ? "UNK" : unit.getUnitCode());
    data.setUpdateBy(userId);
    data.setUpdateDate(new SimpleDateFormat("dd MMM yyyy HH:mm").format(Calendar.getInstance().getTime()));
    data.setVisitNumber(admHosp.getVisitNumber() == null ? "N/A" : admHosp.getVisitNumber());
    data.setWardAdmDate(txICU.getWardAdmDate() == null ? "N/A"
            : new SimpleDateFormat("dd MMM yyyy HH:mm").format(txICU.getWardAdmDate()));
    data.setWardExitDate(txICU.getWardExitDate() == null ? "N/A"
            : new SimpleDateFormat("dd MMM yyyy HH:mm").format(txICU.getWardExitDate()));
    data.setWardTferDate(txICU.getWardTferDate() == null ? "N/A"
            : new SimpleDateFormat("dd MMM yyyy HH:mm").format(txICU.getWardTferDate()));

    return fileName.toString();
}

From source file:au.org.intersect.dms.bookinggw.impl.DateUtils.java

License:Open Source License

/**
 * Returns given date with zero time/*w  w  w . jav  a2  s . c  o m*/
 * 
 * @param date date to truncate time
 * @return
 */
public static Date getFromDate(Date date) {
    DateTime dateTime = new DateTime(date);
    DateTime fromDate = dateTime.withTime(0, 0, 0, 0);
    return fromDate.toDate();
}

From source file:au.org.intersect.dms.bookinggw.impl.DateUtils.java

License:Open Source License

/**
 * Return given date with time set to 23:59:59
 * //  w w  w  .  ja  va 2 s. c o m
 * @param date date to round time
 * @return
 */
public static Date getToDate(Date date) {
    DateTime dateTime = new DateTime(date);
    DateTime toDate = dateTime.withTime(DAY_END_HOUR, DAY_END_MINUTES, DAY_END_SECONDS, 0);
    return toDate.toDate();
}

From source file:au.org.intersect.dms.instrument.harvester.CellRMtbParser.java

License:Open Source License

private String convertPropertyValue(String name, Object value, Map<String, Object> row) {
    if (types.containsKey(name)) {
        if ("date".equals(types.get(name))) {
            MutableDateTime date = new MutableDateTime(value);
            Object timeValue = row.get("Document Creation Time");
            LOGGER.trace("Converting date. Day: {}, time: {}", value, timeValue);
            DateTime time = new DateTime(timeValue);
            date.setTime(time);//  w  ww  .  jav a2s.  c o m
            LOGGER.trace("Date converted to: {}", date);
            return convertDate2UTC(date.toDateTime());
        }
    }

    return value.toString();
}

From source file:azkaban.app.JobManager.java

License:Apache License

private List<JobExecution> loadJobExecutions(String jobName, File jobDir) throws IOException {
    List<JobExecution> execs = new ArrayList<JobExecution>();
    File[] files = jobDir.listFiles();
    if (files != null) {
        for (File execDir : files) {
            // Sometimes there are os or other maintenance files that should be skipped.
            if (!execDir.isDirectory() || execDir.getName().startsWith(".")) {
                continue;
            }/*  w  ww.  j  a v a2 s.  co  m*/
            File runProps = new File(execDir, "run.properties");
            DateTime start = null;
            DateTime end = null;
            boolean succeeded = false;
            DateTime dirDate = null;
            try {
                dirDate = JOB_EXEC_DATE_FORMAT.parseDateTime(execDir.getName());
            } catch (Exception e) {
                logger.info("Ignoring unknown directory found in logs:" + execDir.getAbsolutePath(), e);
                continue;
            }
            if (runProps.canRead()) {
                Props props = new Props(null, runProps.getAbsolutePath());
                start = new DateTime(props.getLong("start"));
                end = new DateTime(props.getLong("end"));
                succeeded = props.getBoolean("succeeded");
            }
            String logFile = jobName + File.separator + execDir.getName() + File.separator + jobName + "."
                    + execDir.getName() + ".log";
            execs.add(
                    new JobExecution(jobName, start == null ? dirDate : start, end, succeeded, false, logFile));
        }
    }
    return execs;
}

From source file:azkaban.migration.scheduler.Schedule.java

License:Apache License

public String toString() {
    return projectName + "." + flowName + " (" + projectId + ")" + " to be run at (starting) "
            + new DateTime(firstSchedTime).toDateTimeISO() + " with recurring period of "
            + (period == null ? "non-recurring" : createPeriodString(period));
}

From source file:azkaban.migration.scheduler.Schedule.java

License:Apache License

public boolean updateTime() {
    if (new DateTime(nextExecTime).isAfterNow()) {
        return true;
    }/*ww w.  j a v a2s .  c  o m*/

    if (period != null) {
        DateTime nextTime = getNextRuntime(nextExecTime, timezone, period);

        this.nextExecTime = nextTime.getMillis();
        return true;
    }

    return false;
}

From source file:azkaban.serialization.Verifier.java

License:Apache License

public static DateTime getOptionalDateTime(Map<String, Object> descriptor, String key) {
    Object obj = descriptor.get(key);

    if (obj == null) {
        return null;
    }/*from  w  ww .  j  ava2 s .  co  m*/

    return new DateTime(obj.toString());
}

From source file:azkaban.sla.SLAManager.java

License:Apache License

private void sendSlaAlertEmail(SLA s, ExecutableFlow exflow) {
    String message = null;/* ww  w . j a va2  s . c  om*/
    ExecutableNode exnode;
    switch (s.getRule()) {
    case FINISH:
        if (s.getJobName().equals("")) {
            message = "Flow " + exflow.getFlowId() + " failed to finish with set SLA." + String.format("%n");
            message += "Flow started at " + new DateTime(exflow.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Flow status at " + s.getCheckTime().toDateTimeISO() + " is " + exflow.getStatus();
        } else {
            exnode = exflow.getExecutableNode(s.getJobName());
            message = "Job " + s.getJobName() + " of flow " + exflow.getFlowId()
                    + " failed to finish with set SLA." + String.format("%n");
            message += "Job started at " + new DateTime(exnode.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Job status at " + s.getCheckTime().toDateTimeISO() + " is " + exnode.getStatus();
        }
        break;
    case SUCCESS:
        if (s.getJobName().equals("")) {
            message = "Flow " + exflow.getFlowId() + " didn't finish successfully with set SLA. "
                    + String.format("%n");
            message += "Flow started at " + new DateTime(exflow.getStartTime()).toDateTimeISO()
                    + String.format("  %n");
            message += "Flow status at " + s.getCheckTime().toDateTimeISO() + " is " + exflow.getStatus();
        } else {
            exnode = exflow.getExecutableNode(s.getJobName());
            message = "Job " + s.getJobName() + " of flow " + exflow.getFlowId()
                    + " didn't finish successfully with set SLA." + String.format("%n");
            message += "Job started at " + new DateTime(exnode.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Job status at " + s.getCheckTime().toDateTimeISO() + " is " + exnode.getStatus();
        }
        break;
    default:
        logger.error("Unknown SLA rules!");
        message = "Unknown SLA was not met!";
        break;
    }
    mailer.sendSlaEmail(s, message);
}

From source file:azkaban.sla.SLAManager.java

License:Apache License

private void sendSlaSuccessEmail(SLA s, ExecutableFlow exflow) {
    String message = null;//  ww  w  .  j  av  a 2  s  .co  m
    ExecutableNode exnode;
    switch (s.getRule()) {
    case FINISH:
        if (s.getJobName().equals("")) {
            message = "Flow " + exflow.getFlowId() + " finished within the set SLA." + String.format("%n");
            message += "Flow started at " + new DateTime(exflow.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Flow status at " + s.getCheckTime().toDateTimeISO() + " is " + exflow.getStatus();
        } else {
            exnode = exflow.getExecutableNode(s.getJobName());
            message = "Job " + s.getJobName() + " of flow " + exflow.getFlowId()
                    + " finished within the set SLA." + String.format("%n");
            message += "Job started at " + new DateTime(exnode.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Job status at " + s.getCheckTime().toDateTimeISO() + " is " + exnode.getStatus();
        }
        break;
    case SUCCESS:
        if (s.getJobName().equals("")) {
            message = "Flow " + exflow.getFlowId() + " successfully finished within the set SLA."
                    + String.format("%n");
            message += "Flow started at " + new DateTime(exflow.getStartTime()).toDateTimeISO()
                    + String.format("  %n");
            message += "Flow status at " + s.getCheckTime().toDateTimeISO() + " is " + exflow.getStatus();
        } else {
            exnode = exflow.getExecutableNode(s.getJobName());
            message = "Job " + s.getJobName() + " of flow " + exflow.getFlowId()
                    + " successfully finished within the set SLA." + String.format("%n");
            message += "Job started at " + new DateTime(exnode.getStartTime()).toDateTimeISO()
                    + String.format("%n");
            message += "Job status at " + s.getCheckTime().toDateTimeISO() + " is " + exnode.getStatus();
        }
        break;
    default:
        logger.error("Unknown SLA rules!");
        message = "Unknown SLA was not met!";
        break;
    }
    mailer.sendSlaEmail(s, message);
}