Search in sources :

Example 6 with EcrfStudyEvent

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

the class PreTreatmentReader method read.

@NotNull
PreTreatmentData read(@NotNull final EcrfPatient patient) throws IOException {
    PreTreatmentData preTreatmentData = null;
    for (final EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_BASELINE)) {
        for (final EcrfForm treatmentForm : studyEvent.nonEmptyFormsPerOID(FORM_TREATMENT, false)) {
            String treatmentGiven = readTreatmentGiven(treatmentForm);
            String radiotherapyGiven = readRadiotherapyGiven(treatmentForm);
            final List<DrugData> drugs = readDrugs(treatmentForm);
            if (preTreatmentData == null) {
                preTreatmentData = ImmutablePreTreatmentData.of(treatmentGiven, radiotherapyGiven, drugs, treatmentForm.status(), treatmentForm.locked());
            } else {
                LOGGER.warn("Multiple pre-therapy forms for found patient: " + patient.patientId());
            }
        }
    }
    return preTreatmentData != null ? preTreatmentData : ImmutablePreTreatmentData.of(null, null, Lists.newArrayList(), FormStatusState.UNKNOWN, false);
}
Also used : DrugData(com.hartwig.hmftools.patientdb.data.DrugData) ImmutableDrugData(com.hartwig.hmftools.patientdb.data.ImmutableDrugData) EcrfStudyEvent(com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent) EcrfForm(com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm) ImmutablePreTreatmentData(com.hartwig.hmftools.patientdb.data.ImmutablePreTreatmentData) PreTreatmentData(com.hartwig.hmftools.patientdb.data.PreTreatmentData) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with EcrfStudyEvent

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

the class TumorMarkerReader method read.

@NotNull
static List<TumorMarkerData> read(@NotNull final EcrfPatient patient) {
    final List<TumorMarkerData> tumorMarkers = Lists.newArrayList();
    for (final EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_TREATMENT)) {
        for (final EcrfForm form : studyEvent.nonEmptyFormsPerOID(FORM_RESPONSE, false)) {
            for (final EcrfItemGroup responseGroup : form.nonEmptyItemGroupsPerOID(ITEMGROUP_RESPONSE, false)) {
                LocalDate date = responseGroup.readItemDate(FIELD_DATE, 0, DATE_FORMATTER, false);
                String marker = responseGroup.readItemString(FIELD_MARKER, 0, false);
                String measurement = responseGroup.readItemString(FIELD_MEASUREMENT, 0, false);
                String unit = responseGroup.readItemString(FIELD_UNIT, 0, false);
                tumorMarkers.add(ImmutableTumorMarkerData.of(patient.patientId(), date, marker, measurement, unit, form.status(), form.locked()));
            }
        }
    }
    return tumorMarkers;
}
Also used : EcrfStudyEvent(com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent) EcrfForm(com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm) EcrfItemGroup(com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup) TumorMarkerData(com.hartwig.hmftools.patientdb.data.TumorMarkerData) ImmutableTumorMarkerData(com.hartwig.hmftools.patientdb.data.ImmutableTumorMarkerData) LocalDate(java.time.LocalDate) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with EcrfStudyEvent

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

the class BiopsyTreatmentReader method read.

@NotNull
List<BiopsyTreatmentData> read(@NotNull final EcrfPatient patient) throws IOException {
    final List<BiopsyTreatmentData> treatments = Lists.newArrayList();
    for (final EcrfStudyEvent studyEvent : patient.studyEventsPerOID(STUDY_AFTERBIOPT)) {
        for (final EcrfForm treatmentForm : studyEvent.nonEmptyFormsPerOID(FORM_TREATMENT, false)) {
            final String treatmentGiven = readTreatmentGiven(treatmentForm);
            final String radiotherapyGiven = readRadiotherapyGiven(treatmentForm);
            final List<DrugData> drugs = readDrugs(treatmentForm);
            treatments.add(ImmutableBiopsyTreatmentData.of(treatmentGiven, radiotherapyGiven, drugs, treatmentForm.status(), treatmentForm.locked()));
        }
    }
    return treatments;
}
Also used : DrugData(com.hartwig.hmftools.patientdb.data.DrugData) ImmutableDrugData(com.hartwig.hmftools.patientdb.data.ImmutableDrugData) EcrfStudyEvent(com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent) EcrfForm(com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm) ImmutableBiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.ImmutableBiopsyTreatmentData) BiopsyTreatmentData(com.hartwig.hmftools.patientdb.data.BiopsyTreatmentData) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with EcrfStudyEvent

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

the class BiopsyTreatmentResponseReaderTest method buildTestPatient.

@NotNull
private static EcrfPatient buildTestPatient() {
    final String patient = "dummy";
    EcrfItemGroup response1 = new EcrfItemGroup(patient);
    response1.addItem(BiopsyTreatmentResponseReader.FIELD_MEASUREMENT_DONE, "Yes");
    response1.addItem(BiopsyTreatmentResponseReader.FIELD_RESPONSE, "PR");
    EcrfForm form1 = new EcrfForm(patient, FormStatusState.SAVED, true);
    form1.addItemGroup(BiopsyTreatmentResponseReader.ITEMGROUP_TUMOR_MEASUREMENT, response1);
    EcrfItemGroup response2 = new EcrfItemGroup(patient);
    EcrfForm form2 = new EcrfForm(patient, FormStatusState.SAVED, true);
    form1.addItemGroup(BiopsyTreatmentResponseReader.ITEMGROUP_TUMOR_MEASUREMENT, response2);
    EcrfStudyEvent studyEvent = new EcrfStudyEvent(patient);
    studyEvent.addForm(BiopsyTreatmentResponseReader.FORM_TUMOR_MEASUREMENT, form1);
    studyEvent.addForm(BiopsyTreatmentResponseReader.FORM_TUMOR_MEASUREMENT, form2);
    Map<String, List<EcrfStudyEvent>> studyEvents = Maps.newHashMap();
    studyEvents.put(BiopsyTreatmentResponseReader.STUDY_TREATMENT, Lists.newArrayList(studyEvent));
    return new EcrfPatient(patient, studyEvents, Lists.newArrayList());
}
Also used : EcrfStudyEvent(com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent) EcrfItemGroup(com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup) EcrfForm(com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm) List(java.util.List) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with EcrfStudyEvent

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

the class XMLPatientReader method readPatient.

@NotNull
private static EcrfPatient readPatient(@NotNull final XMLStreamReader reader, @NotNull final XMLEcrfDatamodel datamodel, @NotNull final FormStatusModel formStatusModel) throws XMLStreamException {
    final String patientId = toCPCTPatientId(reader.getAttributeValue("", PATIENT_ID_ATTRIBUTE));
    final Map<String, List<EcrfStudyEvent>> studyEventsPerOID = Maps.newHashMap();
    final List<EcrfDataField> fields = Lists.newArrayList();
    String currentStudyEventOID = Strings.EMPTY;
    String currentStudyEventIdx = Strings.EMPTY;
    String currentFormOID = Strings.EMPTY;
    String currentFormIdx = Strings.EMPTY;
    String currentItemGroupOID = Strings.EMPTY;
    String currentItemGroupIdx = Strings.EMPTY;
    EcrfStudyEvent currentStudy = new EcrfStudyEvent(patientId);
    EcrfForm currentForm = new EcrfForm(patientId, FormStatusState.UNKNOWN, false);
    EcrfItemGroup currentItemGroup = new EcrfItemGroup(patientId);
    while (reader.hasNext() && !isPatientEnd(reader)) {
        if (isStudyEventStart(reader)) {
            currentStudyEventOID = reader.getAttributeValue("", STUDY_EVENT_OID_ATTRIBUTE);
            currentStudyEventIdx = reader.getAttributeValue("", STUDY_EVENT_REPEAT_KEY_ATTRIBUTE);
            currentStudy = new EcrfStudyEvent(patientId);
            if (!studyEventsPerOID.containsKey(currentStudyEventOID)) {
                studyEventsPerOID.put(currentStudyEventOID, Lists.newArrayList());
            }
            studyEventsPerOID.get(currentStudyEventOID).add(currentStudy);
        } else if (isFormStart(reader)) {
            currentFormOID = reader.getAttributeValue("", FORM_OID_ATTRIBUTE);
            currentFormIdx = reader.getAttributeValue("", FORM_REPEAT_KEY_ATTRIBUTE);
            final String formName = datamodel.forms().get(currentFormOID).name();
            final String studyEventName = datamodel.studyEvents().get(currentStudyEventOID).name();
            final FormStatusKey formKey = new ImmutableFormStatusKey(patientId, formName, currentFormIdx, studyEventName, currentStudyEventIdx);
            final FormStatusData formStatus = formStatusModel.formStatuses().get(formKey);
            if (formStatus != null) {
                currentForm = new EcrfForm(patientId, formStatus.state(), formStatus.locked());
            } else {
                currentForm = new EcrfForm(patientId, FormStatusState.UNKNOWN, false);
            }
            currentStudy.addForm(currentFormOID, currentForm);
        } else if (isItemGroupStart(reader)) {
            currentItemGroupOID = reader.getAttributeValue("", ITEM_GROUP_OID_ATTRIBUTE);
            currentItemGroupIdx = reader.getAttributeValue("", ITEM_GROUP_REPEAT_KEY);
            currentItemGroup = new EcrfItemGroup(patientId);
            currentForm.addItemGroup(currentItemGroupOID, currentItemGroup);
        } else if (isFieldStart(reader)) {
            String OID = reader.getAttributeValue("", ITEM_OID_ATTRIBUTE);
            String value = Strings.EMPTY;
            try {
                value = datamodel.resolveValue(OID, reader.getAttributeValue("", ITEM_VALUE_ATTRIBUTE));
            } catch (EcrfResolveException exception) {
                LOGGER.warn("Resolve issue for " + patientId + ": " + exception.getMessage());
            }
            currentItemGroup.addItem(OID, value);
            fields.add(EcrfDataField.of(patientId, currentStudyEventOID, currentStudyEventIdx, currentFormOID, currentFormIdx, currentItemGroupOID, currentItemGroupIdx, OID, value, currentForm.status().stateString(), Boolean.toString(currentForm.locked())));
        }
        reader.next();
    }
    return new EcrfPatient(patientId, studyEventsPerOID, fields);
}
Also used : FormStatusData(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusData) EcrfItemGroup(com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup) ImmutableFormStatusKey(com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusKey) FormStatusKey(com.hartwig.hmftools.common.ecrf.formstatus.FormStatusKey) ImmutableFormStatusKey(com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusKey) EcrfResolveException(com.hartwig.hmftools.common.ecrf.datamodel.EcrfResolveException) EcrfStudyEvent(com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent) EcrfForm(com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm) List(java.util.List) EcrfPatient(com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient) EcrfDataField(com.hartwig.hmftools.common.ecrf.datamodel.EcrfDataField) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

EcrfStudyEvent (com.hartwig.hmftools.common.ecrf.datamodel.EcrfStudyEvent)10 EcrfForm (com.hartwig.hmftools.common.ecrf.datamodel.EcrfForm)9 NotNull (org.jetbrains.annotations.NotNull)9 EcrfItemGroup (com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup)7 EcrfPatient (com.hartwig.hmftools.common.ecrf.datamodel.EcrfPatient)3 LocalDate (java.time.LocalDate)3 List (java.util.List)3 DrugData (com.hartwig.hmftools.patientdb.data.DrugData)2 ImmutableDrugData (com.hartwig.hmftools.patientdb.data.ImmutableDrugData)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 EcrfDataField (com.hartwig.hmftools.common.ecrf.datamodel.EcrfDataField)1 EcrfResolveException (com.hartwig.hmftools.common.ecrf.datamodel.EcrfResolveException)1 FormStatusData (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusData)1 FormStatusKey (com.hartwig.hmftools.common.ecrf.formstatus.FormStatusKey)1 ImmutableFormStatusKey (com.hartwig.hmftools.common.ecrf.formstatus.ImmutableFormStatusKey)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 ImmutableBaselineData (com.hartwig.hmftools.patientdb.data.ImmutableBaselineData)1 ImmutableBiopsyData (com.hartwig.hmftools.patientdb.data.ImmutableBiopsyData)1