Search in sources :

Example 6 with ValidationFinding

use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding in project hmftools by hartwigmedical.

the class TreatmentMatcher method matchTreatmentsToBiopsies.

@NotNull
public static MatchResult<BiopsyTreatmentData> matchTreatmentsToBiopsies(@NotNull final String patientId, @NotNull final List<BiopsyData> biopsies, @NotNull final List<BiopsyTreatmentData> treatments) {
    final List<BiopsyTreatmentData> matchedTreatments = Lists.newArrayList();
    final List<ValidationFinding> findings = Lists.newArrayList();
    List<BiopsyData> remainingBiopsies = biopsies;
    for (final BiopsyTreatmentData treatment : treatments) {
        final String treatmentGiven = treatment.treatmentGiven();
        if (treatmentGiven == null || treatmentGiven.toLowerCase().equals("no")) {
            matchedTreatments.add(treatment);
            continue;
        }
        final Map<Boolean, List<BiopsyData>> partitions = remainingBiopsies.stream().collect(Collectors.partitioningBy(clinicalBiopsy -> isPossibleMatch(clinicalBiopsy.date(), treatment.startDate())));
        final List<BiopsyData> possibleMatches = partitions.get(true);
        if (possibleMatches.size() == 0) {
            findings.add(treatmentMatchFinding(patientId, "no biopsy match for treatment", treatment.toString()));
            matchedTreatments.add(treatment);
        } else if (possibleMatches.size() > 1) {
            findings.add(treatmentMatchFinding(patientId, "multiple biopsy matches for treatment", treatment + ". biopsies:  " + possibleMatches.stream().map(BiopsyData::toString).collect(Collectors.toList())));
            matchedTreatments.add(treatment);
        } else if (possibleMatches.get(0).date() == null) {
            findings.add(treatmentMatchFinding(patientId, "treatment matched biopsy with null date.", treatment.toString()));
            matchedTreatments.add(treatment);
        } else {
            final BiopsyData clinicalBiopsy = possibleMatches.get(0);
            matchedTreatments.add(ImmutableBiopsyTreatmentData.builder().from(treatment).biopsyId(clinicalBiopsy.id()).build());
            remainingBiopsies = partitions.get(false);
        }
    }
    return new MatchResult<>(matchedTreatments, findings);
}
Also used : ImmutableBiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyTreatmentData) Config(com.hartwig.hmftools.patientdb.Config) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) Collectors(java.util.stream.Collectors) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) FormStatusState(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Lists(com.google.common.collect.Lists) FORM_TREATMENT(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FORM_TREATMENT) Duration(java.time.Duration) LocalDate(java.time.LocalDate) Map(java.util.Map) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) NotNull(org.jetbrains.annotations.NotNull) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) List(java.util.List) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) ImmutableBiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyTreatmentData) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with ValidationFinding

use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding in project hmftools by hartwigmedical.

the class PatientValidator method validateBiopsies.

@NotNull
@VisibleForTesting
static List<ValidationFinding> validateBiopsies(@NotNull final String patientIdentifier, @NotNull final List<BiopsyData> biopsies, @NotNull final List<BiopsyTreatmentData> treatments) {
    final List<ValidationFinding> findings = Lists.newArrayList();
    biopsies.forEach(biopsy -> findings.addAll(validateBiopsyData(patientIdentifier, biopsy)));
    if (biopsies.isEmpty()) {
        findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FORM_BIOPS, "no biopsies found", FormStatusState.UNKNOWN, false));
    }
    if (biopsies.size() > 0 && treatments.size() > 0) {
        biopsies.sort(comparing(BiopsyData::date, nullsLast(naturalOrder())));
        Collections.sort(treatments);
        final LocalDate firstBiopsyDate = biopsies.get(0).date();
        final LocalDate firstTreatmentStart = treatments.get(0).startDate();
        if (firstBiopsyDate != null && firstTreatmentStart != null && firstTreatmentStart.isBefore(firstBiopsyDate)) {
            findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FORM_TREATMENT, FORM_BIOPS), "first treatment start is before first biopsy date", FormStatusState.best(biopsies.get(0).formStatus(), treatments.get(0).formStatus()), biopsies.get(0).formLocked() || treatments.get(0).formLocked()));
        }
    }
    return findings;
}
Also used : ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) LocalDate(java.time.LocalDate) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ValidationFinding

use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding 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;
}
Also used : Comparator.naturalOrder(java.util.Comparator.naturalOrder) FIELD_DEATH_DATE(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_DEATH_DATE) FORM_TUMOR_MEASUREMENT(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentResponseReader.FORM_TUMOR_MEASUREMENT) FORM_BIOPS(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FORM_BIOPS) FIELD_BIOPSY_DATE(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FIELD_BIOPSY_DATE) TreatmentData(com.hartwig.hmftools.patientdb.data.TreatmentData) Comparator.nullsLast(java.util.Comparator.nullsLast) Duration(java.time.Duration) FIELD_PRE_DRUG(com.hartwig.hmftools.patientdb.readers.PreTreatmentReader.FIELD_PRE_DRUG) FIELD_PRETREATMENT_GIVEN(com.hartwig.hmftools.patientdb.readers.PreTreatmentReader.FIELD_PRETREATMENT_GIVEN) FIELD_PRIMARY_TUMOR_LOCATION_OTHER(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_PRIMARY_TUMOR_LOCATION_OTHER) Patient(com.hartwig.hmftools.patientdb.data.Patient) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) Collectors(java.util.stream.Collectors) FIELD_RESPONSE_DATE(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentResponseReader.FIELD_RESPONSE_DATE) FIELD_DRUG(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FIELD_DRUG) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) List(java.util.List) FIELD_PRIMARY_TUMOR_LOCATION(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_PRIMARY_TUMOR_LOCATION) FORM_TREATMENT(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FORM_TREATMENT) LocalDate(java.time.LocalDate) FIELD_RESPONSE(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentResponseReader.FIELD_RESPONSE) Strings(org.apache.logging.log4j.util.Strings) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) NotNull(org.jetbrains.annotations.NotNull) BiopsyTreatmentResponseData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentResponseData) FIELD_DRUG_START(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FIELD_DRUG_START) FIELD_ASSESSMENT_DATE(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentResponseReader.FIELD_ASSESSMENT_DATE) FIELD_BIRTH_YEAR3(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_BIRTH_YEAR3) FIELD_BIRTH_YEAR2(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_BIRTH_YEAR2) Config(com.hartwig.hmftools.patientdb.Config) FIELD_TREATMENT_GIVEN(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FIELD_TREATMENT_GIVEN) FIELD_PRERADIOTHERAPY_GIVEN(com.hartwig.hmftools.patientdb.readers.PreTreatmentReader.FIELD_PRERADIOTHERAPY_GIVEN) FIELD_MEASUREMENT_DONE(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentResponseReader.FIELD_MEASUREMENT_DONE) PreTreatmentData(com.hartwig.hmftools.patientdb.data.PreTreatmentData) FIELD_SITE_OTHER(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FIELD_SITE_OTHER) FIELD_HOSPITAL2(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_HOSPITAL2) FIELD_INFORMED_CONSENT_DATE(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_INFORMED_CONSENT_DATE) FIELD_HOSPITAL1(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_HOSPITAL1) Lists(com.google.common.collect.Lists) Comparator.comparing(java.util.Comparator.comparing) BaselineData(com.hartwig.hmftools.patientdb.data.BaselineData) FIELD_BIRTH_YEAR1(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_BIRTH_YEAR1) FIELD_SITE(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FIELD_SITE) DrugData(com.hartwig.hmftools.patientdb.data.DrugData) FIELD_LOCATION(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FIELD_LOCATION) FIELD_REGISTRATION_DATE2(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_REGISTRATION_DATE2) FIELD_REGISTRATION_DATE1(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_REGISTRATION_DATE1) FIELD_RADIOTHERAPY_GIVEN(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FIELD_RADIOTHERAPY_GIVEN) FIELD_SEX(com.hartwig.hmftools.patientdb.readers.CpctPatientReader.FIELD_SEX) FIELD_DRUG_END(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FIELD_DRUG_END) FormStatusState(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState) CuratedTreatment(com.hartwig.hmftools.patientdb.data.CuratedTreatment) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) FIELD_DRUG_OTHER(com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FIELD_DRUG_OTHER) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) LocalDate(java.time.LocalDate) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ValidationFinding

use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding 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;
}
Also used : ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) LocalDate(java.time.LocalDate) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with ValidationFinding

use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding in project hmftools by hartwigmedical.

the class BiopsyMatcher method matchBiopsiesToTumorSamples.

@NotNull
public static MatchResult<BiopsyData> matchBiopsiesToTumorSamples(@NotNull final String patientId, @NotNull final List<SampleData> sequencedBiopsies, @NotNull final List<BiopsyData> clinicalBiopsies) {
    final List<BiopsyData> matchedBiopsies = Lists.newArrayList();
    final List<ValidationFinding> findings = Lists.newArrayList();
    if (clinicalBiopsies.size() < sequencedBiopsies.size()) {
        findings.add(biopsyMatchFinding(patientId, "less ecrf biopsies than biopsies sequenced.", "ecrf biopsies: " + clinicalBiopsies.size() + "; sequenced: " + sequencedBiopsies.size()));
    }
    List<BiopsyData> remainingBiopsies = clinicalBiopsies;
    for (final SampleData sequencedBiopsy : sequencedBiopsies) {
        final Map<Boolean, List<BiopsyData>> partitions = remainingBiopsies.stream().collect(Collectors.partitioningBy(clinicalBiopsy -> isPossibleMatch(sequencedBiopsy, clinicalBiopsy)));
        final List<BiopsyData> possibleMatches = partitions.get(true);
        if (possibleMatches.size() == 1 && possibleMatches.get(0).date() != null) {
            final BiopsyData clinicalBiopsy = possibleMatches.get(0);
            matchedBiopsies.add(ImmutableBiopsyData.builder().from(clinicalBiopsy).sampleId(sequencedBiopsy.sampleId()).build());
            if (hasMismatchOnSamplingDate(sequencedBiopsy, clinicalBiopsy)) {
                findings.add(biopsyMatchFinding(patientId, "sampling date does not equal biopsy date in matched biopsy", "sampling date: " + sequencedBiopsy.samplingDate() + "; ecrf biopsy date: " + clinicalBiopsy.date()));
            }
            remainingBiopsies = partitions.get(false);
        } else if (possibleMatches.size() == 0 || (possibleMatches.size() == 1 && possibleMatches.get(0).date() == null)) {
            findings.add(biopsyMatchFinding(patientId, "could not match any clinical biopsy with sequenced sample.", "sample: " + sampleDataToString(sequencedBiopsy) + "; ecrf biopsies: " + clinicalBiopsies.stream().map(BiopsyData::date).collect(Collectors.toList()) + ". match criteria: " + getMatchDateCriteria(sequencedBiopsy)));
            // MIVO: abort finding new matches if we can't match one sequenced biopsy
            return new MatchResult<>(clinicalBiopsies, findings);
        } else if (possibleMatches.size() > 1) {
            findings.add(biopsyMatchFinding(patientId, "more than 1 possible clinical biopsy match for sequenced sample.", "sample: " + sampleDataToString(sequencedBiopsy) + "; ecrf biopsies: " + clinicalBiopsies.stream().map(BiopsyData::date).collect(Collectors.toList()) + ". match criteria: " + getMatchDateCriteria(sequencedBiopsy)));
            // MIVO: abort finding new matches if we can't match one sequenced biopsy
            return new MatchResult<>(clinicalBiopsies, findings);
        }
    }
    matchedBiopsies.addAll(remainingBiopsies);
    return new MatchResult<>(matchedBiopsies, findings);
}
Also used : Config(com.hartwig.hmftools.patientdb.Config) FORM_BIOPS(com.hartwig.hmftools.patientdb.readers.BiopsyReader.FORM_BIOPS) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) Collectors(java.util.stream.Collectors) ImmutableBiopsyData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyData) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) FormStatusState(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState) List(java.util.List) Lists(com.google.common.collect.Lists) Duration(java.time.Duration) LocalDate(java.time.LocalDate) Map(java.util.Map) SampleData(com.hartwig.hmftools.patientdb.data.SampleData) NotNull(org.jetbrains.annotations.NotNull) SampleData(com.hartwig.hmftools.patientdb.data.SampleData) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) List(java.util.List) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) ImmutableBiopsyData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ValidationFinding (com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding)13 NotNull (org.jetbrains.annotations.NotNull)11 LocalDate (java.time.LocalDate)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 BiopsyTreatmentData (com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData)7 BiopsyData (com.hartwig.hmftools.patientdb.data.BiopsyData)6 BiopsyTreatmentResponseData (com.hartwig.hmftools.patientdb.data.BiopsyTreatmentResponseData)6 List (java.util.List)6 Lists (com.google.common.collect.Lists)5 FormStatusState (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState)5 Config (com.hartwig.hmftools.patientdb.Config)5 Patient (com.hartwig.hmftools.patientdb.data.Patient)5 Duration (java.time.Duration)5 Collectors (java.util.stream.Collectors)5 BaselineData (com.hartwig.hmftools.patientdb.data.BaselineData)4 PreTreatmentData (com.hartwig.hmftools.patientdb.data.PreTreatmentData)4 FORM_BIOPS (com.hartwig.hmftools.patientdb.readers.BiopsyReader.FORM_BIOPS)4 FORM_TREATMENT (com.hartwig.hmftools.patientdb.readers.BiopsyTreatmentReader.FORM_TREATMENT)4 CuratedTreatment (com.hartwig.hmftools.patientdb.data.CuratedTreatment)3 DrugData (com.hartwig.hmftools.patientdb.data.DrugData)3