Object o
whp-adherence/src/main/java/org/motechproject/whp/adherence/domain/TreatmentWeek.java
if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TreatmentWeek that = (TreatmentWeek) o;

        return !(startDate() != null ? !startDate().equals(that.startDate()) : that.startDate() != null);
boolean equals(Object o)
whp-adherence/src/test/java/org/motechproject/whp/adherence/domain/TreatmentWeekTest.java
LocalDate monday = new LocalDate(2012, 4, 30);
        LocalDate sunday = new LocalDate(2012, 5, 6);
        LocalDate nextMonday = new LocalDate(2012, 5, 7);
        assertEquals(new TreatmentWeek(monday), new TreatmentWeek(sunday));
        assertNotSame(new TreatmentWeek(null), new TreatmentWeek(sunday));
        assertNotSame(new TreatmentWeek(monday), new TreatmentWeek(null));
        assertNotSame(new TreatmentWeek(monday), new TreatmentWeek(nextMonday));
void shouldCompareTwoWeeksToSeeIfTheyAreTheSameWeek()
whp-adherence/src/test/java/org/motechproject/whp/adherence/service/WHPAdherenceServiceTest.java
WeeklyAdherence adherence = adherenceIsRecordedForTheFirstTime(); //capturing adherence for last week -> this is the first ever adherence captured week
        mockCurrentDate(today.plusDays(3)); //moving to the sunday -> capturing adherence for this week -> subsequent to first ever adherence captured week
    @Test
    public void shouldResetDoseStartDateWhenNoAdherenceIsPostedForSameWeek() {
        adherenceIsRecordedForTheFirstTime();
        mockCurrentDate(today.plusDays(1));
        adherenceService.recordAdherence(PATIENT_ID, new WeeklyAdherence(), user, source);
        assertNull(allPatients.findByPatientId(PATIENT_ID).getCurrentProvidedTreatment().getTreatment().getDoseStartDate());
void shouldNotStartPatientOnTreatmentWhenRecordingAdherenceForAnyWeekSubsequentToFirstEverAdherenceCapturedWeek()
whp-adherence/src/main/java/org/motechproject/whp/adherence/domain/WeeklyAdherence.java
for (Adherence adherence : adherenceList) {
            if (PillStatus.Taken == adherence.getPillStatus())
                return true;
boolean isAnyDoseTaken()
Patient patient  WeeklyAdherence adherence
whp-adherence/src/main/java/org/motechproject/whp/patient/domain/TreatmentStartCriteria.java
return (isNewPatient(patient)
                && isAnyDoseTaken(adherence))
                && isFirstEverDoseBeingTaken(patient, adherence);
    private static boolean isFirstEverDoseBeingTaken(Patient patient, WeeklyAdherence adherence) {
        return isNotOnTreatment(patient.getCurrentProvidedTreatment()) ||isAdherenceBeingCapturedForEarlierDate(patient, adherence);
    private static boolean isAdherenceBeingCapturedForEarlierDate(Patient patient, WeeklyAdherence adherence) {
        return patient.getCurrentProvidedTreatment().getTreatment().getDoseStartDate().isAfter(adherence.firstDoseTakenOn());
    private static boolean isNewPatient(Patient patient) {
        return patient.getPatientType().equals(PatientType.New);
boolean shouldStartTreatment(Patient patient, WeeklyAdherence adherence)