use of com.hartwig.hmftools.common.ecrf.datamodel.EcrfDatamodelField in project hmftools by hartwigmedical.
the class XMLEcrfDatamodelToEcrfFieldsTest method canConvertXMLObjectContainerToEcrfFields.
@Test
public void canConvertXMLObjectContainerToEcrfFields() {
final String studyOID = "SE.Study";
final String formOID = "FRM.Form";
final String itemGroupOID = "GRP.ItemGroup";
final String itemOID = "GRP.Item";
final String description = "bla";
final String codeListOID = "list";
final String option1 = "x";
final String option2 = "y";
final List<StudyEvent> studyEvents = Lists.newArrayList(new ImmutableStudyEvent(studyOID, description, Lists.newArrayList(formOID)));
final List<Form> forms = Lists.newArrayList(new ImmutableForm(formOID, description, Lists.newArrayList(itemGroupOID)));
final List<ItemGroup> itemGroups = Lists.newArrayList(new ImmutableItemGroup(itemGroupOID, description, Lists.newArrayList(itemOID)));
final List<Item> items = Lists.newArrayList(new ImmutableItem(itemOID, description, codeListOID));
final Map<Integer, String> codeListItems = Maps.newHashMap();
codeListItems.put(1, option1);
codeListItems.put(2, option2);
final List<CodeList> codeLists = Lists.newArrayList(new ImmutableCodeList(codeListOID, description, codeListItems));
final XMLEcrfDatamodel datamodel = XMLEcrfDatamodel.of(studyEvents, forms, itemGroups, items, codeLists);
final List<EcrfDatamodelField> fields = XMLEcrfDatamodelToEcrfFields.convert(datamodel);
assertEquals(1, fields.size());
final EcrfDatamodelField field = fields.get(0);
assertEquals("STUDY.FORM.ITEMGROUP.ITEM", field.name());
assertEquals(description, field.description());
final Map<Integer, String> values = field.codeList();
assertEquals(option1, values.get(1));
assertEquals(option2, values.get(2));
}
use of com.hartwig.hmftools.common.ecrf.datamodel.EcrfDatamodelField in project hmftools by hartwigmedical.
the class XMLEcrfDatamodelToEcrfFields method convert.
@NotNull
public static List<EcrfDatamodelField> convert(@NotNull final XMLEcrfDatamodel datamodel) {
final List<EcrfDatamodelField> fields = Lists.newArrayList();
for (final StudyEvent studyEvent : datamodel.studyEvents().values()) {
for (final String formOID : studyEvent.formOIDs()) {
final Form form = findByOID(datamodel.forms().values(), formOID);
for (final String itemGroupOID : form.itemGroupOIDs()) {
final ItemGroup itemGroup = findByOID(datamodel.itemGroups().values(), itemGroupOID);
for (final String itemOID : itemGroup.itemOIDs()) {
final Item item = findByOID(datamodel.items().values(), itemOID);
Map<Integer, String> codeList = Maps.newHashMap();
String codeListOID = item.codeListOID();
if (codeListOID != null) {
final CodeList codeListObj = findByOID(datamodel.codeLists().values(), codeListOID);
codeList = codeListObj.values();
}
final EcrfDatamodelField field = new ImmutableEcrfDatamodelField(studyEvent.oid(), form.oid(), itemGroup.oid(), item.oid(), item.name(), codeList);
fields.add(field);
}
}
}
}
return fields;
}
use of com.hartwig.hmftools.common.ecrf.datamodel.EcrfDatamodelField in project hmftools by hartwigmedical.
the class XMLPatientReaderTest method canReadPatients.
@Test
public void canReadPatients() throws FileNotFoundException, XMLStreamException {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(new FileInputStream(PATIENTS_TEST));
final String studyOID = "SE.Study";
final String formOID = "FRM.Form";
final String itemGroupOID = "GRP.ItemGroup";
final Map<Integer, String> codeListValues = Maps.newHashMap();
codeListValues.put(1, "one");
codeListValues.put(2, "two");
codeListValues.put(3, "three");
final String item1OID = "FLD.ItemGroup.field1";
final String item2OID = "FLD.ItemGroup.field2";
final String birthDateOID = "FLD.ItemGroup.BIRTHDTC";
final String codeListOID = "codeList";
final StudyEvent studyEvent = new ImmutableStudyEvent(studyOID, studyOID, Lists.newArrayList(formOID));
final Form form = new ImmutableForm(formOID, formOID, Lists.newArrayList(itemGroupOID));
final ItemGroup itemGroup = new ImmutableItemGroup(itemGroupOID, itemGroupOID, Lists.newArrayList(item1OID, item2OID, birthDateOID));
final Item item1 = new ImmutableItem(item1OID, item1OID, codeListOID);
final Item item2 = new ImmutableItem(item2OID, item2OID, "");
final Item birthDate = new ImmutableItem(birthDateOID, birthDateOID, "");
final CodeList codeList = new ImmutableCodeList(codeListOID, codeListOID, codeListValues);
final List<EcrfPatient> patients = XMLPatientReader.readPatients(reader, XMLEcrfDatamodel.of(Lists.newArrayList(studyEvent), Lists.newArrayList(form), Lists.newArrayList(itemGroup), Lists.newArrayList(item1, item2, birthDate), Lists.newArrayList(codeList)), new ImmutableFormStatusModel(Maps.newHashMap()));
final EcrfDatamodelField field1 = new ImmutableEcrfDatamodelField(studyOID, formOID, itemGroupOID, "FLD.ItemGroup.field1", "", codeListValues);
final EcrfDatamodelField field2 = new ImmutableEcrfDatamodelField(studyOID, formOID, itemGroupOID, "FLD.ItemGroup.field2", "", Maps.newHashMap());
final EcrfDatamodelField birthDateField = new ImmutableEcrfDatamodelField(studyOID, formOID, itemGroupOID, "FLD.ItemGroup.BIRTHDTC", "", Maps.newHashMap());
// @formatter:off
assertEquals(3, patients.size());
assertEquals(4, patients.get(0).fields().size());
assertEquals(PATIENT_1, patients.get(0).patientId());
verifyFirstFieldValue("one", patients.get(0).fieldValuesByEcrfField(field1));
verifyFirstFieldValue("hi", patients.get(0).fieldValuesByEcrfField(field2));
verifyFirstFieldValue("2016-01-01", patients.get(0).fieldValuesByEcrfField(birthDateField));
verifyFirstFieldValue("one", patients.get(0).studyEventsPerOID(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().get(item1OID));
verifyFirstFieldValue("hi", patients.get(0).studyEventsPerOID(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().get(item2OID));
verifyFirstFieldValue("2016-01-01", patients.get(0).studyEventsPerOID(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().get(birthDateOID));
assertEquals(1, patients.get(0).studyEventsPerOID().size());
assertEquals(1, patients.get(0).studyEventsPerOID().get(studyOID).size());
assertEquals(1, patients.get(0).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).size());
assertEquals(1, patients.get(0).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).size());
assertEquals(4, patients.get(0).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().size());
assertEquals(4, patients.get(1).fields().size());
assertEquals(PATIENT_2, patients.get(1).patientId());
verifyFirstFieldValue("two", patients.get(1).studyEventsPerOID(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().get(item1OID));
verifyFirstFieldValue("hi there", patients.get(1).studyEventsPerOID(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().get(item2OID));
verifyFirstFieldValue("2016-01-01", patients.get(1).studyEventsPerOID(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().get(birthDateOID));
assertEquals(1, patients.get(1).studyEventsPerOID().size());
assertEquals(1, patients.get(1).studyEventsPerOID().get(studyOID).size());
assertEquals(1, patients.get(1).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).size());
assertEquals(1, patients.get(1).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).size());
assertEquals(4, patients.get(1).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).itemsPerOID().size());
// @formatter:on
}
Aggregations