Search in sources :

Example 1 with ImmutableFormStatusModel

use of com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel in project hmftools by hartwigmedical.

the class CpctEcrfModelTest method loadDataFromRealXML.

@Test
public void loadDataFromRealXML() throws IOException, XMLStreamException {
    if (Files.exists(new File(TEST_ECRF).toPath())) {
        final CpctEcrfModel model = CpctEcrfModel.loadFromXML(TEST_ECRF, new ImmutableFormStatusModel(Maps.newHashMap()));
        assertTrue(hasField(model, "BASELINE.CARCINOMA.CARCINOMA.PTUMLOC"));
        assertFalse(hasField(model, "Does Not Exist"));
        assertNotNull(model.datamodel().studyEvents().get("SE.BASELINE"));
        assertNotNull(model.datamodel().forms().get("FRM.CARCINOMA"));
        assertNotNull(model.datamodel().itemGroups().get("GRP.CARCINOMA.CARCINOMA"));
        assertNotNull(model.datamodel().items().get("FLD.CARCINOMA.PTUMLOC"));
        assertNull(model.datamodel().studyEvents().get("Does Not Exist"));
        assertNull(model.datamodel().forms().get("Does Not Exist"));
        assertNull(model.datamodel().itemGroups().get("Does Not Exist"));
        assertNull(model.datamodel().items().get("Does Not Exist"));
        assertTrue(hasPatient(model, "CPCT02252500"));
        assertFalse(hasPatient(model, "Does Not Exist"));
    } else {
        LOGGER.warn("Could not run CpctEcrfModelTest since test xml is not present: " + TEST_ECRF);
    }
}
Also used : File(java.io.File) ImmutableFormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel) Test(org.junit.Test)

Example 2 with ImmutableFormStatusModel

use of com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel in project hmftools by hartwigmedical.

the class LoadDrupEcrfData method main.

public static void main(@NotNull final String[] args) throws ParseException, IOException, XMLStreamException, SQLException {
    final Options options = createOptions();
    final CommandLine cmd = createCommandLine(args, options);
    final String userName = cmd.getOptionValue(DB_USER);
    final String password = cmd.getOptionValue(DB_PASS);
    final String databaseUrl = cmd.getOptionValue(DB_URL);
    final String ecrfFile = cmd.getOptionValue(ECRF_FILE);
    final String runsFolderPath = cmd.getOptionValue(RUNS_DIR);
    if (Utils.anyNull(userName, password, databaseUrl, ecrfFile, runsFolderPath)) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("patient-db - load DRUP ecrf", options);
    } else {
        final File runsDirectory = new File(runsFolderPath);
        if (runsDirectory.isDirectory()) {
            final String jdbcUrl = "jdbc:" + databaseUrl;
            final DatabaseAccess dbWriter = new DatabaseAccess(userName, password, jdbcUrl);
            dbWriter.clearDrupEcrf();
            LOGGER.info("Importing DRUP ecrf data from: {}", ecrfFile);
            final CpctEcrfModel model = CpctEcrfModel.loadFromXML(ecrfFile, new ImmutableFormStatusModel(Maps.newHashMap()));
            final List<RunContext> runContexts = RunsFolderReader.getRunContexts(runsDirectory);
            final Set<String> sequencedPatients = Utils.sequencedPatientIds(runContexts);
            LOGGER.info("Writing raw ecrf data for " + model.patientCount() + " patients.");
            dbWriter.writeDrupEcrf(model, sequencedPatients);
            LOGGER.info("Done writing raw ecrf data for " + model.patientCount() + " patients!");
        } else {
            if (!runsDirectory.exists()) {
                LOGGER.warn("dir " + runsDirectory + " does not exist.");
            }
            final HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("patient-db - load DRUP ecrf", options);
        }
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) DatabaseAccess(com.hartwig.hmftools.patientdb.dao.DatabaseAccess) RunContext(com.hartwig.hmftools.common.context.RunContext) File(java.io.File) ImmutableFormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel)

Example 3 with ImmutableFormStatusModel

use of com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel 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
}
Also used : ImmutableEcrfDatamodelField(com.hartwig.hmftools.common.ecrf.datamodel.ImmutableEcrfDatamodelField) EcrfDatamodelField(com.hartwig.hmftools.common.ecrf.datamodel.EcrfDatamodelField) XMLStreamReader(javax.xml.stream.XMLStreamReader) ImmutableEcrfDatamodelField(com.hartwig.hmftools.common.ecrf.datamodel.ImmutableEcrfDatamodelField) FileInputStream(java.io.FileInputStream) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) ImmutableFormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 4 with ImmutableFormStatusModel

use of com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel in project hmftools by hartwigmedical.

the class XMLPatientReaderTest method determinesEmptyItemGroupAndForm.

@Test
public void determinesEmptyItemGroupAndForm() 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 StudyEvent studyEvent = new ImmutableStudyEvent(studyOID, studyOID, Lists.newArrayList(formOID));
    final Form form = new ImmutableForm(formOID, formOID, Lists.newArrayList(itemGroupOID));
    final List<EcrfPatient> patients = XMLPatientReader.readPatients(reader, XMLEcrfDatamodel.of(Lists.newArrayList(studyEvent), Lists.newArrayList(form), Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList()), new ImmutableFormStatusModel(Maps.newHashMap()));
    // @formatter:off
    assertEquals(3, patients.size());
    assertEquals(1, patients.get(2).studyEventsPerOID().size());
    assertEquals(1, patients.get(2).studyEventsPerOID().get(studyOID).size());
    assertEquals(2, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).size());
    assertEquals(1, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).size());
    assertEquals(true, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).itemGroupsPerOID().get(itemGroupOID).get(0).isEmpty());
    assertEquals(true, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(0).isEmpty());
    assertEquals(2, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(1).itemGroupsPerOID().get(itemGroupOID).size());
    assertEquals(true, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(1).itemGroupsPerOID().get(itemGroupOID).get(0).isEmpty());
    assertEquals(false, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(1).itemGroupsPerOID().get(itemGroupOID).get(1).isEmpty());
    assertEquals(false, patients.get(2).studyEventsPerOID().get(studyOID).get(0).formsPerOID().get(formOID).get(1).isEmpty());
// @formatter:on
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) ImmutableFormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel) XMLInputFactory(javax.xml.stream.XMLInputFactory) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

ImmutableFormStatusModel (com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel)4 Test (org.junit.Test)3 EcrfPatient (com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 XMLInputFactory (javax.xml.stream.XMLInputFactory)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 RunContext (com.hartwig.hmftools.common.context.RunContext)1 CpctEcrfModel (com.hartwig.hmftools.common.ecrf.CpctEcrfModel)1 EcrfDatamodelField (com.hartwig.hmftools.common.ecrf.datamodel.EcrfDatamodelField)1 ImmutableEcrfDatamodelField (com.hartwig.hmftools.common.ecrf.datamodel.ImmutableEcrfDatamodelField)1 DatabaseAccess (com.hartwig.hmftools.patientdb.dao.DatabaseAccess)1 CommandLine (org.apache.commons.cli.CommandLine)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Options (org.apache.commons.cli.Options)1