use of com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup in project hmftools by hartwigmedical.
the class CpctPatientReader method setRegistrationAndBirthData.
private static void setRegistrationAndBirthData(@NotNull final ImmutableBaselineData.Builder builder, @NotNull final EcrfStudyEvent studyEvent) {
LocalDate registrationDate1 = null;
LocalDate registrationDate2 = null;
String birthYear1 = null;
String birthYear2 = null;
LocalDate birthYear3 = null;
for (final EcrfForm eligibilityForm : studyEvent.nonEmptyFormsPerOID(FORM_ELIGIBILITY, false)) {
for (final EcrfItemGroup eligibilityItemGroup : eligibilityForm.nonEmptyItemGroupsPerOID(ITEMGROUP_ELIGIBILITY, false)) {
registrationDate1 = eligibilityItemGroup.readItemDate(FIELD_REGISTRATION_DATE1, 0, DATE_FORMATTER, false);
birthYear2 = eligibilityItemGroup.readItemString(FIELD_BIRTH_YEAR2, 0, false);
birthYear3 = eligibilityItemGroup.readItemDate(FIELD_BIRTH_YEAR3, 0, DATE_FORMATTER, false);
builder.eligibilityStatus(eligibilityForm.status());
builder.eligibilityLocked(eligibilityForm.locked());
}
}
for (final EcrfForm selcritForm : studyEvent.nonEmptyFormsPerOID(FORM_SELCRIT, false)) {
for (final EcrfItemGroup selcritItemGroup : selcritForm.nonEmptyItemGroupsPerOID(ITEMGROUP_SELCRIT, false)) {
birthYear1 = selcritItemGroup.readItemString(FIELD_BIRTH_YEAR1, 0, false);
if (registrationDate1 == null) {
registrationDate2 = selcritItemGroup.readItemDate(FIELD_REGISTRATION_DATE2, 0, DATE_FORMATTER, false);
builder.selectionCriteriaStatus(selcritForm.status());
builder.selectionCriteriaLocked(selcritForm.locked());
}
}
}
final LocalDate registrationDate = registrationDate2 == null ? registrationDate1 : registrationDate2;
final Integer birthYear = determineBirthYear(birthYear1, birthYear2, birthYear3);
builder.registrationDate(registrationDate);
builder.birthYear(birthYear);
}
use of com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup 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());
}
use of com.hartwig.hmftools.common.ecrf.datamodel.EcrfItemGroup 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);
}
Aggregations