FormStatusReader { @NotNull public static FormStatusModel buildModelFromCsv(@NotNull final String pathToCsv) throws IOException { Map<FormStatusKey, FormStatus> formStatuses = Maps.newHashMap(); List<String> lines = FileReader.build().readLines(new File(pathToCsv).toPath()); lines.remove(0); for (String line : lines) { String[] parts = splitCsvLine(line, FIELD_SEPARATOR, FIELD_COUNT); if (parts.length == FIELD_COUNT) { FormStatusKey formKey = new ImmutableFormStatusKey(removeQuotes(parts[PATIENT_ID_COLUMN].replaceAll("-", "")), removeParentheses(removeQuotes(parts[FORM_NAME_COLUMN])), removeQuotes(parts[FORM_SEQ_NUM_COLUMN]), removeParentheses(removeQuotes(parts[STUDY_EVENT_NAME_COLUMN])), removeQuotes(parts[STUDY_EVENT_SEQ_NUM_COLUMN])); FormStatus formStatus = new ImmutableFormStatus(interpretState(removeQuotes(parts[DATA_STATUS_COLUMN])), interpretLocked(removeQuotes(parts[LOCKED_COLUMN]))); formStatuses.put(formKey, formStatus); } else if (parts.length > 0) { LOGGER.warn("Could not properly parse line in form status csv: {}", line); } } return new ImmutableFormStatusModel(formStatuses); } private  FormStatusReader(); @NotNull static FormStatusModel buildModelFromCsv(@NotNull final String pathToCsv);  }
@Test public void canLoadFromCsv() throws IOException { FormStatusModel formStatusModel = FormStatusReader.buildModelFromCsv(TEST_FILE); Map<FormStatusKey, FormStatus> formStatuses = formStatusModel.formStatuses(); assertEquals(3, formStatuses.size()); FormStatusKey key1 = new ImmutableFormStatusKey("CPCT02000001", "Anti Coagulants", "0", "Anti Coagulants", "0"); FormStatusKey key2 = new ImmutableFormStatusKey("CPCT02000002", "Death Page", "0", "Neoadjuvant treatment, recurrence and survival", "0"); FormStatusKey key3 = new ImmutableFormStatusKey("CPCT02000004", "Eligibility Screening", "0", "BASELINE", "0"); assertTrue(formStatuses.containsKey(key1)); assertTrue(formStatuses.containsKey(key2)); assertTrue(formStatuses.containsKey(key3)); assertTrue(formStatuses.get(key1).locked()); assertTrue(formStatuses.get(key2).locked()); assertFalse(formStatuses.get(key3).locked()); assertEquals(FormStatusState.SUBMITTED, formStatuses.get(key1).state()); assertEquals(FormStatusState.SUBMITTED_WITH_MISSING, formStatuses.get(key2).state()); assertEquals(FormStatusState.VERIFIED, formStatuses.get(key3).state()); }