PatientValidator { @NotNull @VisibleForTesting static List<ValidationFinding> validateTreatmentCuration(@NotNull String patientIdentifier, @NotNull String curationName, @NotNull List<? extends TreatmentData> treatments) { List<ValidationFinding> findings = Lists.newArrayList(); treatments.forEach(treatment -> treatment.drugs().forEach(drug -> { String drugName = drug.name(); if (drugName != null) { if (drug.curatedDrugs().isEmpty()) { findings.add(ValidationFinding.of(curationName, patientIdentifier, "Failed to curate ecrf drug. Curated list contained no matching entry, or match was ambiguous", treatment.formStatus(), drugName)); } else { List<String> curatedTreatments = drug.curatedDrugs().stream().map(CuratedDrug::name).collect(Collectors.toList()); List<String> matchedTerms = drug.curatedDrugs().stream().map(CuratedDrug::searchTerm).collect(Collectors.toList()); long lengthOfMatchedCharacters = matchedTerms.stream().mapToLong(String::length).sum(); long lengthOfSearchCharacters = drugName.chars().filter(Character::isLetterOrDigit).count(); if (lengthOfMatchedCharacters > 0 && (double) lengthOfMatchedCharacters / lengthOfSearchCharacters < 0.9) { findings.add(ValidationFinding.of(curationName, patientIdentifier, "Matched drugs are based on less than 90% of search term.", treatment.formStatus(), "'" + drugName + "' matched to '" + Strings.join(curatedTreatments, ',') + "' based on '" + Strings.join( matchedTerms, ',') + "'")); } } } })); return findings; }  @NotNull static List<ValidationFinding> validatePatient(@NotNull Patient patient);  }
@Test public void reportsMissingCuratedTreatment() { String curationName = "testTreatmentCuration"; List<ValidationFinding> findings = PatientValidator.validateTreatmentCuration(PATIENT_IDENTIFIER, curationName, Lists.newArrayList(BiopsyTreatmentData.of(null, "Yes", "Yes", Lists.newArrayList(DRUG_MISSING_CURATED_ENTRY), FormStatus.undefined()))); assertEquals(1, findings.size()); findings.stream().map(ValidationFinding::patientIdentifier).forEach(id -> assertEquals(PATIENT_IDENTIFIER, id)); List<String> findingsFields = findings.stream().map(ValidationFinding::level).collect(Collectors.toList()); assertEquals(findingsFields.get(0), curationName); }
@Test public void reportsPartiallyCuratedTreatment() { String curationName = "testTreatmentCuration"; List<ValidationFinding> findings = PatientValidator.validateTreatmentCuration(PATIENT_IDENTIFIER, curationName, Lists.newArrayList(BiopsyTreatmentData.of(null, "Yes", "Yes", Lists.newArrayList(DRUG_WITH_PARTIAL_CURATED_ENTRY), FormStatus.undefined()))); assertEquals(1, findings.size()); findings.stream().map(ValidationFinding::patientIdentifier).forEach(id -> assertEquals(PATIENT_IDENTIFIER, id)); List<String> findingsFields = findings.stream().map(ValidationFinding::level).collect(Collectors.toList()); assertEquals(findingsFields.get(0), curationName); }