use of org.akaza.openclinica.domain.xform.XformItem in project OpenClinica by OpenClinica.
the class XformMetaDataService method createItem.
private Item createItem(XformGroup xformGroup, XformItem xformItem, CrfBean crf, UserAccountBean ub, ArrayList<String> usedItemOids, Errors errors) throws Exception {
ItemDataType newDataType = getItemDataType(xformItem);
Item item = itemDao.findByNameCrfId(xformItem.getItemName(), crf.getCrfId());
if (item != null) {
item.setDescription(xformItem.getItemDescription());
item = itemDao.saveOrUpdate(item);
} else {
item = new Item();
item.setName(xformItem.getItemName());
item.setDescription(xformItem.getItemDescription());
item.setUnits("");
item.setPhiStatus(false);
item.setItemDataType(newDataType);
item.setItemReferenceType(itemRefTypeDao.findByItemReferenceTypeId(1));
item.setStatus(org.akaza.openclinica.domain.Status.AVAILABLE);
item.setUserAccount(userDao.findById(ub.getId()));
item.setOcOid(xformItem.getItemOid());
usedItemOids.add(item.getOcOid());
item = itemDao.saveOrUpdate(item);
}
return item;
}
use of org.akaza.openclinica.domain.xform.XformItem in project OpenClinica by OpenClinica.
the class XformMetaDataService method createGroups.
private void createGroups(XformContainer container, CrfBean crf, CrfVersion crfVersion, FormLayout formLayout, Section section, UserAccountBean ub, Errors errors) throws Exception {
Integer itemOrdinal = 1;
ArrayList<String> usedGroupOids = new ArrayList<String>();
ArrayList<String> usedItemOids = new ArrayList<String>();
// for (Group htmlGroup : htmlGroups) {
for (XformGroup xformGroup : container.getGroups()) {
// XformGroup xformGroup = container.findGroupByRef(htmlGroup.getRef());
ItemGroup itemGroup = itemGroupDao.findByNameCrfId(xformGroup.getGroupName(), crf);
if (itemGroup == null) {
itemGroup = new ItemGroup();
itemGroup.setName(xformGroup.getGroupName());
itemGroup.setLayoutGroupPath(xformGroup.getGroupPath());
itemGroup.setCrf(crf);
itemGroup.setStatus(org.akaza.openclinica.domain.Status.AVAILABLE);
itemGroup.setUserAccount(userDao.findById(ub.getId()));
itemGroup.setOcOid(xformGroup.getGroupOid());
usedGroupOids.add(itemGroup.getOcOid());
itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
} else {
itemGroup.setName(xformGroup.getGroupName());
itemGroup = itemGroupDao.saveOrUpdate(itemGroup);
}
boolean isRepeating = xformGroup.isRepeating();
for (XformItem xformItem : xformGroup.getItems()) {
Item item = createItem(xformGroup, xformItem, crf, ub, usedItemOids, errors);
if (item != null) {
ResponseType responseType = getResponseType(xformItem);
ResponseSet responseSet = responseSetService.getResponseSet(xformItem, crfVersion, responseType, item, errors);
// add if statement
ItemFormMetadata ifmd = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
if (ifmd == null) {
ifmd = createItemFormMetadata(xformItem, item, responseSet, section, crfVersion, itemOrdinal);
} else {
ifmd.setRequired(xformItem.isRequired());
ifmd.setLeftItemText(xformItem.getLeftItemText());
ifmd.setItem(item);
ifmd.setResponseSet(responseSet);
ifmd = itemFormMetadataDao.saveOrUpdate(ifmd);
}
ArrayList<VersioningMap> vm = versioningMapDao.findByVersionIdFormLayoutIdAndItemId(crfVersion.getCrfVersionId(), formLayout.getFormLayoutId(), item.getItemId(), itemOrdinal);
if (vm.size() == 0) {
createVersioningMap(crfVersion, item, formLayout, xformItem.getItemOrderInForm());
}
//
ItemGroupMetadata igmd = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
if (igmd == null) {
igmd = createItemGroupMetadata(item, crfVersion, itemGroup, isRepeating, itemOrdinal);
}
itemOrdinal++;
}
}
}
}
Aggregations