WideEcrfFileReader { @NotNull public static List<WideAvlTreatmentData> readAvlTreatments(@NotNull String pathToCsv) throws IOException { List<WideAvlTreatmentData> wideTreatments = Lists.newArrayList(); char delimiter; if (new BufferedReader(new InputStreamReader(new FileInputStream(pathToCsv))).readLine().startsWith("TRAWPTNR,")) { delimiter = COMMA_DELIMITER; } else if (new BufferedReader(new InputStreamReader(new FileInputStream(pathToCsv))).readLine().startsWith("TRAWPTNR;")) { delimiter = SEMI_COMMA_DELIMITER; } else { delimiter = ' '; } for (CSVRecord line : readCsvSkipHeader(pathToCsv, delimiter)) { if (line.size() == AVL_TREATMENT_DATA_COUNT) { wideTreatments = treatmentData(wideTreatments, line, delimiter); } else { LOGGER.warn("Could not properly parse record in WIDE treatment csv: {}", line); } } return wideTreatments; } private  WideEcrfFileReader(); @NotNull static List<WideFiveDays> readFiveDays(@NotNull String pathToCsv); @NotNull static List<WidePreAvlTreatmentData> readPreAvlTreatments(@NotNull String pathToCsv); @NotNull static List<WideBiopsyData> readBiopsies(@NotNull String pathToCsv); @NotNull static List<WideAvlTreatmentData> readAvlTreatments(@NotNull String pathToCsv); @NotNull static List<WideResponseData> readResponses(@NotNull String pathToCsv);  }
@Test public void canReadWideAvlTreatments() throws IOException { List<WideAvlTreatmentData> treatments = WideEcrfFileReader.readAvlTreatments(WIDE_TEST_DIR + File.separator + "wide_avl_treatments.csv"); assertEquals(4, treatments.size()); assertEquals("WIDE01018888", treatments.get(0).widePatientId()); assertEquals("L01BA04", treatments.get(0).drugCode()); assertEquals("pemetrexed", treatments.get(0).drug()); assertEquals(LocalDate.parse("2018-03-03"), treatments.get(0).startDate()); assertEquals(LocalDate.parse("2018-07-20"), treatments.get(0).endDate()); assertEquals("WIDE01019999", treatments.get(1).widePatientId()); assertEquals("L01XE03", treatments.get(1).drugCode()); assertEquals("erlotinib", treatments.get(1).drug()); assertEquals(LocalDate.parse("2018-10-06"), treatments.get(1).startDate()); assertNull(treatments.get(1).endDate()); assertEquals("WIDE01019999", treatments.get(2).widePatientId()); assertEquals("L01XE03", treatments.get(2).drugCode()); assertEquals("erlotinib", treatments.get(2).drug()); assertEquals(LocalDate.parse("2018-08-18"), treatments.get(2).startDate()); assertNull(treatments.get(2).endDate()); }
@Test public void canReadWideAvlTreatmentsSemi() throws IOException { List<WideAvlTreatmentData> treatments = WideEcrfFileReader.readAvlTreatments(WIDE_TEST_DIR + File.separator + "wide_avl_treatments_semi.csv"); assertEquals(4, treatments.size()); assertEquals("WIDE01018888", treatments.get(0).widePatientId()); assertEquals("L01BA04", treatments.get(0).drugCode()); assertEquals("pemetrexed", treatments.get(0).drug()); assertEquals(LocalDate.parse("2018-03-03"), treatments.get(0).startDate()); assertEquals(LocalDate.parse("2018-07-20"), treatments.get(0).endDate()); assertEquals("WIDE01019999", treatments.get(1).widePatientId()); assertEquals("L01XE03", treatments.get(1).drugCode()); assertEquals("erlotinib", treatments.get(1).drug()); assertEquals(LocalDate.parse("2018-10-06"), treatments.get(1).startDate()); assertNull(treatments.get(1).endDate()); assertEquals("WIDE01019999", treatments.get(2).widePatientId()); assertEquals("L01XE03", treatments.get(2).drugCode()); assertEquals("erlotinib", treatments.get(2).drug()); assertEquals(LocalDate.parse("2018-09-18"), treatments.get(2).startDate()); assertNull(treatments.get(2).endDate()); }