Search in sources :

Example 6 with CrfBean

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

the class OdmImportServiceImpl method importOdmToOC.

@Transactional
public void importOdmToOC(ODM odm) {
    UserAccount userAccount = getCurrentUser();
    // TODO add validation to all entities
    ODMcomplexTypeDefinitionStudy odmStudy = odm.getStudy().get(0);
    Study study = saveOrUpdateStudy(odm, userAccount, odmStudy);
    ParticipantPortalRegistrar portal = new ParticipantPortalRegistrar();
    portal.registerStudy(study.getOc_oid(), study.getOc_oid(), study.getName());
    StudyParameterValue spv = getStudyParameterValueDao().findByStudyIdParameter(study.getStudyId(), "participantPortal");
    // Update OC Study configuration
    if (spv == null) {
        spv = new StudyParameterValue();
        spv.setStudy(study);
    }
    spv.setValue("enabled");
    spv = getStudyParameterValueDao().saveOrUpdate(spv);
    StudyUserRole studyUserRole = null;
    StudyUserRoleId studyUserRoleId = null;
    Form[] fmCrfs = getAllCrfsByProtIdFromFormManager(study);
    ArrayList<StudyUserRole> surRoles = getStudyUserRoleDao().findAllUserRolesByUserAccount(userAccount, study.getStudyId(), study.getStudyId());
    if (surRoles.size() == 0) {
        studyUserRoleId = new StudyUserRoleId();
        studyUserRole = new StudyUserRole();
        studyUserRole = getStudyUserRoleDao().saveOrUpdate(populateUserRole(study, userAccount, studyUserRole, studyUserRoleId));
    }
    StudyEventDefinition studyEventDefinition = null;
    List<ODMcomplexTypeDefinitionMetaDataVersion> odmMetadataVersions = odmStudy.getMetaDataVersion();
    List<ODMcomplexTypeDefinitionStudyEventDef> odmStudyEventDefs = saveOrUpdateEvent(userAccount, study, odmMetadataVersions);
    CrfBean crf = null;
    FormLayout formLayout = null;
    saveOrUpdateCrf(userAccount, study, odmMetadataVersions, fmCrfs);
    List<ODMcomplexTypeDefinitionStudyEventRef> odmStudyEventRefs = odmMetadataVersions.get(0).getProtocol().getStudyEventRef();
    for (ODMcomplexTypeDefinitionStudyEventRef odmStudyEventRef : odmStudyEventRefs) {
        for (ODMcomplexTypeDefinitionStudyEventDef odmStudyEventDef : odmStudyEventDefs) {
            if (odmStudyEventDef.getOID().equals(odmStudyEventRef.getStudyEventOID())) {
                studyEventDefinition = getStudyEventDefDao().findByOcOID(odmStudyEventDef.getOID());
                studyEventDefinition.setOrdinal(odmStudyEventRef.getOrderNumber().intValue());
                studyEventDefinition = getStudyEventDefDao().saveOrUpdate(studyEventDefinition);
                List<EventDefinitionCrf> jsonEventDefCrfList = new ArrayList<>();
                EventDefinitionCrf eventDefinitionCrf = null;
                for (ODMcomplexTypeDefinitionFormRef odmFormRef : odmStudyEventDef.getFormRef()) {
                    crf = getCrfDao().findByOcOID(odmFormRef.getFormOID());
                    eventDefinitionCrf = getEventDefinitionCrfDao().findByStudyEventDefinitionIdAndCRFIdAndStudyId(studyEventDefinition.getStudyEventDefinitionId(), crf.getCrfId(), study.getStudyId());
                    String defaultVersionName = null;
                    OCodmComplexTypeDefinitionConfigurationParameters conf = odmFormRef.getConfigurationParameters();
                    List<OCodmComplexTypeDefinitionFormLayoutRef> formLayoutRefs = odmFormRef.getFormLayoutRef();
                    if (formLayoutRefs.size() == 1 && formLayoutRefs.get(0).getIsDefaultVersion() == null) {
                        defaultVersionName = formLayoutRefs.get(0).getOID();
                    } else {
                        for (OCodmComplexTypeDefinitionFormLayoutRef formLayoutRef : formLayoutRefs) {
                            if (formLayoutRef.getIsDefaultVersion().equalsIgnoreCase("Yes")) {
                                defaultVersionName = formLayoutRef.getOID();
                            }
                        }
                    }
                    if (defaultVersionName == null) {
                        defaultVersionName = formLayoutRefs.get(0).getOID();
                    }
                    formLayout = getFormLayoutDao().findByNameCrfId(defaultVersionName, crf.getCrfId());
                    EventDefinitionCrfDTO edcObj = new EventDefinitionCrfDTO();
                    edcObj.setUserAccount(userAccount);
                    edcObj.setConf(conf);
                    edcObj.setCrf(crf);
                    edcObj.setEventDefinitionCrf(eventDefinitionCrf);
                    edcObj.setOdmFormRef(odmFormRef);
                    edcObj.setStudy(study);
                    edcObj.setFormLayout(formLayout);
                    edcObj.setStudyEventDefinition(studyEventDefinition);
                    EDCTagDTO populateEDCTagParameter = new EDCTagDTO();
                    populateEDCTagParameter.setConf(conf);
                    populateEDCTagParameter.setConf(conf);
                    populateEDCTagParameter.setEventDefinitionCrf(eventDefinitionCrf);
                    populateEDCTagParameter.setUserAccount(userAccount);
                    eventDefinitionCrf = saveOrUpdateEventDefnCrf(new EventDefinitionCrfDTO(edcObj));
                    saveOrUpdateEDCTag(new EDCTagDTO(populateEDCTagParameter), studyEventDefinition, crf);
                    jsonEventDefCrfList.add(eventDefinitionCrf);
                }
                List<EventDefinitionCrf> ocEventDefCrfList = getEventDefinitionCrfDao().findAvailableByStudyEventDefStudy(studyEventDefinition.getStudyEventDefinitionId(), study.getStudyId());
                for (EventDefinitionCrf ocEventDefCrf : ocEventDefCrfList) {
                    if (!jsonEventDefCrfList.contains(ocEventDefCrf)) {
                        ocEventDefCrf.setStatusId(Status.DELETED.getCode());
                        getEventDefinitionCrfDao().saveOrUpdate(ocEventDefCrf);
                    }
                }
            }
        }
    }
}
Also used : CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) Form(org.akaza.openclinica.service.dto.Form) ArrayList(java.util.ArrayList) ODMcomplexTypeDefinitionStudy(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudy) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) ODMcomplexTypeDefinitionMetaDataVersion(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionMetaDataVersion) StudyUserRole(org.akaza.openclinica.domain.datamap.StudyUserRole) ODMcomplexTypeDefinitionFormRef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionFormRef) StudyUserRoleId(org.akaza.openclinica.domain.datamap.StudyUserRoleId) FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) ODMcomplexTypeDefinitionStudy(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudy) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudyParameterValue(org.akaza.openclinica.domain.datamap.StudyParameterValue) ODMcomplexTypeDefinitionStudyEventDef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventDef) ParticipantPortalRegistrar(org.akaza.openclinica.service.pmanage.ParticipantPortalRegistrar) OCodmComplexTypeDefinitionConfigurationParameters(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionConfigurationParameters) OCodmComplexTypeDefinitionFormLayoutRef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutRef) ODMcomplexTypeDefinitionStudyEventRef(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventRef) UserAccount(org.akaza.openclinica.domain.user.UserAccount) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with CrfBean

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

the class GenerateClinicalDataServiceImpl method listOfHiddenCrfs.

private List<CrfBean> listOfHiddenCrfs(Integer siteId, Integer parentStudyId, List<EventDefinitionCrf> edcs, EventCrf ecrf) {
    boolean found = false;
    int crfId = ecrf.getCrfVersion().getCrf().getCrfId();
    List<CrfBean> hiddenCrfs = new ArrayList<CrfBean>();
    LOGGER.info("The study subject is at the site/study " + siteId);
    for (EventDefinitionCrf eventDefCrf : edcs) {
        if (eventDefCrf.getCrf().getCrfId() == crfId && eventDefCrf.getStudy().getStudyId() == siteId) {
            found = true;
            if (eventDefCrf.getHideCrf()) {
                hiddenCrfs.add(eventDefCrf.getCrf());
            }
        }
    }
    if (!found) {
        for (EventDefinitionCrf eventDefCrf : edcs) {
            if (eventDefCrf.getCrf().getCrfId() == crfId && eventDefCrf.getStudy().getStudyId() == parentStudyId && eventDefCrf.getHideCrf()) {
                hiddenCrfs.add(eventDefCrf.getCrf());
            }
        }
    }
    return hiddenCrfs;
}
Also used : CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) ArrayList(java.util.ArrayList) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf)

Example 8 with CrfBean

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

the class CreateXformCRFVersionServlet method processRequest.

// public final String FM_BASEURL = "http://oc.local:8090/api/protocol/";
@Override
protected void processRequest() throws Exception {
    CrfDao crfDao = (CrfDao) SpringServletAccess.getApplicationContext(context).getBean("crfDao");
    XformMetaDataService xformService = (XformMetaDataService) SpringServletAccess.getApplicationContext(context).getBean("xformService");
    Locale locale = LocaleResolver.getLocale(request);
    ResourceBundleProvider.updateLocale(locale);
    resword = ResourceBundleProvider.getWordsBundle(locale);
    // Retrieve submission data from multipart request
    DiskFileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<FileItem> items = upload.parseRequest(request);
    String crfName = retrieveFormFieldValue(items, "crfName");
    DataBinder dataBinder = new DataBinder(new FormVersion());
    Errors errors = dataBinder.getBindingResult();
    int crfId = Integer.valueOf(retrieveFormFieldValue(items, "crfId"));
    if (crfId != 0) {
        CrfBean crfBean = crfDao.findByCrfId(crfId);
        crfName = crfBean.getName();
    }
    FormArtifactTransferObj transferObj = getFormArtifactsFromFM(items, currentStudy.getOid(), crfName);
    if (transferObj.getErr().size() != 0) {
        for (ErrorObj er : transferObj.getErr()) {
            errors.rejectValue("name", er.getCode(), er.getMessage());
        }
    } else {
        List<OCodmComplexTypeDefinitionFormLayoutDef> formLayoutDefs = new ArrayList<>();
        OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef;
        for (FormVersion version : transferObj.getForm().getVersions()) {
            formLayoutDef = new OCodmComplexTypeDefinitionFormLayoutDef();
            formLayoutDef.setOID(version.getName());
            formLayoutDef.setURL(version.getArtifactURL());
            formLayoutDefs.add(formLayoutDef);
        }
        ExecuteIndividualCrfObject eicObj = new ExecuteIndividualCrfObject(transferObj.getForm(), formLayoutDefs, errors, currentStudy, ub, false, null);
        xformService.executeIndividualCrf(eicObj);
    }
    if (errors.hasErrors()) {
        request.setAttribute("errorList", errors.getAllErrors());
    }
    forwardPage(Page.CREATE_XFORM_CRF_VERSION_SERVLET);
}
Also used : Locale(java.util.Locale) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) ExecuteIndividualCrfObject(org.akaza.openclinica.service.crfdata.ExecuteIndividualCrfObject) OCodmComplexTypeDefinitionFormLayoutDef(org.openclinica.ns.odm_ext_v130.v31.OCodmComplexTypeDefinitionFormLayoutDef) ArrayList(java.util.ArrayList) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) CrfDao(org.akaza.openclinica.dao.hibernate.CrfDao) FileItem(org.apache.commons.fileupload.FileItem) Errors(org.springframework.validation.Errors) XformMetaDataService(org.akaza.openclinica.service.crfdata.XformMetaDataService) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FormArtifactTransferObj(org.akaza.openclinica.service.crfdata.FormArtifactTransferObj) DataBinder(org.springframework.validation.DataBinder) FormVersion(org.akaza.openclinica.service.dto.FormVersion) ErrorObj(org.akaza.openclinica.service.crfdata.ErrorObj)

Example 9 with CrfBean

use of org.akaza.openclinica.domain.datamap.CrfBean 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 uniqueId, @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>";
    }
    String flavor = getQuerySet(uniqueId);
    String formLayoutOid = getFormLayoutOid(uniqueId);
    FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
    CrfBean crf = formLayout.getCrf();
    String xformOutput = "";
    String directoryPath = Utils.getCrfMediaFilePath(crf.getOcOid(), formLayout.getOcOid());
    File dir = new File(directoryPath);
    File[] directoryListing = dir.listFiles();
    if (directoryListing != null) {
        for (File child : directoryListing) {
            if (flavor.equals(QUERY_FLAVOR) && child.getName().endsWith(QUERY_SUFFIX) || flavor.equals(NO_FLAVOR) && child.getName().endsWith(NO_SUFFIX)) {
                xformOutput = new String(Files.readAllBytes(Paths.get(child.getPath())));
                break;
            }
        }
    }
    try {
        if (StringUtils.isNotEmpty(xformOutput)) {
            xform = xformOutput;
        }
    } catch (Exception 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=\"" + formId + ".xml" + "\";");
    response.setContentType("text/xml; charset=utf-8");
    return xform;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)9 ArrayList (java.util.ArrayList)5 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)5 File (java.io.File)3 IOException (java.io.IOException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)3 StringWriter (java.io.StringWriter)2 Date (java.util.Date)2 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)2 Study (org.akaza.openclinica.domain.datamap.Study)2 XForm (org.akaza.openclinica.web.pform.formlist.XForm)2 XFormList (org.akaza.openclinica.web.pform.formlist.XFormList)2 MediaFile (org.akaza.openclinica.web.pform.manifest.MediaFile)2 Transactional (org.springframework.transaction.annotation.Transactional)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1