use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class UpdateSubStudyServlet method submitSiteEventDefinitions.
private void submitSiteEventDefinitions(StudyBean site) throws MalformedURLException {
FormProcessor fp = new FormProcessor(request);
Validator v = new Validator(request);
HashMap<String, Boolean> changes = new HashMap<String, Boolean>();
HashMap<String, Boolean> changeStatus = (HashMap<String, Boolean>) session.getAttribute("changed");
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
ArrayList<EventDefinitionCRFBean> defCrfs = new ArrayList<EventDefinitionCRFBean>();
StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
StudyBean parentStudyBean;
if (site.getParentStudyId() == 0) {
parentStudyBean = site;
} else {
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
parentStudyBean = (StudyBean) studyDAO.findByPK(site.getParentStudyId());
}
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyBean.getId());
ArrayList<EventDefinitionCRFBean> toBeCreatedEventDefBean = new ArrayList<>();
ArrayList<EventDefinitionCRFBean> toBeUpdatedEventDefBean = new ArrayList<>();
ArrayList<EventDefinitionCRFBean> edcsInSession = new ArrayList<EventDefinitionCRFBean>();
boolean changestate = false;
seds = (ArrayList<StudyEventDefinitionBean>) session.getAttribute("definitions");
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(parentStudyBean.getId(), "participantPortal").getValue();
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
for (StudyEventDefinitionBean sed : seds) {
ArrayList<EventDefinitionCRFBean> edcs = sed.getCrfs();
int start = 0;
for (EventDefinitionCRFBean edcBean : edcs) {
int edcStatusId = edcBean.getStatus().getId();
if (edcStatusId == 5 || edcStatusId == 7) {
} else {
String order = start + "-" + edcBean.getId();
int defaultVersionId = fp.getInt("defaultVersionId" + order);
String requiredCRF = fp.getString("requiredCRF" + order);
String doubleEntry = fp.getString("doubleEntry" + order);
String electronicSignature = fp.getString("electronicSignature" + order);
String hideCRF = fp.getString("hideCRF" + order);
String participantForm = fp.getString("participantForm" + order);
String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + order);
String submissionUrl = fp.getString("submissionUrl" + order);
String offline = fp.getString("offline" + order);
int sdvId = fp.getInt("sdvOption" + order);
ArrayList<String> selectedVersionIdList = fp.getStringArray("versionSelection" + order);
int selectedVersionIdListSize = selectedVersionIdList.size();
String selectedVersionIds = "";
if (selectedVersionIdListSize > 0) {
for (String id : selectedVersionIdList) {
selectedVersionIds += id + ",";
}
selectedVersionIds = selectedVersionIds.substring(0, selectedVersionIds.length() - 1);
}
String sdvOption = fp.getString("sdvOption" + order);
boolean changed = false;
if (changeStatus != null && changeStatus.get(sed.getId() + "-" + edcBean.getId()) != null) {
changed = changeStatus.get(sed.getId() + "-" + edcBean.getId());
edcBean.setSubmissionUrl(submissionUrl);
}
boolean isRequired = !StringUtil.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim()) ? true : false;
boolean isDouble = !StringUtil.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim()) ? true : false;
boolean hasPassword = !StringUtil.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim()) ? true : false;
boolean isHide = !StringUtil.isBlank(hideCRF) && "yes".equalsIgnoreCase(hideCRF.trim()) ? true : false;
System.out.println("crf name :" + edcBean.getCrfName());
System.out.println("submissionUrl: " + submissionUrl);
if (edcBean.getParentId() > 0) {
int dbDefaultVersionId = edcBean.getDefaultVersionId();
if (defaultVersionId != dbDefaultVersionId) {
changed = true;
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultVersionId);
edcBean.setDefaultVersionId(defaultVersionId);
edcBean.setDefaultVersionName(defaultVersion.getName());
}
if (isRequired != edcBean.isRequiredCRF()) {
changed = true;
edcBean.setRequiredCRF(isRequired);
}
if (isDouble != edcBean.isDoubleEntry()) {
changed = true;
edcBean.setDoubleEntry(isDouble);
}
if (hasPassword != edcBean.isElectronicSignature()) {
changed = true;
edcBean.setElectronicSignature(hasPassword);
}
if (isHide != edcBean.isHideCrf()) {
changed = true;
edcBean.setHideCrf(isHide);
}
if (!submissionUrl.equals(edcBean.getSubmissionUrl())) {
changed = true;
edcBean.setSubmissionUrl(submissionUrl);
}
if (!StringUtil.isBlank(selectedVersionIds) && !selectedVersionIds.equals(edcBean.getSelectedVersionIds())) {
changed = true;
String[] ids = selectedVersionIds.split(",");
ArrayList<Integer> idList = new ArrayList<Integer>();
for (String id : ids) {
idList.add(Integer.valueOf(id));
}
edcBean.setSelectedVersionIdList(idList);
edcBean.setSelectedVersionIds(selectedVersionIds);
}
if (sdvId > 0 && sdvId != edcBean.getSourceDataVerification().getCode()) {
changed = true;
edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
}
if (changed) {
edcBean.setUpdater(ub);
edcBean.setUpdatedDate(new Date());
logger.debug("update for site");
toBeUpdatedEventDefBean.add(edcBean);
// edcdao.update(edcBean);
}
} else {
// only if definition-crf has been modified, will it be
// saved for the site
int defaultId = defaultVersionId > 0 ? defaultVersionId : edcBean.getDefaultVersionId();
int dbDefaultVersionId = edcBean.getDefaultVersionId();
if (defaultId == dbDefaultVersionId) {
if (isRequired == edcBean.isRequiredCRF()) {
if (isDouble == edcBean.isDoubleEntry()) {
if (hasPassword == edcBean.isElectronicSignature()) {
if (isHide == edcBean.isHideCrf()) {
if (submissionUrl.equals("")) {
if (selectedVersionIdListSize > 0) {
if (selectedVersionIdListSize == edcBean.getVersions().size()) {
if (sdvId > 0) {
if (sdvId != edcBean.getSourceDataVerification().getCode()) {
changed = true;
}
}
} else {
changed = true;
}
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
} else {
changed = true;
}
if (changed) {
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultId);
edcBean.setDefaultVersionId(defaultId);
edcBean.setDefaultVersionName(defaultVersion.getName());
edcBean.setRequiredCRF(isRequired);
edcBean.setDoubleEntry(isDouble);
edcBean.setElectronicSignature(hasPassword);
edcBean.setHideCrf(isHide);
edcBean.setSubmissionUrl(submissionUrl);
if (selectedVersionIdListSize > 0 && selectedVersionIdListSize != edcBean.getVersions().size()) {
String[] ids = selectedVersionIds.split(",");
ArrayList<Integer> idList = new ArrayList<Integer>();
for (String id : ids) {
idList.add(Integer.valueOf(id));
}
edcBean.setSelectedVersionIdList(idList);
edcBean.setSelectedVersionIds(selectedVersionIds);
}
if (sdvId > 0 && sdvId != edcBean.getSourceDataVerification().getCode()) {
edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
}
// edcBean.setParentId(edcBean.getId());
edcBean.setStudyId(site.getId());
edcBean.setUpdater(ub);
edcBean.setUpdatedDate(new Date());
logger.debug("create for the site");
toBeCreatedEventDefBean.add(edcBean);
// edcdao.create(edcBean);
}
}
++start;
changes.put(sed.getId() + "-" + edcBean.getId(), changed);
}
edcsInSession.add(edcBean);
}
sed.setPopulated(false);
eventDefCrfList = validateSubmissionUrl(edcsInSession, eventDefCrfList, v, sed);
edcsInSession.clear();
}
errors = v.validate();
if (!errors.isEmpty()) {
logger.info("has errors");
StudyBean study = createStudyBean();
session.setAttribute("newStudy", study);
request.setAttribute("formMessages", errors);
session.setAttribute("changed", changes);
forwardPage(Page.UPDATE_SUB_STUDY);
} else {
for (EventDefinitionCRFBean toBeCreated : toBeCreatedEventDefBean) {
toBeCreated.setParentId(toBeCreated.getId());
edcdao.create(toBeCreated);
}
for (EventDefinitionCRFBean toBeUpdated : toBeUpdatedEventDefBean) {
edcdao.update(toBeUpdated);
}
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ViewEventDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int defId = fp.getInt("id", true);
if (defId == 0) {
addPageMessage(respage.getString("please_choose_a_definition_to_view"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
// definition id
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
if (currentStudy.getId() != sed.getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
checkRoleByUserAndStudy(ub, sed.getStudyId(), 0);
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(this.currentStudy, defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
// edc.setCrfLabel(crf.getLabel());
edc.setCrfName(crf.getName());
// to show/hide edit action on jsp page
if (crf.getStatus().equals(Status.AVAILABLE)) {
edc.setOwner(crf.getOwner());
}
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
}
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("participateFormStatus", participateFormStatus);
request.setAttribute("definition", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("defSize", new Integer(eventDefinitionCRFs.size()));
// request.setAttribute("eventDefinitionCRFs", new
// ArrayList(tm.values()));
forwardPage(Page.VIEW_EVENT_DEFINITION);
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ViewNoteServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
Locale locale = LocaleResolver.getLocale(request);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
dndao.setFetchMapping(true);
int noteId = fp.getInt(NOTE_ID, true);
DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);
String entityType = note.getEntityType();
if (note.getEntityId() > 0 && !entityType.equals("")) {
if (!StringUtil.isBlank(entityType)) {
if ("itemData".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(note.getEntityId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
note.setEntityValue(itemData.getValue());
note.setEntityName(item.getName());
// Mantis Issue 5165. It should be itemData.getId() instead of item.getId()
note.setEntityId(itemData.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
note.setCrfName(crf.getName());
} else if ("studySub".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(note.getEntityId());
note.setStudySub(ssub);
// System.out.println("column" + note.getColumn());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
if (!StringUtil.isBlank(note.getColumn())) {
if ("enrollment_date".equalsIgnoreCase(note.getColumn())) {
if (ssub.getEnrollmentDate() != null) {
note.setEntityValue(dateFormatter.format(ssub.getEnrollmentDate()));
}
note.setEntityName(resword.getString("enrollment_date"));
} else if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
}
}
} else if ("subject".equalsIgnoreCase(entityType)) {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(note.getEntityId());
StudySubjectBean ssub = new StudySubjectBean();
ssub.setLabel(sub.getUniqueIdentifier());
note.setStudySub(ssub);
if (!StringUtil.isBlank(note.getColumn())) {
if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(note.getColumn())) {
note.setEntityName(resword.getString("unique_identifier"));
note.setEntityValue(sub.getUniqueIdentifier());
}
}
} else if ("studyEvent".equalsIgnoreCase(entityType)) {
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(note.getEntityId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
if (!StringUtil.isBlank(note.getColumn())) {
if ("location".equalsIgnoreCase(note.getColumn())) {
request.setAttribute("entityValue", se.getLocation());
request.setAttribute("entityName", resword.getString("location"));
note.setEntityName(resword.getString("location"));
note.setEntityValue(se.getLocation());
} else if ("date_start".equalsIgnoreCase(note.getColumn())) {
if (se.getDateStarted() != null) {
note.setEntityValue(dateFormatter.format(se.getDateStarted()));
}
note.setEntityName(resword.getString("start_date"));
} else if ("date_end".equalsIgnoreCase(note.getColumn())) {
if (se.getDateEnded() != null) {
note.setEntityValue(dateFormatter.format(se.getDateEnded()));
}
note.setEntityName(resword.getString("end_date"));
}
}
} else if ("eventCrf".equalsIgnoreCase(entityType)) {
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(note.getEntityId());
StudySubjectBean ssub = (StudySubjectBean) new StudySubjectDAO(sm.getDataSource()).findByPK(ec.getStudySubjectId());
note.setStudySub(ssub);
StudyEventBean event = (StudyEventBean) new StudyEventDAO(sm.getDataSource()).findByPK(ec.getStudyEventId());
note.setEvent(event);
if (!StringUtil.isBlank(note.getColumn())) {
if ("date_interviewed".equals(note.getColumn())) {
if (ec.getDateInterviewed() != null) {
note.setEntityValue(dateFormatter.format(ec.getDateInterviewed()));
}
note.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(note.getColumn())) {
note.setEntityValue(ec.getInterviewerName());
note.setEntityName(resword.getString("interviewer_name"));
}
}
}
}
}
// Mantis Issue 8495.
if (note.getStudyId() != currentStudy.getId()) {
if (currentStudy.getParentStudyId() > 0) {
if (currentStudy.getId() != note.getStudySub().getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
} else {
// The SubjectStudy is not belong to currentstudy and current study is not a site.
StudyDAO studydao = new StudyDAO(sm.getDataSource());
Collection sites;
sites = studydao.findOlnySiteIdsByStudy(currentStudy);
if (!sites.contains(note.getStudySub().getStudyId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
}
}
// Check end
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);
Date lastUpdatedDate = note.getCreatedDate();
UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId == 0) { note = n; note.setLastUpdator((UserAccountBean)
* udao.findByPK(n.getOwnerId()));
* note.setLastDateUpdated(n.getCreatedDate()); lastUpdatedDate =
* note.getLastDateUpdated(); lastUpdator = note.getLastUpdator(); } }
*/
// BWP 3029 >> This algorithm needs to be changed to properly set
// the parent note's status and updated date
// First sort the notes on their ID; this will put the parent note
// first; and
// the note with the latest status and updated date last
java.util.Collections.sort(notes);
DiscrepancyNoteBean lastChild = notes.get(notes.size() - 1);
lastUpdatedDate = lastChild.getCreatedDate();
lastUpdator = (UserAccountBean) udao.findByPK(lastChild.getOwnerId());
note.setLastUpdator(lastUpdator);
note.setLastDateUpdated(lastUpdatedDate);
note.setUpdatedDate(lastUpdatedDate);
for (DiscrepancyNoteBean dnBean : notes) {
if (dnBean.getParentDnId() > 0) {
note.getChildren().add(dnBean);
}
}
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId > 0) { note.getChildren().add(n);
*
* if (!n.getCreatedDate().before(lastUpdatedDate)) { lastUpdatedDate =
* n.getCreatedDate(); lastUpdator = (UserAccountBean)
* udao.findByPK(n.getOwnerId()); note.setLastUpdator(lastUpdator);
* note.setLastDateUpdated(lastUpdatedDate);
* note.setResolutionStatusId(n.getResolutionStatusId());
* note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId())); } } }
*/
note.setNumChildren(note.getChildren().size());
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
request.setAttribute(DIS_NOTE, note);
forwardPage(Page.VIEW_SINGLE_NOTE);
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ViewCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
int crfVersionId = fp.getInt("id");
if (crfVersionId == 0) {
addPageMessage(respage.getString("please_choose_a_crf_to_view_details"));
forwardPage(Page.CRF_LIST_SERVLET);
} else {
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
// tbh
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) crfdao.findByPK(version.getCrfId());
CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(sm.getDataSource());
ArrayList<SectionBean> sections = metadataUtil.retrieveFormMetadata(version);
request.setAttribute("sections", sections);
request.setAttribute("version", version);
// tbh
request.setAttribute("crfname", crf.getName());
// tbh
forwardPage(Page.VIEW_CRF_VERSION);
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class RestoreEventDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
String idString = request.getParameter("id");
int defId = Integer.valueOf(idString.trim()).intValue();
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
// find all CRFs
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
edc.setCrfName(crf.getName());
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
}
// finds all events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_SED_to_restore"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
if (!sed.getStatus().equals(Status.DELETED)) {
addPageMessage(respage.getString("this_SED_cannot_be_restored") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
return;
}
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("definitionToRestore", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("events", events);
forwardPage(Page.RESTORE_DEFINITION);
} else {
logger.info("submit to restore the definition");
// restore definition
sed.setStatus(Status.AVAILABLE);
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sdao.update(sed);
// restore all crfs
for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
if (edc.getStatus().equals(Status.AUTO_DELETED)) {
edc.setStatus(Status.AVAILABLE);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edao.update(edc);
}
}
// restore all events
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
if (event.getStatus().equals(Status.AUTO_DELETED)) {
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// remove all the item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_SED") + " " + sed.getName() + "(" + respage.getString("and_all_associated_event_data_restored_to_study") + currentStudy.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
}
}
Aggregations