Search in sources :

Example 1 with QueryBean

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);
        }
    }
}
Also used : DiscrepancyNote(org.akaza.openclinica.domain.datamap.DiscrepancyNote) QueriesBean(org.akaza.openclinica.core.form.xform.QueriesBean) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ItemData(org.akaza.openclinica.domain.datamap.ItemData) QueryBean(org.akaza.openclinica.core.form.xform.QueryBean)

Example 2 with 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;
}
Also used : ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) QueryBean(org.akaza.openclinica.core.form.xform.QueryBean) AuditLogEvent(org.akaza.openclinica.domain.datamap.AuditLogEvent) DiscrepancyNote(org.akaza.openclinica.domain.datamap.DiscrepancyNote) QueriesBean(org.akaza.openclinica.core.form.xform.QueriesBean) LogBean(org.akaza.openclinica.core.form.xform.LogBean) UserAccount(org.akaza.openclinica.domain.user.UserAccount)

Aggregations

ArrayList (java.util.ArrayList)2 QueriesBean (org.akaza.openclinica.core.form.xform.QueriesBean)2 QueryBean (org.akaza.openclinica.core.form.xform.QueryBean)2 DiscrepancyNote (org.akaza.openclinica.domain.datamap.DiscrepancyNote)2 IOException (java.io.IOException)1 LogBean (org.akaza.openclinica.core.form.xform.LogBean)1 AuditLogEvent (org.akaza.openclinica.domain.datamap.AuditLogEvent)1 ItemData (org.akaza.openclinica.domain.datamap.ItemData)1 UserAccount (org.akaza.openclinica.domain.user.UserAccount)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 DateTime (org.joda.time.DateTime)1