use of org.akaza.openclinica.core.form.xform.QueryBean in project OpenClinica by OpenClinica.
the class QueryServiceImpl method process.
@Override
public void process(QueryServiceHelperBean helperBean, SubmissionContainer container, Node itemNode, int itemOrdinal) throws Exception {
String node = itemNode.getTextContent();
if (StringUtils.isEmpty(node))
return;
helperBean.setContainer(container);
helperBean.setItemOrdinal(itemOrdinal);
helperBean.setItemNode(itemNode);
ItemData id = getItemData(helperBean);
if (id == null) {
helperBean.setItemData(createBlankItemData(helperBean));
} else {
helperBean.setItemData(id);
}
QueriesBean queries = null;
try {
ObjectMapper objectMapper = new ObjectMapper();
queries = objectMapper.readValue(node, QueriesBean.class);
} catch (IOException e) {
logger.error(e.getMessage());
throw e;
}
List<Integer> idList = new ArrayList();
List<QueryBean> qBeans = queries.getQueries();
QueryBean queryBean = null;
DiscrepancyNote childDN = null;
DiscrepancyNote parentDN = null;
List<DiscrepancyNote> childDns = null;
if (qBeans.size() > 0) {
for (QueryBean qBean : qBeans) {
idList.add(Integer.valueOf(qBean.getId()));
}
Collections.reverse(idList);
queryBean = qBeans.get(0);
parentDN = findQueryParent(helperBean);
if (parentDN == null) {
parentDN = createQuery(helperBean, queryBean);
parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);
helperBean.setDn(parentDN);
saveQueryItemDatamap(helperBean);
}
childDns = findChildQueries(helperBean);
if (childDns.size() < qBeans.size()) {
// Enketo passes JSON "id" attribute for unsubmitted queries only
// if (StringUtils.isEmpty(queryBean.getId())){
childDN = createQuery(helperBean, queryBean);
childDN.setParentDiscrepancyNote(parentDN);
childDN = discrepancyNoteDao.saveOrUpdate(childDN);
parentDN.setUserAccount(childDN.getUserAccount());
setResolutionStatus(queryBean, parentDN);
parentDN.setUserAccountByOwnerId(helperBean.getContainer().getUser());
parentDN.setDetailedNotes(childDN.getDetailedNotes());
parentDN.setDiscrepancyNoteType(childDN.getDiscrepancyNoteType());
parentDN = discrepancyNoteDao.saveOrUpdate(parentDN);
helperBean.setDn(childDN);
saveQueryItemDatamap(helperBean);
handleEmailNotification(helperBean, queryBean);
}
}
}
use of org.akaza.openclinica.core.form.xform.QueryBean in project OpenClinica by OpenClinica.
the class EnketoUrlService method buildQueryElement.
public QueriesBean buildQueryElement(ItemData itemdata) {
QueriesBean queryElement = new QueriesBean();
List<QueryBean> queryBeans = new ArrayList<>();
List<LogBean> logBeans = new ArrayList<LogBean>();
List<DiscrepancyNote> dns = discrepancyNoteDao.findChildQueriesByItemData(itemdata.getItemDataId());
int i = 0;
for (DiscrepancyNote dn : dns) {
i++;
QueryBean query = new QueryBean();
query.setId(String.valueOf(i));
query.setAssigned_to(dn.getUserAccountByOwnerId().getUserName());
query.setComment(escapedValue(dn.getDetailedNotes()));
query.setStatus(dn.getResolutionStatus().getName().toLowerCase());
DateTime dateTime = new DateTime(dn.getDateCreated());
query.setDate_time(convertDateFormat(dateTime));
query.setNotify(false);
query.setUser(dn.getUserAccountByOwnerId().getUserName());
query.setType(COMMENT);
queryBeans.add(query);
}
AuditLogEvent auditLog = new AuditLogEvent();
auditLog.setEntityId(new Integer(itemdata.getItemDataId()));
auditLog.setAuditTable(ITEMDATA);
ArrayList<AuditLogEvent> auditLogEvents = auditLogEventDao.findByParam(auditLog, null);
for (AuditLogEvent audit : auditLogEvents) {
LogBean logBean = new LogBean();
String oldValue = audit.getOldValue() != null ? audit.getOldValue() : "";
String newValue = audit.getNewValue() != null ? audit.getNewValue() : "";
logBean.setMessage("Value Changed from \"" + escapedValue(oldValue) + "\" to \"" + escapedValue(newValue) + "\"");
DateTime dateTime = new DateTime(audit.getAuditDate());
logBean.setDate_time(convertDateFormat(dateTime));
UserAccount uAccount = userAccountDao.findById(audit.getUserAccount().getUserId());
logBean.setUser(uAccount.getUserName());
logBean.setAssigned_to(uAccount.getUserName());
logBean.setType(AUDIT);
logBeans.add(logBean);
}
queryElement.setQueries(queryBeans);
queryElement.setLogs(logBeans);
if (queryElement.getQueries().size() != 0 || queryElement.getLogs().size() != 0)
return queryElement;
else
return null;
}
Aggregations