use of org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean 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 crfVersion = form.getCrfVersion();
if (crfVersion != null && crfVersion.length() > 0) {
xml.append("\" OpenClinica:Version=\"" + StringEscapeUtils.escapeXml(crfVersion));
}
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() + "\" ");
}
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;
String value = StringEscapeUtils.escapeXml(item.getValue());
if (value != null && value.indexOf("&#") > -1) {
value = item.getValue();
}
xml.append("Value=\"" + value + "\"");
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.ImportItemDataBean in project OpenClinica by OpenClinica.
the class GenerateClinicalDataServiceImpl method populateImportItemGrpBean.
private ArrayList<ImportItemGroupDataBean> populateImportItemGrpBean(HashMap<String, ArrayList<String>> oidMap, HashMap<String, List<ItemData>> oidDNAuditMap) {
Set<String> keysGrpOIDs = oidMap.keySet();
ArrayList<ImportItemGroupDataBean> iigDataBean = new ArrayList<ImportItemGroupDataBean>();
ImportItemGroupDataBean importItemGrpDataBean = new ImportItemGroupDataBean();
for (String grpOID : keysGrpOIDs) {
ArrayList<String> vals = oidMap.get(grpOID);
importItemGrpDataBean = new ImportItemGroupDataBean();
int groupIdx = grpOID.indexOf(GROUPOID_ORDINAL_DELIM);
if (groupIdx != -1) {
importItemGrpDataBean.setItemGroupOID(grpOID.substring(0, groupIdx));
importItemGrpDataBean.setItemGroupRepeatKey(grpOID.substring(groupIdx + 1, grpOID.length()));
ArrayList<ImportItemDataBean> iiDList = new ArrayList<ImportItemDataBean>();
for (String value : vals) {
ImportItemDataBean iiDataBean = new ImportItemDataBean();
int index = value.indexOf(DELIMITER);
if (!value.trim().equalsIgnoreCase(DELIMITER)) {
iiDataBean.setItemOID(value.substring(0, index));
iiDataBean.setValue(value.substring(index + 1, value.length()));
if (isCollectAudits() || isCollectDns()) {
iiDataBean = fetchItemDataAuditValue(oidDNAuditMap.get(grpOID), iiDataBean);
}
// if(isCollectDns())
// iiDataBean.setDiscrepancyNotes(fetchDiscrepancyNotes(oidDNAuditMap.get(grpOID)));
iiDList.add(iiDataBean);
}
}
importItemGrpDataBean.setItemData(iiDList);
iigDataBean.add(importItemGrpDataBean);
}
}
return iigDataBean;
}
use of org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean in project OpenClinica by OpenClinica.
the class TriggerService method generateHardValidationErrorMessage.
public String generateHardValidationErrorMessage(ArrayList<SubjectDataBean> subjectData, HashMap<String, String> hardValidationErrors, boolean isValid) {
StringBuffer sb = new StringBuffer();
String studyEventRepeatKey = "1";
String groupRepeatKey = "1";
sb.append("<table border=\'0\' cellpadding=\'0\' cellspacing=\'0\' width=\'100%\'>");
for (SubjectDataBean subjectDataBean : subjectData) {
sb.append("<tr valign=\'top\'> <td class=\'table_header_row\' colspan=\'4\'>Study Subject: " + subjectDataBean.getSubjectOID() + "</td> </tr>");
// next step here
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
sb.append("<tr valign=\'top\'> <td class=\'table_header_row\'>Event CRF OID</td> <td class=\'table_header_row\' colspan=\'3\'></td>");
sb.append("</tr> <tr valign=\'top\'> <td class=\'table_cell_left\'>");
sb.append(studyEventDataBean.getStudyEventOID());
if (studyEventDataBean.getStudyEventRepeatKey() != null) {
studyEventRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
sb.append(" (Repeat key " + studyEventDataBean.getStudyEventRepeatKey() + ")");
} else {
// reset
studyEventRepeatKey = "1";
}
sb.append("</td> <td class=\'table_cell\' colspan=\'3\'></td> </tr>");
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
for (FormDataBean formDataBean : formDataBeans) {
sb.append("<tr valign=\'top\'> <td class=\'table_header_row\'></td> ");
sb.append("<td class=\'table_header_row\'>CRF Version OID</td> <td class=\'table_header_row\' colspan=\'2\'></td></tr>");
sb.append("<tr valign=\'top\'> <td class=\'table_cell_left\'></td> <td class=\'table_cell\'>");
sb.append(formDataBean.getFormOID());
sb.append("</td> <td class=\'table_cell\' colspan=\'2\'></td> </tr>");
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
sb.append("<tr valign=\'top\'> <td class=\'table_header_row\'></td>");
sb.append("<td class=\'table_header_row\'></td> <td class=\'table_header_row\' colspan=\'2\'>");
sb.append(itemGroupDataBean.getItemGroupOID());
if (itemGroupDataBean.getItemGroupRepeatKey() != null) {
groupRepeatKey = itemGroupDataBean.getItemGroupRepeatKey();
sb.append(" (Repeat key " + itemGroupDataBean.getItemGroupRepeatKey() + ")");
} else {
groupRepeatKey = "1";
}
sb.append("</td></tr>");
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
for (ImportItemDataBean itemDataBean : itemDataBeans) {
String oidKey = itemDataBean.getItemOID() + "_" + studyEventRepeatKey + "_" + groupRepeatKey + "_" + subjectDataBean.getSubjectOID();
if (!isValid) {
if (hardValidationErrors.containsKey(oidKey)) {
sb.append("<tr valign=\'top\'> <td class=\'table_cell_left\'></td>");
sb.append("<td class=\'table_cell\'></td> <td class=\'table_cell\'><font color=\'red\'>");
sb.append(itemDataBean.getItemOID());
sb.append("</font></td> <td class=" + "\'table_cell\'>");
sb.append(itemDataBean.getValue() + "<br/>");
sb.append(hardValidationErrors.get(oidKey));
sb.append("</td></tr>");
/*
* <tr valign="top"> <td class="table_cell_left"></td> <td class="table_cell"></td>
* <td class="table_cell"><font color="red"><c:out
* value="${itemData.itemOID}"/></font></td> <td class="table_cell"> <c:out
* value="${itemData.value}"/><br/> <c:out value="${hardValidationErrors[oidKey]}"/>
* </td> </tr>
*/
}
} else {
if (!hardValidationErrors.containsKey(oidKey)) {
sb.append("<tr valign=\'top\'> <td class=\'table_cell_left\'></td>");
sb.append("<td class=\'table_cell\'></td> <td class=\'table_cell\'>");
sb.append(itemDataBean.getItemOID());
sb.append("</td> <td class=" + "\'table_cell\'>");
sb.append(itemDataBean.getValue());
sb.append("</td></tr>");
}
}
}
}
}
}
}
sb.append("</table>");
return sb.toString();
}
use of org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean in project OpenClinica by OpenClinica.
the class TriggerService method generateHardValidationErrorMessage.
public String generateHardValidationErrorMessage(ArrayList<SubjectDataBean> subjectData, HashMap<String, String> hardValidationErrors, String groupRepeatKey) {
StringBuffer sb = new StringBuffer();
String studyEventRepeatKey = null;
sb.append("");
for (SubjectDataBean subjectDataBean : subjectData) {
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
studyEventRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
for (FormDataBean formDataBean : formDataBeans) {
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
for (ImportItemDataBean itemDataBean : itemDataBeans) {
String oidKey = itemDataBean.getItemOID() + "_" + studyEventRepeatKey + "_" + groupRepeatKey + "_" + subjectDataBean.getSubjectOID();
if (hardValidationErrors.containsKey(oidKey)) {
// What about event repeat ordinal and item group and item group repeat ordinal?
sb.append(subjectDataBean.getSubjectOID() + "." + studyEventDataBean.getStudyEventOID());
if (studyEventDataBean.getStudyEventRepeatKey() != null)
sb.append("(" + studyEventDataBean.getStudyEventRepeatKey() + ")");
sb.append("." + formDataBean.getFormOID() + "." + itemGroupDataBean.getItemGroupOID());
if (itemGroupDataBean.getItemGroupRepeatKey() != null)
sb.append("(" + itemGroupDataBean.getItemGroupRepeatKey() + ")");
sb.append("." + itemDataBean.getItemOID());
sb.append(": ");
sb.append(itemDataBean.getValue() + " -- ");
sb.append(hardValidationErrors.get(oidKey));
sb.append("");
}
}
}
}
}
}
sb.append("");
return sb.toString();
}
use of org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean in project OpenClinica by OpenClinica.
the class ImportCRFDataService method lookupValidationErrors.
public List<DisplayItemBeanWrapper> lookupValidationErrors(HttpServletRequest request, ODMContainer odmContainer, UserAccountBean ub, HashMap<String, String> totalValidationErrors, HashMap<String, String> hardValidationErrors, ArrayList<Integer> permittedEventCRFIds) throws OpenClinicaException {
DisplayItemBeanWrapper displayItemBeanWrapper = null;
HashMap validationErrors = new HashMap();
List<DisplayItemBeanWrapper> wrappers = new ArrayList<DisplayItemBeanWrapper>();
ImportHelper importHelper = new ImportHelper();
FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
DiscrepancyValidator discValidator = new DiscrepancyValidator(request, discNotes);
// create a second Validator, this one for hard edit checks
HashMap<String, String> hardValidator = new HashMap<String, String>();
StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
StudyDAO studyDAO = new StudyDAO(ds);
StudyBean studyBean = studyDAO.findByOid(odmContainer.getCrfDataPostImportContainer().getStudyOID());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(ds);
HashMap<String, ItemDataBean> blankCheck = new HashMap<String, ItemDataBean>();
String hardValidatorErrorMsgs = "";
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
int totalEventCRFCount = 0;
int totalItemDataBeanCount = 0;
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<DisplayItemBean> displayItemBeans = new ArrayList<DisplayItemBean>();
logger.debug("iterating through subject data beans: found " + subjectDataBean.getSubjectOID());
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
totalEventCRFCount += studyEventDataBeans.size();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
int parentStudyId = studyBean.getParentStudyId();
StudyEventDefinitionBean sedBean = sedDao.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), parentStudyId);
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
logger.debug("iterating through study event data beans: found " + studyEventDataBean.getStudyEventOID());
int ordinal = 1;
try {
ordinal = new Integer(studyEventDataBean.getStudyEventRepeatKey()).intValue();
} catch (Exception e) {
// trying to catch NPEs, because tags can be without the
// repeat key
}
StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), sedBean.getId(), ordinal);
displayItemBeans = new ArrayList<DisplayItemBean>();
for (FormDataBean formDataBean : formDataBeans) {
Map<String, Integer> groupMaxOrdinals = new HashMap<String, Integer>();
displayItemBeanWrapper = null;
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
EventCRFDAO eventCRFDAO = new EventCRFDAO(ds);
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
if ((crfVersionBeans == null) || (crfVersionBeans.size() == 0)) {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("your_crf_version_oid_did_not_generate"));
Object[] arguments = { formDataBean.getFormOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
CRFVersionBean crfVersion = crfVersionBeans.get(0);
// if you have a mispelled form oid you get an error here
// need to error out gracefully and post an error
logger.debug("iterating through form beans: found " + crfVersion.getOid());
// may be the point where we cut off item groups etc and
// instead work on sections
EventCRFBean eventCRFBean = eventCRFDAO.findByEventCrfVersion(studyEvent, crfVersion);
EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(ds);
EventDefinitionCRFBean eventDefinitionCRF = eventDefinitionCRFDAO.findByStudyEventIdAndCRFVersionId(studyBean, studyEvent.getId(), crfVersion.getId());
if (eventCRFBean != null) {
if (permittedEventCRFIds.contains(new Integer(eventCRFBean.getId()))) {
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
groupMaxOrdinals.put(itemGroupDataBean.getItemGroupOID(), 1);
}
// correctness, tbh
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
ArrayList<ItemBean> blankCheckItems = new ArrayList<ItemBean>();
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
logger.debug("iterating through group beans: " + itemGroupDataBean.getItemGroupOID());
// put a checker in here
ItemGroupDAO itemGroupDAO = new ItemGroupDAO(ds);
ItemGroupBean testBean = itemGroupDAO.findByOid(itemGroupDataBean.getItemGroupOID());
if (testBean == null) {
// TODO i18n of message
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("your_item_group_oid_for_form_oid"));
Object[] arguments = { itemGroupDataBean.getItemGroupOID(), formDataBean.getFormOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
totalItemDataBeanCount += itemDataBeans.size();
for (ImportItemDataBean importItemDataBean : itemDataBeans) {
logger.debug(" iterating through item data beans: " + importItemDataBean.getItemOID());
ItemDAO itemDAO = new ItemDAO(ds);
ItemFormMetadataDAO itemFormMetadataDAO = new ItemFormMetadataDAO(ds);
List<ItemBean> itemBeans = itemDAO.findByOid(importItemDataBean.getItemOID());
if (!itemBeans.isEmpty()) {
ItemBean itemBean = itemBeans.get(0);
logger.debug(" found " + itemBean.getName());
// throw a null pointer? hopefully not if its been checked...
DisplayItemBean displayItemBean = new DisplayItemBean();
displayItemBean.setItem(itemBean);
ArrayList<ItemFormMetadataBean> metadataBeans = itemFormMetadataDAO.findAllByItemId(itemBean.getId());
logger.debug(" found metadata item beans: " + metadataBeans.size());
int groupOrdinal = 1;
if (itemGroupDataBean.getItemGroupRepeatKey() != null) {
try {
groupOrdinal = new Integer(itemGroupDataBean.getItemGroupRepeatKey()).intValue();
if (groupOrdinal > groupMaxOrdinals.get(itemGroupDataBean.getItemGroupOID())) {
groupMaxOrdinals.put(itemGroupDataBean.getItemGroupOID(), groupOrdinal);
}
} catch (Exception e) {
// do nothing here currently, we are
// looking for a number format
// exception
// from the above.
logger.debug("found npe for group ordinals, line 344!");
}
}
ItemDataBean itemDataBean = createItemDataBean(itemBean, eventCRFBean, importItemDataBean.getValue(), ub, groupOrdinal);
blankCheckItems.add(itemBean);
String newKey = groupOrdinal + "_" + itemGroupDataBean.getItemGroupOID() + "_" + itemBean.getOid() + "_" + subjectDataBean.getSubjectOID();
blankCheck.put(newKey, itemDataBean);
logger.info("adding " + newKey + " to blank checks");
if (!metadataBeans.isEmpty()) {
ItemFormMetadataBean metadataBean = metadataBeans.get(0);
// also possible nullpointer
displayItemBean.setData(itemDataBean);
displayItemBean.setMetadata(metadataBean);
displayItemBean.setEventDefinitionCRF(eventDefinitionCRF);
String eventCRFRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
// if you do indeed leave off this in the XML it will pass but return 'null'
// tbh
attachValidator(displayItemBean, importHelper, discValidator, hardValidator, request, eventCRFRepeatKey, studySubjectBean.getOid());
displayItemBeans.add(displayItemBean);
} else {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("no_metadata_could_be_found"));
Object[] arguments = { importItemDataBean.getItemOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
} else {
// report the error there
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("no_item_could_be_found"));
Object[] arguments = { importItemDataBean.getItemOID() };
throw new OpenClinicaException(mf.format(arguments), "");
}
}
// end item data beans
logger.debug(".. found blank check: " + blankCheck.toString());
for (int i = 1; i <= groupMaxOrdinals.get(itemGroupDataBean.getItemGroupOID()); i++) {
for (ItemBean itemBean : blankCheckItems) {
String newKey = i + "_" + itemGroupDataBean.getItemGroupOID() + "_" + itemBean.getOid() + "_" + subjectDataBean.getSubjectOID();
if (blankCheck.get(newKey) == null) {
// if it already exists, Do Not Add It.
ItemDataBean itemDataCheck = getItemDataDao().findByItemIdAndEventCRFIdAndOrdinal(itemBean.getId(), eventCRFBean.getId(), i);
logger.debug("found item data bean id: " + itemDataCheck.getId() + " for ordinal " + i);
if (itemDataCheck.getId() == 0) {
ItemDataBean blank = createItemDataBean(itemBean, eventCRFBean, "", ub, i);
DisplayItemBean displayItemBean = new DisplayItemBean();
displayItemBean.setItem(itemBean);
displayItemBean.setData(blank);
// displayItemBean.setMetadata(metadataBean);
// set event def crf?
displayItemBean.setEventDefinitionCRF(eventDefinitionCRF);
String eventCRFRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
// if you do indeed leave off this in the XML it will pass but return
// 'null'
// tbh
displayItemBeans.add(displayItemBean);
logger.debug("... adding display item bean");
}
}
logger.debug("found a blank at " + i + ", adding " + blankCheckItems.size() + " blank items");
}
}
// << tbh #5548
blankCheckItems = new ArrayList<ItemBean>();
}
// end item group data beans
}
// matches if on permittedCRFIDs
CRFDAO crfDAO = new CRFDAO(ds);
CRFBean crfBean = crfDAO.findByVersionId(crfVersion.getCrfId());
// seems like an extravagance, but is not contained in crf
// version or event crf bean
validationErrors = discValidator.validate();
// totalValidationErrors.addAll(validationErrors);
for (Object errorKey : validationErrors.keySet()) {
// JN: to avoid duplicate errors
if (!totalValidationErrors.containsKey(errorKey.toString()))
totalValidationErrors.put(errorKey.toString(), validationErrors.get(errorKey).toString());
// assuming that this will be put back in to the core
// method's hashmap, updating statically, tbh 06/2008
logger.debug("+++ adding " + errorKey.toString());
}
logger.debug("-- hard validation checks: --");
for (Object errorKey : hardValidator.keySet()) {
logger.debug(errorKey.toString() + " -- " + hardValidator.get(errorKey));
hardValidationErrors.put(errorKey.toString(), hardValidator.get(errorKey));
// updating here 'statically' tbh 06/2008
hardValidatorErrorMsgs += hardValidator.get(errorKey) + "<br/><br/>";
}
String studyEventId = studyEvent.getId() + "";
String crfVersionId = crfVersion.getId() + "";
logger.debug("creation of wrapper: original count of display item beans " + displayItemBeans.size() + ", count of item data beans " + totalItemDataBeanCount + " count of validation errors " + validationErrors.size() + " count of study subjects " + subjectDataBeans.size() + " count of event crfs " + totalEventCRFCount + " count of hard error checks " + hardValidator.size());
// check if we need to overwrite
DataEntryStage dataEntryStage = eventCRFBean.getStage();
Status eventCRFStatus = eventCRFBean.getStatus();
boolean overwrite = false;
// //JN: Commenting out the following 2 lines, coz the prompt should come in the cases on
if (// eventCRFStatus.equals(Status.UNAVAILABLE) ||
dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
overwrite = true;
}
// << tbh, adding extra statuses to prevent appending, 06/2009
// SummaryStatsBean ssBean = new SummaryStatsBean();
// ssBean.setDiscNoteCount(totalValidationErrors);
// ssBean.setEventCrfCount(totalEventCRFCount);
// ssBean.setStudySubjectCount(subjectDataBeans.size());
// // add other stats here, tbh
// not working here, need to do it in a different method,
// tbh
// summary stats added tbh 05/2008
// JN: Changed from validationErrors to totalValidationErrors to create discrepancy notes for
// all
// the
displayItemBeanWrapper = new DisplayItemBeanWrapper(displayItemBeans, true, overwrite, validationErrors, studyEventId, crfVersionId, studyEventDataBean.getStudyEventOID(), studySubjectBean.getLabel(), eventCRFBean.getCreatedDate(), crfBean.getName(), crfVersion.getName(), studySubjectBean.getOid(), studyEventDataBean.getStudyEventRepeatKey());
// JN: Commenting out the following code, since we shouldn't re-initialize at this point, as
// validationErrors would get overwritten and the
// older errors will be overriden. Moving it after the form.
// Removing the comments for now, since it seems to be creating duplicate Discrepancy Notes.
validationErrors = new HashMap();
discValidator = new DiscrepancyValidator(request, discNotes);
// reset to allow for new errors...
}
}
// discValidator = new DiscrepancyValidator(request, discNotes);
if (displayItemBeanWrapper != null && displayItemBeans.size() > 0)
wrappers.add(displayItemBeanWrapper);
}
// after study events
// remove repeats here? remove them below by only forwarding the
// first
// each wrapper represents an Event CRF and a Form, but we don't
// have all events for all forms
// need to not add a wrapper for every event + form combination,
// but instead for every event + form combination which is present
// look at the hack below and see what happens
}
// thrown, tbh 06/2008
if (!hardValidator.isEmpty()) {
// throw new OpenClinicaException(hardValidatorErrorMsgs, "");
}
return wrappers;
}
Aggregations