Example usage for org.joda.time Days standardDaysIn

List of usage examples for org.joda.time Days standardDaysIn

Introduction

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

Prototype

public static Days standardDaysIn(ReadablePeriod period) 

Source Link

Document

Creates a new Days representing the number of complete standard length days in the specified period.

Usage

From source file:org.oscarehr.common.dao.PopulationReportDao.java

License:Open Source License

public int[] getUsages(int numYears) {

    int[] shelterUsages = new int[3];

    Map<Integer, Set<Stay>> clientIdToStayMap = new HashMap<Integer, Set<Stay>>();

    Calendar instant = Calendar.getInstance();
    Date end = instant.getTime();
    Date start = DateTimeFormatUtils.getPast(instant, numYears);

    for (Object o : getHibernateTemplate().find(HQL_GET_USAGES, start)) {
        Object[] tuple = (Object[]) o;

        Integer clientId = (Integer) tuple[0];
        Date admission = (Date) tuple[1];
        Date discharge = (Date) tuple[2];

        if (!clientIdToStayMap.containsKey(clientId)) {
            clientIdToStayMap.put(clientId, new HashSet<Stay>());
        }/*from   w  ww  .  j  a v  a  2 s  .com*/

        try {
            Stay stay = new Stay(admission, discharge, start, end);
            clientIdToStayMap.get(clientId).add(stay);
        } catch (IllegalArgumentException e) {
            logger.error("client id: " + clientId);
        }
    }

    for (Entry<Integer, Set<Stay>> entry : clientIdToStayMap.entrySet()) {
        MutablePeriod period = new MutablePeriod(PeriodType.days());

        for (Stay stay : entry.getValue()) {
            period.add(stay.getInterval());
        }

        int days = Days.standardDaysIn(period).getDays();

        if (days <= 10) {
            shelterUsages[LOW] += 1;
        } else if (11 <= days && days <= 179) {
            shelterUsages[MEDIUM] += 1;
        } else if (180 <= days) {
            shelterUsages[HIGH] += 1;
        }
    }

    return shelterUsages;
}