/** * Compares asOfDate to [startDate, endDate], inclusive of both endpoints. * @param asOfDate date to compare if membership is active or inactive * @return boolean true/false if membership is active/inactive */ public boolean isActive(Date asOfDate) { Date date = asOfDate == null ? new Date() : asOfDate; return !this.getVoided() && OpenmrsUtil.compare(startDate, date) <= 0 && OpenmrsUtil.compareWithNullAsLatest(date, endDate) <= 0; }
/** * Returns true if this {@link PatientState} is active as of the passed {@link Date} * * @param onDate - {@link Date} to check for {@link PatientState} enrollment * @return boolean - true if this {@link PatientState} is active as of the passed {@link Date} * @should return false if voided and date in range * @should return false if voided and date not in range * @should return true if not voided and date in range * @should return false if not voided and date earlier than startDate * @should return false if not voided and date later than endDate * @should return true if not voided and date in range with null startDate * @should return true if not voided and date in range with null endDate * @should return true if not voided and both startDate and endDate nulled * @should compare with current date if date null */ public boolean getActive(Date onDate) { if (onDate == null) { onDate = new Date(); } return !getVoided() && (OpenmrsUtil.compareWithNullAsEarliest(startDate, onDate) <= 0) && (OpenmrsUtil.compareWithNullAsLatest(endDate, onDate) > 0); }
int ret = this.getVoided().compareTo(o.getVoided()); if (ret == 0) { ret = -OpenmrsUtil.compareWithNullAsLatest(this.getEndDate(), o.getEndDate());
/** * @see java.lang.Comparable#compareTo(java.lang.Object) * Note: this comparator imposes orderings that are inconsistent with equals. */ @Override @SuppressWarnings("squid:S1210") public int compareTo(PersonAddress other) { int retValue = 0; if (other != null) { retValue = getVoided().compareTo(other.getVoided()); if (retValue == 0) { retValue = other.getPreferred().compareTo(getPreferred()); } if (retValue == 0 && getDateCreated() != null) { retValue = OpenmrsUtil.compareWithNullAsLatest(getDateCreated(), other.getDateCreated()); } if (retValue == 0) { retValue = OpenmrsUtil.compareWithNullAsGreatest(getPersonAddressId(), other.getPersonAddressId()); } // if we've gotten this far, just check all address values. If they are // equal, leave the objects at 0. If not, arbitrarily pick retValue=1 // and return that (they are not equal). if (retValue == 0 && !equalsContent(other)) { retValue = 1; } } return retValue; }
@Override public void validate(Object obj, Errors errors) { if (obj == null || !(obj instanceof Cohort)) { throw new IllegalArgumentException("The parameter obj should not be null and must be of type" + Cohort.class); } Cohort cohort = (Cohort) obj; if (!cohort.getVoided()) { Collection<CohortMembership> members = cohort.getMemberships(); if (!CollectionUtils.isEmpty(members)) { for (CohortMembership member : members) { Patient p = Context.getPatientService().getPatient(member.getPatientId()); int dateCompare = OpenmrsUtil.compareWithNullAsLatest(member.getStartDate(), member.getEndDate()); if (p != null && p.getVoided() && !member.getVoided()) { String message = "Patient " + p.getPatientId() + " is voided, cannot add voided members to a cohort"; errors.rejectValue("memberships", "Cohort.patientAndMemberShouldBeVoided", message); } if (dateCompare == 1) { String message = "Start date is null or end date is before start date"; errors.rejectValue("memberships", "Cohort.startDateShouldNotBeNullOrBeforeEndDate", message); } } } } } }
/** * Compares by startDate with null as earliest and endDate with null as latest. * * @see java.lang.Comparable#compareTo(java.lang.Object) * @should return positive if startDates equal and this endDate null * @should return negative if this startDate null * @should pass if two states have the same start date, end date and uuid * @should return positive or negative if two states have the same start date and end date but different uuids * Note: this comparator imposes orderings that are inconsistent with equals. */ @SuppressWarnings("squid:S1210") @Override public int compareTo(PatientState o) { int result = OpenmrsUtil.compareWithNullAsEarliest(getStartDate(), o.getStartDate()); if (result == 0) { result = OpenmrsUtil.compareWithNullAsLatest(getEndDate(), o.getEndDate()); } if (result == 0) { result = OpenmrsUtil.compareWithNullAsGreatest(getUuid(), o.getUuid()); } return result; } }
@Override public int compare(PersonAttribute pa1, PersonAttribute pa2) { int retValue; if ((retValue = OpenmrsUtil.compareWithNullAsGreatest(pa1.getAttributeType(), pa2.getAttributeType())) != 0) { return retValue; } if ((retValue = pa1.getVoided().compareTo(pa2.getVoided())) != 0) { return retValue; } if ((retValue = OpenmrsUtil.compareWithNullAsLatest(pa1.getDateCreated(), pa2.getDateCreated())) != 0) { return retValue; } if ((retValue = OpenmrsUtil.compareWithNullAsGreatest(pa1.getValue(), pa2.getValue())) != 0) { return retValue; } return OpenmrsUtil.compareWithNullAsGreatest(pa1.getPersonAttributeId(), pa2.getPersonAttributeId()); } }
&& OpenmrsUtil.compareWithNullAsLatest(personAddress.getStartDate(), personAddress.getEndDate()) > 0) { errors.rejectValue("endDate", "PersonAddress.error.endDateBeforeStartDate", new Object[] { "'" + addressString + "'" }, "The End Date for address '" + addressString + "' shouldn't be earlier than the Start Date");
retValue = OpenmrsUtil.compareWithNullAsLatest(pi1.getDateCreated(), pi2.getDateCreated());
&& OpenmrsUtil.compareWithNullAsLatest(patientProgram.getDateCompleted(), patientProgram.getDateEnrolled()) < 0) { errors.rejectValue("dateCompleted", "error.patientProgram.enrolledDateShouldBeBeforecompletionDate"); if (OpenmrsUtil.compareWithNullAsLatest(patientState.getEndDate(), patientState.getStartDate()) < 0) { errors.rejectValue("states", "PatientState.error.endDateCannotBeBeforeStartDate"); return;
ret = OpenmrsUtil.compareWithNullAsLatest(pn1.getDateCreated(), pn2.getDateCreated());
ValidationUtils.rejectIfEmpty(errors, "startDatetime", "Visit.error.startDate.required"); if (visit.getStartDatetime() != null && OpenmrsUtil.compareWithNullAsLatest(visit.getStartDatetime(), visit.getStopDatetime()) > 0) { errors.rejectValue("stopDatetime", "Visit.error.endDateBeforeStartDate");
@Override public int compare(PatientState o1, PatientState o2) { return OpenmrsUtil.compareWithNullAsLatest(o1.getStartDate(), o2.getStartDate()); } });
@Override public int compare(PatientState o1, PatientState o2) { int result = OpenmrsUtil.compareWithNullAsEarliest(o1.getStartDate(), o2.getStartDate()); if (result == 0) { result = OpenmrsUtil.compareWithNullAsLatest(o1.getEndDate(), o2.getEndDate()); } return result; }