PatientValidator { @NotNull @VisibleForTesting static List<ValidationFinding> validateTreatmentResponses(@NotNull String patientIdentifier, @NotNull List<BiopsyTreatmentData> treatments, @NotNull List<BiopsyTreatmentResponseData> responses) { List<ValidationFinding> findings = Lists.newArrayList(); for (int i = 0; i < responses.size(); i++) { findings.addAll(validateTreatmentResponse(patientIdentifier, responses.get(i), i == 0)); } List<BiopsyTreatmentData> matchedTreatmentsMissingResponse = treatments.stream() .filter(treatment -> shouldHaveResponse(treatment) && !hasResponse(treatment.id(), responses) && treatment.biopsyId() != null) .collect(Collectors.toList()); if (matchedTreatmentsMissingResponse.size() > 0) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "No treatment response for at least 1 matched treatment", FormStatus.undefined(), "treatments " + matchedTreatmentsMissingResponse.stream() .map(BiopsyTreatmentData::toString) .collect(Collectors.toList()) + " should have response since they lasted more than " + Config.IMMEDIATE_TREATMENT_END_THRESHOLD + " days and started more than " + Config.START_DATE_RESPONSE_THRESHOLD + " days ago")); } return findings; }  @NotNull static List<ValidationFinding> validatePatient(@NotNull Patient patient);  }
@Test public void reportsMissingResponseForTreatmentMoreThan16Weeks() { List<ValidationFinding> findings = PatientValidator.validateTreatmentResponses(PATIENT_IDENTIFIER, Lists.newArrayList(TREATMENT_JAN_ONGOING), Lists.newArrayList()); assertEquals(1, findings.size()); }
@Test public void doesNotReportMissingResponseForTreatmentEndedImmediately() { List<ValidationFinding> findings = PatientValidator.validateTreatmentResponses(PATIENT_IDENTIFIER, Lists.newArrayList(TREATMENT_JAN_JAN), Lists.newArrayList()); assertEquals(0, findings.size()); }