use of org.akaza.openclinica.domain.datamap.FormLayoutMedia in project OpenClinica by OpenClinica.
the class EnketoAPI method getEditURL.
public EnketoURLResponse getEditURL(FormLayout formLayout, String flavor, String instance, String ecid, String redirect, boolean markComplete, String studyOid, List<FormLayoutMedia> mediaList, String goTo) {
String crfOid = formLayout.getOcOid() + flavor;
if (enketoURL == null)
return null;
try {
// Build instanceId to cache populated instance at Enketo with
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
String hashString = ecid + "." + String.valueOf(cal.getTimeInMillis());
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String instanceId = encoder.encodePassword(hashString, null);
URL eURL = new URL(enketoURL + "/api/v2/instance/fieldsubmission/iframe");
// URL eURL = new URL(enketoURL + "/api/v2/instance/iframe");
String userPasswdCombo = new String(Base64.encodeBase64((token + ":").getBytes()));
InstanceAttachment attachment = new InstanceAttachment();
for (FormLayoutMedia media : mediaList) {
String fileName = media.getName();
String baseUrl = CoreResources.getField("sysURL.base") + "rest2/openrosa/" + studyOid;
String downLoadUrl = baseUrl + "/downloadMedia?formLayoutMediaId=" + media.getFormLayoutMediaId();
attachment.setAdditionalProperty(fileName, downLoadUrl);
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Authorization", "Basic " + userPasswdCombo);
headers.add("Accept-Charset", "UTF-8");
EnketoEditURLRequest body = new EnketoEditURLRequest(ocURL, crfOid, instanceId, redirect, instance, String.valueOf(markComplete), attachment, goTo);
HttpEntity<EnketoEditURLRequest> request = new HttpEntity<EnketoEditURLRequest>(body, headers);
RestTemplate rest = new RestTemplate();
ResponseEntity<EnketoURLResponse> response = rest.postForEntity(eURL.toString(), request, EnketoURLResponse.class);
if (response != null)
return response.getBody();
else
return null;
} catch (Exception e) {
logger.error(e.getMessage());
logger.error(ExceptionUtils.getStackTrace(e));
}
return null;
}
use of org.akaza.openclinica.domain.datamap.FormLayoutMedia in project OpenClinica by OpenClinica.
the class FormLayoutMediaDao method findByEventCrfIdAndFileName.
public FormLayoutMedia findByEventCrfIdAndFileName(int eventCrfId, String fileName) {
String query = "from " + getDomainClassName() + " do where do.eventCrfId = :eventCrfId and do.name = :fileName";
Query q = getCurrentSession().createQuery(query);
q.setInteger("eventCrfId", eventCrfId);
q.setString("fileName", fileName);
return (FormLayoutMedia) q.uniqueResult();
}
use of org.akaza.openclinica.domain.datamap.FormLayoutMedia in project OpenClinica by OpenClinica.
the class FormLayoutMediaDao method findByFormLayoutIdAndFilePath.
public FormLayoutMedia findByFormLayoutIdAndFilePath(int formLayoutId, String dir) {
String query = "from " + getDomainClassName() + " do where do.formLayout.formLayoutId = :formlayoutid and do.path = :dir";
Query q = getCurrentSession().createQuery(query);
q.setInteger("formlayoutid", formLayoutId);
q.setString("dir", dir);
return (FormLayoutMedia) q.uniqueResult();
}
use of org.akaza.openclinica.domain.datamap.FormLayoutMedia in project OpenClinica by OpenClinica.
the class FormLayoutMediaDao method findByFormLayoutIdAndFileName.
public FormLayoutMedia findByFormLayoutIdAndFileName(int formLayoutId, String fileName) {
String query = "from " + getDomainClassName() + " do where do.formLayout.formLayoutId = :formlayoutid and do.name = :fileName";
Query q = getCurrentSession().createQuery(query);
q.setInteger("formlayoutid", formLayoutId);
q.setString("fileName", fileName);
return (FormLayoutMedia) q.uniqueResult();
}
use of org.akaza.openclinica.domain.datamap.FormLayoutMedia 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);
}
}
}
Aggregations