Search in sources :

Example 11 with FormLayout

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

the class OpenRosaSubmissionController method markComplete.

// @RequestMapping(value = "/{studyOID}/fieldsubmission/complete", method = RequestMethod.POST)
public ResponseEntity<String> markComplete(HttpServletRequest request, HttpServletResponse response, @PathVariable("studyOID") String studyOID, @RequestParam(FORM_CONTEXT) String ecid) throws Exception {
    HashMap<String, String> subjectContext = null;
    PFormCache cache = PFormCache.getInstance(context);
    subjectContext = cache.getSubjectContext(ecid);
    int studyEventDefinitionID = Integer.valueOf(subjectContext.get("studyEventDefinitionID"));
    int userAccountID = Integer.valueOf(subjectContext.get("userAccountID"));
    String studySubjectOID = subjectContext.get("studySubjectOID");
    String formLayoutOID = subjectContext.get("formLayoutOID");
    int studyEventOrdinal = Integer.valueOf(subjectContext.get("studyEventOrdinal"));
    UserAccount userAccount = userAccountDao.findById(userAccountID);
    StudySubject studySubject = studySubjectDao.findByOcOID(studySubjectOID);
    Study study = studyDao.findByOcOID(studyOID);
    StudyEventDefinition sed = studyEventDefinitionDao.findById(studyEventDefinitionID);
    FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOID);
    CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
    StudyEvent studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinalTransactional(sed.getOc_oid(), studyEventOrdinal, studySubject.getStudySubjectId());
    EventCrf eventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdFormLayoutId(studyEvent.getStudyEventId(), studySubject.getStudySubjectId(), formLayout.getFormLayoutId());
    if (eventCrf == null) {
        eventCrf = createEventCrf(formLayout, studyEvent, studySubject, userAccount);
        List<Item> items = itemDao.findAllByCrfVersion(crfVersion.getCrfVersionId());
        createItemData(items.get(0), "", eventCrf, userAccount);
    }
    eventCrf.setStatusId(org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode());
    eventCrf.setUserAccount(userAccount);
    eventCrf.setUpdateId(userAccount.getUserId());
    eventCrf.setDateUpdated(new Date());
    eventCrfDao.saveOrUpdate(eventCrf);
    List<EventCrf> eventCrfs = eventCrfDao.findByStudyEventIdStudySubjectId(studyEvent.getStudyEventId(), studySubject.getOcOid());
    List<EventDefinitionCrf> eventDefinitionCrfs = eventDefinitionCrfDao.findAvailableByStudyEventDefStudy(sed.getStudyEventDefinitionId(), study.getStudyId());
    int count = 0;
    for (EventCrf evCrf : eventCrfs) {
        if (evCrf.getStatusId() == org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.DELETED.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.AUTO_DELETED.getCode()) {
            for (EventDefinitionCrf eventDefinitionCrf : eventDefinitionCrfs) {
                if (eventDefinitionCrf.getCrf().getCrfId() == evCrf.getFormLayout().getCrf().getCrfId()) {
                    count++;
                    break;
                }
            }
        }
    }
    if (count == eventDefinitionCrfs.size()) {
        studyEvent.setSubjectEventStatusId(SubjectEventStatus.COMPLETED.getCode());
        studyEvent.setUserAccount(userAccount);
        studyEventDao.saveOrUpdate(studyEvent);
    } else if (studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SCHEDULED.getCode()) {
        studyEvent.setSubjectEventStatusId(SubjectEventStatus.DATA_ENTRY_STARTED.getCode());
        studyEvent.setUserAccount(userAccount);
        studyEventDao.saveOrUpdate(studyEvent);
    }
    String responseMessage = "<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>";
    return new ResponseEntity<String>(responseMessage, HttpStatus.CREATED);
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) Date(java.util.Date) EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) Item(org.akaza.openclinica.domain.datamap.Item) FileItem(org.apache.commons.fileupload.FileItem) ResponseEntity(org.springframework.http.ResponseEntity) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) UserAccount(org.akaza.openclinica.domain.user.UserAccount) PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 12 with FormLayout

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

the class EventProcessor method process.

public ProcessorEnum process(SubmissionContainer container) throws Exception {
    logger.info("Executing Event Processor.");
    Errors errors = container.getErrors();
    StudySubject studySubject = container.getSubject();
    StudyEventDefinition studyEventDefinition = studyEventDefinitionDao.findByStudyEventDefinitionId(Integer.valueOf(container.getSubjectContext().get("studyEventDefinitionID")));
    FormLayout formLayout = formLayoutDao.findByOcOID(container.getSubjectContext().get("formLayoutOID"));
    container.setFormLayout(formLayout);
    CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
    container.setCrfVersion(crfVersion);
    boolean isAnonymous = false;
    if (container.getSubjectContext().get("studySubjectOID") == null)
        isAnonymous = true;
    // Create study event if it doesn't exist
    if (isAnonymous)
        processAnonymous(container, errors, studySubject, studyEventDefinition);
    else
        processParticipant(container, errors, studySubject, studyEventDefinition);
    // TODO: May need to move this to a new processor that runs at the end
    // Update the EventCrf and StudyEvent to the proper status.
    // Don't do it in the initial save so it will have the expected audit trail entries.
    Study study = null;
    if (container.getSubjectContext().get("studyOID") != null)
        study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
    else
        study = container.getStudy();
    container.setEventCrf(updateEventCrf(container.getEventCrf(), study, studySubject, container.getUser(), isAnonymous));
    container.setStudyEvent(updateStudyEvent(container.getStudyEvent(), studyEventDefinition, study, studySubject, container.getUser(), isAnonymous));
    return ProcessorEnum.PROCEED;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Errors(org.springframework.validation.Errors) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion)

Example 13 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout 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 14 with FormLayout

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

the class FormLayoutDao method findByOcOID.

public FormLayout findByOcOID(String OCOID) {
    getSessionFactory().getStatistics().logSummary();
    Query q = getCurrentSession().createQuery(findByOcIdQuery);
    q.setParameter("OCOID", OCOID);
    return (FormLayout) q.uniqueResult();
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Query(org.hibernate.query.Query)

Example 15 with FormLayout

use of org.akaza.openclinica.domain.datamap.FormLayout 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 uniqueId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
    if (!mayProceedPreview(studyOID))
        return null;
    String formLayoutOid = getFormLayoutOid(uniqueId);
    FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
    Manifest manifest = new Manifest();
    List<FormLayoutMedia> mediaList = formLayoutMediaDao.findByFormLayoutIdForNoteTypeMedia(formLayout.getFormLayoutId());
    String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
    if (mediaList != null && mediaList.size() > 0) {
        for (FormLayoutMedia media : mediaList) {
            MediaFile mediaFile = new MediaFile();
            mediaFile.setFilename(media.getName());
            File image = new File(Utils.getCrfMediaSysPath() + media.getPath() + media.getName());
            mediaFile.setHash(DigestUtils.md5Hex(media.getName()) + Double.toString(image.length()));
            mediaFile.setDownloadUrl(urlBase + "/rest2/openrosa/" + studyOID + "/downloadMedia?formLayoutMediaId=" + media.getFormLayoutMediaId());
            manifest.add(mediaFile);
        }
    }
    // Add user list
    MediaFile userList = new MediaFile();
    LinkedHashMap<String, Object> subjectContextCache = (LinkedHashMap<String, Object>) context.getAttribute("subjectContextCache");
    if (subjectContextCache != null) {
        String userXml = getUserXml(context);
        userList.setHash((DigestUtils.md5Hex(userXml)));
    }
    userList.setFilename("users.xml");
    userList.setDownloadUrl(urlBase + "/rest2/openrosa/" + studyOID + "/downloadUsers");
    manifest.add(userList);
    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 : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) Marshaller(org.exolab.castor.xml.Marshaller) XMLContext(org.exolab.castor.xml.XMLContext) FormLayoutMedia(org.akaza.openclinica.domain.datamap.FormLayoutMedia) Calendar(java.util.Calendar) Mapping(org.exolab.castor.mapping.Mapping) Manifest(org.akaza.openclinica.web.pform.manifest.Manifest) Date(java.util.Date) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) StringWriter(java.io.StringWriter) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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