HospitalModelFactory { @NotNull @VisibleForTesting static Map<String, HospitalPersons> readFromHospitalPersons(@NotNull String hospitalPersonsTsv, int expectedFieldCount) throws IOException { Map<String, HospitalPersons> hospitalPersonsMap = Maps.newHashMap(); List<String> lines = FileReader.build().readLines(new File(hospitalPersonsTsv).toPath()); for (String line : lines.subList(1, lines.size())) { String[] parts = line.split(FIELD_SEPARATOR); if (parts.length == expectedFieldCount) { String requesterName = parts.length > 2 ? parts[HOSPITAL_PERSONS_REQUESTER_NAME_COLUMN] : null; String requesterEmail = parts.length > 2 ? parts[HOSPITAL_PERSONS_REQUESTER_EMAIL_COLUMN] : null; HospitalPersons hospitalPersons = ImmutableHospitalPersons.builder() .hospitalPI(parts[HOSPITAL_PERSONS_PI_COLUMN]) .requesterName(requesterName) .requesterEmail(requesterEmail) .build(); hospitalPersonsMap.put(parts[HOSPITAL_PERSONS_ID_COLUMN], hospitalPersons); } else { LOGGER.warn("Could not properly parse line in hospital persons tsv: '{}'", line); } } return hospitalPersonsMap; } private  HospitalModelFactory(); @NotNull static HospitalModel fromLimsDirectory(@NotNull String limsDirectory);  }
@Test public void canReadHospitalContactCPCT() throws IOException { Map<String, HospitalPersons> hospitalContactCPCT = HospitalModelFactory.readFromHospitalPersons(LIMS_DIRECTORY + File.separator + "hospital_cpct.tsv", 2); assertEquals(2, hospitalContactCPCT.size()); HospitalPersons cpct1 = hospitalContactCPCT.get("01"); assertEquals("Someone", cpct1.hospitalPI()); assertNull(cpct1.requesterName()); assertNull(cpct1.requesterEmail()); HospitalPersons cpct2 = hospitalContactCPCT.get("02"); assertEquals("Someone", cpct2.hospitalPI()); assertNull(cpct2.requesterName()); assertNull(cpct2.requesterEmail()); }
@Test public void canReadHospitalContactDRUP() throws IOException { Map<String, HospitalPersons> hospitalContactDRUP = HospitalModelFactory.readFromHospitalPersons(LIMS_DIRECTORY + File.separator + "hospital_drup.tsv", 2); assertEquals(2, hospitalContactDRUP.size()); HospitalPersons drup1 = hospitalContactDRUP.get("01"); assertEquals("Someone", drup1.hospitalPI()); assertNull(drup1.requesterName()); assertNull(drup1.requesterEmail()); HospitalPersons drup2 = hospitalContactDRUP.get("02"); assertEquals("Someone", drup2.hospitalPI()); assertNull(drup2.requesterName()); assertNull(drup2.requesterEmail()); }
@Test public void canReadHospitalContactWIDE() throws IOException { Map<String, HospitalPersons> hospitalContactWIDE = HospitalModelFactory.readFromHospitalPersons(LIMS_DIRECTORY + File.separator + "hospital_wide.tsv", 4); assertEquals(2, hospitalContactWIDE.size()); HospitalPersons wide1 = hospitalContactWIDE.get("01"); assertEquals("Someone", wide1.hospitalPI()); assertEquals("Someone1", wide1.requesterName()); assertEquals("my@email.com", wide1.requesterEmail()); HospitalPersons wide2 = hospitalContactWIDE.get("02"); assertEquals("Someone", wide2.hospitalPI()); assertEquals("Someone1", wide2.requesterName()); assertEquals("my@email.com", wide2.requesterEmail()); }