PatientValidator { @NotNull @VisibleForTesting static List<ValidationFinding> validateTreatmentResponse(@NotNull String patientIdentifier, @NotNull BiopsyTreatmentResponseData treatmentResponse, boolean isFirstResponse) { List<ValidationFinding> findings = Lists.newArrayList(); String measurementDone = treatmentResponse.measurementDone(); String response = treatmentResponse.response(); LocalDate date = treatmentResponse.date(); if (measurementDone == null) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Measurement done field empty", treatmentResponse.formStatus())); } else if (measurementDone.equalsIgnoreCase("yes")) { if (date == null) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Response date and/or assessment date empty or in wrong format", treatmentResponse.formStatus())); } if (response == null && !isFirstResponse) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Measurement done is yes, but response is empty (non-first response)", treatmentResponse.formStatus())); } } else if (measurementDone.equalsIgnoreCase("no")) { if (!treatmentResponse.isNotDoneResponse()) { if (date != null) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Measurement done is no, but assessment date or response date is filled in", treatmentResponse.formStatus(), "Effective response date: " + date)); } if (response != null) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Measurement done is no, but response filled in", treatmentResponse.formStatus(), "Response: " + response)); } } } else { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Measurement done is not yes/no", treatmentResponse.formStatus(), "Measurement done: " + measurementDone)); } if (response != null && date == null && !treatmentResponse.isNotDoneResponse()) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Response filled in, but no assessment date and response date found", treatmentResponse.formStatus(), "Response: " + response)); } return findings; }  @NotNull static List<ValidationFinding> validatePatient(@NotNull Patient patient);  }
@Test public void acceptMissingDataForFirstResponse() { List<ValidationFinding> findings = PatientValidator.validateTreatmentResponse(PATIENT_IDENTIFIER, RESPONSE_MISSING_DATA, true); assertEquals(1, findings.size()); findings.stream().map(ValidationFinding::patientIdentifier).forEach(id -> assertEquals(PATIENT_IDENTIFIER, id)); }