Search in sources :

Example 6 with EventDefinitionCrf

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

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

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

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

the class StudyEventController method completeParticipantEvent.

/**
	 * @api {put} /pages/auth/api/v1/studyevent/studysubject/{studySubjectOid}/studyevent/{studyEventDefOid}/ordinal/{ordinal}/complete Complete a Participant Event
	 * @apiName completeParticipantEvent
	 * @apiPermission Authenticate using api-key. admin
	 * @apiVersion 1.0.0
	 * @apiParam {String} studySubjectOid Study Subject OID.
	 * @apiParam {String} studyEventDefOid Study Event Definition OID.
	 * @apiParam {Integer} ordinal Ordinal of Study Event Repetition.
	 * @apiGroup Form
	 * @apiHeader {String} api_key Users unique access-key.
	 * @apiDescription Completes a participant study event.
	 * @apiErrorExample {json} Error-Response:
	 *                  HTTP/1.1 403 Forbidden
	 *                  {
	 *                  "code": "403",
	 *                  "message": "Request Denied.  Operation not allowed."
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    HTTP/1.1 200 OK
	 *                    {
	 *                    "code": "200",
	 *                    "message": "Success."
	 *                    }
	 */
@RequestMapping(value = "/studysubject/{studySubjectOid}/studyevent/{studyEventDefOid}/ordinal/{ordinal}/complete", method = RequestMethod.PUT)
@ResponseBody
public Map<String, String> completeParticipantEvent(HttpServletRequest request, @PathVariable("studySubjectOid") String studySubjectOid, @PathVariable("studyEventDefOid") String studyEventDefOid, @PathVariable("ordinal") Integer ordinal) throws Exception {
    StudySubject subject = studySubjectDao.findByOcOID(studySubjectOid);
    StudyEvent studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefOid, ordinal, subject.getStudySubjectId());
    StudyEventDefinition studyEventDefinition = studyEventDefinitionDao.findByStudyEventDefinitionId(studyEvent.getStudyEventDefinition().getStudyEventDefinitionId());
    Study study = studyEventDefinition.getStudy();
    Map<String, String> response = new HashMap<String, String>();
    // Verify this request is allowed.
    if (!mayProceed(study)) {
        response.put("code", String.valueOf(HttpStatus.FORBIDDEN.value()));
        response.put("message", "Request Denied.  Operation not allowed.");
        return response;
    }
    // Get list of eventCRFs
    // By this point we can assume all Participant forms have been submitted at least once and have an event_crf entry.
    // Non-Participant forms may not have an entry.
    List<EventDefinitionCrf> eventDefCrfs = eventDefinitionCrfDao.findByStudyEventDefinitionId(studyEventDefinition.getStudyEventDefinitionId());
    List<EventCrf> eventCrfs = eventCrfDao.findByStudyEventIdStudySubjectId(studyEvent.getStudyEventId(), studySubjectOid);
    try {
        completeData(studyEvent, eventDefCrfs, eventCrfs);
    } catch (Exception e) {
        // Transaction has been rolled back due to an exception.
        logger.error("Error encountered while completing Study Event: " + e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
        response.put("code", String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()));
        response.put("message", "Error encountered while completing participant event.");
        return response;
    }
    response.put("code", String.valueOf(HttpStatus.OK.value()));
    response.put("message", "Success.");
    return response;
//return new ResponseEntity<String>("<message>Success</message>", org.springframework.http.HttpStatus.OK);
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) HashMap(java.util.HashMap) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)9 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)4 Study (org.akaza.openclinica.domain.datamap.Study)4 ArrayList (java.util.ArrayList)3 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)3 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)3 Date (java.util.Date)2 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)2 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)2 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)2 UserAccount (org.akaza.openclinica.domain.user.UserAccount)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashMap (java.util.HashMap)1 ExportFormDataBean (org.akaza.openclinica.bean.submit.crfdata.ExportFormDataBean)1 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)1 Item (org.akaza.openclinica.domain.datamap.Item)1 StudyParameterValue (org.akaza.openclinica.domain.datamap.StudyParameterValue)1 StudyUserRole (org.akaza.openclinica.domain.datamap.StudyUserRole)1 StudyUserRoleId (org.akaza.openclinica.domain.datamap.StudyUserRoleId)1 StudyEventChangeDetails (org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails)1