use of org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method setOCEventDataAuditLogs.
protected void setOCEventDataAuditLogs(StudyBean study, OdmClinicalDataBean data, String studySubjectOids, HashMap<String, String> evnOidPoses) {
this.setOCEventDataAuditsTypesExpected();
logger.debug("Begin to execute GetOCEventDataAuditsSql");
logger.debug("getOCEventDataAuditsSql= " + this.getOCEventDataAuditsSql(studySubjectOids));
ArrayList rows = select(this.getOCEventDataAuditsSql(studySubjectOids));
Iterator iter = rows.iterator();
while (iter.hasNext()) {
HashMap row = (HashMap) iter.next();
String studySubjectLabel = (String) row.get("study_subject_oid");
String sedOid = (String) row.get("definition_oid");
Integer auditId = (Integer) row.get("audit_id");
String type = (String) row.get("name");
Integer userId = (Integer) row.get("user_id");
Date auditDate = (Date) row.get("audit_date");
String auditReason = (String) row.get("reason_for_change");
String oldValue = (String) row.get("old_value");
String newValue = (String) row.get("new_value");
Integer typeId = (Integer) row.get("audit_log_event_type_id");
if (evnOidPoses.containsKey(studySubjectLabel + sedOid)) {
String[] poses = evnOidPoses.get(studySubjectLabel + sedOid).split("---");
ExportStudyEventDataBean se = data.getExportSubjectData().get(Integer.parseInt(poses[0])).getExportStudyEventData().get(Integer.parseInt(poses[1]));
AuditLogBean auditLog = new AuditLogBean();
auditLog.setOid("AL_" + auditId);
auditLog.setUserId("USR_" + userId);
auditLog.setDatetimeStamp(auditDate);
auditLog.setType(type);
auditLog.setReasonForChange(auditReason);
if (typeId == 17 || typeId == 18 || typeId == 19 || typeId == 20 || typeId == 21 || typeId == 22 || typeId == 23 || typeId == 31) {
if ("0".equals(newValue)) {
auditLog.setOldValue(SubjectEventStatus.INVALID.getName());
} else {
auditLog.setNewValue(SubjectEventStatus.getFromMap(Integer.parseInt(newValue)).getName());
}
if ("0".equals(oldValue)) {
auditLog.setOldValue(SubjectEventStatus.INVALID.getName());
} else {
auditLog.setOldValue(SubjectEventStatus.getFromMap(Integer.parseInt(oldValue)).getName());
}
} else {
auditLog.setNewValue(newValue);
auditLog.setOldValue(oldValue);
}
AuditLogsBean logs = se.getAuditLogs();
if (logs.getEntityID() == null || logs.getEntityID().length() <= 0) {
logs.setEntityID(se.getStudyEventOID());
}
logs.getAuditLogs().add(auditLog);
se.setAuditLogs(logs);
}
}
}
use of org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method getClinicalData.
public void getClinicalData(StudyBean study, DatasetBean dataset, OdmClinicalDataBean data, String odmVersion, String studySubjectIds, String odmType) {
String dbName = CoreResources.getDBName();
String subprev = "";
HashMap<String, Integer> sepos = new HashMap<String, Integer>();
String seprev = "";
String formprev = "";
HashMap<String, Integer> igpos = new HashMap<String, Integer>();
String igprev = "";
String oidPos = "";
HashMap<Integer, String> oidPoses = new HashMap<Integer, String>();
HashMap<Integer, String> idataOidPoses = new HashMap<Integer, String>();
// String studyIds = "";
// if (study.getParentStudyId() > 0) {
// studyIds += study.getId();
// } else {
// ArrayList<Integer> ids = (ArrayList<Integer>) (new
// StudyDAO(this.ds)).findAllSiteIdsByStudy(study);
// for (int i = 0; i < ids.size() - 1; ++i) {
// studyIds += ids.get(i) + ",";
// }
// studyIds += ids.get(ids.size() - 1);
// }
String studyIds = study.getId() + "";
int datasetItemStatusId = dataset.getDatasetItemStatus().getId();
String sql = dataset.getSQLStatement().split("order by")[0].trim();
sql = sql.split("study_event_definition_id in")[1];
String[] ss = sql.split("and item_id in");
String sedIds = ss[0];
String[] sss = ss[1].split("and");
String itemIds = sss[0];
String dateConstraint = "";
if ("postgres".equalsIgnoreCase(dbName)) {
dateConstraint = "and " + sss[1] + " and " + sss[2];
dateConstraint = dateConstraint.replace("date_created", "ss.enrollment_date");
} else if ("oracle".equalsIgnoreCase(dbName)) {
String[] os = (sss[1] + sss[2]).split("'");
dateConstraint = "and trunc(ss.enrollment_date) >= to_date('" + os[1] + "') and trunc(ss.enrollment_date) <= to_date('" + os[3] + "')";
}
logger.debug("Begin to GetSubjectEventFormSql");
if (odmVersion.startsWith("oc")) {
logger.debug("getOCSubjectEventFormSql=" + getOCSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
this.setSubjectEventFormDataTypesExpected(odmVersion);
ArrayList viewRows = select(getOCSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
Iterator iter = viewRows.iterator();
this.setDataWithOCAttributes(study, dataset, data, odmVersion, iter, oidPoses, odmType);
} else {
logger.debug("getSubjectEventFormSql=" + getSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
this.setSubjectEventFormDataTypesExpected();
ArrayList viewRows = select(getSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
Iterator iter = viewRows.iterator();
// updated as well because this method came from here.
while (iter.hasNext()) {
JobTerminationMonitor.check();
HashMap row = (HashMap) iter.next();
String studySubjectLabel = (String) row.get("study_subject_oid");
String sedOID = (String) row.get("definition_oid");
Boolean studyEventRepeating = (Boolean) row.get("definition_repeating");
Integer sampleOrdinal = (Integer) row.get("sample_ordinal");
String cvOID = (String) row.get("crf_version_oid");
// ecId
Integer ecId = (Integer) row.get("event_crf_id");
CRFVersionBean cvBean = cvdao.findByOid(cvOID);
CRFBean cBean = (CRFBean) crfdao.findByPK(cvBean.getCrfId());
// should
// be unique;
String key = studySubjectLabel;
ExportSubjectDataBean sub = new ExportSubjectDataBean();
if (subprev.equals(studySubjectLabel)) {
int p = data.getExportSubjectData().size() - 1;
sub = data.getExportSubjectData().get(p);
} else {
subprev = studySubjectLabel;
sub.setSubjectOID(studySubjectLabel);
data.getExportSubjectData().add(sub);
seprev = "";
formprev = "";
igprev = "";
}
oidPos = data.getExportSubjectData().size() - 1 + "";
ExportStudyEventDataBean se = new ExportStudyEventDataBean();
// key += sedOID + sampleOrdinal;
key += sedOID;
if (!seprev.equals(key) || !sepos.containsKey(key + sampleOrdinal)) {
sepos.put(key + sampleOrdinal, sub.getExportStudyEventData().size());
seprev = key;
se.setStudyEventOID(sedOID);
se.setStudyEventRepeatKey(studyEventRepeating ? sampleOrdinal + "" : "-1");
sub.getExportStudyEventData().add(se);
formprev = "";
igprev = "";
} else {
se = sub.getExportStudyEventData().get(sepos.get(key + sampleOrdinal));
}
oidPos += "---" + (sub.getExportStudyEventData().size() - 1);
ExportFormDataBean form = new ExportFormDataBean();
key += cvOID;
if (formprev.equals(key)) {
form = se.getExportFormData().get(se.getExportFormData().size() - 1);
} else {
formprev = key;
form.setFormOID(cBean.getOid());
se.getExportFormData().add(form);
igprev = "";
}
oidPos += "---" + (se.getExportFormData().size() - 1);
// ecId should be distinct
oidPoses.put(ecId, oidPos);
oidPos = "";
}
}
this.setEventGroupItemDataWithUnitTypesExpected();
logger.debug("Begin to GetEventGroupItemWithUnitSql");
ArrayList viewRows = select(getEventGroupItemWithUnitSql(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
logger.debug("getEventGroupItemWithUnitSql : " + getEventGroupItemWithUnitSql(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
String idataIds = "";
if (viewRows.size() > 0) {
Iterator iter = viewRows.iterator();
ExportSubjectDataBean sub = new ExportSubjectDataBean();
ExportStudyEventDataBean se = new ExportStudyEventDataBean();
ExportFormDataBean form = new ExportFormDataBean();
int ecprev = -1;
igprev = "";
boolean goon = true;
String itprev = "";
// HashMap<String, String> nullValueMap =
// ClinicalDataUnit.getNullValueMap();
HashMap<String, String> nullValueCVs = this.getNullValueCVs(study);
HashSet<Integer> itemDataIds = new HashSet<Integer>();
String yearMonthFormat = StringUtil.parseDateFormat(ResourceBundleProvider.getFormatBundle(locale).getString("date_format_year_month"));
String yearFormat = StringUtil.parseDateFormat(ResourceBundleProvider.getFormatBundle(locale).getString("date_format_year"));
while (iter.hasNext()) {
JobTerminationMonitor.check();
HashMap row = (HashMap) iter.next();
Integer ecId = (Integer) row.get("event_crf_id");
Integer igId = (Integer) row.get("item_group_id");
String igOID = (String) row.get("item_group_oid");
String igName = (String) row.get("item_group_name");
Integer itId = (Integer) row.get("item_id");
String itOID = (String) row.get("item_oid");
Integer itDataOrdinal = (Integer) row.get("item_data_ordinal");
String itValue = (String) row.get("value");
Integer datatypeid = (Integer) row.get("item_data_type_id");
Integer idataId = (Integer) row.get("item_data_id");
String muOid = (String) row.get("mu_oid");
String key = "";
if (ecId != ecprev) {
logger.debug("Found ecId=" + ecId + " in subjectEventFormSql is:" + oidPoses.containsKey(ecId));
if (oidPoses.containsKey(ecId)) {
goon = true;
String[] poses = oidPoses.get(ecId).split("---");
sub = data.getExportSubjectData().get(Integer.valueOf(poses[0]));
se = sub.getExportStudyEventData().get(Integer.valueOf(poses[1]));
form = se.getExportFormData().get(Integer.valueOf(poses[2]));
} else {
goon = false;
}
ecprev = ecId;
}
if (goon) {
ImportItemGroupDataBean ig = new ImportItemGroupDataBean();
// key = ecId + igOID;
key = ecId + "-" + igId;
if (!igprev.equals(key) || !igpos.containsKey(key + itDataOrdinal)) {
igpos.put(key + itDataOrdinal, form.getItemGroupData().size());
igprev = key;
ig.setItemGroupOID(igOID + "");
ig.setItemGroupRepeatKey("ungrouped".equalsIgnoreCase(igName) ? "-1" : itDataOrdinal + "");
form.getItemGroupData().add(ig);
} else {
ig = form.getItemGroupData().get(igpos.get(key + itDataOrdinal));
}
String newpos = oidPoses.get(ecId) + "---" + igpos.get(key + itDataOrdinal);
// item should be distinct; but duplicated item data have
// been reported because "save" have been clicked twice.
// those duplicated item data have been arranged together by
// "distinct" because of their same
// ecId+igOID+itOID+itDataOrdinal (08-2008)
key = itId + "_" + itDataOrdinal + key;
if (!itprev.equals(key)) {
itprev = key;
ImportItemDataBean it = new ImportItemDataBean();
it.setItemOID(itOID);
it.setTransactionType("Insert");
String nullKey = study.getId() + "-" + se.getStudyEventOID() + "-" + form.getFormOID();
if (ClinicalDataUtil.isNull(itValue, nullKey, nullValueCVs)) {
// if
// (nullValueMap.containsKey(itValue.trim().toUpperCase()))
// {
// itValue =
// nullValueMap.get(itValue.trim().toUpperCase());
it.setIsNull("Yes");
String nullvalues = ClinicalDataUtil.presetNullValueStr(nullValueCVs.get(nullKey));
boolean hasValueWithNull = ClinicalDataUtil.isValueWithNull(itValue, nullvalues);
it.setHasValueWithNull(hasValueWithNull);
if (hasValueWithNull) {
it.setValue(itValue);
it.setReasonForNull(ClinicalDataUtil.getNullsInValue(itValue, nullvalues));
} else {
it.setReasonForNull(itValue.trim());
}
} else {
if (datatypeid == 9) {
try {
itValue = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat(oc_df_string).parse(itValue));
} catch (Exception fe) {
logger.debug("Item -" + itOID + " value " + itValue + " might not be ODM date format yyyy-MM-dd.");
}
}
/*
* not be supported in openclinica-3.0.40.1
* else if (datatypeid == 10 && odmVersion.contains("1.3")) {
* if (StringUtil.isFormatDate(itValue, oc_df_string)) {
* try {
* itValue = new SimpleDateFormat("yyyy-MM-dd").format(new
* SimpleDateFormat(oc_df_string).parse(itValue));
* } catch (Exception e) {
* logger.info("Item -" + itOID + " value " + itValue +
* " might not be ODM partialDate format yyyy[-MM[-dd]].");
* }
* } else {
* if (StringUtil.isPartialYearMonth(itValue, yearMonthFormat)) {
* try {
* itValue = new SimpleDateFormat("yyyy-MM").format(new
* SimpleDateFormat(yearMonthFormat).parse(itValue));
* } catch (Exception e) {
* logger.info("Item -" + itOID + " value " + itValue +
* " might not be ODM partialDate format yyyy[-MM[-dd]].");
* }
* } else {
* try {
* itValue = new SimpleDateFormat("yyyy").format(new
* SimpleDateFormat(yearFormat).parse(itValue));
* } catch (Exception e) {
* logger.info("Item -" + itOID + " value " + itValue +
* " might not be ODM partialDate format yyyy[-MM[-dd]].");
* }
* }
* }
* }
*/
it.setValue(itValue);
}
if (muOid != null && muOid.length() > 0) {
ElementRefBean measurementUnitRef = new ElementRefBean();
measurementUnitRef.setElementDefOID(muOid);
it.setMeasurementUnitRef(measurementUnitRef);
}
ig.getItemData().add(it);
newpos += "---" + (ig.getItemData().size() - 1);
idataOidPoses.put(idataId, newpos);
}
idataIds += "'" + idataId + "', ";
}
}
}
idataIds = idataIds.length() > 0 ? idataIds.substring(0, idataIds.length() - 2) : idataIds;
if (idataIds.length() > 0 && itemIds.length() > 0) {
this.setErasedScoreItemDataValues(data, itemIds, idataIds, idataOidPoses, odmVersion);
} else {
logger.info("OdmExtractDAO.setScoreItemDataNullValues was not called because of empty item_data_ids or/and item_ids");
}
if (odmType != null && odmType.equalsIgnoreCase("clinical_data")) {
logger.debug("Do not create discrepancy notes");
} else if (odmVersion.startsWith("oc")) {
if (idataIds.length() > 0) {
setOCItemDataAuditLogs(study, data, idataIds, idataOidPoses);
setOCItemDataDNs(data, idataIds, idataOidPoses);
} else {
logger.info("OdmExtractDAO.setOCItemDataAuditLogs & setOCItemDataDNs weren't called because of empty idataIds");
}
}
}
use of org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean in project OpenClinica by OpenClinica.
the class GenerateClinicalDataServiceImpl method setExportStudyEventDataBean.
private ArrayList<ExportStudyEventDataBean> setExportStudyEventDataBean(StudySubject ss, List<StudyEvent> sEvents, String formVersionOID) {
ArrayList<ExportStudyEventDataBean> al = new ArrayList<ExportStudyEventDataBean>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
for (StudyEvent se : sEvents) {
if (se != null) {
ExportStudyEventDataBean expSEBean = new ExportStudyEventDataBean();
expSEBean.setLocation(se.getLocation());
if (se.getDateEnd() != null)
if (se.getEndTimeFlag())
expSEBean.setEndDate(se.getDateEnd() + "");
else {
String temp = sdf.format(se.getDateEnd());
expSEBean.setEndDate(temp);
}
if (se.getStartTimeFlag())
expSEBean.setStartDate(se.getDateStart() + "");
else {
String temp = sdf.format(se.getDateStart());
expSEBean.setStartDate(temp);
}
expSEBean.setStudyEventOID(se.getStudyEventDefinition().getOc_oid());
expSEBean.setStudyEventRepeatKey(se.getSampleOrdinal().toString());
if (se.getStudySubject().getSubject().getDateOfBirth() != null && se.getDateStart() != null)
expSEBean.setAgeAtEvent(Utils.getAge(se.getStudySubject().getSubject().getDateOfBirth(), se.getDateStart()));
expSEBean.setStatus(fetchStudyEventStatus(se.getSubjectEventStatusId()));
if (collectAudits)
expSEBean.setAuditLogs(fetchAuditLogs(se.getStudyEventId(), "study_event", se.getStudyEventDefinition().getOc_oid(), null));
if (collectDns)
expSEBean.setDiscrepancyNotes(fetchDiscrepancyNotes(se));
expSEBean.setExportFormData(getFormDataForClinicalStudy(ss, se, formVersionOID));
expSEBean.setStudyEventDefinition(se.getStudyEventDefinition());
al.add(expSEBean);
}
}
return al;
}
use of org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean in project OpenClinica by OpenClinica.
the class ClinicalDataReportBean method addNodeClinicalData.
public void addNodeClinicalData(boolean header, boolean footer) {
String ODMVersion = this.getODMVersion();
// when collecting data, only item with value has been collected.
StringBuffer xml = this.getXmlOutput();
String indent = this.getIndent();
String nls = System.getProperty("line.separator");
if (header) {
xml.append(indent + "<ClinicalData StudyOID=\"" + StringEscapeUtils.escapeXml(clinicalData.getStudyOID()) + "\" MetaDataVersionOID=\"" + StringEscapeUtils.escapeXml(this.clinicalData.getMetaDataVersionOID()) + "\">");
xml.append(nls);
}
ArrayList<ExportSubjectDataBean> subs = (ArrayList<ExportSubjectDataBean>) this.clinicalData.getExportSubjectData();
for (ExportSubjectDataBean sub : subs) {
xml.append(indent + indent + "<SubjectData SubjectKey=\"" + StringEscapeUtils.escapeXml(sub.getSubjectOID()));
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
xml.append("\" OpenClinica:StudySubjectID=\"" + StringEscapeUtils.escapeXml(sub.getStudySubjectId()));
String uniqueIdentifier = sub.getUniqueIdentifier();
if (uniqueIdentifier != null && uniqueIdentifier.length() > 0) {
xml.append("\" OpenClinica:UniqueIdentifier=\"" + StringEscapeUtils.escapeXml(uniqueIdentifier));
}
String status = sub.getStatus();
if (status != null && status.length() > 0) {
xml.append("\" OpenClinica:Status=\"" + StringEscapeUtils.escapeXml(status));
}
String secondaryId = sub.getSecondaryId();
if (secondaryId != null && secondaryId.length() > 0) {
xml.append("\" OpenClinica:SecondaryID=\"" + StringEscapeUtils.escapeXml(secondaryId));
}
Integer year = sub.getYearOfBirth();
if (year != null) {
xml.append("\" OpenClinica:YearOfBirth=\"" + sub.getYearOfBirth());
} else {
if (sub.getDateOfBirth() != null) {
xml.append("\" OpenClinica:DateOfBirth=\"" + sub.getDateOfBirth());
}
}
String gender = sub.getSubjectGender();
if (gender != null && gender.length() > 0) {
xml.append("\" OpenClinica:Sex=\"" + StringEscapeUtils.escapeXml(gender));
}
String enrollmentDate = sub.getEnrollmentDate();
if (enrollmentDate != null && enrollmentDate.length() > 0) {
xml.append("\" OpenClinica:EnrollmentDate=\"" + enrollmentDate);
}
}
xml.append("\">");
xml.append(nls);
//
ArrayList<ExportStudyEventDataBean> ses = (ArrayList<ExportStudyEventDataBean>) sub.getExportStudyEventData();
for (ExportStudyEventDataBean se : ses) {
xml.append(indent + indent + indent + "<StudyEventData StudyEventOID=\"" + StringEscapeUtils.escapeXml(se.getStudyEventOID()));
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
String location = se.getLocation();
if (location != null && location.length() > 0) {
xml.append("\" OpenClinica:StudyEventLocation=\"" + StringEscapeUtils.escapeXml(location));
}
String startDate = se.getStartDate();
if (startDate != null && startDate.length() > 0) {
xml.append("\" OpenClinica:StartDate=\"" + startDate);
}
String endDate = se.getEndDate();
if (endDate != null && endDate.length() > 0) {
xml.append("\" OpenClinica:EndDate=\"" + endDate);
}
String status = se.getStatus();
if (status != null && status.length() > 0) {
xml.append("\" OpenClinica:Status=\"" + StringEscapeUtils.escapeXml(status));
}
if (se.getAgeAtEvent() != null) {
xml.append("\" OpenClinica:SubjectAgeAtEvent=\"" + se.getAgeAtEvent());
}
}
xml.append("\"");
if (!"-1".equals(se.getStudyEventRepeatKey())) {
xml.append(" StudyEventRepeatKey=\"" + se.getStudyEventRepeatKey() + "\"");
}
xml.append(">");
xml.append(nls);
//
ArrayList<ExportFormDataBean> forms = se.getExportFormData();
for (ExportFormDataBean form : forms) {
xml.append(indent + indent + indent + indent + "<FormData FormOID=\"" + StringEscapeUtils.escapeXml(form.getFormOID()));
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
String formLayout = form.getFormLayout();
if (!StringUtils.isEmpty(formLayout)) {
xml.append("\" OpenClinica:FormLayoutOID=\"" + StringEscapeUtils.escapeXml(formLayout));
}
String interviewerName = form.getInterviewerName();
if (interviewerName != null && interviewerName.length() > 0) {
xml.append("\" OpenClinica:InterviewerName=\"" + StringEscapeUtils.escapeXml(interviewerName));
}
if (form.getInterviewDate() != null && form.getInterviewDate().length() > 0) {
xml.append("\" OpenClinica:InterviewDate=\"" + form.getInterviewDate());
}
String status = form.getStatus();
if (status != null && status.length() > 0) {
xml.append("\" OpenClinica:Status=\"" + StringEscapeUtils.escapeXml(status));
}
}
xml.append("\">");
xml.append(nls);
//
ArrayList<ImportItemGroupDataBean> igs = form.getItemGroupData();
sortImportItemGroupDataBeanList(igs);
for (ImportItemGroupDataBean ig : igs) {
xml.append(indent + indent + indent + indent + indent + "<ItemGroupData ItemGroupOID=\"" + StringEscapeUtils.escapeXml(ig.getItemGroupOID()) + "\" ");
if (!"-1".equals(ig.getItemGroupRepeatKey())) {
xml.append("ItemGroupRepeatKey=\"" + ig.getItemGroupRepeatKey() + "\" ");
}
if (ig.getItemData().get(0).isDeleted()) {
xml.append("OpenClinica:Removed=\"" + (ig.getItemData().get(0).isDeleted() ? "Yes" : "No") + "\" ");
}
xml.append("TransactionType=\"Insert\">");
xml.append(nls);
ArrayList<ImportItemDataBean> items = ig.getItemData();
sortImportItemDataBeanList(items);
for (ImportItemDataBean item : items) {
boolean printValue = true;
xml.append(indent + indent + indent + indent + indent + indent + "<ItemData ItemOID=\"" + StringEscapeUtils.escapeXml(item.getItemOID()) + "\" ");
if ("Yes".equals(item.getIsNull())) {
xml.append("IsNull=\"Yes\"");
if (!item.isHasValueWithNull()) {
printValue = false;
}
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
xml.append(" OpenClinica:ReasonForNull=\"" + StringEscapeUtils.escapeXml(item.getReasonForNull()) + "\" ");
if (!printValue) {
xml.append("/>");
xml.append(nls);
}
}
}
if (printValue) {
Boolean hasElm = false;
xml.append("Value=\"" + StringEscapeUtils.escapeXml(item.getValue()) + "\"");
String muRefOid = item.getMeasurementUnitRef().getElementDefOID();
if (muRefOid != null && muRefOid.length() > 0) {
if (hasElm) {
} else {
xml.append(">");
xml.append(nls);
hasElm = true;
}
xml.append(indent + indent + indent + indent + indent + indent + indent + "<MeasurementUnitRef MeasurementUnitOID=\"" + StringEscapeUtils.escapeXml(muRefOid) + "\"/>");
xml.append(nls);
}
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
if (item.getAuditLogs() != null && item.getAuditLogs().getAuditLogs().size() > 0) {
if (hasElm) {
} else {
xml.append(">");
xml.append(nls);
hasElm = true;
}
this.addAuditLogs(item.getAuditLogs(), indent + indent + indent + indent + indent + indent + indent, "item");
}
//
if (item.getDiscrepancyNotes() != null && item.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
if (hasElm) {
} else {
xml.append(">");
xml.append(nls);
hasElm = true;
}
this.addDiscrepancyNotes(item.getDiscrepancyNotes(), indent + indent + indent + indent + indent + indent + indent);
}
}
if (hasElm) {
xml.append(indent + indent + indent + indent + indent + indent + "</ItemData>");
xml.append(nls);
hasElm = false;
} else {
xml.append("/>");
xml.append(nls);
}
}
}
xml.append(indent + indent + indent + indent + indent + "</ItemGroupData>");
xml.append(nls);
}
//
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
if (form.getAuditLogs() != null && form.getAuditLogs().getAuditLogs().size() > 0) {
this.addAuditLogs(form.getAuditLogs(), indent + indent + indent + indent + indent, "form");
}
//
if (form.getDiscrepancyNotes() != null && form.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
this.addDiscrepancyNotes(form.getDiscrepancyNotes(), indent + indent + indent + indent + indent);
}
}
xml.append(indent + indent + indent + indent + "</FormData>");
xml.append(nls);
}
//
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
if (se.getAuditLogs() != null && se.getAuditLogs().getAuditLogs().size() > 0) {
this.addAuditLogs(se.getAuditLogs(), indent + indent + indent + indent, "se");
}
//
if (se.getDiscrepancyNotes() != null && se.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
this.addDiscrepancyNotes(se.getDiscrepancyNotes(), indent + indent + indent + indent);
}
}
xml.append(indent + indent + indent + "</StudyEventData>");
xml.append(nls);
}
if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
ArrayList<SubjectGroupDataBean> sgddata = (ArrayList<SubjectGroupDataBean>) sub.getSubjectGroupData();
if (sgddata.size() > 0) {
for (SubjectGroupDataBean sgd : sgddata) {
String cid = sgd.getStudyGroupClassId() != null ? "OpenClinica:StudyGroupClassID=\"" + StringEscapeUtils.escapeXml(sgd.getStudyGroupClassId()) + "\" " : "";
if (cid.length() > 0) {
String cn = sgd.getStudyGroupClassName() != null ? "OpenClinica:StudyGroupClassName=\"" + StringEscapeUtils.escapeXml(sgd.getStudyGroupClassName()) + "\" " : "";
String gn = sgd.getStudyGroupName() != null ? "OpenClinica:StudyGroupName=\"" + StringEscapeUtils.escapeXml(sgd.getStudyGroupName()) + "\" " : "";
xml.append(indent + indent + indent + "<OpenClinica:SubjectGroupData " + cid + cn + gn);
}
xml.append(" />");
xml.append(nls);
}
}
//
if (sub.getAuditLogs() != null && sub.getAuditLogs().getAuditLogs().size() > 0) {
this.addAuditLogs(sub.getAuditLogs(), indent + indent + indent, "sub");
}
//
if (sub.getDiscrepancyNotes() != null && sub.getDiscrepancyNotes().getDiscrepancyNotes().size() > 0) {
this.addDiscrepancyNotes(sub.getDiscrepancyNotes(), indent + indent + indent);
}
}
xml.append(indent + indent + "</SubjectData>");
xml.append(nls);
}
if (footer) {
xml.append(indent + "</ClinicalData>");
xml.append(nls);
}
}
use of org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method setDataWithOCAttributes.
protected void setDataWithOCAttributes(StudyBean study, DatasetBean dataset, OdmClinicalDataBean data, String odmVersion, Iterator iter, HashMap<Integer, String> oidPoses, String odmType) {
String subprev = "";
HashMap<String, Integer> sepos = new HashMap<String, Integer>();
String seprev = "";
String formprev = "";
HashMap<String, Integer> igpos = new HashMap<String, Integer>();
String igprev = "";
String oidPos = "";
StudyBean parentStudy = study.getParentStudyId() > 0 ? (StudyBean) new StudyDAO(this.ds).findByPK(study.getParentStudyId()) : study;
setStudyParemeterConfig(parentStudy);
HashSet<Integer> sgcIdSet = new HashSet<Integer>();
HashMap<String, String> subOidPoses = new HashMap<String, String>();
HashMap<String, String> evnOidPoses = new HashMap<String, String>();
String studySubjectOids = "";
String sedOids = "";
String ecIds = "";
while (iter.hasNext()) {
HashMap row = (HashMap) iter.next();
String studySubjectLabel = (String) row.get("study_subject_oid");
// String label = (String) row.get("label");
Integer sgcId = (Integer) row.get("sgc_id");
String sgcName = (String) row.get("sgc_name");
String sgName = (String) row.get("sg_name");
String sedOID = (String) row.get("definition_oid");
Boolean studyEventRepeating = (Boolean) row.get("definition_repeating");
Integer sampleOrdinal = (Integer) row.get("sample_ordinal");
Date startDate = (Date) row.get("date_start");
String cvOID = (String) row.get("crf_version_oid");
// ecId should
Integer ecId = (Integer) row.get("event_crf_id");
// be unique;
Date dob = (Date) row.get("date_of_birth");
CRFVersionBean cvBean = cvdao.findByOid(cvOID);
CRFBean cBean = (CRFBean) crfdao.findByPK(cvBean.getCrfId());
String key = studySubjectLabel;
ExportSubjectDataBean sub = new ExportSubjectDataBean();
if (subprev.equals(studySubjectLabel)) {
int p = data.getExportSubjectData().size() - 1;
sub = data.getExportSubjectData().get(p);
// ------ add openclinica subject_group
if (sgcId > 0) {
int presize = sgcIdSet.size();
sgcIdSet.add(sgcId);
if (sgcIdSet.size() > presize) {
sgcIdSet.add(sgcId);
SubjectGroupDataBean sgd = new SubjectGroupDataBean();
sgd.setStudyGroupClassId("SGC_" + sgcId);
sgd.setStudyGroupClassName(sgcName);
sgd.setStudyGroupName(sgName);
sub.getSubjectGroupData().add(sgd);
}
}
// ------ finish adding openclinica subject_group
} else {
subprev = studySubjectLabel;
studySubjectOids += "'" + studySubjectLabel + "', ";
sub.setSubjectOID(studySubjectLabel);
// ----- add openclinica subject attributes
sub.setStudySubjectId((String) row.get("label"));
if (dataset.isShowSubjectUniqueIdentifier()) {
sub.setUniqueIdentifier((String) row.get("unique_identifier"));
}
if (dataset.isShowSubjectSecondaryId()) {
sub.setSecondaryId((String) row.get("secondary_label"));
}
if (dob != null) {
if (dataset.isShowSubjectDob()) {
if (parentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
Calendar cal = Calendar.getInstance();
cal.setTime(dob);
int year = cal.get(Calendar.YEAR);
if (year > 0) {
sub.setYearOfBirth(year);
}
} else {
sub.setDateOfBirth(new SimpleDateFormat("yyyy-MM-dd").format(dob));
}
}
}
if (dataset.isShowSubjectGender()) {
sub.setSubjectGender((String) row.get("gender"));
}
if (dataset.isShowSubjectStatus()) {
sub.setStatus(Status.get((Integer) row.get("status_id")).getName());
}
// ------ add openclinica subject_group
if (sgcId > 0) {
sgcIdSet.clear();
sgcIdSet.add(sgcId);
SubjectGroupDataBean sgd = new SubjectGroupDataBean();
sgd.setStudyGroupClassId("SGC_" + sgcId);
sgd.setStudyGroupClassName(sgcName);
sgd.setStudyGroupName(sgName);
sub.getSubjectGroupData().add(sgd);
}
// ------ finish adding openclinica subject_group
data.getExportSubjectData().add(sub);
seprev = "";
formprev = "";
igprev = "";
}
oidPos = data.getExportSubjectData().size() - 1 + "";
subOidPoses.put(studySubjectLabel, oidPos);
ExportStudyEventDataBean se = new ExportStudyEventDataBean();
// key += sedOID + sampleOrdinal;
key += sedOID;
if (!seprev.equals(key) || !sepos.containsKey(key + sampleOrdinal)) {
sepos.put(key + sampleOrdinal, sub.getExportStudyEventData().size());
seprev = key;
sedOids += "'" + sedOID + "', ";
se.setStudyEventOID(sedOID);
// ----- add openclinica study event attributes
if (startDate != null && dataset.isShowSubjectAgeAtEvent() && dob != null) {
se.setAgeAtEvent(Utils.getAge(dob, startDate));
}
if (dataset.isShowEventLocation()) {
se.setLocation((String) row.get("se_location"));
}
if (dataset.isShowEventStart() && startDate != null) {
if ((Boolean) row.get("start_time_flag") == Boolean.TRUE) {
se.setStartDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(startDate));
} else {
se.setStartDate(new SimpleDateFormat("yyyy-MM-dd").format(startDate));
}
}
Date endDate = (Date) row.get("date_end");
if (dataset.isShowEventEnd() && endDate != null) {
if ((Boolean) row.get("end_time_flag") == Boolean.TRUE) {
se.setEndDate(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(endDate));
} else {
se.setEndDate(new SimpleDateFormat("yyyy-MM-dd").format(endDate));
}
}
if (dataset.isShowEventStatus()) {
se.setStatus(SubjectEventStatus.get((Integer) row.get("event_status_id")).getName());
}
// ----- finish adding study event attributes
se.setStudyEventRepeatKey(studyEventRepeating ? sampleOrdinal + "" : "-1");
sub.getExportStudyEventData().add(se);
formprev = "";
igprev = "";
} else {
se = sub.getExportStudyEventData().get(sepos.get(key + sampleOrdinal));
}
oidPos += "---" + (sub.getExportStudyEventData().size() - 1);
evnOidPoses.put(key, oidPos);
ExportFormDataBean form = new ExportFormDataBean();
key += cvOID;
if (formprev.equals(key)) {
form = se.getExportFormData().get(se.getExportFormData().size() - 1);
} else {
formprev = key;
ecIds += "'" + ecId + "', ";
form.setFormOID(cBean.getOid());
// ----- add openclinica crf attributes
if (dataset.isShowCRFversion()) {
form.setCrfVersion((String) row.get("crf_version"));
}
if (dataset.isShowCRFstatus()) {
form.setStatus(this.getCrfVersionStatus(se.getStatus(), (Integer) row.get("cv_status_id"), (Integer) row.get("ec_status_id"), (Integer) row.get("validator_id")));
}
if (dataset.isShowCRFinterviewerName()) {
form.setInterviewerName((String) row.get("interviewer_name"));
}
if (dataset.isShowCRFinterviewerDate()) {
try {
form.setInterviewDate(new SimpleDateFormat("yyyy-MM-dd").format((Date) row.get("date_interviewed")));
} catch (NullPointerException npe) {
logger.debug("caught NPE for interviewDate");
// Comment it out for: 11592. For this exaction function, interviewDate should be kept as the
// same as in database.
// form.setInterviewDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
}
}
// ----- finish adding crf attributes
se.getExportFormData().add(form);
igprev = "";
}
oidPos += "---" + (se.getExportFormData().size() - 1);
// ecId should be distinct
oidPoses.put(ecId, oidPos);
oidPos = "";
}
studySubjectOids = studySubjectOids.length() > 0 ? studySubjectOids.substring(0, studySubjectOids.length() - 2).trim() : studySubjectOids;
sedOids = sedOids.length() > 0 ? sedOids.substring(0, sedOids.length() - 2).trim() : sedOids;
ecIds = ecIds.length() > 0 ? ecIds.substring(0, ecIds.length() - 2).trim() : ecIds;
if (odmType != null && odmType.equalsIgnoreCase("clinical_data")) {
logger.debug("No Audit logs or discrepancy Notes");
} else {
if (studySubjectOids.length() > 0) {
this.setOCSubjectDataAuditLogs(parentStudy, data, studySubjectOids, subOidPoses);
this.setOCEventDataAuditLogs(parentStudy, data, studySubjectOids, evnOidPoses);
if (ecIds.length() > 0) {
this.setOCFormDataAuditLogs(parentStudy, data, studySubjectOids, ecIds, oidPoses);
} else {
logger.debug("OdmExtractDAO.setOCFormDataAuditLogs wasn't called because of empty ecIds");
}
this.setOCSubjectDataDNs(data, studySubjectOids, subOidPoses);
if (sedOids.length() > 0) {
this.setOCEventDataDNs(data, sedOids, studySubjectOids, evnOidPoses);
} else {
logger.info("OdmExtractDAO.setOCEventDataDNs wasn't called because of empty sedOids");
}
} else {
logger.debug("OdmExtractDAO methods(setOCSubjectDataAuditLogs,setOCEventDataAuditLogs,setOCFormDataAuditLogs," + "setOCSubjectDataDNs,setOCEventDataDNs) weren't called because of empty studySubjectOids");
}
if (ecIds.length() > 0) {
this.setOCFormDataDNs(data, ecIds, oidPoses);
} else {
logger.debug("OdmExtractDAO.setOCFormDataDNs wasn't called because of empty ecIds");
}
}
}
Aggregations