use of org.akaza.openclinica.web.pform.widget.WidgetFactory in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method mapBeansToDTO.
/**
* @param html
* @param crf
* @param crfVersion
* @param crfSections
* @return
* @throws Exception
*/
private Integer mapBeansToDTO(Html html, CRFBean crf, CRFVersionBean crfVersion, ArrayList<SectionBean> crfSections) throws Exception {
boolean expressionEvaluate = true;
int sectionCount = 0;
ItemFormMetadataBean itemFormMetadataBean = null;
Body body = html.getBody();
ArrayList<Group> allSections = new ArrayList<Group>();
ArrayList<Bind> bindList = new ArrayList<Bind>();
WidgetFactory factory = new WidgetFactory(crfVersion);
html.getHead().setTitle(crf.getName());
for (SectionBean section : crfSections) {
ArrayList<Group> groups = new ArrayList<Group>();
Group singleSection = new Group();
singleSection.setUsercontrol(new ArrayList<UserControl>());
String ref = "/" + crfVersion.getOid() + "/" + "SECTION_" + section.getLabel().replaceAll("\\W", "_");
singleSection.setRef(ref);
String sectionExpression = null;
igdao = new ItemGroupDAO(dataSource);
ArrayList<ItemGroupBean> groupBeans = (ArrayList<ItemGroupBean>) igdao.findGroupBySectionId(section.getId());
int count = 0;
if (groupBeans.size() > 0) {
for (ItemGroupBean groupBean : groupBeans) {
ExpressionExpressionEvaluate eev = getSkipPattern(null, groupBean);
String expr = eev.getExpression();
expressionEvaluate = eev.isExpressionEvaluate();
if (expr != null) {
if (sectionExpression != null) {
sectionExpression = sectionExpression + " and " + expr;
count++;
} else {
sectionExpression = expr;
count++;
}
}
}
if (sectionExpression != null && groupBeans.size() == count) {
sectionExpression = getFullExpressionToParse(sectionExpression, crfVersion, expressionEvaluate);
} else {
sectionExpression = null;
}
setSectionWidget(section, crfVersion, sectionExpression, bindList, factory, singleSection);
HashMap<String, Object> groupMap = null;
boolean isGroupRepeating = false;
Group group = null;
Repeat repeat = null;
idao = new ItemDAO(dataSource);
ArrayList<ItemBean> items = (ArrayList<ItemBean>) idao.findAllBySectionIdOrderedByItemFormMetadataOrdinal(section.getId());
Integer itemGroupId = 0;
for (ItemBean item : items) {
ItemGroupBean itemGroupBean = getItemGroupBeanByItemId(item.getId());
if (itemGroupId != itemGroupBean.getId()) {
groupMap = getGroupInfo(itemGroupBean, crfVersion, section, factory, bindList);
isGroupRepeating = (Boolean) groupMap.get("isGroupRepeating");
group = (Group) groupMap.get("group");
repeat = (Repeat) groupMap.get("repeat");
}
itemFormMetadataBean = getItemFormMetadata(item, crfVersion);
int responseTypeId = itemFormMetadataBean.getResponseSet().getResponseTypeId();
boolean isItemRequired = itemFormMetadataBean.isRequired();
String responseLayout = itemFormMetadataBean.getResponseLayout();
String itemExpression = null;
ExpressionExpressionEvaluate eev = getSkipPattern(item, itemGroupBean);
itemExpression = eev.getExpression();
expressionEvaluate = eev.isExpressionEvaluate();
if (itemExpression != null)
itemExpression = getFullExpressionToParse(itemExpression, crfVersion, expressionEvaluate);
// Add the Item Header
setHeaderWidget(item, itemFormMetadataBean, itemGroupBean, bindList, factory, isGroupRepeating, repeat, group, itemExpression);
// Add the Item SubHeader
setSubHeaderWidget(item, itemFormMetadataBean, itemGroupBean, bindList, factory, isGroupRepeating, repeat, group, itemExpression);
// Add the Item itself
setItemWidget(item, responseTypeId, itemFormMetadataBean, itemGroupBean, bindList, factory, isGroupRepeating, repeat, group, isItemRequired, responseLayout, itemExpression);
if (itemGroupId != itemGroupBean.getId()) {
groups.add(group);
itemGroupId = itemGroupBean.getId();
}
}
// end of item loop
singleSection.setGroup(groups);
allSections.add(singleSection);
}
// end of groups per section if exist
sectionCount = allSections.size();
}
// end of section loop
body.setGroup(allSections);
html.getHead().getModel().setBind(bindList);
return sectionCount;
}
Aggregations