Search in sources :

Example 1 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.

the class FormLayoutDao method findByFormLayoutId.

public FormLayout findByFormLayoutId(int formLayoutId) {
    String query = "from " + getDomainClassName() + " form_layout  where form_layout.formLayoutId = :formlayoutid ";
    Query q = getCurrentSession().createQuery(query);
    q.setParameter("formlayoutid", formLayoutId);
    return (FormLayout) q.uniqueResult();
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Query(org.hibernate.query.Query)

Example 2 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.

the class OdmImportServiceImpl method saveOrUpdateCrfAndFormLayouts.

private void saveOrUpdateCrfAndFormLayouts(String crfOid, List<OCodmComplexTypeDefinitionFormLayoutDef> formLayoutDefs, Form[] fmCrfs, UserAccount userAccount, Study study, String crfName) {
    DataBinder dataBinder = new DataBinder(new FormLayout());
    Errors errors = dataBinder.getBindingResult();
    StudyBean currentStudy = new StudyBean();
    currentStudy.setId(study.getStudyId());
    UserAccountBean ub = new UserAccountBean();
    ub.setId(userAccount.getUserId());
    ub.setActiveStudyId(currentStudy.getId());
    for (Form crf : fmCrfs) {
        if (crf.getOcoid().equals(crfOid)) {
            ExecuteIndividualCrfObject eicObj = new ExecuteIndividualCrfObject(crf, formLayoutDefs, errors, currentStudy, ub, true, null);
            xformService.executeIndividualCrf(eicObj);
        }
    }
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Errors(org.springframework.validation.Errors) ExecuteIndividualCrfObject(org.akaza.openclinica.service.crfdata.ExecuteIndividualCrfObject) Form(org.akaza.openclinica.service.dto.Form) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) DataBinder(org.springframework.validation.DataBinder)

Example 3 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.

the class XformMetaDataService method createCRFMetaData.

@Transactional
public FormLayout createCRFMetaData(CrfMetaDataObject cmdObject) throws Exception {
    CrfVersion crfVersion = null;
    FormLayout formLayout = null;
    CrfBean crfBean = null;
    Section section = null;
    crfBean = (CrfBean) crfDao.findByOcOID(cmdObject.crf.getOcoid());
    if (crfBean != null) {
        crfBean.setUpdateId(cmdObject.ub.getId());
        crfBean.setDateUpdated(new Date());
        crfBean = crfDao.saveOrUpdate(crfBean);
        formLayout = formLayoutDao.findByOcOID(cmdObject.version.getOcoid());
        if (formLayout == null) {
            formLayout = new FormLayout();
            formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
            formLayout = formLayoutDao.saveOrUpdate(formLayout);
        }
        crfVersion = crfVersionDao.findAllByCrfId(crfBean.getCrfId()).get(0);
        section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
    } else {
        crfBean = new CrfBean();
        crfBean = populateCrf(crfBean, cmdObject);
        Integer crfId = (Integer) crfDao.save(crfBean);
        crfBean.setCrfId(crfId);
        // Create new Form Layout
        formLayout = new FormLayout();
        formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
        formLayout = formLayoutDao.saveOrUpdate(formLayout);
        // Create new CRF Version
        crfVersion = new CrfVersion();
        crfVersion = populateCrfVersion(crfBean, crfVersion, cmdObject);
        crfVersion = crfVersionDao.saveOrUpdate(crfVersion);
        // Create Section
        section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
        if (section == null) {
            section = new Section();
            section = populateCrfVersion(section, crfVersion, cmdObject);
            sectionDao.saveOrUpdate(section);
            section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
        }
    }
    createGroups(cmdObject.container, crfBean, crfVersion, formLayout, section, cmdObject.ub, cmdObject.errors);
    if (cmdObject.errors.hasErrors()) {
        logger.error("Encounter validation errors while saving CRF.  Rolling back transaction.");
        throw new RuntimeException("Encountered validation errors while saving CRF.");
    }
    return formLayout;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) Section(org.akaza.openclinica.domain.datamap.Section) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.

the class XformMetaDataService method saveFormMetadata.

public void saveFormMetadata(ExecuteIndividualCrfObject eicObj, FormVersion version, XformContainer container, OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef, List<String> fileLinks) {
    try {
        try {
            FormLayout formLayout = createCRFMetaData(new CrfMetaDataObject(eicObj.form, version, container, eicObj.getCurrentStudy(), eicObj.ub, eicObj.errors, formLayoutDef.getURL()));
            saveFormArtifactsInOCDataDirectory(fileLinks, eicObj.form.getOcoid(), version.getOcoid());
            saveMediaFiles(fileLinks, eicObj.form.getOcoid(), formLayout);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (RuntimeException e) {
        logger.error("Error encountered while saving CRF: " + e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        if (!eicObj.errors.hasErrors())
            throw e;
    }
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException)

Example 5 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.

the class EnketoFormServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormLayoutDao formLayoutDao = (FormLayoutDao) SpringServletAccess.getApplicationContext(context).getBean("formLayoutDao");
    StudyEventDao studyEventDao = (StudyEventDao) SpringServletAccess.getApplicationContext(context).getBean("studyEventDaoDomain");
    EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
    EnketoCredentials enketoCredentials = (EnketoCredentials) SpringServletAccess.getApplicationContext(context).getBean("enketoCredentials");
    String originatingPage = request.getParameter(ORIGINATING_PAGE);
    String formLayoutId = request.getParameter(FORM_LAYOUT_ID);
    String studyEventId = request.getParameter(STUDY_EVENT_ID);
    String eventCrfId = request.getParameterValues(EVENT_CRF_ID)[0];
    String formUrl = null;
    StudyEvent studyEvent = studyEventDao.findByStudyEventId(Integer.valueOf(studyEventId));
    FormLayout formLayout = formLayoutDao.findById(Integer.valueOf(formLayoutId));
    // Cache the subject context for use during xform submission
    PFormCache cache = PFormCache.getInstance(context);
    PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
    subjectContext.setStudySubjectOid(studyEvent.getStudySubject().getOcOid());
    subjectContext.setStudyEventDefinitionId(studyEvent.getStudyEventDefinition().getStudyEventDefinitionId());
    subjectContext.setOrdinal(studyEvent.getSampleOrdinal());
    subjectContext.setFormLayoutOid(formLayout.getOcOid());
    subjectContext.setUserAccountId(ub.getId());
    String contextHash = cache.putSubjectContext(subjectContext);
    Study study = enketoCredentials.getParentStudy(currentStudy.getOid());
    if (Integer.valueOf(eventCrfId) > 0) {
        formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, study.getOc_oid(), formLayout, studyEvent, QUERY_FLAVOR);
    } else {
        formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, study.getOc_oid(), QUERY_FLAVOR);
    }
    int hashIndex = formUrl.lastIndexOf("#");
    String part1 = formUrl;
    String part2 = "";
    if (hashIndex != -1) {
        part1 = formUrl.substring(0, hashIndex);
        part2 = formUrl.substring(hashIndex);
    }
    request.setAttribute(FORM_URL1, part1);
    request.setAttribute(FORM_URL2, part2);
    // request.setAttribute(FORM_URL, "https://enke.to/i/::widgets?a=b");
    request.setAttribute(ORIGINATING_PAGE, originatingPage);
    forwardPage(Page.ENKETO_FORM_SERVLET);
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDao(org.akaza.openclinica.dao.hibernate.StudyEventDao) FormLayoutDao(org.akaza.openclinica.dao.hibernate.FormLayoutDao) EnketoUrlService(org.akaza.openclinica.service.crfdata.EnketoUrlService) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) EnketoCredentials(org.akaza.openclinica.service.crfdata.xform.EnketoCredentials) PFormCache(org.akaza.openclinica.web.pform.PFormCache) PFormCacheSubjectContextEntry(org.akaza.openclinica.service.crfdata.xform.PFormCacheSubjectContextEntry)

Aggregations

FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)16 Date (java.util.Date)6 IOException (java.io.IOException)5 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)5 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)4 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)4 Study (org.akaza.openclinica.domain.datamap.Study)4 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)4 File (java.io.File)3 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)3 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)3 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)3 StringWriter (java.io.StringWriter)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Calendar (java.util.Calendar)2 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)2