use of org.akaza.openclinica.bean.odmbeans.ElementRefBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method setOCSubjectDataDNs.
protected void setOCSubjectDataDNs(OdmClinicalDataBean data, String studySubjectOids, HashMap<String, String> subOidPoses) {
this.setOCSubjectDataDNsTypesExpected();
HashMap<String, ArrayList<ChildNoteBean>> pDNs = new HashMap<String, ArrayList<ChildNoteBean>>();
// HashMap<String, ArrayList<DiscrepancyNoteBean>> sDNs = new HashMap<String, ArrayList<DiscrepancyNoteBean>>();
logger.debug("Begin to execute GetOCSubjectDataDNsSql");
logger.debug("getOCSubjectDataDNsSql= " + this.getOCSubjectDataDNsSql(studySubjectOids));
ArrayList rows = select(this.getOCSubjectDataDNsSql(studySubjectOids));
Iterator iter = rows.iterator();
while (iter.hasNext()) {
HashMap row = (HashMap) iter.next();
String studySubjectLabel = (String) row.get("study_subject_oid");
Integer pdnId = (Integer) row.get("parent_dn_id");
Integer dnId = (Integer) row.get("dn_id");
String description = (String) row.get("description");
String detailedNote = (String) row.get("detailed_notes");
Integer ownerId = (Integer) row.get("owner_id");
Date dateCreated = (Date) row.get("date_created");
String status = (String) row.get("status");
String noteType = (String) row.get("name");
if (pdnId != null && pdnId > 0) {
String key = studySubjectLabel + "-" + pdnId;
ChildNoteBean cn = new ChildNoteBean();
cn.setDateCreated(dateCreated);
cn.setDescription(description);
cn.setDetailedNote(detailedNote);
cn.setStatus(status);
cn.setOid("CDN_" + dnId);
ElementRefBean userRef = new ElementRefBean();
userRef.setElementDefOID("USR_" + ownerId);
cn.setUserRef(userRef);
ArrayList<ChildNoteBean> cns = pDNs.containsKey(key) ? pDNs.get(key) : new ArrayList<ChildNoteBean>();
cns.add(cn);
pDNs.put(key, cns);
} else {
DiscrepancyNoteBean dn = new DiscrepancyNoteBean();
String k = studySubjectLabel + "-" + dnId;
if (pDNs != null && pDNs.containsKey(k)) {
dn.setChildNotes(pDNs.get(k));
dn.setNumberOfChildNotes(dn.getChildNotes().size());
}
dn.setDateUpdated(dateCreated);
dn.setNoteType(noteType);
dn.setStatus(status);
dn.setOid("DN_" + dnId);
ElementRefBean userRef = new ElementRefBean();
userRef.setElementDefOID("USR_" + ownerId);
if (subOidPoses.containsKey(studySubjectLabel)) {
int i = Integer.parseInt(subOidPoses.get(studySubjectLabel));
String entityID = data.getExportSubjectData().get(i).getSubjectOID();
data.getExportSubjectData().get(i).getDiscrepancyNotes().setEntityID(entityID);
data.getExportSubjectData().get(i).getDiscrepancyNotes().getDiscrepancyNotes().add(dn);
}
}
}
}
use of org.akaza.openclinica.bean.odmbeans.ElementRefBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method fetchItemGroupMetaData.
private void fetchItemGroupMetaData(MetaDataVersionBean metadata, String cvIds, String odmVersion) {
ArrayList rows = select(this.getItemDataMaxLengths(cvIds));
Iterator it = rows.iterator();
HashMap maxLengths = null;
// while (it.hasNext()) {
// HashMap row = (HashMap) it.next();
// maxLengths.put((Integer) row.get("item_id"), (Integer) row.get("max_length"));
// }
this.setItemGroupAndItemMetaWithUnitTypesExpected();
rows.clear();
logger.debug("Begin to execute GetItemGroupAndItemMetaWithUnitSql");
logger.debug("getItemGroupandItemMetaWithUnitsql= " + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
rows = select(this.getItemGroupAndItemMetaWithUnitSql(cvIds));
it = rows.iterator();
ArrayList<ItemGroupDefBean> itemGroupDefs = (ArrayList<ItemGroupDefBean>) metadata.getItemGroupDefs();
ArrayList<ItemDefBean> itemDefs = (ArrayList<ItemDefBean>) metadata.getItemDefs();
ArrayList<CodeListBean> codeLists = (ArrayList<CodeListBean>) metadata.getCodeLists();
ArrayList<MultiSelectListBean> multiSelectLists = (ArrayList<MultiSelectListBean>) metadata.getMultiSelectLists();
ArrayList<ElementRefBean> itemGroupRefs = new ArrayList<ElementRefBean>();
Set<String> igset = new HashSet<String>();
HashMap<String, Integer> igdPos = new HashMap<String, Integer>();
Set<String> itset = new HashSet<String>();
Set<Integer> itdset = new HashSet<Integer>();
Set<Integer> clset = new HashSet<Integer>();
Set<Integer> mslset = new HashSet<Integer>();
ItemGroupDefBean igdef = new ItemGroupDefBean();
HashMap<String, String> igMandatories = new HashMap<String, String>();
boolean isLatest = false;
int cvprev = -1;
String igrprev = "";
String igdprev = "";
String itMandatory = "No";
int itOrder = 0;
Integer igId = -1;
String sectionIds = ",";
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
Integer cId = (Integer) row.get("crf_id");
Integer cvId = (Integer) row.get("crf_version_id");
igId = (Integer) row.get("item_group_id");
Integer itId = (Integer) row.get("item_id");
Integer rsId = (Integer) row.get("response_set_id");
String cvOID = (String) row.get("crf_version_oid");
String igOID = (String) row.get("item_group_oid");
String itOID = (String) row.get("item_oid");
String igName = (String) row.get("item_group_name");
String itName = (String) row.get("item_name");
Integer dataTypeId = (Integer) row.get("item_data_type_id");
Integer secId = (Integer) row.get("section_id");
String header = (String) row.get("item_header");
String left = (String) row.get("left_item_text");
String right = (String) row.get("right_item_text");
Boolean itRequired = (Boolean) row.get("item_required");
String regexp = (String) row.get("regexp");
String regexpErr = (String) row.get("regexp_error_msg");
String widthDecimal = (String) row.get("width_decimal");
Integer rsTypeId = (Integer) row.get("response_type_id");
String rsText = (String) row.get("options_text");
String rsValue = (String) row.get("options_values");
String rsLabel = (String) row.get("response_label");
String igHeader = (String) row.get("item_group_header");
Boolean isRepeating = (Boolean) row.get("repeating_group");
String itDesc = (String) row.get("item_description");
String itQuesNum = (String) row.get("question_number_label");
String muOid = (String) row.get("mu_oid");
if (cvprev != cvId) {
// at this point, itemGroupRefs is for old cvId
if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
String temp = igMandatories.containsKey(igdprev) ? igMandatories.get(igdprev) : itMandatory;
itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(temp);
}
itMandatory = "No";
// now update to new cvId
cvprev = cvId;
FormDefBean formDef = new FormDefBean();
HashMap cvIdPoses = null;
// if (cvIdPoses.containsKey(cvId)) {
// int p = (Integer) cvIdPoses.get(cvId);
// formDef = metadata.getFormDefs().get(p);
// } else {
// logger.debug("crf_version_id=" + cvId + " couldn't find from studyEventAndFormMetaSql");
// }
itemGroupRefs = (ArrayList<ElementRefBean>) formDef.getItemGroupRefs();
}
// mandatory is based on the last crf-version
String igDefKey = igId + "";
if (!igdprev.equals(igDefKey)) {
if (igdPos.containsKey(igDefKey)) {
igdef = itemGroupDefs.get(igdPos.get(igDefKey));
isLatest = false;
itOrder = igdef.getItemRefs().size();
} else {
igdef = new ItemGroupDefBean();
itOrder = 0;
igMandatories.put(igdprev, itMandatory);
isLatest = true;
igdef.setOid(igOID);
igdef.setName("ungrouped".equalsIgnoreCase(igName) ? igOID : igName);
// igdef.setName(igName);
igdef.setRepeating(isRepeating ? "Yes" : "No");
igdef.setComment(igHeader);
igdef.setPreSASDatasetName(igName.toUpperCase());
itemGroupDefs.add(igdef);
igdPos.put(igDefKey, itemGroupDefs.size() - 1);
}
igdprev = igDefKey;
}
String igRefKey = igId + "-" + cvId;
if (igrprev.equals(igRefKey)) {
itMandatory = isLatest && itRequired && "No".equals(itMandatory) ? "Yes" : itMandatory;
} else {
if (!igset.contains(igRefKey)) {
igset.add(igRefKey);
ElementRefBean igref = new ElementRefBean();
igref.setElementDefOID(igOID);
int size = itemGroupRefs.size();
if (size > 0) {
String prev = igrprev.split("-")[0].trim();
String temp = igMandatories.containsKey(prev) ? igMandatories.get(prev) : itMandatory;
itemGroupRefs.get(size - 1).setMandatory(temp);
}
itemGroupRefs.add(igref);
itMandatory = "No";
}
igrprev = igRefKey;
}
String mandatory = itRequired ? "Yes" : "No";
if (!itset.contains(igDefKey + "-" + itId)) {
++itOrder;
itset.add(igDefKey + "-" + itId);
ElementRefBean itemRef = new ElementRefBean();
itemRef.setElementDefOID(itOID);
if (itemRef.getMandatory() == null || itemRef.getMandatory().length() <= 0) {
itemRef.setMandatory(mandatory);
}
itemRef.setOrderNumber(itOrder);
igdef.getItemRefs().add(itemRef);
}
boolean hasCode = MetadataUnit.needCodeList(rsTypeId, dataTypeId);
LinkedHashMap<String, String> codes = new LinkedHashMap<String, String>();
if (hasCode) {
/*
* //null value will not be added to codelist if (nullMap.containsKey(cvId)) { codes =
* MetadataUnit.parseCode(rsText, rsValue,
* nullMap.get(cvId)); } else { codes = MetadataUnit.parseCode(rsText, rsValue); }
*/
codes = MetadataUnit.parseCode(rsText, rsValue);
// no action has been taken if rsvalue/rstext go wrong,
// since they have been validated when uploading crf.
}
boolean hasMultiSelect = MetadataUnit.needMultiSelectList(rsTypeId);
LinkedHashMap<String, String> multi = new LinkedHashMap<String, String>();
if (hasMultiSelect) {
multi = MetadataUnit.parseCode(rsText, rsValue);
// no action has been taken if rsvalue/rstext go wrong,
// since they have been validated when uploading crf.
}
String datatype = MetadataUnit.getOdmItemDataType(rsTypeId, dataTypeId, odmVersion);
if (sectionIds.contains("," + secId + ",")) {
} else {
sectionIds += secId + ",";
}
if (!itdset.contains(itId)) {
itdset.add(itId);
ItemDefBean idef = new ItemDefBean();
idef.setOid(itOID);
idef.setName(itName);
idef.setComment(itDesc);
if (muOid != null && muOid.length() > 0) {
ElementRefBean measurementUnitRef = new ElementRefBean();
measurementUnitRef.setElementDefOID(muOid);
idef.setMeasurementUnitRef(measurementUnitRef);
}
idef.setPreSASFieldName(itName);
idef.setCodeListOID(hasCode ? "CL_" + rsId : "");
if (hasMultiSelect) {
ElementRefBean multiSelectListRef = new ElementRefBean();
multiSelectListRef.setElementDefOID("MSL_" + rsId);
idef.setMultiSelectListRef(multiSelectListRef);
}
// if(nullMap.containsKey(cvId)) {
// }
idef.getQuestion().setQuestionNumber(itQuesNum);
idef.getQuestion().getQuestion().setText(MetadataUnit.getItemQuestionText(header, left, right));
if (regexp != null && regexp.startsWith("func:")) {
idef.setRangeCheck(MetadataUnit.getItemRangeCheck(regexp.substring(5).trim(), metadata.getSoftHard(), regexpErr, muOid));
}
idef.setDataType(datatype);
int len = 0;
int sig = 0;
if (widthDecimal != null && widthDecimal.length() > 0) {
// now there is no validation for width_decimal here.
len = parseWidth(widthDecimal);
sig = parseDecimal(widthDecimal);
}
if (rsTypeId == 3 || rsTypeId == 7) {
// 3:checkbox;
// //7:multi-select
// len = maxLengths.containsKey(itId) ? maxLengths.get(itId) : 0;
// len = Math.max(len, Math.max(rsText.length(), rsValue.length()));
Iterator<String> iter = multi.keySet().iterator();
String temp = "";
while (iter.hasNext()) {
temp += iter.next();
temp += ",";
}
idef.setLength(temp.length());
} else if ("text".equalsIgnoreCase(datatype)) {
if (len > 0) {
idef.setLength(len);
} else {
// idef.setLength((Integer) (hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) :
// maxLengths.containsKey(itId) ? maxLengths.get(itId) : MetaDataCollector.getTextLength()));
idef.setLength(0);
}
} else if ("integer".equalsIgnoreCase(datatype)) {
if (len > 0) {
idef.setLength(len);
} else {
idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 10);
}
} else if ("float".equalsIgnoreCase(datatype)) {
if (len > 0) {
idef.setLength(len);
} else {
// idef.setLength(hasCode ?
// MetadataUnit.getDataTypeLength(codes.keySet()) : 32);
idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 25);
}
} else {
idef.setLength(0);
}
idef.setSignificantDigits(sig > 0 ? sig : MetadataUnit.getSignificantDigits(datatype, codes.keySet(), hasCode));
itemDefs.add(idef);
}
if (hasCode && !clset.contains(rsId)) {
clset.add(rsId);
CodeListBean cl = new CodeListBean();
cl.setOid("CL_" + rsId);
cl.setName(rsLabel);
cl.setPreSASFormatName(rsLabel);
cl.setDataType(datatype);
Iterator<String> iter = codes.keySet().iterator();
while (iter.hasNext()) {
String de = iter.next();
CodeListItemBean cli = new CodeListItemBean();
cli.setCodedValue(de);
TranslatedTextBean tt = cli.getDecode();
// cli.getDecode().setText(codes.get(de));
tt.setText(codes.get(de));
tt.setXmlLang(CoreResources.getField("translated_text_language"));
cli.setDecode(tt);
cl.getCodeListItems().add(cli);
}
codeLists.add(cl);
}
if (odmVersion.startsWith("oc") && hasMultiSelect && !mslset.contains(rsId)) {
mslset.add(rsId);
MultiSelectListBean msl = new MultiSelectListBean();
msl.setOid("MSL_" + rsId);
msl.setName(rsLabel);
msl.setDataType(datatype);
msl.setActualDataType(datatype);
Iterator<String> iter = multi.keySet().iterator();
while (iter.hasNext()) {
String de = iter.next();
MultiSelectListItemBean msli = new MultiSelectListItemBean();
msli.setCodedOptionValue(de);
TranslatedTextBean tt = new TranslatedTextBean();
String t = multi.get(de);
tt.setText(t);
tt.setXmlLang(CoreResources.getField("translated_text_language"));
msli.setDecode(tt);
msl.getMultiSelectListItems().add(msli);
}
multiSelectLists.add(msl);
}
}
if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
String last = igMandatories.containsKey(igId + "") ? igMandatories.get(igId + "") : itMandatory;
itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(last);
}
sectionIds = sectionIds.length() > 0 ? sectionIds.substring(1, sectionIds.length() - 1) : "";
metadata.setSectionIds(sectionIds);
}
use of org.akaza.openclinica.bean.odmbeans.ElementRefBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method setOCEventDataDNs.
protected void setOCEventDataDNs(OdmClinicalDataBean data, String definitionOids, String studySubjectOids, HashMap<String, String> evnOidPoses) {
this.setOCEventDataDNsTypesExpected();
HashMap<String, ArrayList<ChildNoteBean>> pDNs = new HashMap<String, ArrayList<ChildNoteBean>>();
// HashMap<String, ArrayList<DiscrepancyNoteBean>> sDNs = new HashMap<String, ArrayList<DiscrepancyNoteBean>>();
logger.debug("Begin to execute GetOCEventDataDNsSql");
logger.debug("getOCEventDataDNsSql= " + this.getOCEventDataDNsSql(definitionOids, studySubjectOids));
ArrayList rows = select(this.getOCEventDataDNsSql(definitionOids, studySubjectOids));
Iterator iter = rows.iterator();
while (iter.hasNext()) {
HashMap row = (HashMap) iter.next();
String studySubjectLabel = (String) row.get("study_subject_oid");
String defOid = (String) row.get("definition_oid");
Integer pdnId = (Integer) row.get("parent_dn_id");
Integer dnId = (Integer) row.get("dn_id");
String description = (String) row.get("description");
String detailedNote = (String) row.get("detailed_notes");
Integer ownerId = (Integer) row.get("owner_id");
Date dateCreated = (Date) row.get("date_created");
String status = (String) row.get("status");
String noteType = (String) row.get("name");
String oidKey = studySubjectLabel + defOid;
if (pdnId != null && pdnId > 0) {
String key = oidKey + pdnId;
ChildNoteBean cn = new ChildNoteBean();
cn.setDateCreated(dateCreated);
cn.setDescription(description);
cn.setDetailedNote(detailedNote);
cn.setStatus(status);
cn.setOid("CDN_" + dnId);
ElementRefBean userRef = new ElementRefBean();
userRef.setElementDefOID("USR_" + ownerId);
cn.setUserRef(userRef);
ArrayList<ChildNoteBean> cns = pDNs.containsKey(key) ? pDNs.get(key) : new ArrayList<ChildNoteBean>();
cns.add(cn);
pDNs.put(key, cns);
} else {
DiscrepancyNoteBean dn = new DiscrepancyNoteBean();
String k = oidKey + dnId;
if (pDNs != null && pDNs.containsKey(k)) {
dn.setChildNotes(pDNs.get(k));
dn.setNumberOfChildNotes(dn.getChildNotes().size());
}
dn.setDateUpdated(dateCreated);
dn.setNoteType(noteType);
dn.setStatus(status);
dn.setOid("DN_" + dnId);
ElementRefBean userRef = new ElementRefBean();
userRef.setElementDefOID("USR_" + ownerId);
if (evnOidPoses.containsKey(oidKey)) {
String[] poses = evnOidPoses.get(oidKey).split("---");
int p0 = Integer.parseInt(poses[0]);
int p1 = Integer.parseInt(poses[1]);
String entityID = data.getExportSubjectData().get(p0).getExportStudyEventData().get(p1).getStudyEventOID();
data.getExportSubjectData().get(p0).getExportStudyEventData().get(p1).getDiscrepancyNotes().setEntityID(entityID);
data.getExportSubjectData().get(p0).getExportStudyEventData().get(p1).getDiscrepancyNotes().getDiscrepancyNotes().add(dn);
}
}
}
}
use of org.akaza.openclinica.bean.odmbeans.ElementRefBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method getODMMetadata.
/**
* metadata for ODM extraction only
*/
public void getODMMetadata(int parentStudyId, int studyId, MetaDataVersionBean metadata, String odmVersion) {
String cvIds = "";
HashMap<Integer, Integer> cvIdPoses = new HashMap<Integer, Integer>();
this.setStudyEventAndFormMetaTypesExpected();
logger.debug("Begin to execute GetStudyEventAndFormMetaSql");
logger.debug("getStudyEventAndFormMetaSQl= " + this.getStudyEventAndFormMetaSql(parentStudyId, studyId, false));
ArrayList rows = this.select(this.getStudyEventAndFormMetaSql(parentStudyId, studyId, false));
Iterator it = rows.iterator();
String sedprev = "";
MetaDataVersionProtocolBean protocol = metadata.getProtocol();
HashMap<Integer, String> nullMap = new HashMap<Integer, String>();
HashMap<String, String> nullValueCVs = new HashMap<String, String>();
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
Integer sedOrder = (Integer) row.get("definition_order");
Integer cvId = (Integer) row.get("crf_version_id");
String sedOID = (String) row.get("definition_oid");
String sedName = (String) row.get("definition_name");
Boolean sedRepeat = (Boolean) row.get("definition_repeating");
String sedType = (String) row.get("definition_type");
String cvOID = (String) row.get("cv_oid");
String cvName = (String) row.get("cv_name");
Boolean cvRequired = (Boolean) row.get("cv_required");
String nullValue = (String) row.get("null_values");
String crfName = (String) row.get("crf_name");
String crfOid = (String) row.get("crf_oid");
StudyEventDefBean sedef = new StudyEventDefBean();
if (sedprev.equals(sedOID)) {
int p = metadata.getStudyEventDefs().size() - 1;
sedef = metadata.getStudyEventDefs().get(p);
} else {
sedprev = sedOID;
ElementRefBean sedref = new ElementRefBean();
sedref.setElementDefOID(sedOID);
sedref.setMandatory("Yes");
sedref.setOrderNumber(sedOrder);
protocol.getStudyEventRefs().add(sedref);
sedef.setOid(sedOID);
sedef.setName(sedName);
sedef.setRepeating(sedRepeat ? "Yes" : "No");
String type = sedType.toLowerCase();
type = type.substring(0, 1).toUpperCase() + type.substring(1);
sedef.setType(type);
metadata.getStudyEventDefs().add(sedef);
}
ElementRefBean formref = new ElementRefBean();
formref.setElementDefOID(crfOid);
formref.setMandatory(cvRequired ? "Yes" : "No");
sedef.getFormRefs().add(formref);
if (!cvIdPoses.containsKey(cvId)) {
FormDefBean formdef = new FormDefBean();
formdef.setOid(crfOid);
formdef.setName(crfName);
formdef.setRepeating("No");
metadata.getFormDefs().add(formdef);
cvIdPoses.put(cvId, metadata.getFormDefs().size() - 1);
cvIds += cvId + ",";
if (nullValue != null && nullValue.length() > 0) {
nullMap.put(cvId, nullValue);
nullValueCVs.put(sedOID + "-" + cvOID, nullValue);
}
}
}
cvIds = cvIds.substring(0, cvIds.length() - 1);
metadata.setCvIds(cvIds);
HashMap<Integer, Integer> maxLengths = new HashMap<Integer, Integer>();
this.setItemDataMaxLengthTypesExpected();
rows.clear();
logger.debug("Begin to execute GetItemDataMaxLengths");
rows = select(this.getItemDataMaxLengths(cvIds));
it = rows.iterator();
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
maxLengths.put((Integer) row.get("item_id"), (Integer) row.get("max_length"));
}
this.setItemGroupAndItemMetaWithUnitTypesExpected();
rows.clear();
logger.debug("Begin to execute GetItemGroupAndItemMetaWithUnitSql");
logger.debug("getItemGroupandItemMetaWithUnitsql= " + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
rows = select(this.getItemGroupAndItemMetaWithUnitSql(cvIds));
it = rows.iterator();
ArrayList<ItemGroupDefBean> itemGroupDefs = (ArrayList<ItemGroupDefBean>) metadata.getItemGroupDefs();
ArrayList<ItemDefBean> itemDefs = (ArrayList<ItemDefBean>) metadata.getItemDefs();
ArrayList<CodeListBean> codeLists = (ArrayList<CodeListBean>) metadata.getCodeLists();
ArrayList<MultiSelectListBean> multiSelectLists = (ArrayList<MultiSelectListBean>) metadata.getMultiSelectLists();
ArrayList<ElementRefBean> itemGroupRefs = new ArrayList<ElementRefBean>();
Set<String> igset = new HashSet<String>();
HashMap<String, Integer> igdPos = new HashMap<String, Integer>();
Set<String> itset = new HashSet<String>();
Set<Integer> itdset = new HashSet<Integer>();
Set<Integer> clset = new HashSet<Integer>();
Set<Integer> mslset = new HashSet<Integer>();
ItemGroupDefBean igdef = new ItemGroupDefBean();
HashMap<String, String> igMandatories = new HashMap<String, String>();
boolean isLatest = false;
int cvprev = -1;
String igrprev = "";
String igdprev = "";
String itMandatory = "No";
int itOrder = 0;
Integer igId = -1;
String sectionIds = ",";
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
Integer cId = (Integer) row.get("crf_id");
Integer cvId = (Integer) row.get("crf_version_id");
igId = (Integer) row.get("item_group_id");
Integer itId = (Integer) row.get("item_id");
Integer rsId = (Integer) row.get("response_set_id");
String cvOID = (String) row.get("crf_version_oid");
String igOID = (String) row.get("item_group_oid");
String itOID = (String) row.get("item_oid");
String igName = (String) row.get("item_group_name");
String itName = (String) row.get("item_name");
Integer dataTypeId = (Integer) row.get("item_data_type_id");
Integer secId = (Integer) row.get("section_id");
String header = (String) row.get("item_header");
String left = (String) row.get("left_item_text");
String right = (String) row.get("right_item_text");
Boolean itRequired = (Boolean) row.get("item_required");
String regexp = (String) row.get("regexp");
String regexpErr = (String) row.get("regexp_error_msg");
String widthDecimal = (String) row.get("width_decimal");
Integer rsTypeId = (Integer) row.get("response_type_id");
String rsText = (String) row.get("options_text");
String rsValue = (String) row.get("options_values");
String rsLabel = (String) row.get("response_label");
String igHeader = (String) row.get("item_group_header");
Boolean isRepeating = (Boolean) row.get("repeating_group");
String itDesc = (String) row.get("item_description");
String itQuesNum = (String) row.get("question_number_label");
String muOid = (String) row.get("mu_oid");
if (cvprev != cvId) {
// at this point, itemGroupRefs is for old cvId
if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
String temp = igMandatories.containsKey(igdprev) ? igMandatories.get(igdprev) : itMandatory;
itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(temp);
}
itMandatory = "No";
// now update to new cvId
cvprev = cvId;
FormDefBean formDef = new FormDefBean();
if (cvIdPoses.containsKey(cvId)) {
int p = cvIdPoses.get(cvId);
formDef = metadata.getFormDefs().get(p);
} else {
logger.debug("crf_version_id=" + cvId + " couldn't find from studyEventAndFormMetaSql");
}
itemGroupRefs = (ArrayList<ElementRefBean>) formDef.getItemGroupRefs();
}
// mandatory is based on the last crf-version
String igDefKey = igId + "";
if (!igdprev.equals(igDefKey)) {
if (igdPos.containsKey(igDefKey)) {
igdef = itemGroupDefs.get(igdPos.get(igDefKey));
isLatest = false;
itOrder = igdef.getItemRefs().size();
} else {
igdef = new ItemGroupDefBean();
itOrder = 0;
igMandatories.put(igdprev, itMandatory);
isLatest = true;
igdef.setOid(igOID);
igdef.setName("ungrouped".equalsIgnoreCase(igName) ? igOID : igName);
// igdef.setName(igName);
igdef.setRepeating(isRepeating ? "Yes" : "No");
igdef.setComment(igHeader);
igdef.setPreSASDatasetName(igName.toUpperCase());
itemGroupDefs.add(igdef);
igdPos.put(igDefKey, itemGroupDefs.size() - 1);
}
igdprev = igDefKey;
}
String igRefKey = igId + "-" + cvId;
if (igrprev.equals(igRefKey)) {
itMandatory = isLatest && itRequired && "No".equals(itMandatory) ? "Yes" : itMandatory;
} else {
if (!igset.contains(igRefKey)) {
igset.add(igRefKey);
ElementRefBean igref = new ElementRefBean();
igref.setElementDefOID(igOID);
int size = itemGroupRefs.size();
if (size > 0) {
String prev = igrprev.split("-")[0].trim();
String temp = igMandatories.containsKey(prev) ? igMandatories.get(prev) : itMandatory;
itemGroupRefs.get(size - 1).setMandatory(temp);
}
itemGroupRefs.add(igref);
itMandatory = "No";
}
igrprev = igRefKey;
}
String mandatory = itRequired ? "Yes" : "No";
if (!itset.contains(igDefKey + "-" + itId)) {
++itOrder;
itset.add(igDefKey + "-" + itId);
ElementRefBean itemRef = new ElementRefBean();
itemRef.setElementDefOID(itOID);
if (itemRef.getMandatory() == null || itemRef.getMandatory().length() <= 0) {
itemRef.setMandatory(mandatory);
}
itemRef.setOrderNumber(itOrder);
igdef.getItemRefs().add(itemRef);
}
boolean hasCode = MetadataUnit.needCodeList(rsTypeId, dataTypeId);
LinkedHashMap<String, String> codes = new LinkedHashMap<String, String>();
if (hasCode) {
/*
* //null value will not be added to codelist if (nullMap.containsKey(cvId)) { codes =
* MetadataUnit.parseCode(rsText, rsValue,
* nullMap.get(cvId)); } else { codes = MetadataUnit.parseCode(rsText, rsValue); }
*/
codes = MetadataUnit.parseCode(rsText, rsValue);
// no action has been taken if rsvalue/rstext go wrong,
// since they have been validated when uploading crf.
}
boolean hasMultiSelect = MetadataUnit.needMultiSelectList(rsTypeId);
LinkedHashMap<String, String> multi = new LinkedHashMap<String, String>();
if (hasMultiSelect) {
multi = MetadataUnit.parseCode(rsText, rsValue);
// no action has been taken if rsvalue/rstext go wrong,
// since they have been validated when uploading crf.
}
String datatype = MetadataUnit.getOdmItemDataType(rsTypeId, dataTypeId, odmVersion);
if (sectionIds.contains("," + secId + ",")) {
} else {
sectionIds += secId + ",";
}
if (!itdset.contains(itId)) {
itdset.add(itId);
ItemDefBean idef = new ItemDefBean();
idef.setOid(itOID);
idef.setName(itName);
idef.setComment(itDesc);
if (muOid != null && muOid.length() > 0) {
ElementRefBean measurementUnitRef = new ElementRefBean();
measurementUnitRef.setElementDefOID(muOid);
idef.setMeasurementUnitRef(measurementUnitRef);
}
idef.setPreSASFieldName(itName);
idef.setCodeListOID(hasCode ? "CL_" + rsId : "");
if (hasMultiSelect) {
ElementRefBean multiSelectListRef = new ElementRefBean();
multiSelectListRef.setElementDefOID("MSL_" + rsId);
idef.setMultiSelectListRef(multiSelectListRef);
}
// if(nullMap.containsKey(cvId)) {
// }
idef.getQuestion().setQuestionNumber(itQuesNum);
idef.getQuestion().getQuestion().setText(MetadataUnit.getItemQuestionText(header, left, right));
if (regexp != null && regexp.startsWith("func:")) {
idef.setRangeCheck(MetadataUnit.getItemRangeCheck(regexp.substring(5).trim(), metadata.getSoftHard(), regexpErr, muOid));
}
idef.setDataType(datatype);
int len = 0;
int sig = 0;
if (widthDecimal != null && widthDecimal.length() > 0) {
// now there is no validation for width_decimal here.
len = parseWidth(widthDecimal);
sig = parseDecimal(widthDecimal);
}
if (rsTypeId == 3 || rsTypeId == 7) {
// 3:checkbox;
// //7:multi-select
// len = maxLengths.containsKey(itId) ? maxLengths.get(itId) : 0;
// len = Math.max(len, Math.max(rsText.length(), rsValue.length()));
Iterator<String> iter = multi.keySet().iterator();
String temp = "";
while (iter.hasNext()) {
temp += iter.next();
temp += ",";
}
idef.setLength(temp.length());
} else if ("text".equalsIgnoreCase(datatype)) {
if (len > 0) {
idef.setLength(len);
} else {
idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : maxLengths.containsKey(itId) ? maxLengths.get(itId) : MetaDataCollector.getTextLength());
}
} else if ("integer".equalsIgnoreCase(datatype)) {
if (len > 0) {
idef.setLength(len);
} else {
idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 10);
}
} else if ("float".equalsIgnoreCase(datatype)) {
if (len > 0) {
idef.setLength(len);
} else {
// idef.setLength(hasCode ?
// MetadataUnit.getDataTypeLength(codes.keySet()) : 32);
idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 25);
}
} else {
idef.setLength(0);
}
idef.setSignificantDigits(sig > 0 ? sig : MetadataUnit.getSignificantDigits(datatype, codes.keySet(), hasCode));
itemDefs.add(idef);
}
if (hasCode && !clset.contains(rsId)) {
clset.add(rsId);
CodeListBean cl = new CodeListBean();
cl.setOid("CL_" + rsId);
cl.setName(rsLabel);
cl.setPreSASFormatName(rsLabel);
cl.setDataType(datatype);
Iterator<String> iter = codes.keySet().iterator();
while (iter.hasNext()) {
String de = iter.next();
CodeListItemBean cli = new CodeListItemBean();
cli.setCodedValue(de);
TranslatedTextBean tt = cli.getDecode();
// cli.getDecode().setText(codes.get(de));
tt.setText(codes.get(de));
tt.setXmlLang(CoreResources.getField("translated_text_language"));
cli.setDecode(tt);
cl.getCodeListItems().add(cli);
}
codeLists.add(cl);
}
if (odmVersion.startsWith("oc") && hasMultiSelect && !mslset.contains(rsId)) {
mslset.add(rsId);
MultiSelectListBean msl = new MultiSelectListBean();
msl.setOid("MSL_" + rsId);
msl.setName(rsLabel);
msl.setDataType(datatype);
msl.setActualDataType(datatype);
Iterator<String> iter = multi.keySet().iterator();
while (iter.hasNext()) {
String de = iter.next();
MultiSelectListItemBean msli = new MultiSelectListItemBean();
msli.setCodedOptionValue(de);
TranslatedTextBean tt = new TranslatedTextBean();
String t = multi.get(de);
tt.setText(t);
tt.setXmlLang(CoreResources.getField("translated_text_language"));
msli.setDecode(tt);
msl.getMultiSelectListItems().add(msli);
}
multiSelectLists.add(msl);
}
}
if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
String last = igMandatories.containsKey(igId + "") ? igMandatories.get(igId + "") : itMandatory;
itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(last);
}
sectionIds = sectionIds.length() > 0 ? sectionIds.substring(1, sectionIds.length() - 1) : "";
metadata.setSectionIds(sectionIds);
}
use of org.akaza.openclinica.bean.odmbeans.ElementRefBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method getFormLayoutRefs.
List<ElementRefBean> getFormLayoutRefs(ElementRefBean formRef, int defaultVersionId) {
CRFBean crfBean = crfdao.findByOid(formRef.getElementDefOID());
List<FormLayoutBean> formLayouts = fldao.findAllByCRFId(crfBean.getId());
List<ElementRefBean> elementRefs = new ArrayList<>();
ElementRefBean element;
for (FormLayoutBean formLayout : formLayouts) {
element = new ElementRefBean();
element.setName(formLayout.getName());
if (formLayout.getId() == defaultVersionId) {
element.setDefaultVersion(true);
} else {
element.setDefaultVersion(false);
}
elementRefs.add(element);
}
return elementRefs;
}
Aggregations