XMLEcrfDatamodelReader extends EcrfReader { @NotNull public static XMLEcrfDatamodel readXMLDatamodel(@NotNull final XMLStreamReader reader) throws XMLStreamException { List<StudyEvent> studyEvents = Lists.newArrayList(); List<Form> forms = Lists.newArrayList(); List<ItemGroup> itemGroups = Lists.newArrayList(); List<Item> items = Lists.newArrayList(); List<CodeList> codeLists = Lists.newArrayList(); while (reader.hasNext() && !isClinicalDataStart(reader)) { if (isStudyEventStart(reader)) { studyEvents.add(extractStudyEvent(reader)); } else if (isFormStart(reader)) { forms.add(extractForm(reader)); } else if (isItemGroupStart(reader)) { itemGroups.add(extractItemGroup(reader)); } else if (isItemStart(reader)) { items.add(extractItem(reader)); } else if (isCodeListStart(reader)) { codeLists.add(extractCodeList(reader)); } next(reader); } return XMLEcrfDatamodel.of(studyEvents, forms, itemGroups, items, codeLists); } private  XMLEcrfDatamodelReader(); @NotNull static XMLEcrfDatamodel readXMLDatamodel(@NotNull final XMLStreamReader reader);  }
@Test public void canExtractDatamodelFromEcrf() throws FileNotFoundException, XMLStreamException { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream(DATAMODEL_TEST)); XMLEcrfDatamodel datamodel = XMLEcrfDatamodelReader.readXMLDatamodel(reader); assertEquals(1, datamodel.studyEvents().size()); assertEquals(1, datamodel.forms().size()); assertEquals(1, datamodel.itemGroups().size()); assertEquals(2, datamodel.items().size()); assertEquals(2, datamodel.codeLists().size()); }