Search in sources :

Example 6 with CpctEcrfModel

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

the class PatientReaderTest method canReadTumorMarkers.

@Test
public void canReadTumorMarkers() {
    final CpctEcrfModel model = loadTestEcrf();
    assertEquals(1, model.patientCount());
    final EcrfPatient cpctPatient = model.patients().iterator().next();
    final List<TumorMarkerData> tumorMarkers = TumorMarkerReader.read(cpctPatient);
    assertEquals(0, tumorMarkers.size());
}
Also used : TumorMarkerData(com.hartwig.hmftools.patientdb.data.TumorMarkerData) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel) Test(org.junit.Test)

Example 7 with CpctEcrfModel

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

the class PatientReaderTest method canReadCpctPatientInfo.

@Test
public void canReadCpctPatientInfo() {
    final CpctEcrfModel model = loadTestEcrf();
    assertEquals(1, model.patientCount());
    final EcrfPatient cpctPatient = model.patients().iterator().next();
    final CpctPatientReader cpctPatientReader = new CpctPatientReader(model, createTumorLocationCurator());
    final BaselineData baselineData = cpctPatientReader.read(cpctPatient);
    assertEquals("Breast cancer", baselineData.cancerType().searchTerm());
    assertEquals("Breast", baselineData.cancerType().category());
    assertEquals("Breast Cancer: subtype unknown", baselineData.cancerType().subcategory());
    assertEquals("female", baselineData.gender());
    assertEquals("Bernhoven uden", baselineData.hospital());
    assertEquals(new Integer(1963), baselineData.birthYear());
    assertEquals(LocalDate.parse("2012-06-22", DATE_FORMATTER), baselineData.deathDate());
    assertEquals(LocalDate.parse("2012-02-17", DATE_FORMATTER), baselineData.registrationDate());
    assertEquals(LocalDate.parse("2012-02-17", DATE_FORMATTER), baselineData.informedConsentDate());
}
Also used : EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) BaselineData(com.hartwig.hmftools.patientdb.data.BaselineData) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel) Test(org.junit.Test)

Example 8 with CpctEcrfModel

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

the class LoadClinicalData method writeClinicalData.

private static void writeClinicalData(@NotNull final Options clinicalOptions, @NotNull final CommandLine cmd, @NotNull final List<RunContext> runContexts, @NotNull final DatabaseAccess dbAccess) throws IOException, XMLStreamException {
    final String ecrfFilePath = cmd.getOptionValue(ECRF_FILE);
    final String limsJson = cmd.getOptionValue(LIMS_JSON);
    final String preLIMSArrivalDatesCsv = cmd.getOptionValue(PRE_LIMS_ARRIVAL_DATES_CSV);
    final String formStatusCsv = cmd.getOptionValue(FORM_STATUS_CSV);
    final String csvOutputDir = cmd.getOptionValue(CSV_OUT_DIR);
    final Optional<String> cancerTypesLink = Optional.ofNullable(cmd.getOptionValue(CANCER_TYPES_LINK));
    final Optional<String> portalDataLink = Optional.ofNullable(cmd.getOptionValue(PORTAL_DATA_LINK));
    if (Utils.anyNull(ecrfFilePath, limsJson, preLIMSArrivalDatesCsv, formStatusCsv, csvOutputDir)) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("patient-db", clinicalOptions);
    } else {
        LOGGER.info("Clearing database...");
        dbAccess.clearClinicalTables();
        LOGGER.info("Cleared database, loading samples from LIMS...");
        Lims lims = LimsFactory.fromLimsJsonWithPreLIMSArrivalDates(limsJson, preLIMSArrivalDatesCsv);
        Map<String, List<SampleData>> samplesPerPatient = readSamplesPerPatient(lims, runContexts);
        LOGGER.info("Loaded samples for {} patients from LIMS, loading ecrf...", samplesPerPatient.size());
        FormStatusModel formStatusModel = FormStatusReader.buildModelFromCsv(formStatusCsv);
        CpctEcrfModel ecrfModel = CpctEcrfModel.loadFromXML(ecrfFilePath, formStatusModel);
        TreatmentCurator treatmentCurator = TreatmentCurator.fromProductionResource();
        TumorLocationCurator tumorLocationCurator = TumorLocationCurator.fromProductionResource();
        PatientReader patientReader = new PatientReader(ecrfModel, treatmentCurator, tumorLocationCurator);
        final Map<String, Patient> readPatients = readEcrfPatients(patientReader, ecrfModel.patients(), samplesPerPatient);
        LOGGER.info("Loaded {} patients from ecrf", readPatients.size());
        DumpClinicalData.writeClinicalDumps(csvOutputDir, readPatients.values(), cancerTypesLink, portalDataLink);
        LOGGER.info("Writing clinical data for {} sequenced patients.", readPatients.size());
        for (final String patientIdentifier : samplesPerPatient.keySet()) {
            final Patient patient = readPatients.get(patientIdentifier);
            if (patient == null) {
                if (patientIdentifier.startsWith("CPCT")) {
                    LOGGER.error("Could not find patient with id: " + patientIdentifier + " in ecrf file.");
                }
                dbAccess.writeSampleClinicalData(patientIdentifier, samplesPerPatient.get(patientIdentifier));
            } else {
                dbAccess.writeFullClinicalData(patient);
                final List<ValidationFinding> findings = PatientValidator.validatePatient(patient);
                dbAccess.writeValidationFindings(findings);
                dbAccess.writeValidationFindings(patient.matchFindings());
            }
        }
        dbAccess.writeValidationFindings(CurationValidator.validateTreatmentCurator(treatmentCurator));
        dbAccess.writeValidationFindings(CurationValidator.validateTumorLocationCurator(tumorLocationCurator));
        LOGGER.info("Done!");
    }
}
Also used : FormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel) TreatmentCurator(com.hartwig.hmftools.patientdb.curators.TreatmentCurator) Lims(com.hartwig.hmftools.common.lims.Lims) PatientReader(com.hartwig.hmftools.patientdb.readers.PatientReader) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) Patient(com.hartwig.hmftools.patientdb.data.Patient) HelpFormatter(org.apache.commons.cli.HelpFormatter) TumorLocationCurator(com.hartwig.hmftools.patientdb.curators.TumorLocationCurator) ValidationFinding(com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding) List(java.util.List) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel)

Example 9 with CpctEcrfModel

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

the class LoadClinicalData method writeRawEcrf.

private static void writeRawEcrf(@NotNull final Options ecrfOptions, @NotNull final CommandLine cmd, @NotNull final List<RunContext> runContexts, @NotNull final DatabaseAccess dbWriter) throws IOException, XMLStreamException {
    final String ecrfFilePath = cmd.getOptionValue(ECRF_FILE);
    final String formStatusPath = cmd.getOptionValue(FORM_STATUS_CSV);
    if (Utils.anyNull(ecrfFilePath, formStatusPath)) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("patient-db -" + DO_LOAD_RAW_ECRF, ecrfOptions);
    } else {
        dbWriter.clearCpctEcrf();
        LOGGER.info("Loading ecrf model...");
        final FormStatusModel formStatusModel = FormStatusReader.buildModelFromCsv(formStatusPath);
        final CpctEcrfModel model = CpctEcrfModel.loadFromXML(ecrfFilePath, formStatusModel);
        final Set<String> sequencedPatients = Utils.sequencedPatientIds(runContexts);
        LOGGER.info("Writing raw ecrf data for " + sequencedPatients.size() + " patients.");
        dbWriter.writeCpctEcrf(model, sequencedPatients);
        LOGGER.info("Done writing raw ecrf data for " + sequencedPatients.size() + " patients!");
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) FormStatusModel(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel) CpctEcrfModel(com.hartwig.hmftools.common.ecrf.CpctEcrfModel)

Aggregations

CpctEcrfModel (com.hartwig.hmftools.common.ecrf.CpctEcrfModel)9 EcrfPatient (com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient)7 Test (org.junit.Test)6 HelpFormatter (org.apache.commons.cli.HelpFormatter)3 FormStatusModel (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusModel)2 RunContext (com.hartwig.hmftools.common.context.RunContext)1 ValidationFinding (com.hartwig.hmftools.common.ecrf.datamodel.ValidationFinding)1 ImmutableFormStatusModel (com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusModel)1 Lims (com.hartwig.hmftools.common.lims.Lims)1 TreatmentCurator (com.hartwig.hmftools.patientdb.curators.TreatmentCurator)1 TumorLocationCurator (com.hartwig.hmftools.patientdb.curators.TumorLocationCurator)1 DatabaseAccess (com.hartwig.hmftools.patientdb.dao.DatabaseAccess)1 BaselineData (com.hartwig.hmftools.patientdb.data.BaselineData)1 BiopsyData (com.hartwig.hmftools.patientdb.data.BiopsyData)1 BiopsyTreatmentData (com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData)1 BiopsyTreatmentResponseData (com.hartwig.hmftools.patientdb.data.BiopsyTreatmentResponseData)1 DrugData (com.hartwig.hmftools.patientdb.data.DrugData)1 Patient (com.hartwig.hmftools.patientdb.data.Patient)1 PreTreatmentData (com.hartwig.hmftools.patientdb.data.PreTreatmentData)1 TumorMarkerData (com.hartwig.hmftools.patientdb.data.TumorMarkerData)1