Search in sources :

Example 1 with BiopsyData

use of com.hartwig.hmftools.patientdb.data.BiopsyData in project hmftools by hartwigmedical.

the class PatientReader method read.

@NotNull
public Patient read(@NotNull final EcrfPatient ecrfPatient, @NotNull final List<SampleData> sequencedSamples) throws IOException {
    LOGGER.info("Reading patient " + ecrfPatient.patientId() + " with samples: " + sequencedSamples);
    final BaselineData baselineData = cpctPatientReader.read(ecrfPatient);
    final PreTreatmentData preTreatmentData = preTreatmentReader.read(ecrfPatient);
    final List<BiopsyData> clinicalBiopsies = BiopsyReader.read(ecrfPatient);
    final List<BiopsyTreatmentData> treatments = biopsyTreatmentReader.read(ecrfPatient);
    final List<BiopsyTreatmentResponseData> treatmentResponses = BiopsyTreatmentResponseReader.read(ecrfPatient);
    final List<TumorMarkerData> tumorMarkers = TumorMarkerReader.read(ecrfPatient);
    final MatchResult<BiopsyData> matchedBiopsies = BiopsyMatcher.matchBiopsiesToTumorSamples(ecrfPatient.patientId(), sequencedSamples, clinicalBiopsies);
    final MatchResult<BiopsyTreatmentData> matchedTreatments = TreatmentMatcher.matchTreatmentsToBiopsies(ecrfPatient.patientId(), clinicalBiopsies, treatments);
    final MatchResult<BiopsyTreatmentResponseData> matchedResponses = TreatmentResponseMatcher.matchTreatmentResponsesToTreatments(ecrfPatient.patientId(), treatments, treatmentResponses);
    final List<ValidationFinding> findings = Lists.newArrayList();
    findings.addAll(matchedBiopsies.findings());
    findings.addAll(matchedTreatments.findings());
    findings.addAll(matchedResponses.findings());
    return new Patient(ecrfPatient.patientId(), baselineData, preTreatmentData, sequencedSamples, matchedBiopsies.values(), matchedTreatments.values(), matchedResponses.values(), tumorMarkers, findings);
}
Also used : Patient(com.hartwig.hmftools.patientdb.data.Patient) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) BaselineData(com.hartwig.hmftools.patientdb.data.BaselineData) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) BiopsyTreatmentResponseData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentResponseData) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) TumorMarkerData(com.hartwig.hmftools.patientdb.data.TumorMarkerData) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) PreTreatmentData(com.hartwig.hmftools.patientdb.data.PreTreatmentData) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with BiopsyData

use of com.hartwig.hmftools.patientdb.data.BiopsyData in project hmftools by hartwigmedical.

the class PatientValidator method validateInformedConsentDate.

@NotNull
static List<ValidationFinding> validateInformedConsentDate(@NotNull final String patientIdentifier, @NotNull final BaselineData baselineData, @NotNull final List<BiopsyData> biopsies) {
    final List<ValidationFinding> findings = Lists.newArrayList();
    final LocalDate informedConsentDate = baselineData.informedConsentDate();
    if (informedConsentDate != null && !biopsies.isEmpty()) {
        final List<BiopsyData> biopsiesPriorToInformedConsent = biopsies.stream().filter(biopsy -> {
            final LocalDate biopsyDate = biopsy.date();
            return biopsyDate != null && biopsyDate.isBefore(informedConsentDate);
        }).collect(Collectors.toList());
        if (biopsiesPriorToInformedConsent.size() > 0) {
            final String detailsMessage = "informedConsentDate: " + informedConsentDate + ". biopsies: " + biopsiesPriorToInformedConsent.stream().map(BiopsyData::toString).collect(Collectors.toList());
            FormStatusState best = baselineData.informedConsentStatus();
            boolean locked = baselineData.informedConsentLocked();
            for (BiopsyData biopsy : biopsies) {
                best = FormStatusState.best(best, biopsy.formStatus());
                locked = locked || biopsy.formLocked();
            }
            findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FIELD_INFORMED_CONSENT_DATE, FIELD_BIOPSY_DATE), "at least 1 biopsy taken before informed consent date", best, locked, detailsMessage));
        }
    }
    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) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) FormStatusState(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusState) LocalDate(java.time.LocalDate) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BiopsyData

use of com.hartwig.hmftools.patientdb.data.BiopsyData in project hmftools by hartwigmedical.

the class PatientReaderTest method canReadCpctPatientBiopsies.

@Test
public void canReadCpctPatientBiopsies() {
    final CpctEcrfModel model = loadTestEcrf();
    assertEquals(1, model.patientCount());
    final EcrfPatient cpctPatient = model.patients().iterator().next();
    final List<BiopsyData> biopsies = BiopsyReader.read(cpctPatient);
    assertEquals(1, biopsies.size());
    assertEquals("Soft tissue", biopsies.get(0).site());
    assertEquals("near right scapula", biopsies.get(0).location());
    assertEquals(LocalDate.parse("2012-02-17", DATE_FORMATTER), biopsies.get(0).date());
}
Also used : EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel) Test(org.junit.Test)

Example 4 with BiopsyData

use of com.hartwig.hmftools.patientdb.data.BiopsyData 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 5 with BiopsyData

use of com.hartwig.hmftools.patientdb.data.BiopsyData in project hmftools by hartwigmedical.

the class BiopsyReader method read.

@NotNull
static List<BiopsyData> read(@NotNull final EcrfPatient patient) {
    final List<BiopsyData> biopsies = Lists.newArrayList();
    for (final EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_BIOPSY)) {
        for (final EcrfForm form : studyEvent.nonEmptyFormsPerOID(FORM_BIOPS, false)) {
            String biopsyTaken = null;
            String biopsyEvaluable = null;
            // KODU: This works as there is generally a 1:N relation between BIOPSY and BIOPSIES item groups.
            for (final EcrfItemGroup biopsyGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_BIOPSY, false)) {
                biopsyTaken = biopsyGroup.readItemString(FIELD_BIOPSY_TAKEN, 0, false);
                biopsyEvaluable = biopsyGroup.readItemString(FIELD_BIOPSY_EVALUABLE, 0, false);
            }
            for (final EcrfItemGroup biopsiesGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_BIOPSIES, false)) {
                final LocalDate date = biopsiesGroup.readItemDate(FIELD_BIOPSY_DATE, 0, DATE_FORMATTER, false);
                final String location = biopsiesGroup.readItemString(FIELD_LOCATION, 0, false);
                final String site = biopsiesGroup.readItemString(FIELD_SITE, 0, false);
                final String siteOther = biopsiesGroup.readItemString(FIELD_SITE_OTHER, 0, false);
                final String finalSite = (site == null || site.trim().toLowerCase().startsWith("other")) ? siteOther : site;
                BiopsyData biopsy = ImmutableBiopsyData.of(date, biopsyTaken, biopsyEvaluable, finalSite, location, form.status(), form.locked());
                // form needed to be created for every treatment response.
                if (!isDuplicate(biopsies, biopsy) && !isEmpty(biopsy)) {
                    biopsies.add(biopsy);
                }
            }
        }
    }
    return biopsies;
}
Also used : EcrfStudyEvent(com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent) EcrfForm(com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm) EcrfItemGroup(com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup) BiopsyData(com.hartwig.hmftools.patientdb.data.BiopsyData) ImmutableBiopsyData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyData) LocalDate(java.time.LocalDate) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

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