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;
}
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;
}
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;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class UrlRewriteServlet method getOpenClinicaResourceFromURL.
/**
* Method to parse the request URL parameters and get the respective
* database identifiers
*
* @param URLPath
* - example "S_CPCS/320999/SE_CPCS%5B1%5D/F_CPCS_1"
* @param queryString
* - example
* "format=html&mode=view&tabId=1&exitTo=ViewStudySubject"
* @return
*/
public OpenClinicaResource getOpenClinicaResourceFromURL(String URLPath) /*
* ,
* String
* queryString
*/
{
OpenClinicaResource openClinicaResource = new OpenClinicaResource();
if ((null != URLPath) && (!URLPath.equals(""))) {
if (URLPath.contains("/")) {
String[] tokens = URLPath.split("/");
if (tokens.length != 0) {
String URLParamValue = "";
StudyDAO stdao = new StudyDAO(getDataSource());
StudySubjectDAO ssubdao = new StudySubjectDAO(getDataSource());
StudyEventDefinitionDAO sedefdao = new StudyEventDefinitionDAO(getDataSource());
CRFDAO crfdao = new CRFDAO(getDataSource());
CRFVersionDAO crfvdao = new CRFVersionDAO(getDataSource());
ItemDAO idao = new ItemDAO(getDataSource());
ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyBean study = null;
StudySubjectBean subject = null;
StudyEventDefinitionBean sed = null;
CRFBean c = null;
CRFVersionBean cv = null;
ItemBean item = null;
ItemGroupBean ig = null;
StudyEventBean studyEvent = null;
Integer studySubjectId = 0;
Integer eventDefId = 0;
Integer eventRepeatKey = 0;
for (int i = 0; i < tokens.length; i++) {
// when interpreting these request URL parameters, the
// assumption is that the position of
// each type of parameters will be fixed. Meaning, study
// OID is always going to be at the start
// followed by StudySubjectKey followed by study event
// definition OID followed by
// study event repeat key followed by form OID followed
// by item group OID followed by
// item group repeat key followed by item OID
// It can also be done based on the start of OID value
// (example study OID presently
// starts with 'S_' but we will have to change it if we
// change the method of generating
// oID values in future.
URLParamValue = tokens[i].trim();
// System.out.println("URLParamValue::"+URLParamValue);
logger.info("URLPAramValue::" + URLParamValue);
if ((null != URLParamValue) && (!URLParamValue.equals(""))) {
switch(i) {
case 0:
{
// study OID
study = stdao.findByOid(URLParamValue);
// validate study OID
if (study == null) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_study_oid"));
return openClinicaResource;
} else {
openClinicaResource.setStudyOID(URLParamValue);
if (null != study) {
openClinicaResource.setStudyID(study.getId());
}
}
break;
}
case 1:
{
// StudySubjectKey
subject = ssubdao.findByOidAndStudy(URLParamValue, study.getId());
// validate subject OID
if (subject == null) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_subject_oid"));
return openClinicaResource;
} else {
openClinicaResource.setStudySubjectOID(URLParamValue);
if (null != subject) {
studySubjectId = subject.getId();
openClinicaResource.setStudySubjectID(studySubjectId);
}
}
break;
}
case 2:
{
// study event definition OID
// separate study event OID and study event
// repeat key
String seoid = "";
String eventOrdinal = "";
if (URLParamValue.contains("%5B") && URLParamValue.contains("%5D")) {
seoid = URLParamValue.substring(0, URLParamValue.indexOf("%5B"));
openClinicaResource.setStudyEventDefOID(seoid);
eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("%5B") + 3, URLParamValue.indexOf("%5D"));
} else if (URLParamValue.contains("[") && URLParamValue.contains("]")) {
seoid = URLParamValue.substring(0, URLParamValue.indexOf("["));
logger.info("seoid" + seoid);
openClinicaResource.setStudyEventDefOID(seoid);
eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("[") + 1, URLParamValue.indexOf("]"));
logger.info("eventOrdinal::" + eventOrdinal);
} else {
// event ordinal not specified
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("event_ordinal_not_specified"));
return openClinicaResource;
}
if ((null != seoid) && (null != study)) {
sed = sedefdao.findByOidAndStudy(seoid, study.getId(), study.getParentStudyId());
// validate study event oid
if (null == sed) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_event_oid"));
return openClinicaResource;
} else {
eventDefId = sed.getId();
openClinicaResource.setStudyEventDefID(eventDefId);
}
}
if (null != eventRepeatKey) {
eventRepeatKey = Integer.parseInt(eventOrdinal.trim());
// validate the event ordinal specified exists in database
studyEvent = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(subject.getId(), sed.getId(), eventRepeatKey);
// this method return new StudyEvent (not null) even if no studyEvent can be found
if (null == studyEvent || studyEvent.getId() == 0) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_event_ordinal"));
return openClinicaResource;
} else {
openClinicaResource.setStudyEventRepeatKey(eventRepeatKey);
}
}
break;
}
case 3:
{
// form OID
openClinicaResource.setFormVersionOID(URLParamValue);
// validate the crf version oid
cv = crfvdao.findByOid(URLParamValue);
if (cv == null) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_crf_oid"));
return openClinicaResource;
} else {
openClinicaResource.setFormVersionID(cv.getId());
// validate if crf is removed
if (cv.getStatus().equals(Status.DELETED)) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("removed_crf"));
return openClinicaResource;
} else {
if (null != study) {
// cv =
// crfvdao.findByCrfVersionOidAndStudy(URLParamValue,
// study.getId());
// if (null != cv) {
// openClinicaResource.setFormVersionID(cv.getId());
// openClinicaResource.setFormID(cv.getCrfId());
// }
HashMap studySubjectCRFDataDetails = sedao.getStudySubjectCRFData(study, studySubjectId, eventDefId, URLParamValue, eventRepeatKey);
if ((null != studySubjectCRFDataDetails) && (studySubjectCRFDataDetails.size() != 0)) {
if (studySubjectCRFDataDetails.containsKey("event_crf_id")) {
openClinicaResource.setEventCrfId((Integer) studySubjectCRFDataDetails.get("event_crf_id"));
}
if (studySubjectCRFDataDetails.containsKey("event_definition_crf_id")) {
openClinicaResource.setEventDefinitionCrfId((Integer) studySubjectCRFDataDetails.get("event_definition_crf_id"));
}
if (studySubjectCRFDataDetails.containsKey("study_event_id")) {
openClinicaResource.setStudyEventId((Integer) studySubjectCRFDataDetails.get("study_event_id"));
}
} else {
// no data was found in the database for the combination of parameters in the RESTful URL. There are 2 possible reasons:
// a. The data entry is not started yet for this event CRF. As of OpenClinica 3.1.3 we have not implemented the
// RESTful URL functionality in this case.
// b. The form version OID entered in the URL could be different than the one used in the data entry
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("either_no_data_for_crf_or_data_entry_not_started"));
return openClinicaResource;
}
}
}
}
break;
}
case 4:
{
// item group OID
// separate item group OID and item group
// repeat key
String igoid = "";
String igRepeatKey = "";
if (URLParamValue.contains("[")) {
igoid = URLParamValue.substring(1, URLParamValue.indexOf("["));
igRepeatKey = URLParamValue.substring(URLParamValue.indexOf("["), URLParamValue.indexOf("}]"));
}
if ((null != igoid) && (null != cv)) {
ig = igdao.findByOidAndCrf(URLParamValue, cv.getCrfId());
if (null != ig) {
openClinicaResource.setItemGroupID(ig.getId());
}
}
if (null != igRepeatKey) {
openClinicaResource.setItemGroupRepeatKey(Integer.parseInt(igRepeatKey));
}
break;
}
case 5:
{
// item = idao.find
break;
}
}
// switch end
}
}
}
}
}
return openClinicaResource;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class AnonymousFormControllerV2 method getEnketoForm.
/**
* @api {post} /pages/api/v2/anonymousform/form Retrieve anonymous form URL
* @apiName getEnketoForm
* @apiPermission Module participate - enabled
* @apiVersion 3.8.0
* @apiParam {String} studyOid Study Oid
* @apiParam {String} submissionUri Submission Url
* @apiGroup Form
* @apiDescription Retrieve anonymous form url.
* @apiParamExample {json} Request-Example:
* {
* "studyOid": "S_BL101",
* "submissionUri": "abcde"
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "url": "http://localhost:8006/::YYYi?iframe=true&ecid=abb764d026830e98b895ece6d9dcaf3c5e817983cc00a4ebfaabcb6c3700b4d5",
* "offline": "false"
* }
*/
@RequestMapping(value = "/form", method = RequestMethod.POST)
public ResponseEntity<AnonymousUrlResponse> getEnketoForm(@RequestBody HashMap<String, String> map) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
EventDefinitionCrfTagService tagService = (EventDefinitionCrfTagService) SpringServletAccess.getApplicationContext(context).getBean("eventDefinitionCrfTagService");
String formUrl = null;
String studyOid = map.get("studyOid");
if (!mayProceed(studyOid))
return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
String submissionUri = map.get("submissionUri");
if (submissionUri != "" && submissionUri != null) {
StudyBean study = getStudy(studyOid);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(dataSource);
ArrayList<EventDefinitionCRFBean> edcBeans = edcdao.findAllSubmissionUriAndStudyId(submissionUri, study.getId());
if (edcBeans.size() != 0) {
EventDefinitionCRFBean edcBean = edcBeans.get(0);
CRFDAO crfdao = new CRFDAO(dataSource);
CRFVersionDAO cvdao = new CRFVersionDAO(dataSource);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
CRFVersionBean crfVersionBean = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
CRFBean crf = (CRFBean) crfdao.findByPK(crfVersionBean.getCrfId());
StudyBean sBean = (StudyBean) sdao.findByPK(edcBean.getStudyId());
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
String tagPath = sedBean.getOid() + "." + crf.getOid();
boolean isOffline = tagService.getEventDefnCrfOfflineStatus(2, tagPath, true);
String offline = null;
if (isOffline)
offline = "true";
else
offline = "false";
formUrl = createAnonymousEnketoUrl(sBean.getOid(), crfVersionBean, edcBean, isOffline);
AnonymousUrlResponse anonResponse = new AnonymousUrlResponse(formUrl, offline, crf.getName(), crfVersionBean.getDescription());
return new ResponseEntity<AnonymousUrlResponse>(anonResponse, org.springframework.http.HttpStatus.OK);
} else {
return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
}
} else {
return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
}
}
Aggregations