BiopsyReader { @NotNull List<BiopsyData> read(@NotNull EcrfPatient patient, @NotNull CuratedTumorLocation curatedTumorLocation) { List<BiopsyData> biopsies = Lists.newArrayList(); for (EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_BIOPSY)) { for (EcrfForm form : studyEvent.nonEmptyFormsPerOID(FORM_BIOPS)) { String biopsyTaken = null; String biopsyEvaluable = null; for (EcrfItemGroup biopsyGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_BIOPSY)) { biopsyTaken = biopsyGroup.readItemString(FIELD_BIOPSY_TAKEN); biopsyEvaluable = biopsyGroup.readItemString(FIELD_BIOPSY_EVALUABLE); } for (EcrfItemGroup biopsiesGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_BIOPSIES)) { LocalDate date = biopsiesGroup.readItemDate(FIELD_BIOPSY_DATE); String site = biopsiesGroup.readItemString(FIELD_SITE); String siteOther = biopsiesGroup.readItemString(FIELD_SITE_OTHER); String finalSite = (site == null || site.trim().toLowerCase().startsWith("other")) ? siteOther : site; String location = biopsiesGroup.readItemString(FIELD_LOCATION); CuratedBiopsyType curatedBiopsyType = biopsySiteCurator.search(curatedTumorLocation.primaryTumorLocation(), curatedTumorLocation.subType(), finalSite, location); BiopsyData biopsy = BiopsyData.of(date, biopsyTaken, biopsyEvaluable, curatedBiopsyType, finalSite, location, form.status()); if (!isDuplicate(biopsies, biopsy) && !isEmpty(biopsy)) { biopsies.add(biopsy); } } } } return biopsies; } BiopsyReader(@NotNull final BiopsySiteCurator biopsySiteCurator);   }
@Test public void canFilterOutEmptyAndDuplicateForms() { BiopsyReader biopsyReader = new BiopsyReader(TestCuratorFactory.biopsySiteCurator()); List<BiopsyData> biopsies = biopsyReader.read(buildTestPatient(), ImmutableCuratedTumorLocation.of(null, null, null)); assertEquals(1, biopsies.size()); assertNotNull(biopsies.get(0).date()); assertNotNull(biopsies.get(0).biopsyTaken()); }
@Test public void canReadCpctPatientBiopsies() { BiopsyReader biopsyReader = new BiopsyReader(TestCuratorFactory.biopsySiteCurator()); List<BiopsyData> biopsies = biopsyReader.read(buildTestPatient(), ImmutableCuratedTumorLocation.of(null, null, null)); assertEquals(1, biopsies.size()); assertEquals("body", biopsies.get(0).site()); assertEquals("liver", biopsies.get(0).location()); assertEquals(LocalDate.parse("2017-11-10", DATE_FORMATTER), biopsies.get(0).date()); }