Example usage for org.joda.time MutablePeriod setYears

List of usage examples for org.joda.time MutablePeriod setYears

Introduction

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

Prototype

public void setYears(int years) 

Source Link

Document

Sets the number of years of the period.

Usage

From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java

License:LGPL

/**
 * Helper method to negate a copy of period
 * /*  w w w  .  j a v a2  s  . c  o m*/
 * @param mPeriod
 * @return a negated copy of period
 */
static Period negatePeriod(Period period) {
    MutablePeriod mPeriod = period.toMutablePeriod();
    mPeriod.setYears(-mPeriod.getYears());
    mPeriod.setMonths(-mPeriod.getMonths());
    mPeriod.setWeeks(-mPeriod.getWeeks());
    mPeriod.setDays(-mPeriod.getDays());
    mPeriod.setHours(-mPeriod.getHours());
    mPeriod.setMinutes(-mPeriod.getMinutes());
    mPeriod.setSeconds(-mPeriod.getSeconds());
    mPeriod.setMillis(-mPeriod.getMillis());
    return mPeriod.toPeriod();
}

From source file:org.phenotips.data.internal.controller.MedicationController.java

License:Open Source License

@Override
public PatientData<Medication> load(Patient patient) {
    try {/*from   w  w w .ja  v  a2  s  . co  m*/
        XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument());
        List<BaseObject> data = doc.getXObjects(Medication.CLASS_REFERENCE);
        if (data == null || data.isEmpty()) {
            this.logger.debug("No medication data for patient [{}]", patient.getDocument());
            return null;
        }
        List<Medication> result = new LinkedList<>();
        for (BaseObject medication : data) {
            if (medication == null) {
                continue;
            }
            MutablePeriod p = new MutablePeriod();
            p.setYears(medication.getIntValue(DURATION_YEARS));
            p.setMonths(medication.getIntValue(DURATION_MONTHS));
            result.add(new Medication(medication.getStringValue(Medication.NAME),
                    medication.getStringValue(Medication.GENERIC_NAME),
                    medication.getStringValue(Medication.DOSE), medication.getStringValue(Medication.FREQUENCY),
                    p.toPeriod(), medication.getStringValue(Medication.EFFECT),
                    medication.getLargeStringValue(Medication.NOTES)));
        }
        if (!result.isEmpty()) {
            return new IndexedPatientData<Medication>(DATA_NAME, result);
        }
    } catch (Exception ex) {
        this.logger.error("Could not find requested document or some unforeseen"
                + " error has occurred during controller loading ", ex.getMessage());
    }
    return null;
}