use of com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData 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;
}
use of com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData in project hmftools by hartwigmedical.
the class PatientValidator method validateDeathDate.
@NotNull
@VisibleForTesting
static List<ValidationFinding> validateDeathDate(@NotNull final String patientIdentifier, @NotNull final BaselineData baselineData, @NotNull final List<BiopsyTreatmentData> treatments) {
final List<ValidationFinding> findings = Lists.newArrayList();
final LocalDate deathDate = baselineData.deathDate();
if (deathDate != null && !treatments.isEmpty()) {
treatments.sort(comparing(BiopsyTreatmentData::endDate, nullsLast(naturalOrder())));
final BiopsyTreatmentData lastTreatment = treatments.get(treatments.size() - 1);
final LocalDate lastTreatmentEndDate = lastTreatment.endDate();
final LocalDate firstTreatmentStart = treatments.get(0).startDate();
if (lastTreatmentEndDate == null || lastTreatmentEndDate.isAfter(deathDate)) {
String details = "death date (" + deathDate + ") before end of last treatment (" + lastTreatmentEndDate + ")" + " and start treatment is (" + firstTreatmentStart + ")";
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FIELD_DEATH_DATE, FORM_TREATMENT), "death date before end of last treatment", FormStatusState.best(baselineData.deathStatus(), lastTreatment.formStatus()), baselineData.deathLocked() || lastTreatment.formLocked(), details));
}
}
return findings;
}
use of com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData in project hmftools by hartwigmedical.
the class TreatmentResponseMatcher method matchTreatmentResponsesToTreatments.
@NotNull
public static MatchResult<BiopsyTreatmentResponseData> matchTreatmentResponsesToTreatments(@NotNull String patientId, @NotNull List<BiopsyTreatmentData> treatments, @NotNull List<BiopsyTreatmentResponseData> responses) {
final List<BiopsyTreatmentResponseData> matchedResponses = Lists.newArrayList();
final List<ValidationFinding> findings = Lists.newArrayList();
Collections.sort(responses);
List<BiopsyTreatmentData> sortedTreatments = sortAndFilter(treatments);
if (hasOverlappingTreatments(sortedTreatments)) {
if (!responses.isEmpty()) {
findings.add(responseMatchFinding(patientId, "treatments are overlapping. Cannot match any response.", "treatments: " + sortedTreatments));
}
return new MatchResult<>(responses, findings);
}
Iterator<BiopsyTreatmentData> treatmentIterator = sortedTreatments.iterator();
BiopsyTreatmentData currentTreatment = treatmentIterator.hasNext() ? treatmentIterator.next() : null;
LocalDate firstTreatmentStart = currentTreatment != null ? currentTreatment.startDate() : null;
BiopsyTreatmentData nextTreatment = treatmentIterator.hasNext() ? treatmentIterator.next() : null;
boolean hasNewBaselineResponseFound = false;
for (BiopsyTreatmentResponseData response : responses) {
LocalDate responseDate = response.date();
if (responseMatchable(responseDate, firstTreatmentStart)) {
LocalDate nextTreatmentStart = nextTreatment != null ? nextTreatment.startDate() : null;
while (nextTreatmentStart != null && responseDate.isAfter(nextTreatmentStart)) {
currentTreatment = nextTreatment;
nextTreatment = treatmentIterator.hasNext() ? treatmentIterator.next() : null;
nextTreatmentStart = nextTreatment != null ? nextTreatment.startDate() : null;
hasNewBaselineResponseFound = false;
}
if (hasNewBaselineResponseFound) {
matchedResponses.add(response);
findings.add(responseMatchFinding(patientId, "response after new baseline and before next treatment", "response: " + response));
} else {
String actualResponse = response.response();
if (actualResponse != null && actualResponse.equalsIgnoreCase("ne")) {
matchedResponses.add(response);
hasNewBaselineResponseFound = true;
} else {
matchedResponses.add(ImmutableBiopsyTreatmentResponseData.builder().from(response).treatmentId(currentTreatment.id()).build());
}
}
} else {
matchedResponses.add(response);
}
}
return new MatchResult<>(matchedResponses, findings);
}
use of com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData in project hmftools by hartwigmedical.
the class BiopsyTreatmentReader method read.
@NotNull
List<BiopsyTreatmentData> read(@NotNull final EcrfPatient patient) throws IOException {
final List<BiopsyTreatmentData> treatments = Lists.newArrayList();
for (final EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_AFTERBIOPT)) {
for (final EcrfForm treatmentForm : studyEvent.nonEmptyFormsPerOID(FORM_TREATMENT, false)) {
final String treatmentGiven = readTreatmentGiven(treatmentForm);
final String radiotherapyGiven = readRadiotherapyGiven(treatmentForm);
final List<DrugData> drugs = readDrugs(treatmentForm);
treatments.add(ImmutableBiopsyTreatmentData.of(treatmentGiven, radiotherapyGiven, drugs, treatmentForm.status(), treatmentForm.locked()));
}
}
return treatments;
}
Aggregations