use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding 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);
}
use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding in project hmftools by hartwigmedical.
the class PatientValidator method validateDrugData.
@NotNull
@VisibleForTesting
static List<ValidationFinding> validateDrugData(@NotNull final String patientIdentifier, @NotNull final DrugData drugData, @NotNull final FormStatusState formStatus, final boolean formLocked) {
final LocalDate drugStart = drugData.startDate();
final List<ValidationFinding> findings = Lists.newArrayList();
if (drugStart == null) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FIELD_DRUG_START, "drug start date empty or in wrong format", formStatus, formLocked));
} else {
final LocalDate drugEnd = drugData.endDate();
if (drugEnd != null) {
if (drugStart.isAfter(drugEnd)) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FIELD_DRUG_START, FIELD_DRUG_END), "drug startDate is after drug endDate", formStatus, formLocked));
}
}
}
if (drugData.name() == null) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FIELD_DRUG, FIELD_DRUG_OTHER), "drug name empty", formStatus, formLocked));
}
return findings;
}
use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding in project hmftools by hartwigmedical.
the class PatientValidator method validateTreatmentResponse.
@NotNull
@VisibleForTesting
static List<ValidationFinding> validateTreatmentResponse(@NotNull final String patientIdentifier, @NotNull final BiopsyTreatmentResponseData treatmentResponse, boolean isFirstResponse) {
final List<ValidationFinding> findings = Lists.newArrayList();
final String measurementDone = treatmentResponse.measurementDone();
final String response = treatmentResponse.response();
final LocalDate date = treatmentResponse.date();
if (measurementDone == null) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FIELD_MEASUREMENT_DONE, "measurement done field empty", treatmentResponse.formStatus(), treatmentResponse.formLocked()));
} else if (measurementDone.trim().toLowerCase().equals("yes")) {
if (date == null) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FIELD_ASSESSMENT_DATE, FIELD_RESPONSE_DATE), "response date and assessment date empty or in wrong format", treatmentResponse.formStatus(), treatmentResponse.formLocked()));
}
if (response == null && !isFirstResponse) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FIELD_RESPONSE, "measurement done is yes, but response is empty (non-first response)", treatmentResponse.formStatus(), treatmentResponse.formLocked()));
}
} else if (measurementDone.trim().equalsIgnoreCase("no")) {
if (!treatmentResponse.isNotDoneResponse()) {
if (date != null) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FIELD_MEASUREMENT_DONE, "measurement done is no, but assessment date or response date is filled in", treatmentResponse.formStatus(), treatmentResponse.formLocked(), "effective response date: " + date));
}
if (response != null) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FIELD_MEASUREMENT_DONE, "measurement done is no, but response filled in", treatmentResponse.formStatus(), treatmentResponse.formLocked(), "response: " + response));
}
}
} else {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, FIELD_MEASUREMENT_DONE, "measurement done is not yes/no", treatmentResponse.formStatus(), treatmentResponse.formLocked(), "measurement done: " + measurementDone));
}
if (response != null && date == null && !treatmentResponse.isNotDoneResponse()) {
findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, fields(FIELD_ASSESSMENT_DATE, FIELD_RESPONSE_DATE), "response filled in, but no assessment date and response date found", treatmentResponse.formStatus(), treatmentResponse.formLocked(), "response: " + response));
}
return findings;
}
use of com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding 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.common.ecrf.datamodel.ValidationFinding 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;
}
Aggregations