Search in sources :

Example 61 with StudyEventDefinitionBean

use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.

the class StudyController method createEventDefn.

public StudyEventDefinitionBean createEventDefn(StudyEventDefinitionBean sedBean, UserAccountBean owner) {
    seddao = new StudyEventDefinitionDAO(dataSource);
    StudyEventDefinitionBean sdBean = (StudyEventDefinitionBean) seddao.create(sedBean);
    sdBean = (StudyEventDefinitionBean) seddao.findByPK(sdBean.getId());
    return sdBean;
}
Also used : StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Example 62 with StudyEventDefinitionBean

use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.

the class StudyController method createEventDefinition.

/**
	 * @api {post} /pages/auth/api/v1/studies/:uniqueProtocolId/eventdefinitions Create a study event
	 * @apiName createEventDefinition
	 * @apiPermission Authenticate using api-key. admin
	 * @apiVersion 3.8.0
	 * @apiParam {String} uniqueProtocolId Study unique protocol ID.
	 * @apiParam {String} name Event Name.
	 * @apiParam {String} description Event Description.
	 * @apiParam {String} category Category Name.
	 * @apiParam {Boolean} repeating 'True' or 'False'.
	 * @apiParam {String} type 'Scheduled' , 'UnScheduled' or 'Common'.
	 * @apiGroup Study Event
	 * @apiHeader {String} api_key Users unique access-key.
	 * @apiDescription Creates a study event definition.
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "name": "Event Name",
	 *                  "description": "Event Description",
	 *                  "category": "Category Name",
	 *                  "repeating": "true",
	 *                  "type":"Scheduled"
	 *                  }
	 * @apiErrorExample {json} Error-Response:
	 *                  HTTP/1.1 400 Bad Request
	 *                  {
	 *                  "name": "Event Name",
	 *                  "message": "VALIDATION FAILED",
	 *                  "type": "",
	 *                  "errors": [
	 *                  {"field": "Type","resource": "Event Definition Object","code": "Type Field should be Either 'Scheduled' , 'UnScheduled' or 'Common'"},
	 *                  {"field": "Type","resource": "Event Definition Object","code": "This field cannot be blank."}
	 *                  ],
	 *                  "category": "Category Name",
	 *                  "description": "Event Description",
	 *                  "eventDefOid": null,
	 *                  "repeating": "true"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    HTTP/1.1 200 OK
	 *                    {
	 *                    "message": "SUCCESS",
	 *                    "name": "Event Name",
	 *                    "eventDefOid": "SE_EVENTNAME"
	 *                    }
	 */
@RequestMapping(value = "/{uniqueProtocolID}/eventdefinitions", method = RequestMethod.POST)
public ResponseEntity<Object> createEventDefinition(HttpServletRequest request, @RequestBody HashMap<String, Object> map, @PathVariable("uniqueProtocolID") String uniqueProtocolID) throws Exception {
    System.out.println("I'm in Create Event Definition ");
    ArrayList<ErrorObject> errorObjects = new ArrayList();
    StudyEventDefinitionBean eventBean = null;
    ResponseEntity<Object> response = null;
    String validation_failed_message = "VALIDATION FAILED";
    String validation_passed_message = "SUCCESS";
    String name = (String) map.get("name");
    String description = (String) map.get("description");
    String category = (String) map.get("category");
    String type = (String) map.get("type");
    String repeating = (String) map.get("repeating");
    EventDefinitionDTO eventDefinitionDTO = buildEventDefnDTO(name, description, category, repeating, type);
    if (name == null) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Name");
        errorObjects.add(errorOBject);
    } else {
        name = name.trim();
    }
    if (description == null) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Description");
        errorObjects.add(errorOBject);
    } else {
        description = description.trim();
    }
    if (category == null) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Category");
        errorObjects.add(errorOBject);
    } else {
        category = category.trim();
    }
    if (type == null) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Type");
        errorObjects.add(errorOBject);
    } else {
        type = type.trim();
    }
    if (repeating == null) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "Missing Field", "Repeating");
        errorObjects.add(errorOBject);
    } else {
        repeating = repeating.trim();
    }
    if (repeating != null) {
        if (!repeating.equalsIgnoreCase("true") && !repeating.equalsIgnoreCase("false")) {
            ErrorObject errorOBject = createErrorObject("Event Definition Object", "Repeating Field should be Either 'True' or 'False'", "Repeating");
            errorObjects.add(errorOBject);
        }
    }
    if (type != null) {
        if (!type.equalsIgnoreCase("scheduled") && !type.equalsIgnoreCase("unscheduled") && !type.equalsIgnoreCase("common")) {
            ErrorObject errorOBject = createErrorObject("Event Definition Object", "Type Field should be Either 'Scheduled' , 'UnScheduled' or 'Common'", "Type");
            errorObjects.add(errorOBject);
        }
    }
    request.setAttribute("name", name);
    request.setAttribute("description", description);
    request.setAttribute("category", category);
    request.setAttribute("type", type);
    request.setAttribute("repeating", repeating);
    StudyBean parentStudy = getStudyByUniqId(uniqueProtocolID);
    if (parentStudy == null) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Study Protocol Id provided in the URL is not a valid Protocol Id", "Unique Study Protocol Id");
        errorObjects.add(errorOBject);
    } else if (parentStudy.getParentStudyId() != 0) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Study Protocol Id provided in the URL is not a valid Study Protocol Id", "Unique Study Protocol Id");
        errorObjects.add(errorOBject);
    }
    UserAccountBean ownerUserAccount = getStudyOwnerAccount(request);
    if (ownerUserAccount == null) {
        ErrorObject errorOBject = createErrorObject("Study Object", "The Owner User Account is not Valid Account or Does not have Admin user type", "Owner Account");
        errorObjects.add(errorOBject);
    }
    Validator v1 = new Validator(request);
    v1.addValidation("name", Validator.NO_BLANKS);
    HashMap vError1 = v1.validate();
    if (!vError1.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "This field cannot be blank.", "Name");
        errorObjects.add(errorOBject);
    }
    if (name != null) {
        Validator v2 = new Validator(request);
        v2.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
        HashMap vError2 = v2.validate();
        if (!vError2.isEmpty()) {
            ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Length Should not exceed 2000.", "Name");
            errorObjects.add(errorOBject);
        }
    }
    if (description != null) {
        Validator v3 = new Validator(request);
        v3.addValidation("description", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
        HashMap vError3 = v3.validate();
        if (!vError3.isEmpty()) {
            ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Length Should not exceed 2000.", "Description");
            errorObjects.add(errorOBject);
        }
    }
    if (category != null) {
        Validator v4 = new Validator(request);
        v4.addValidation("category", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
        HashMap vError4 = v4.validate();
        if (!vError4.isEmpty()) {
            ErrorObject errorOBject = createErrorObject("Event Definition Object", "The Length Should not exceed 2000.", "Category");
            errorObjects.add(errorOBject);
        }
    }
    Validator v5 = new Validator(request);
    v5.addValidation("repeating", Validator.NO_BLANKS);
    HashMap vError5 = v5.validate();
    if (!vError5.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "This field cannot be blank.", "Repeating");
        errorObjects.add(errorOBject);
    }
    Validator v6 = new Validator(request);
    v6.addValidation("type", Validator.NO_BLANKS);
    HashMap vError6 = v6.validate();
    if (!vError6.isEmpty()) {
        ErrorObject errorOBject = createErrorObject("Event Definition Object", "This field cannot be blank.", "Type");
        errorObjects.add(errorOBject);
    }
    eventDefinitionDTO.setErrors(errorObjects);
    if (errorObjects != null && errorObjects.size() != 0) {
        eventDefinitionDTO.setMessage(validation_failed_message);
        response = new ResponseEntity(eventDefinitionDTO, org.springframework.http.HttpStatus.BAD_REQUEST);
    } else {
        eventBean = buildEventDefBean(name, description, category, type, repeating, ownerUserAccount, parentStudy);
        StudyEventDefinitionBean sedBean = createEventDefn(eventBean, ownerUserAccount);
        eventDefinitionDTO.setEventDefOid(sedBean.getOid());
        eventDefinitionDTO.setMessage(validation_passed_message);
    }
    ResponseSuccessEventDefDTO responseSuccess = new ResponseSuccessEventDefDTO();
    responseSuccess.setMessage(eventDefinitionDTO.getMessage());
    responseSuccess.setEventDefOid(eventDefinitionDTO.getEventDefOid());
    responseSuccess.setName(eventDefinitionDTO.getName());
    response = new ResponseEntity(responseSuccess, org.springframework.http.HttpStatus.OK);
    return response;
}
Also used : HashMap(java.util.HashMap) ErrorObject(org.akaza.openclinica.bean.login.ErrorObject) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ResponseEntity(org.springframework.http.ResponseEntity) EventDefinitionDTO(org.akaza.openclinica.bean.login.EventDefinitionDTO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ErrorObject(org.akaza.openclinica.bean.login.ErrorObject) ResponseSuccessEventDefDTO(org.akaza.openclinica.bean.login.ResponseSuccessEventDefDTO) Validator(org.akaza.openclinica.control.form.Validator)

Example 63 with StudyEventDefinitionBean

use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.

the class OdmController method generateStudyEventData.

private ODMcomplexTypeDefinitionStudyEventData generateStudyEventData(StudyEventBean studyEvent) {
    ODMcomplexTypeDefinitionStudyEventData studyEventData = new ODMcomplexTypeDefinitionStudyEventData();
    studyEventData.setStartDate(studyEvent.getDateStarted().toString());
    StudyEventDefinitionBean studyEventDefBean = getStudyEventDefinitionBean(studyEvent.getStudyEventDefinitionId());
    studyEventData.setEventName(studyEventDefBean.getName());
    studyEventData.setStudyEventOID(studyEventDefBean.getOid());
    studyEventData.setStudyEventRepeatKey(String.valueOf(studyEvent.getSampleOrdinal()));
    return studyEventData;
}
Also used : StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ODMcomplexTypeDefinitionStudyEventData(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionStudyEventData)

Example 64 with StudyEventDefinitionBean

use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.

the class OdmController method getStudyEventDefinitionBean.

private StudyEventDefinitionBean getStudyEventDefinitionBean(int ID) {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
    StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) seddao.findByPK(ID);
    return studyEventDefinitionBean;
}
Also used : StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Example 65 with StudyEventDefinitionBean

use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.

the class StudyController method buildEventDefBean.

public StudyEventDefinitionBean buildEventDefBean(String name, String description, String category, String type, String repeating, UserAccountBean owner, StudyBean parentStudy) {
    StudyEventDefinitionBean sed = new StudyEventDefinitionBean();
    seddao = new StudyEventDefinitionDAO(dataSource);
    ArrayList defs = seddao.findAllByStudy(parentStudy);
    if (defs == null || defs.isEmpty()) {
        sed.setOrdinal(1);
    } else {
        int lastCount = defs.size() - 1;
        StudyEventDefinitionBean last = (StudyEventDefinitionBean) defs.get(lastCount);
        sed.setOrdinal(last.getOrdinal() + 1);
    }
    sed.setName(name);
    sed.setCategory(category);
    sed.setType(type.toLowerCase());
    sed.setDescription(description);
    sed.setRepeating(Boolean.valueOf(repeating));
    sed.setStudyId(parentStudy.getId());
    sed.setOwner(owner);
    sed.setStatus(Status.AVAILABLE);
    return sed;
}
Also used : StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)

Aggregations

StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)155 ArrayList (java.util.ArrayList)109 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)85 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)65 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)61 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)61 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)56 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)55 HashMap (java.util.HashMap)51 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)51 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)50 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)49 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)49 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)48 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)45 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)45 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)42 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)39 Date (java.util.Date)37 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)37