use of com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentResponseReader.FORM_TUMOR_MEASUREMENT in project hmftools by hartwigmedical.
the class PatientValidator method validateTreatmentResponses.
@NotNull
@VisibleForTesting
static List<ValidationFinding> validateTreatmentResponses(@NotNull final String patientIdentifier, @NotNull final List<BiopsyTreatmentData> treatments, @NotNull final List<BiopsyTreatmentResponseData> responses) {
final List<ValidationFinding> findings = Lists.newArrayList();
for (int i = 0; i < responses.size(); i++) {
findings.addAll(validateTreatmentResponse(patientIdentifier, responses.get(i), i == 0));
}
Collections.sort(treatments);
Collections.sort(responses);
if (treatments.isEmpty() && !responses.isEmpty()) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FORM_TREATMENT, "treatment response filled in, but treatment data missing", FormStatusState.UNKNOWN, false));
}
if (!treatments.isEmpty() && !responses.isEmpty()) {
final LocalDate firstResponseDate = responses.get(0).date();
final LocalDate firstTreatmentStart = treatments.get(0).startDate();
if (firstResponseDate != null && firstTreatmentStart != null && firstResponseDate.isAfter(firstTreatmentStart)) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FORM_TREATMENT, FORM_TUMOR_MEASUREMENT), "first (baseline) measurement date is after first treatment start", FormStatusState.best(treatments.get(0).formStatus(), responses.get(0).formStatus()), treatments.get(0).formLocked() || responses.get(0).formLocked(), "first treatment response: " + firstResponseDate + "; first treatment start: " + firstTreatmentStart));
}
}
final List<BiopsyTreatmentData> treatmentsMissingResponse = treatments.stream().filter(treatment -> shouldHaveResponse(treatment) && !hasResponse(treatment.id(), responses)).collect(Collectors.toList());
if (treatmentsMissingResponse.size() > 0) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FORM_TUMOR_MEASUREMENT, "no treatment response for at least 1 treatment", FormStatusState.UNKNOWN, false, "treatments " + treatmentsMissingResponse.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;
}
Aggregations