use of org.akaza.openclinica.domain.datamap.ItemFormMetadata in project OpenClinica by OpenClinica.
the class XformMetaDataService method createItemFormMetadata.
private ItemFormMetadata createItemFormMetadata(XformItem xformItem, Item item, ResponseSet responseSet, Section section, CrfVersion crfVersion, Integer itemOrdinal) {
ItemFormMetadata itemFormMetadata = new ItemFormMetadata();
itemFormMetadata.setCrfVersionId(crfVersion.getCrfVersionId());
itemFormMetadata.setResponseSet(responseSet);
itemFormMetadata.setItem(item);
itemFormMetadata.setSubheader("");
itemFormMetadata.setHeader("");
itemFormMetadata.setLeftItemText(xformItem.getLeftItemText());
itemFormMetadata.setRightItemText("");
itemFormMetadata.setParentId(0);
itemFormMetadata.setSection(section);
itemFormMetadata.setOrdinal(itemOrdinal);
itemFormMetadata.setParentLabel("");
itemFormMetadata.setColumnNumber(0);
itemFormMetadata.setPageNumberLabel("");
itemFormMetadata.setQuestionNumberLabel("");
itemFormMetadata.setRegexp("");
itemFormMetadata.setRegexpErrorMsg("");
itemFormMetadata.setRequired(xformItem.isRequired());
itemFormMetadata.setDefaultValue("");
itemFormMetadata.setResponseLayout("Vertical");
itemFormMetadata.setWidthDecimal("");
itemFormMetadata.setShowItem(true);
itemFormMetadata = itemFormMetadataDao.saveOrUpdate(itemFormMetadata);
return itemFormMetadata;
}
use of org.akaza.openclinica.domain.datamap.ItemFormMetadata in project OpenClinica by OpenClinica.
the class EnketoUrlService method getItemValue.
private String getItemValue(ItemData itemData, CrfVersion crfVersion) {
String itemValue = null;
if (itemData != null) {
itemValue = itemData.getValue();
ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(itemData.getItem().getItemId(), crfVersion.getCrfVersionId());
// Convert space separated Enketo multiselect values to comma separated OC
// multiselect
// values
Integer responseTypeId = itemFormMetadata.getResponseSet().getResponseType().getResponseTypeId();
if (responseTypeId == 3 || responseTypeId == 7) {
itemValue = itemValue.replaceAll(",", " ");
}
}
return escapedValue(itemValue);
}
use of org.akaza.openclinica.domain.datamap.ItemFormMetadata in project OpenClinica by OpenClinica.
the class FSItemProcessor method processFieldSubmissionGroupItems.
private void processFieldSubmissionGroupItems(ArrayList<HashMap> listOfUploadFilePaths, Node repeatNode, Node itemNode, SubmissionContainer container, ItemGroup itemGroup) throws Exception {
String itemName;
Integer itemOrdinal = 1;
String itemValue;
// Node repeatGroupNode = itemNode.getParentNode();
if (repeatNode != null) {
final NamedNodeMap attributes = repeatNode.getAttributes();
// check to see if groupNode has any enketo attributes
for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) {
if (attributes.item(attrIndex).getNodeName().equals(ENKETO_ORDINAL)) {
logger.debug("found enketo attribute");
logger.debug(attributes.item(attrIndex).getNodeName());
logger.debug(attributes.item(attrIndex).getNodeValue());
itemOrdinal = new Integer(attributes.item(attrIndex).getNodeValue());
}
}
} else {
itemOrdinal = 1;
}
FormLayout formLayout = container.getFormLayout();
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
container.setCrfVersion(crfVersion);
Item item = null;
ItemGroupMetadata igm = null;
if (container.getRequestType() == FieldRequestTypeEnum.DELETE_FIELD) {
List<ItemGroupMetadata> igms = itemGroupMetadataDao.findByItemGroupCrfVersion(itemGroup.getItemGroupId(), crfVersion.getCrfVersionId());
for (ItemGroupMetadata ig : igms) {
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(ig.getItem().getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
// ItemData existingItemData = lookupFieldItemData(itemGroup, itemOrdinal, container);
if (existingItemData != null) {
existingItemData.setDeleted(true);
existingItemData.setValue("");
existingItemData.setOldStatus(existingItemData.getStatus());
existingItemData.setUserAccount(container.getUser());
existingItemData.setStatus(Status.AVAILABLE);
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setInstanceId(container.getInstanceId());
existingItemData = itemDataDao.saveOrUpdate(existingItemData);
resetSdvStatus(container);
// Close discrepancy notes
closeItemDiscrepancyNotes(container, existingItemData);
}
}
return;
}
// igm = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
// Item loop
QueryServiceHelperBean helperBean = new QueryServiceHelperBean();
if (queryService.getQueryAttribute(helperBean, itemNode) != null) {
queryService.process(helperBean, container, itemNode, itemOrdinal);
} else if (shouldProcessItemNode(itemNode)) {
itemName = itemNode.getNodeName().trim();
itemValue = itemNode.getTextContent();
item = itemDao.findByNameCrfId(itemNode.getNodeName(), crfVersion.getCrf().getCrfId());
if (item == null) {
logger.error("Failed to lookup item: '" + itemName + "'. Continuing with submission.");
}
ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
// Convert space separated Enketo multiselect values to comma separated OC multiselect values
Integer responseTypeId = itemFormMetadata.getResponseSet().getResponseType().getResponseTypeId();
if (responseTypeId == 3 || responseTypeId == 7) {
itemValue = itemValue.replaceAll(" ", ",");
}
if (responseTypeId == 4) {
/*
* for (HashMap uploadFilePath : listOfUploadFilePaths) {
* if ((boolean) uploadFilePath.containsKey(itemValue) && itemValue != "") {
* itemValue = (String) uploadFilePath.get(itemValue);
* break;
* }
* }
*/
FormLayoutMedia media = formLayoutMediaDao.findByEventCrfIdAndFileName(container.getEventCrf().getEventCrfId(), itemValue);
if (media == null) {
media = new FormLayoutMedia();
}
media.setName(itemValue);
media.setFormLayout(formLayout);
media.setEventCrfId(container.getEventCrf().getEventCrfId());
media.setPath("/" + container.getStudy().getOc_oid() + "/");
formLayoutMediaDao.saveOrUpdate(media);
}
ItemData newItemData = createItemData(item, itemValue, itemOrdinal, container);
Errors itemErrors = validateItemData(newItemData, item, responseTypeId);
if (itemErrors.hasErrors()) {
container.getErrors().addAllErrors(itemErrors);
throw new Exception("Item validation error. Rolling back submission changes.");
}
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(item.getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
if (existingItemData == null) {
newItemData.setStatus(Status.UNAVAILABLE);
itemDataDao.saveOrUpdate(newItemData);
resetSdvStatus(container);
} else if (existingItemData.getValue().equals(newItemData.getValue())) {
} else {
// Existing item. Value changed. Update existing value.
existingItemData.setInstanceId(container.getInstanceId());
existingItemData.setValue(newItemData.getValue());
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setDateUpdated(new Date());
itemDataDao.saveOrUpdate(existingItemData);
resetSdvStatus(container);
}
}
}
use of org.akaza.openclinica.domain.datamap.ItemFormMetadata in project OpenClinica by OpenClinica.
the class ItemProcessor method processGroupItems.
private void processGroupItems(ArrayList<HashMap> listOfUploadFilePaths, HashMap<Integer, Set<Integer>> groupOrdinalMapping, Node groupNode, ItemGroup itemGroup, SubmissionContainer container) throws Exception {
String itemName;
String itemValue;
if (itemGroup != null && !groupOrdinalMapping.containsKey(itemGroup.getItemGroupId())) {
groupOrdinalMapping.put(itemGroup.getItemGroupId(), new TreeSet<Integer>());
}
NodeList itemNodeList = groupNode.getChildNodes();
// Item loop
for (int m = 0; m < itemNodeList.getLength(); m = m + 1) {
Node itemNode = itemNodeList.item(m);
if (ShouldProcessItemNode(itemNode)) {
itemName = itemNode.getNodeName().trim();
itemValue = itemNode.getTextContent();
Item item = lookupItem(itemName, container.getCrfVersion());
if (item == null) {
logger.error("Failed to lookup item: '" + itemName + "'. Continuing with submission.");
continue;
}
ItemMetadata im = itemGroupMetadataDao.findMetadataByItemCrfVersion(item.getItemId(), container.getCrfVersion().getCrfVersionId());
ItemGroupMetadata itemGroupMeta = im.getIgm();
ItemFormMetadata itemFormMetadata = im.getIfm();
// ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(),
// crfVersion.getCrfVersionId());
Integer itemOrdinal = getItemOrdinal(groupNode, itemGroupMeta.isRepeatingGroup(), container.getItems(), item);
// Convert space separated Enketo multiselect values to comma separated OC multiselect values
Integer responseTypeId = itemFormMetadata.getResponseSet().getResponseType().getResponseTypeId();
if (responseTypeId == 3 || responseTypeId == 7) {
itemValue = itemValue.replaceAll(" ", ",");
}
if (responseTypeId == 4) {
for (HashMap uploadFilePath : listOfUploadFilePaths) {
if ((boolean) uploadFilePath.containsKey(itemValue) && itemValue != "") {
itemValue = (String) uploadFilePath.get(itemValue);
break;
}
}
}
// Build set of submitted row numbers to be used to find deleted DB rows later
Set<Integer> ordinals = groupOrdinalMapping.get(itemGroup.getItemGroupId());
ordinals.add(itemOrdinal);
groupOrdinalMapping.put(itemGroup.getItemGroupId(), ordinals);
ItemData newItemData = createItemData(item, itemValue, itemOrdinal, container);
Errors itemErrors = validateItemData(newItemData, item, responseTypeId);
if (itemErrors.hasErrors()) {
container.getErrors().addAllErrors(itemErrors);
throw new Exception("Item validation error. Rolling back submission changes.");
} else {
container.getItems().add(newItemData);
}
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(item.getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
if (existingItemData == null) {
// No existing value, create new item.
if (newItemData.getOrdinal() < 0) {
newItemData.setOrdinal(itemDataDao.getMaxGroupRepeat(container.getEventCrf().getEventCrfId(), item.getItemId()) + 1);
groupOrdinalMapping.get(itemGroup.getItemGroupId()).add(newItemData.getOrdinal());
}
newItemData.setStatus(Status.UNAVAILABLE);
newItemData.setInstanceId(container.getInstanceId());
itemDataDao.saveOrUpdate(newItemData);
} else if (existingItemData.getValue().equals(newItemData.getValue())) {
// Existing item. Value unchanged. Do nothing.
} else {
// Existing item. Value changed. Update existing value.
existingItemData.setValue(newItemData.getValue());
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setDateUpdated(new Date());
itemDataDao.saveOrUpdate(existingItemData);
}
}
}
}
use of org.akaza.openclinica.domain.datamap.ItemFormMetadata 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