Search in sources :

Example 76 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method markCRFComplete.

/**
 * The following methods are for 'mark CRF complete'
 * @param request TODO
 *
 * @return
 */
protected boolean markCRFComplete(HttpServletRequest request) throws Exception {
    locale = LocaleResolver.getLocale(request);
    HttpSession session = request.getSession();
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    // < respage =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
    // locale);
    // < restext =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
    // <
    // resexception=ResourceBundle.getBundle(
    // "org.akaza.openclinica.i18n.exceptions",locale);
    getEventCRFBean(request);
    getEventDefinitionCRFBean(request);
    DataEntryStage stage = ecb.getStage();
    // request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN,
    // ecb);
    // request.setAttribute(INPUT_EVENT_CRF_ID, new Integer(ecb.getId()));
    LOGGER.trace("inout_event_crf_id:" + ecb.getId());
    if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
        addPageMessage(respage.getString("not_mark_CRF_complete1"), request);
        return false;
    }
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        if (!edcb.isDoubleEntry()) {
            addPageMessage(respage.getString("not_mark_CRF_complete2"), request);
            return false;
        }
    }
    if (isEachRequiredFieldFillout(request) == false) {
        addPageMessage(respage.getString("not_mark_CRF_complete4"), request);
        return false;
    }
    /*
         * if (ecb.getInterviewerName().trim().equals("")) { throw new InconsistentStateException(errorPage, "You may not mark this Event CRF complete, because
         * the interviewer name is blank."); }
         */
    Status newStatus = ecb.getStatus();
    boolean ide = true;
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
        newStatus = Status.PENDING;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
    } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
        newStatus = Status.UNAVAILABLE;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
        ecb.setDateValidateCompleted(new Date());
    } else if (stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && edcb.isDoubleEntry()) {
        newStatus = Status.UNAVAILABLE;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
        ecb.setDateValidateCompleted(new Date());
        ide = false;
    } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        newStatus = Status.UNAVAILABLE;
        ecb.setDateValidateCompleted(new Date());
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ide = false;
    }
    // create them
    if (!isEachSectionReviewedOnce(request)) {
        boolean canSave = saveItemsToMarkComplete(newStatus, request);
        if (canSave == false) {
            addPageMessage(respage.getString("not_mark_CRF_complete3"), request);
            return false;
        }
    }
    ecb.setStatus(newStatus);
    /*
         * Marking the data entry as signed if the corresponding EventDefinitionCRF is being enabled for electronic signature.
         */
    if (edcb.isElectronicSignature()) {
        ecb.setElectronicSignatureStatus(true);
    }
    ecb = (EventCRFBean) ecdao.update(ecb);
    // note the below statement only updates the DATES, not the STATUS
    ecdao.markComplete(ecb, ide);
    // update all the items' status to complete
    iddao.updateStatusByEventCRF(ecb, newStatus);
    // change status for study event
    StudyEventDAO sedao = new StudyEventDAO(getDataSource());
    StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
    seb.setUpdatedDate(new Date());
    seb.setUpdater(ub);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    ArrayList allCRFs = ecdao.findAllByStudyEventAndStatus(seb, Status.UNAVAILABLE);
    StudyBean study = (StudyBean) session.getAttribute("study");
    ArrayList allEDCs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
    CRFVersionDAO crfversionDao = new CRFVersionDAO(getDataSource());
    boolean eventCompleted = true;
    boolean allRequired = true;
    // JN Adding another flag
    boolean allCrfsCompleted = false;
    int allEDCsize = allEDCs.size();
    ArrayList nonRequiredCrfIds = new ArrayList();
    ArrayList requiredCrfIds = new ArrayList();
    if (allCRFs.size() == allEDCs.size()) {
        // was
        // JN: all crfs are completed and then set the subject event status as complete
        seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
    }
    seb = (StudyEventBean) sedao.update(seb);
    request.setAttribute(INPUT_EVENT_CRF, ecb);
    request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
    return true;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HttpSession(javax.servlet.http.HttpSession) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 77 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class ImportCRFDataService method fetchEventCRFStatuses.

/*
     * purpose: Build a map of EventCRFs and the statuses they should have post-import. Assumes EventCRFs have been
     * created for "Not Started" forms.
     */
public HashMap<Integer, String> fetchEventCRFStatuses(ODMContainer odmContainer) {
    HashMap<Integer, String> eventCRFStatuses = new HashMap<Integer, String>();
    EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
    StudyDAO studyDAO = new StudyDAO(ds);
    StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
    String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
    StudyBean studyBean = studyDAO.findByOid(studyOID);
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
            StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
            logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
            StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
            for (FormDataBean formDataBean : formDataBeans) {
                CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
                for (CRFVersionBean crfVersionBean : crfVersionBeans) {
                    ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if (!eventCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
                            eventCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
                        }
                    }
                }
            }
        }
    }
    return eventCRFStatuses;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 78 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class OpenRosaServices method getManifest.

/**
 * @api {get} /rest2/openrosa/:studyOID/manifest Get Form Manifest
 * @apiName getManifest
 * @apiPermission admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOID Study Oid.
 * @apiGroup Form
 * @apiDescription Gets additional information on a particular Form, including links to associated media.
 */
@GET
@Path("/{studyOID}/manifest")
@Produces(MediaType.TEXT_XML)
public String getManifest(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formId") String crfOID, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
    if (!mayProceedPreview(studyOID))
        return null;
    CRFVersionDAO cVersionDao = new CRFVersionDAO(getDataSource());
    CrfVersionMediaDao mediaDao = (CrfVersionMediaDao) SpringServletAccess.getApplicationContext(context).getBean("crfVersionMediaDao");
    CRFVersionBean crfVersion = cVersionDao.findByOid(crfOID);
    List<MediaFile> mediaFiles = new ArrayList<MediaFile>();
    Manifest manifest = new Manifest();
    List<CrfVersionMedia> mediaList = mediaDao.findByCrfVersionId(crfVersion.getId());
    if (mediaList != null && mediaList.size() > 0) {
        for (CrfVersionMedia media : mediaList) {
            String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
            MediaFile mediaFile = new MediaFile();
            mediaFile.setFilename(media.getName());
            File image = new File(media.getPath() + media.getName());
            mediaFile.setHash(DigestUtils.md5Hex(media.getName()) + Double.toString(image.length()));
            mediaFile.setDownloadUrl(urlBase + "/rest2/openrosa/" + studyOID + "/downloadMedia?crfVersionMediaId=" + media.getCrfVersionMediaId());
            manifest.add(mediaFile);
        }
    }
    try {
        // Create the XML manifest using a Castor mapping file.
        XMLContext xmlContext = new XMLContext();
        Mapping mapping = xmlContext.createMapping();
        mapping.loadMapping(getCoreResources().getURL("openRosaManifestMapping.xml"));
        xmlContext.addMapping(mapping);
        Marshaller marshaller = xmlContext.createMarshaller();
        StringWriter writer = new StringWriter();
        marshaller.setWriter(writer);
        marshaller.marshal(manifest);
        // Set response headers
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        Date currentDate = new Date();
        cal.setTime(currentDate);
        SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz");
        format.setCalendar(cal);
        response.setHeader("Content-Type", "text/xml; charset=UTF-8");
        response.setHeader("Date", format.format(currentDate));
        response.setHeader("X-OpenRosa-Version", "1.0");
        return writer.toString();
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        return "<Error>" + e.getMessage() + "</Error>";
    }
}
Also used : MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) Marshaller(org.exolab.castor.xml.Marshaller) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) XMLContext(org.exolab.castor.xml.XMLContext) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Mapping(org.exolab.castor.mapping.Mapping) CrfVersionMediaDao(org.akaza.openclinica.dao.hibernate.CrfVersionMediaDao) Manifest(org.akaza.openclinica.web.pform.manifest.Manifest) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) CrfVersionMedia(org.akaza.openclinica.domain.datamap.CrfVersionMedia) StringWriter(java.io.StringWriter) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Path(javax.ws.rs.Path) XPath(javax.xml.xpath.XPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 79 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class OpenRosaServices method getFormXml.

/**
 * @api {get} /rest2/openrosa/:studyOID/formXml Get Form XML
 * @apiName getFormXml
 * @apiPermission admin
 * @apiVersion 3.8.0
 * @apiParam {String} studyOID Study Oid.
 * @apiGroup Form
 * @apiDescription Downloads the contents of a form
 */
@GET
@Path("/{studyOID}/formXml")
@Produces(MediaType.APPLICATION_XML)
public String getFormXml(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formID") String crfOID, @RequestHeader("Authorization") String authorization) throws Exception {
    if (!mayProceedPreview(studyOID))
        return null;
    String xform = null;
    // get parameters
    String formId = request.getParameter("formId");
    if (formId == null) {
        return "<error>formID is null :(</error>";
    }
    try {
        CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
        CRFVersionBean crfVersion = versionDAO.findByOid(formId);
        if (crfVersion.getXform() != null && !crfVersion.getXform().equals("")) {
            xform = updateRepeatGroupsWithOrdinal(crfVersion.getXform());
        } else {
            OpenRosaXmlGenerator generator = new OpenRosaXmlGenerator(coreResources, dataSource, ruleActionPropertyDao);
            xform = generator.buildForm(formId);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        System.out.println(ExceptionUtils.getStackTrace(e));
        LOGGER.error(e.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        return "<error>" + e.getMessage() + "</error>";
    }
    response.setHeader("Content-Type", "text/xml; charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + crfOID + ".xml" + "\";");
    response.setContentType("text/xml; charset=utf-8");
    return xform;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) XPath(javax.xml.xpath.XPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 80 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class UpdateStudyEventServlet method getUncompletedCRFs.

private ArrayList getUncompletedCRFs(ArrayList eventDefinitionCRFs, ArrayList eventCRFs) {
    int i;
    HashMap completed = new HashMap();
    HashMap startedButIncompleted = new HashMap();
    ArrayList answer = new ArrayList();
    for (i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        completed.put(new Integer(edcrf.getCrfId()), Boolean.FALSE);
        startedButIncompleted.put(new Integer(edcrf.getCrfId()), new EventCRFBean());
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    for (i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecrf = (EventCRFBean) eventCRFs.get(i);
        int crfId = cvdao.getCRFIdFromCRFVersionId(ecrf.getCRFVersionId());
        ArrayList idata = iddao.findAllByEventCRFId(ecrf.getId());
        if (!idata.isEmpty()) {
            // this crf has data already
            completed.put(new Integer(crfId), Boolean.TRUE);
        } else {
            // event crf got created, but no data entered
            startedButIncompleted.put(new Integer(crfId), ecrf);
        }
    }
    for (i = 0; i < eventDefinitionCRFs.size(); i++) {
        DisplayEventDefinitionCRFBean dedc = new DisplayEventDefinitionCRFBean();
        EventDefinitionCRFBean edcrf = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        dedc.setEdc(edcrf);
        Boolean b = (Boolean) completed.get(new Integer(edcrf.getCrfId()));
        EventCRFBean ev = (EventCRFBean) startedButIncompleted.get(new Integer(edcrf.getCrfId()));
        if (b == null || !b.booleanValue()) {
            dedc.setEventCRF(ev);
            answer.add(dedc);
        }
    }
    return answer;
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Aggregations

CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)105 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)83 ArrayList (java.util.ArrayList)80 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)68 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)63 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)60 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)58 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)54 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)52 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)48 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)46 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)42 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)41 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)35 HashMap (java.util.HashMap)34 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)34 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)31 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)26 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)25