use of org.akaza.openclinica.bean.managestudy.StudyBean 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.StudyBean in project OpenClinica by OpenClinica.
the class AccountController method buildParticipantUserName.
private HashMap buildParticipantUserName(StudySubjectBean studySubjectBean) {
HashMap<String, String> map = new HashMap();
String studySubjectOid = studySubjectBean.getOid();
Integer studyId = studySubjectBean.getStudyId();
StudyBean study = getParentStudy(studyId);
Integer pStudyId = study.getId();
String pUserName = study.getOid() + "." + studySubjectOid;
map.put("pUserName", pUserName);
map.put("pStudyId", pStudyId.toString());
map.put("studySubjectOid", studySubjectOid);
return map;
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class AccountController method getAccount3.
/**
* @api {get} /pages/accounts/study/:studyOid/studysubject/:studySubjectId Retrieve a user account - participant
* @apiName getAccount3
* @apiPermission Module participate - enabled & admin
* @apiVersion 3.8.0
* @apiParam {String} studyOid Study Oid.
* @apiParam {String} studySubjectId Study Subject Id .
* @apiGroup User Account
* @apiDescription Retrieves the participant user account with the given studySubjectId and studyOid
* @apiParamExample {json} Request-Example:
* {
* "studyOid": " S_BL101",
* "studySubjectId": "Sub100"
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "lName": "",
* "mobile": "JTaa7WGRdH5dGs42XyTrgA==",
* "accessCode": "5s02UFpiMBijWuzaxSOojg==",
* "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
* "email": "XzJadh3l3V7uUoPCggbSoIfoNW8IQU3qsvrtHfJH7J0=",
* "userName": "S_BL101.SS_SUB100",
* "studySubjectId": null,
* "fName": "pdyGCN1CdAKIGOUEERz/yQ=="
* }
*/
@RequestMapping(value = "/study/{studyOid}/studysubject/{studySubjectId}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getAccount3(@PathVariable("studyOid") String studyOid, @PathVariable("studySubjectId") String studySubjectId) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
uDTO = null;
StudyBean parentStudy = getParentStudy(studyOid);
String oid = parentStudy.getOid();
StudySubjectBean studySubjectBean = getStudySubject(studySubjectId, parentStudy);
if (isStudyASiteLevelStudy(studyOid))
return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
if (!mayProceed(oid, studySubjectBean))
return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
if (isStudyDoesNotExist(oid))
return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
if (isStudySubjectDoesNotExist(studySubjectBean))
return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
// build UserName
HashMap<String, String> mapValues = buildParticipantUserName(studySubjectBean);
// Participant User Name
String pUserName = mapValues.get("pUserName");
UserAccountDAO udao = new UserAccountDAO(dataSource);
UserAccountBean userAccountBean = (UserAccountBean) udao.findByUserName(pUserName);
if (!userAccountBean.isActive()) {
uDTO = new UserDTO();
return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
} else {
buildUserDTO(userAccountBean);
return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
}
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class SDVController method viewAllSubjectFormHandler.
@RequestMapping("/viewAllSubjectSDVform")
public ModelMap viewAllSubjectFormHandler(HttpServletRequest request, HttpServletResponse response, @RequestParam("studyId") int studyId) {
ModelMap gridMap = new ModelMap();
StudyDAO studyDAO = new StudyDAO(dataSource);
// StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
StudyBean studyBean = (StudyBean) studyDAO.findByPK(studyId);
String pattern = "MM/dd/yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
// List<StudyEventBean> studyEventBeans = studyEventDAO.findAllByStudy(studyBean);
// List<EventCRFBean> eventCRFBeans = sdvUtil.getAllEventCRFs(studyEventBeans);
// set up the parameters to take part in filtering
ServletRequestDataBinder dataBinder = new ServletRequestDataBinder(new SdvFilterDataBean());
dataBinder.setAllowedFields(new String[] { "study_subject_id", "studyEventDefinition", "studyEventStatus", "eventCRFStatus", "sdvRequirement", "eventcrfSDVStatus", "startUpdatedDate", "endDate", "eventCRFName" });
dataBinder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(sdf, true));
dataBinder.bind(request);
BindingResult bindingResult = dataBinder.getBindingResult();
// eventCRFBeans = sdvUtil.filterEventCRFs(eventCRFBeans,bindingResult);
// set up request attributes for sidebar
// Not necessary when using old page design...
// setUpSidebar(request);
request.setAttribute("studyId", studyId);
// We need a study subject id for the first tab; take it somewhat arbitrarily from the first study event bean
/* int studySubjectId = 0;
StudyEventBean studyBeanUrl = studyEventBeans.get(0);
if(studyBeanUrl != null) {
studySubjectId= studyBeanUrl.getStudySubjectId();
}
request.setAttribute("studySubjectId",studySubjectId);*/
// set up the elements for the view's filter box
/*sdvUtil.prepareSDVSelectElements(request,studyBean);*/
ArrayList<String> pageMessages = (ArrayList<String>) request.getAttribute("pageMessages");
if (pageMessages == null) {
pageMessages = new ArrayList<String>();
}
request.setAttribute("pageMessages", pageMessages);
String sdvMatrix = sdvUtil.renderEventCRFTableWithLimit(request, studyId, "");
gridMap.addAttribute(SUBJECT_SDV_TABLE_ATTRIBUTE, sdvMatrix);
return gridMap;
}
use of org.akaza.openclinica.bean.managestudy.StudyBean in project OpenClinica by OpenClinica.
the class StudyController method createNewStudy.
/**
* @api {post} /pages/auth/api/v1/studies/ Create a study
* @apiName createNewStudy
* @apiPermission Authenticate using api-key. admin
* @apiVersion 3.8.0
* @apiParam {String} uniqueProtococlId Study unique protocol ID.
* @apiParam {String} briefTitle Brief Title .
* @apiParam {String} principalInvestigator Principal Investigator Name.
* @apiParam {Integer} expectedTotalEnrollment Expected Total Enrollment number
* @apiParam {String} sponsor Sponsor name.
* @apiParam {String} protocolType 'Interventional' or ' Observational'
* @apiParam {String} status 'Available' or 'Design'
* @apiParam {String} briefSummary Study Summary
* @apiParam {Date} startDate Start date
* @apiParam {Array} assignUserRoles Assign Users to Roles for this Study.
* @apiGroup Study
* @apiHeader {String} api_key Users unique access-key.
* @apiDescription This API is to create a New Study in OC.
* All the fields are required fields and can't be left blank.
* You need to provide your Api-key to be connected.
* @apiParamExample {json} Request-Example:
* {
* "briefTitle": "Study Protocol ID Name",
* "principalInvestigator": "Principal Investigator Name",
* "expectedTotalEnrollment": "10",
* "sponsor": "Sponsor Name",
* "protocolType": "Interventional",
* "status": "available",
* "assignUserRoles": [
* { "username": "usera", "role": "Data Manager" },
* { "username": "userb", "role": "Study Director" },
* { "username": "userc", "role": "Data Specialist" },
* { "username": "userd", "role": "Monitor" },
* { "username": "usere", "role": "Data Entry Person" }
* ],
* "uniqueProtocolID": "Study Protocol ID",
* "briefSummary": "Study Summary",
* "startDate": "2011-11-11"
* }
* @apiErrorExample {json} Error-Response:
* HTTP/1.1 400 Bad Request
* {
* "message": "VALIDATION FAILED",
* "status": "available",
* "principalInvestigator": "Principal Investigator Name",
* "expectedTotalEnrollment": "10",
* "sponsor": "Sponsor Name",
* "protocolType": "Interventional",
* "errors": [
* {"field": "UniqueProtocolId","resource": "Study Object","code": "Unique Protocol Id exist in the System"}
* ],
* "startDate": "2011-11-11",
* "assignUserRoles": [
* {"username": "usera","role": "Data Manager"},
* {"username": "userb","role": "Study Director"},
* {"username": "userc","role": "Data Specialist"}
* ],
* "uniqueProtocolID": "Study Protocol ID",
* "briefTitle": "Study Protocol ID",
* "briefSummary": "Study Summary",
* "studyOid": null
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "message": "SUCCESS",
* "uniqueProtocolID": "Study Protocol ID",
* "studyOid": "S_STUDYPRO",
* }
*/
@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<Object> createNewStudy(HttpServletRequest request, @RequestBody HashMap<String, Object> map) throws Exception {
ArrayList<ErrorObject> errorObjects = new ArrayList();
StudyBean studyBean = null;
System.out.println("I'm in Create Study");
ResponseEntity<Object> response = null;
String validation_failed_message = "VALIDATION FAILED";
String validation_passed_message = "SUCCESS";
String uniqueProtocolID = (String) map.get("uniqueProtocolID");
String name = (String) map.get("briefTitle");
String principalInvestigator = (String) map.get("principalInvestigator");
String briefSummary = (String) map.get("briefSummary");
String sponsor = (String) map.get("sponsor");
String protocolType = (String) map.get("protocolType");
String startDate = (String) map.get("startDate");
String expectedTotalEnrollment = (String) map.get("expectedTotalEnrollment");
String status = (String) map.get("status");
ArrayList<UserRole> assignUserRoles = (ArrayList<UserRole>) map.get("assignUserRoles");
ArrayList<UserRole> userList = new ArrayList<>();
if (assignUserRoles != null) {
for (Object userRole : assignUserRoles) {
UserRole uRole = new UserRole();
uRole.setUsername((String) ((HashMap<String, Object>) userRole).get("username"));
uRole.setRole((String) ((HashMap<String, Object>) userRole).get("role"));
udao = new UserAccountDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(uRole.getUsername());
if (assignedUserBean == null || !assignedUserBean.isActive()) {
ErrorObject errorOBject = createErrorObject("Study Object", "The Assigned Username " + uRole.getUsername() + " is not a Valid User", "Assigned User");
errorObjects.add(errorOBject);
}
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
if (getStudyRole(uRole.getRole(), resterm) == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Assigned Role for " + uRole.getUsername() + " is not a Valid Study Role", "Assigned Role");
errorObjects.add(errorOBject);
}
userList.add(uRole);
}
}
StudyDTO studyDTO = buildStudyDTO(uniqueProtocolID, name, briefSummary, principalInvestigator, sponsor, expectedTotalEnrollment, protocolType, status, startDate, userList);
if (uniqueProtocolID == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "UniqueProtocolID");
errorObjects.add(errorOBject);
} else {
uniqueProtocolID = uniqueProtocolID.trim();
}
if (name == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "BriefTitle");
errorObjects.add(errorOBject);
} else {
name = name.trim();
}
if (principalInvestigator == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "PrincipalInvestigator");
errorObjects.add(errorOBject);
} else {
principalInvestigator = principalInvestigator.trim();
}
if (briefSummary == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "BriefSummary");
errorObjects.add(errorOBject);
} else {
briefSummary = briefSummary.trim();
}
if (sponsor == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "Sponsor");
errorObjects.add(errorOBject);
} else {
sponsor = sponsor.trim();
}
if (protocolType == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "ProtocolType");
errorObjects.add(errorOBject);
} else {
protocolType = protocolType.trim();
}
if (startDate == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "StartDate");
errorObjects.add(errorOBject);
} else {
startDate = startDate.trim();
}
if (expectedTotalEnrollment == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "ExpectedTotalEnrollment");
errorObjects.add(errorOBject);
} else {
expectedTotalEnrollment = expectedTotalEnrollment.trim();
}
if (status == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "Status");
errorObjects.add(errorOBject);
} else {
status = status.trim();
}
if (assignUserRoles == null) {
ErrorObject errorOBject = createErrorObject("Study Object", "Missing Field", "AssignUserRoles");
errorObjects.add(errorOBject);
}
if (status != null && !status.equalsIgnoreCase("available") && !status.equalsIgnoreCase("design") && !status.equals("")) {
ErrorObject errorOBject = createErrorObject("Study Object", "Status Field Should have 'Available' or 'Design' Status only, If left empty , will default to 'Design' Mode", "Status");
errorObjects.add(errorOBject);
}
request.setAttribute("uniqueProId", uniqueProtocolID);
// Brief Title
request.setAttribute("name", name);
request.setAttribute("prinInvestigator", principalInvestigator);
request.setAttribute("description", briefSummary);
request.setAttribute("sponsor", sponsor);
request.setAttribute("startDate", startDate);
request.setAttribute("expectedTotalEnrollment", expectedTotalEnrollment);
request.setAttribute("status", status);
String format = "yyyy-MM-dd";
SimpleDateFormat formatter = null;
Date formattedDate = null;
if (startDate != "" && startDate != null) {
try {
formatter = new SimpleDateFormat(format);
formattedDate = formatter.parse(startDate);
} catch (ParseException e) {
ErrorObject errorOBject = createErrorObject("Study Object", "The StartDate format is not a valid 'yyyy-MM-dd' format", "StartDate");
errorObjects.add(errorOBject);
}
if (formattedDate != null) {
if (!startDate.equals(formatter.format(formattedDate))) {
ErrorObject errorOBject = createErrorObject("Study Object", "The StartDate format is not a valid 'yyyy-MM-dd' format", "StartDate");
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 v0 = new Validator(request);
v0.addValidation("name", Validator.NO_BLANKS);
HashMap vError0 = v0.validate();
if (!vError0.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "BriefTitle");
errorObjects.add(errorOBject);
}
Validator v1 = new Validator(request);
v1.addValidation("uniqueProId", Validator.NO_BLANKS);
HashMap vError1 = v1.validate();
if (!vError1.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "UniqueProtocolId");
errorObjects.add(errorOBject);
}
Validator v2 = new Validator(request);
v2.addValidation("description", Validator.NO_BLANKS);
HashMap vError2 = v2.validate();
if (!vError2.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "BriefSummary");
errorObjects.add(errorOBject);
}
Validator v3 = new Validator(request);
v3.addValidation("prinInvestigator", Validator.NO_BLANKS);
HashMap vError3 = v3.validate();
if (!vError3.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "PrincipleInvestigator");
errorObjects.add(errorOBject);
}
Validator v4 = new Validator(request);
v4.addValidation("sponsor", Validator.NO_BLANKS);
HashMap vError4 = v4.validate();
if (!vError4.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "Sponsor");
errorObjects.add(errorOBject);
}
Validator v5 = new Validator(request);
v5.addValidation("startDate", Validator.NO_BLANKS);
HashMap vError5 = v5.validate();
if (!vError5.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "StartDate");
errorObjects.add(errorOBject);
}
Validator v6 = new Validator(request);
HashMap vError6 = v6.validate();
if (uniqueProtocolID != null)
validateUniqueProId(request, vError6);
if (!vError6.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "Unique Protocol Id exist in the System", "UniqueProtocolId");
errorObjects.add(errorOBject);
}
Validator v7 = new Validator(request);
v7.addValidation("expectedTotalEnrollment", Validator.NO_BLANKS);
HashMap vError7 = v7.validate();
if (!vError7.isEmpty()) {
ErrorObject errorOBject = createErrorObject("Study Object", "This field cannot be blank.", "ExpectedTotalEnrollment");
errorObjects.add(errorOBject);
}
if (protocolType != null && !verifyProtocolTypeExist(protocolType)) {
ErrorObject errorOBject = createErrorObject("Study Object", "Protocol Type is not Valid", "ProtocolType");
errorObjects.add(errorOBject);
}
studyDTO.setErrors(errorObjects);
if (errorObjects != null && errorObjects.size() != 0) {
studyDTO.setMessage(validation_failed_message);
response = new ResponseEntity(studyDTO, org.springframework.http.HttpStatus.BAD_REQUEST);
} else {
studyBean = buildStudyBean(uniqueProtocolID, name, briefSummary, principalInvestigator, sponsor, Integer.valueOf(expectedTotalEnrollment), protocolType, status, formattedDate, ownerUserAccount);
StudyBean sBean = createStudy(studyBean, ownerUserAccount);
studyDTO.setStudyOid(sBean.getOid());
studyDTO.setMessage(validation_passed_message);
StudyUserRoleBean sub = new StudyUserRoleBean();
sub.setRole(Role.COORDINATOR);
sub.setStudyId(sBean.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ownerUserAccount);
StudyUserRoleBean surb = createRole(ownerUserAccount, sub);
ResourceBundle resterm = org.akaza.openclinica.i18n.util.ResourceBundleProvider.getTermsBundle();
for (UserRole userRole : userList) {
sub = new StudyUserRoleBean();
sub.setRole(getStudyRole(userRole.getRole(), resterm));
sub.setStudyId(sBean.getId());
sub.setStatus(Status.AVAILABLE);
sub.setOwner(ownerUserAccount);
udao = new UserAccountDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(userRole.getUsername());
surb = createRole(assignedUserBean, sub);
}
ResponseSuccessStudyDTO responseSuccess = new ResponseSuccessStudyDTO();
responseSuccess.setMessage(studyDTO.getMessage());
responseSuccess.setStudyOid(studyDTO.getStudyOid());
responseSuccess.setUniqueProtocolID(studyDTO.getUniqueProtocolID());
response = new ResponseEntity(responseSuccess, org.springframework.http.HttpStatus.OK);
}
return response;
}
Aggregations