PatientValidator { @NotNull @VisibleForTesting static List<ValidationFinding> validateInformedConsentDate(@NotNull String patientIdentifier, @NotNull BaselineData baselineData, @NotNull List<BiopsyData> biopsies) { List<ValidationFinding> findings = Lists.newArrayList(); LocalDate informedConsentDate = baselineData.informedConsentDate(); if (informedConsentDate != null && !biopsies.isEmpty()) { List<BiopsyData> biopsiesPriorToInformedConsent = biopsies.stream().filter(biopsy -> { LocalDate biopsyDate = biopsy.date(); return biopsyDate != null && biopsyDate.isBefore(informedConsentDate); }).collect(Collectors.toList()); if (biopsiesPriorToInformedConsent.size() > 0) { String detailsMessage = "InformedConsentDate: " + informedConsentDate + ". biopsies: " + biopsiesPriorToInformedConsent.stream() .map(BiopsyData::toString) .collect(Collectors.toList()); FormStatus mergedFormStatus = baselineData.informedConsentStatus(); for (BiopsyData biopsy : biopsies) { mergedFormStatus = FormStatus.merge(mergedFormStatus, biopsy.formStatus()); } findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "At least 1 biopsy taken before informed consent date", mergedFormStatus, detailsMessage)); } } return findings; }  @NotNull static List<ValidationFinding> validatePatient(@NotNull Patient patient);  }
@Test public void reportsBiopsyBeforeInformedConsent() { List<ValidationFinding> findings = PatientValidator.validateInformedConsentDate(PATIENT_IDENTIFIER, baselineBuilder().informedConsentDate(MAR).build(), Lists.newArrayList(BIOPSY_FEB_WITH_SITE)); assertEquals(1, findings.size()); }