use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class EnterDataForStudyEventServlet method getStudyEvent.
private StudyEventBean getStudyEvent(int eventId) throws Exception {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyBean studyWithSED = currentStudy;
if (currentStudy.getParentStudyId() > 0) {
studyWithSED = new StudyBean();
studyWithSED.setId(currentStudy.getParentStudyId());
}
AuditableEntityBean aeb = sedao.findByPKAndStudy(eventId, studyWithSED);
if (!aeb.isActive()) {
addPageMessage(respage.getString("study_event_to_enter_data_not_belong_study"));
throw new InsufficientPermissionException(Page.LIST_STUDY_SUBJECTS_SERVLET, resexception.getString("study_event_not_belong_study"), "1");
}
StudyEventBean seb = (StudyEventBean) aeb;
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(seb.getStudyEventDefinitionId());
seb.setStudyEventDefinition(sedb);
// A. Hamid mantis issue 5048
if (!(currentRole.isDirector() || currentRole.isCoordinator()) && seb.getSubjectEventStatus().isLocked()) {
seb.setEditable(false);
}
return seb;
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class FindStudyEventServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
String browseBy = fp.getString(INPUT_BROWSEBY);
int id = fp.getInt(INPUT_ID);
// User is going to Step 1
if (browseBy.equals("")) {
forwardPage(Page.FIND_STUDY_EVENTS_STEP1);
} else if (invalidBrowseBy(browseBy)) {
addPageMessage(respage.getString("must_browse_study_events_by_subject_or_event_definition"));
forwardPage(Page.FIND_STUDY_EVENTS_STEP1);
} else // User was at Step 1, is going to Step 2
if (id <= 0) {
int pageNum = fp.getInt(INPUT_PAGENUM);
ArrayList allDisplayEntities = new ArrayList();
if (browseBy.equals(ARG_BROWSEBY_SUBJECT)) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
allDisplayEntities = ssdao.findAllWithStudyEvent(currentStudy);
} else {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
allDisplayEntities = seddao.findAllWithStudyEvent(currentStudy);
}
if (pageNum < 0) {
pageNum = 0;
} else if (pageNum > allDisplayEntities.size() / NUM_ENTITIES_PER_PAGE) {
pageNum = allDisplayEntities.size() / NUM_ENTITIES_PER_PAGE;
}
int firstIndex = NUM_ENTITIES_PER_PAGE * pageNum;
int lastIndex = NUM_ENTITIES_PER_PAGE * (pageNum + 1);
if (allDisplayEntities.size() > lastIndex) {
request.setAttribute(BEAN_DISPLAY_NEXT_PAGE, ARG_DISPLAY_NEXT_PAGE_YES);
} else {
request.setAttribute(BEAN_DISPLAY_NEXT_PAGE, ARG_DISPLAY_NEXT_PAGE_NO);
lastIndex = allDisplayEntities.size();
}
List displayEntities = allDisplayEntities.subList(firstIndex, lastIndex);
request.setAttribute(INPUT_BROWSEBY, browseBy);
request.setAttribute(BEAN_DISPLAY_ENTITIES, displayEntities);
request.setAttribute(INPUT_PAGENUM, new Integer(pageNum));
forwardPage(Page.FIND_STUDY_EVENTS_STEP2);
} else // User is coming from Step 2, is going to Step 3
{
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = new ArrayList();
EntityBean entityWithStudyEvents;
if (browseBy.equals(ARG_BROWSEBY_SUBJECT)) {
events = sedao.findAllByStudyAndStudySubjectId(currentStudy, id);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
entityWithStudyEvents = ssdao.findByPK(id);
} else {
events = sedao.findAllByStudyAndEventDefinitionId(currentStudy, id);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
entityWithStudyEvents = seddao.findByPK(id);
}
request.setAttribute(INPUT_BROWSEBY, browseBy);
request.setAttribute(BEAN_DISPLAY_ENTITIES, events);
request.setAttribute(BEAN_ENTITY_WITH_STUDY_EVENTS, entityWithStudyEvents);
forwardPage(Page.FIND_STUDY_EVENTS_STEP3);
}
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class ChangeCRFVersionController method chooseCRFVersion.
/*
* Allows user to select new CRF version
*
*/
// @RequestMapping(value="/managestudy/chooseCRFVersion", method = RequestMethod.GET)
@RequestMapping(value = "/managestudy/chooseCRFVersion", method = RequestMethod.GET)
public ModelMap chooseCRFVersion(HttpServletRequest request, HttpServletResponse response, @RequestParam("crfId") int crfId, @RequestParam("crfName") String crfName, @RequestParam("formLayoutId") int formLayoutId, @RequestParam("formLayoutName") String formLayoutName, @RequestParam("studySubjectLabel") String studySubjectLabel, @RequestParam("studySubjectId") int studySubjectId, @RequestParam("eventCRFId") int eventCRFId, @RequestParam("eventDefinitionCRFId") int eventDefinitionCRFId) {
// to be removed for aquamarine
if (!mayProceed(request)) {
try {
response.sendRedirect(request.getContextPath() + "/MainMenu?message=authentication_failed");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
resetPanel(request);
ModelMap gridMap = new ModelMap();
request.setAttribute("eventCRFId", eventCRFId);
request.setAttribute("studySubjectLabel", studySubjectLabel);
request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId);
request.setAttribute("studySubjectId", studySubjectId);
request.setAttribute("crfId", crfId);
request.setAttribute("crfName", crfName);
request.setAttribute("formLayoutId", formLayoutId);
request.setAttribute("formLayoutName", formLayoutName.trim());
ArrayList<String> pageMessages = initPageMessages(request);
Object errorMessage = request.getParameter("errorMessage");
if (errorMessage != null) {
pageMessages.add((String) errorMessage);
}
// get CRF by ID with all versions
// create List of all versions (label + value)
// set default CRF version label
setupResource(request);
// from event_crf get
StudyBean study = (StudyBean) request.getSession().getAttribute("study");
CRFDAO cdao = new CRFDAO(dataSource);
CRFBean crfBean = (CRFBean) cdao.findByPK(crfId);
FormLayoutDAO formLayoutDao = new FormLayoutDAO(dataSource);
ArrayList<FormLayoutBean> formLayouts = (ArrayList<FormLayoutBean>) formLayoutDao.findAllActiveByCRF(crfId);
StudyEventDefinitionDAO sfed = new StudyEventDefinitionDAO(dataSource);
StudyEventDefinitionBean sedb = sfed.findByEventDefinitionCRFId(eventDefinitionCRFId);
request.setAttribute("eventName", sedb.getName());
EventCRFDAO ecdao = new EventCRFDAO(dataSource);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudyEventDAO sedao = new StudyEventDAO(dataSource);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
request.setAttribute("eventCreateDate", formatDate(seb.getCreatedDate()));
if (sedb.isRepeating()) {
request.setAttribute("eventOrdinal", seb.getSampleOrdinal());
}
if (study.getParentStudyId() > 0) {
EventDefinitionCRFDAO edfdao = new EventDefinitionCRFDAO(dataSource);
EventDefinitionCRFBean edf = (EventDefinitionCRFBean) edfdao.findByPK(eventDefinitionCRFId);
if (!edf.getSelectedVersionIds().equals("")) {
String[] version_ids = edf.getSelectedVersionIds().split(",");
HashMap<String, String> tmp = new HashMap<String, String>(version_ids.length);
for (String vs : version_ids) {
tmp.put(vs, vs);
}
ArrayList<FormLayoutBean> site_versions = new ArrayList<FormLayoutBean>(formLayouts.size());
for (FormLayoutBean vs : formLayouts) {
if (tmp.get(String.valueOf(vs.getId())) != null) {
site_versions.add(vs);
}
}
formLayouts = site_versions;
}
}
crfBean.setVersions(formLayouts);
gridMap.addAttribute("numberOfVersions", crfBean.getVersions().size() + 1);
gridMap.addAttribute("crfBean", crfBean);
return gridMap;
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteController method buidDiscrepancyNote.
@RequestMapping(value = "/dnote", method = RequestMethod.POST)
public ResponseEntity buidDiscrepancyNote(@RequestBody HashMap<String, String> map, HttpServletRequest request) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
System.out.println("I'm in EnketoForm DN Rest Method");
org.springframework.http.HttpStatus httpStatus = null;
String se_oid = map.get("EntityID");
String ordinal = map.get("Ordinal");
// start_date , end_date , location
String entityName = map.get("EntityName");
String studySubjectOid = map.get("SS_OID");
String noteType = map.get("NoteType");
String resolutionStatus = map.get("Status");
String assignedUser = map.get("AssignedUser");
String owner = map.get("Owner");
String description = map.get("Description");
String detailedNotes = map.get("DetailedNote");
String dn_id = map.get("DN_Id");
dn_id = dn_id != null ? dn_id.replaceFirst("DN_", "") : dn_id;
UserAccountDAO udao = new UserAccountDAO(dataSource);
StudySubjectDAO ssdao = new StudySubjectDAO(dataSource);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
StudyEventDAO sedao = new StudyEventDAO(dataSource);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(dataSource);
UserAccountBean assignedUserBean = (UserAccountBean) udao.findByUserName(assignedUser);
UserAccountBean ownerBean = (UserAccountBean) request.getSession().getAttribute("userBean");
StudySubjectBean ssBean = ssdao.findByOid(studySubjectOid);
StudyEventDefinitionBean sedBean = seddao.findByOid(se_oid);
StudyBean studyBean = getStudy(sedBean.getStudyId());
StudyEventBean seBean = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(ssBean.getId(), sedBean.getId(), Integer.valueOf(ordinal));
String entityType = "studyEvent";
DiscrepancyNoteBean parent = (DiscrepancyNoteBean) dndao.findByPK(Integer.valueOf(dn_id));
if (!mayProceed(resolutionStatus, noteType, seBean, entityName, parent, ownerBean)) {
httpStatus = org.springframework.http.HttpStatus.BAD_REQUEST;
return new ResponseEntity(httpStatus);
}
if (!parent.isActive()) {
saveFieldNotes(description, detailedNotes, seBean.getId(), entityType, studyBean, ownerBean, assignedUserBean, resolutionStatus, noteType, entityName);
httpStatus = org.springframework.http.HttpStatus.OK;
} else {
createDiscrepancyNoteBean(description, detailedNotes, seBean.getId(), entityType, studyBean, ownerBean, assignedUserBean, parent.getId(), resolutionStatus, noteType, entityName);
httpStatus = org.springframework.http.HttpStatus.OK;
}
return new ResponseEntity(httpStatus);
}
use of org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO in project OpenClinica by OpenClinica.
the class DiscrepancyNoteOutputServlet method populateRowsWithAttachedData.
private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList<DiscrepancyNoteBean> noteRows) {
Locale l = LocaleResolver.getLocale(request);
resword = ResourceBundleProvider.getWordsBundle(l);
resformat = ResourceBundleProvider.getFormatBundle(l);
SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
ItemGroupMetadataDAO<String, ArrayList> igmdao = new ItemGroupMetadataDAO<String, ArrayList>(sm.getDataSource());
ItemGroupDAO<String, ArrayList> igdao = new ItemGroupDAO<String, ArrayList>(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
for (int i = 0; i < noteRows.size(); i++) {
DiscrepancyNoteBean dnb = noteRows.get(i);
dnb.setCreatedDateString(dnb.getCreatedDate() == null ? "" : sdf.format(dnb.getCreatedDate()));
if (dnb.getParentDnId() == 0) {
ArrayList children = dndao.findAllByStudyAndParent(currentStudy, dnb.getId());
children = children == null ? new ArrayList() : children;
dnb.setNumChildren(children.size());
dnb.setChildren(children);
int lastDnId = dnb.getId();
int lastChild = 0;
for (int j = 0; j < children.size(); j++) {
DiscrepancyNoteBean child = (DiscrepancyNoteBean) children.get(j);
child.setCreatedDateString(child.getCreatedDate() == null ? "" : sdf.format(child.getCreatedDate()));
child.setUpdatedDateString(child.getCreatedDate() != null ? sdf.format(child.getCreatedDate()) : "");
if (child.getId() > lastDnId) {
lastDnId = child.getId();
lastChild = j;
}
}
if (children.size() > 0) {
DiscrepancyNoteBean lastdn = (DiscrepancyNoteBean) children.get(lastChild);
//dnb.setResStatus(ResolutionStatus.get(lastdn.getResolutionStatusId()));
/*
* The update date is the date created of the latest child
* note
*/
dnb.setUpdatedDate(lastdn.getCreatedDate());
dnb.setUpdatedDateString(dnb.getUpdatedDate() != null ? sdf.format(dnb.getUpdatedDate()) : "");
}
}
String entityType = dnb.getEntityType();
if (dnb.getEntityId() > 0 && !entityType.equals("")) {
AuditableEntityBean aeb = dndao.findEntity(dnb);
dnb.setEntityName(aeb.getName());
if (entityType.equalsIgnoreCase("subject")) {
// allNotes.add(dnb);
SubjectBean sb = (SubjectBean) aeb;
StudySubjectBean ssb = studySubjectDAO.findBySubjectIdAndStudy(sb.getId(), currentStudy);
dnb.setStudySub(ssb);
dnb.setSubjectName(ssb.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("gender".equalsIgnoreCase(column)) {
dnb.setEntityValue(sb.getGender() + "");
dnb.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equals(column)) {
if (sb.getDateOfBirth() != null) {
dnb.setEntityValue(sb.getDateOfBirth().toString());
}
dnb.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(column)) {
dnb.setEntityName(resword.getString("unique_identifier"));
dnb.setEntityValue(sb.getUniqueIdentifier());
}
}
} else if (entityType.equalsIgnoreCase("studySub")) {
// allNotes.add(dnb);
StudySubjectBean ssb = (StudySubjectBean) aeb;
dnb.setStudySub(ssb);
dnb.setSubjectName(ssb.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("enrollment_date".equals(column)) {
if (ssb.getEnrollmentDate() != null) {
dnb.setEntityValue(ssb.getEnrollmentDate().toString());
}
dnb.setEntityName(resword.getString("enrollment_date"));
}
}
} else if (entityType.equalsIgnoreCase("eventCRF")) {
StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
EventCRFBean ecb = (EventCRFBean) aeb;
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
dnb.setStageId(ecb.getStage().getId());
dnb.setEntityName(cb.getName() + " (" + cvb.getName() + ")");
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setSubjectName(ssub.getLabel());
if (se != null) {
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
}
dnb.setCrfName(cb.getName());
String crfStatus = resword.getString(ecb.getStage().getNameRaw());
if (crfStatus.equals("Invalid")) {
crfStatus = "";
} else if (crfStatus.equals("Data Entry Complete")) {
crfStatus = "Complete";
}
dnb.setCrfStatus(crfStatus);
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("date_interviewed".equals(column)) {
if (ecb.getDateInterviewed() != null) {
dnb.setEntityValue(ecb.getDateInterviewed().toString());
}
dnb.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(column)) {
dnb.setEntityValue(ecb.getInterviewerName());
dnb.setEntityName(resword.getString("interviewer_name"));
}
}
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
// }
} else if (entityType.equalsIgnoreCase("studyEvent")) {
// allNotes.add(dnb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
dnb.setEntityName(sedb.getName());
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(se.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
dnb.setSubjectName(ssub.getLabel());
String column = dnb.getColumn().trim();
if (!StringUtil.isBlank(column)) {
if ("date_start".equals(column)) {
if (se.getDateStarted() != null) {
dnb.setEntityValue(se.getDateStarted().toString());
}
dnb.setEntityName(resword.getString("start_date"));
} else if ("date_end".equals(column)) {
if (se.getDateEnded() != null) {
dnb.setEntityValue(se.getDateEnded().toString());
}
dnb.setEntityName(resword.getString("end_date"));
} else if ("location".equals(column)) {
dnb.setEntityValue(se.getLocation());
dnb.setEntityName(resword.getString("location"));
}
}
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
} else if (entityType.equalsIgnoreCase("itemData")) {
ItemDataBean idb = (ItemDataBean) iddao.findByPK(dnb.getEntityId());
ItemBean ib = (ItemBean) idao.findByPK(idb.getItemId());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
ItemGroupMetadataBean itemGroupMetadataBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(ib.getId(), cvb.getId());
Boolean isRepeatForSure = itemGroupMetadataBean.isRepeatingGroup();
if (isRepeatForSure) {
ItemGroupBean ig = (ItemGroupBean) igdao.findByPK(itemGroupMetadataBean.getItemGroupId());
dnb.setItemDataOrdinal(idb.getOrdinal());
dnb.setItemGroupName(ig.getName());
}
// allNotes.add(dnb);
dnb.setStageId(ec.getStage().getId());
dnb.setEntityName(ib.getName());
dnb.setEntityValue(idb.getValue());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ec.getStudyEventId());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ec.getStudySubjectId());
dnb.setStudySub(ssub);
dnb.setSubjectName(ssub.getLabel());
dnb.setEventStart(se.getDateStarted());
dnb.setEventName(se.getName());
dnb.setCrfName(cb.getName());
String crfStatus = resword.getString(ec.getStage().getNameRaw());
if (crfStatus.equals("Invalid")) {
crfStatus = "";
} else if (crfStatus.equals("Data Entry Complete")) {
crfStatus = "Complete";
}
dnb.setCrfStatus(crfStatus);
dnb.setEvent(se);
dnb.setStudyEventDefinitionBean(sedb);
}
}
dnb.setStudy((StudyBean) studyDao.findByPK(dnb.getStudyId()));
if (dnb.getParentDnId() == 0 && dnb.getChildren().size() > 0) {
ArrayList<DiscrepancyNoteBean> children = dnb.getChildren();
int childrenSize = children.size();
for (int j = 0; j < childrenSize; j++) {
DiscrepancyNoteBean child = children.get(j);
child.setSubjectName(dnb.getSubjectName());
child.setEventName(dnb.getEventName());
child.setCrfName(dnb.getCrfName());
child.setCrfStatus(dnb.getCrfStatus());
child.setEntityName(dnb.getEntityName());
child.setEntityValue(dnb.getEntityValue());
child.setStudySub(dnb.getStudySub());
child.setStudy(dnb.getStudy());
}
}
allNotes.add(dnb);
}
return allNotes;
}
Aggregations