BiopsyTreatmentResponseReader { @NotNull static List<BiopsyTreatmentResponseData> read(@NotNull EcrfPatient patient) { List<BiopsyTreatmentResponseData> treatmentResponses = Lists.newArrayList(); for (EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_TREATMENT)) { for (EcrfForm form : studyEvent.nonEmptyFormsPerOID(FORM_TUMOR_MEASUREMENT)) { LocalDate assessmentDate = null; for (EcrfItemGroup itemGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_MEASUREMENT)) { LocalDate date = itemGroup.readItemDate(FIELD_ASSESSMENT_DATE); if (date != null) { assessmentDate = date; break; } } LocalDate responseDate = null; String measurementDone = null; String boneOnlyDisease = null; String response = null; for (EcrfItemGroup itemGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_TUMOR_MEASUREMENT)) { LocalDate responseDateValue = itemGroup.readItemDate(FIELD_RESPONSE_DATE); if (responseDateValue != null) { responseDate = responseDateValue; } String measurementDoneValue = itemGroup.readItemString(FIELD_MEASUREMENT_DONE); if (measurementDoneValue != null) { measurementDone = measurementDoneValue; } String boneOnlyDiseaseValue = itemGroup.readItemString(FIELD_BONE_ONLY_DISEASE); if (boneOnlyDiseaseValue != null) { boneOnlyDisease = boneOnlyDiseaseValue; } String responseValue = itemGroup.readItemString(FIELD_RESPONSE); if (responseValue != null) { response = responseValue; } } BiopsyTreatmentResponseData responseData = BiopsyTreatmentResponseData.of(null, assessmentDate, responseDate, response, measurementDone, boneOnlyDisease, form.status()); if (!isEmpty(responseData)) { treatmentResponses.add(responseData); } } } return treatmentResponses; } private  BiopsyTreatmentResponseReader();   }
@Test public void canFilterOutEmptyForms() { List<BiopsyTreatmentResponseData> responses = BiopsyTreatmentResponseReader.read(buildTestPatient()); assertEquals(1, responses.size()); assertNotNull(responses.get(0).measurementDone()); assertNotNull(responses.get(0).response()); }