use of com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FORM_TREATMENT 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;
}
use of com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FORM_TREATMENT in project hmftools by hartwigmedical.
the class PatientValidator method validateTreatments.
@NotNull
@VisibleForTesting
static List<ValidationFinding> validateTreatments(@NotNull final String patientIdentifier, @NotNull final List<BiopsyTreatmentData> treatments) {
final List<ValidationFinding> findings = Lists.newArrayList();
treatments.forEach(treatment -> findings.addAll(validateTreatmentData(patientIdentifier, treatment)));
Collections.sort(treatments);
if (treatments.size() > 1) {
for (int index = 1; index < treatments.size(); index++) {
final BiopsyTreatmentData currentTreatment = treatments.get(index);
final LocalDate startDate = currentTreatment.startDate();
final LocalDate previousTreatmentEnd = treatments.get(index - 1).endDate();
if (startDate != null && (previousTreatmentEnd == null || startDate.isBefore(previousTreatmentEnd))) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FORM_TREATMENT, "subsequent treatment starts before the end of previous treatment", currentTreatment.formStatus(), currentTreatment.formLocked()));
}
}
final List<BiopsyTreatmentData> nonFinishedTreatments = treatments.stream().filter(treatment -> treatment.endDate() == null).collect(Collectors.toList());
if (nonFinishedTreatments.size() > 1) {
nonFinishedTreatments.forEach(treatment -> findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FORM_TREATMENT, "end of at least 1 non-final treatment is missing", treatment.formStatus(), treatment.formLocked())));
}
}
return findings;
}
Aggregations