PatientValidator { @NotNull @VisibleForTesting static List<ValidationFinding> validateDeathDate(@NotNull String patientIdentifier, @NotNull BaselineData baselineData, @NotNull List<BiopsyTreatmentData> treatments) { List<ValidationFinding> findings = Lists.newArrayList(); LocalDate deathDate = baselineData.deathDate(); if (deathDate != null && !treatments.isEmpty()) { treatments.sort(comparing(BiopsyTreatmentData::endDate, nullsLast(naturalOrder()))); BiopsyTreatmentData lastTreatment = treatments.get(treatments.size() - 1); String treatmentGiven = lastTreatment.treatmentGiven(); if (treatmentGiven != null && treatmentGiven.equalsIgnoreCase("yes")) { LocalDate lastTreatmentEndDate = lastTreatment.endDate(); if (lastTreatmentEndDate == null || lastTreatmentEndDate.isAfter(deathDate)) { String details = "Death date (" + deathDate + ") before end of last treatment (" + lastTreatmentEndDate + ")"; findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Death date before end of last treatment", FormStatus.merge(baselineData.deathStatus(), lastTreatment.formStatus()), details)); } } } return findings; }  @NotNull static List<ValidationFinding> validatePatient(@NotNull Patient patient);  }
@Test public void doesNotReportDeathTimelineWhenNoTreatmentGiven() { List<ValidationFinding> findings = PatientValidator.validateDeathDate(PATIENT_IDENTIFIER, baselineBuilder().deathDate(MAR).build(), Lists.newArrayList(TREATMENT_JAN_FEB, TREATMENT_GIVEN_NULL)); assertEquals(0, findings.size()); }
@Test public void reportsDeathDateBeforeEndOfTreatment() { List<ValidationFinding> findings = PatientValidator.validateDeathDate(PATIENT_IDENTIFIER, baselineBuilder().deathDate(MAR).build(), Lists.newArrayList(TREATMENT_JAN_ONGOING, TREATMENT_JAN_FEB)); assertEquals(1, findings.size()); }