use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class RemoveSiteServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String idString = request.getParameter("id");
logger.info("site id:" + idString);
int siteId = Integer.valueOf(idString.trim()).intValue();
StudyBean study = (StudyBean) sdao.findByPK(siteId);
if (currentStudy.getId() != study.getParentStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
// find all user and roles
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(siteId);
// find all subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_site_to_remove"));
forwardPage(Page.SITE_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("siteToRemove", study);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
forwardPage(Page.REMOVE_SITE);
} else {
logger.info("submit to remove the site");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setOldStatus(study.getStatus());
study.setStatus(Status.DELETED);
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
// YW << So study_user_role table status_id field can be
// updated
udao.updateStudyUserRole(role, role.getUserName());
}
// YW 06-18-2007 >>
}
// YW << bug fix that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
// currentRole.setRole(Role.INVALID);
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
}
// remove all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean group = (StudyGroupBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (!sgMap.getStatus().equals(Status.DELETED)) {
sgMap.setStatus(Status.AUTO_DELETED);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// remove all events
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (!subject.getStatus().equals(Status.DELETED)) {
subject.setStatus(Status.AUTO_DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
ArrayList events = sedao.findAllByStudySubject(subject);
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.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
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.DELETED)) {
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AUTO_DELETED);
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.DELETED)) {
item.setOldStatus(item.getStatus());
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for subjects
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (!data.getStatus().equals(Status.DELETED)) {
data.setStatus(Status.AUTO_DELETED);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(respage.getString("this_site_has_been_removed_succesfully"));
String fromListSite = (String) session.getAttribute("fromListSite");
if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
session.removeAttribute("fromListSite");
forwardPage(Page.SITE_LIST_SERVLET);
} else {
session.removeAttribute("fromListSite");
if (currentRole.getRole().equals(Role.ADMIN)) {
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
forwardPage(Page.SITE_LIST_SERVLET);
}
}
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class UnlockEventDefinitionServlet 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());
}
// finds all events
StudyEventDAO sedao = new StudyEventDAO(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_unlock"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
if (!sed.getStatus().equals(Status.LOCKED)) {
addPageMessage(respage.getString("this_SED_cannot_be_unlocked") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
return;
}
request.setAttribute("definitionToUnlock", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("events", events);
forwardPage(Page.UNLOCK_DEFINITION);
} else {
logger.info("submit to lock the definition");
// unlock definition
sed.setStatus(Status.AVAILABLE);
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sdao.update(sed);
// lock all crfs
for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
edc.setStatus(Status.AVAILABLE);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edao.update(edc);
}
// unlock all events
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// unlock all the item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
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);
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
String emailBody = respage.getString("the_SED") + " " + sed.getName() + respage.getString("has_been_unlocked_for_the_study") + " " + currentStudy.getName() + ". " + respage.getString("subject_event_data_is_as_it_was_before");
addPageMessage(emailBody);
sendEmail(emailBody);
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ExtractBean method getCRFCompletionDate.
protected String getCRFCompletionDate(int h, int i, int j) {
StudyEventBean seb = getEvent(h, i, j);
EventCRFBean eventCRF = null;
if (seb.getEventCRFs().size() > 0) {
eventCRF = (EventCRFBean) seb.getEventCRFs().get(0);
}
// need
return eventCRF.getDateValidateCompleted() == null ? sdf.format(eventCRF.getDateCompleted()) : sdf.format(eventCRF.getDateValidateCompleted());
// to
// be
// fixed?
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ExtractBean method addStudyEventData.
// addStudySubjectData
/*
* public void addStudySubjectData(Integer studySubjectId, String
* studySubjectLabel, Date dateOfBirth, String gender, Integer
* subjectStatusId, Boolean dobCollected, String uniqueIdentifier, String
* subjectSecondaryLabel) { if (!subjectsAdded.containsKey(studySubjectId))
* { StudySubjectBean sub = new StudySubjectBean();
* sub.setId(studySubjectId.intValue()); sub.setLabel(studySubjectLabel);
*
* sub.setDateOfBirth(dateOfBirth); if (gender != null && gender.length() >
* 0) { sub.setGender(gender.charAt(0)); } else { sub.setGender(' '); }
* sub.setStatus(Status.get(subjectStatusId.intValue())); //
* sub.setSecondaryLabel(secondaryID);//????
* sub.setUniqueIdentifier(uniqueIdentifier);
* sub.setSecondaryLabel(subjectSecondaryLabel); //
* sub.setEnrollmentDate(enrollmentDate); // TODO need to find enrollment
* date, later, tbh subjects.add(sub); subjectsAdded.put(studySubjectId,
* Boolean.TRUE); } }
*/
/**
* @vbc 08/06/2008 NEW EXTRACT DATA IMPLEMENTATION Combines the two HashMaps
* into eventData entries - the data is already filtered for null
* values
*/
public void addStudyEventData() {
/**
* The two ArrayList are synchronized because they are extracted with
* "ORDER BY aitem_data_id"
*/
boolean isfnd = false;
// initialize
eventData = new HashMap();
for (int ik = 0; ik < aBASE_ITEMDATAID.size(); ik++) {
// get the item_group side
extractDataset_ITEMGROUPSIDE objgrp = (extractDataset_ITEMGROUPSIDE) hBASE_ITEMGROUPSIDE.get(ik);
extractDataset_EVENTSIDE objev = (extractDataset_EVENTSIDE) hBASE_EVENTSIDE.get(ik);
// sanity check - assume both are not null
Integer itemdataid = (Integer) aBASE_ITEMDATAID.get(ik);
Integer itemdataid_objgrp = objgrp.itemDataId;
Integer itemdataid_objev = objev.itemDataId;
if (itemdataid_objgrp.intValue() == itemdataid.intValue() && itemdataid_objev.intValue() == itemdataid.intValue()) {
// OK - add entries to the dataEvent
// initialize
StudyEventBean event = new StudyEventBean();
EventCRFBean eventCRF = new EventCRFBean();
//
// studyEventDefinitionName
event.setName(objev.studyEventDefinitionName);
// studyEventStart
event.setDateStarted(objev.studyEventDateStart);
// studyEventEnd
event.setDateEnded(objev.studyEventDateEnd);
// studyEventLocation
event.setLocation(objev.studyEventLoacation);
// sampleOrdinal
event.setSampleOrdinal(objev.sampleOrdinal.intValue());
// .
// intValue
// ()
// studyEventDefinitionId
event.setStudyEventDefinitionId(objev.studyEvenetDefinitionId.intValue());
// .
// intValue
// (
// )
// studySubjectId
event.setStudySubjectId(objev.studySubjectId.intValue());
// .
// intValue
// ()
// se
event.setStartTimeFlag(objev.studyEventStartTimeFlag.booleanValue());
// .
// getStartTimeFlag
// (
// )
// se
event.setEndTimeFlag(objev.studyEventEndTimeFlag.booleanValue());
// .
// getEndTimeFlag
// (
// )
// below needs to be added, tbh
// TODO - @vbc - validate this
// se
event.setStatus(Status.get(objev.studyEventStatusId.intValue()));
// .
// getStatus
// (
// )
// se
event.setSubjectEventStatus(SubjectEventStatus.get(objev.studyEventSubjectEventStatusId.intValue()));
// .
// getSubjectEventStatus
// (
// )
// @vbc 08/06/2008 NEW EXTRACT DATA IMPLEMENTATION
// the stage is set on setStatus - skip it
// event.setStage(se.getStage());
// se.getId()
event.setId(objev.studyEventId.intValue());
// end tbh, 03/08
// completionStatusId
eventCRF.setCompletionStatusId(objgrp.eventCrfCompletionStatusId);
// .
// intValue
// (
// )
// interviewerName
eventCRF.setInterviewerName(objgrp.interviewerName);
// dateCompleted
eventCRF.setDateCompleted(objgrp.eventCrfDateCompleted);
// dateValidateCompleted
eventCRF.setDateValidateCompleted(objgrp.eventCrfDateValidateCompleted);
eventCRF.setStatus(Status.get(objgrp.eventCrfStatusId));
// eventCRF.setCreatedDate();//same as interviewed date? NO
// dateInterviewedv
eventCRF.setDateInterviewed(objgrp.dateInterviewed);
// eventCRF.setStatus(status); //this is the one that we want,
// tbh
CRFVersionBean crfVersion = new CRFVersionBean();
// crfVersionName
crfVersion.setName(objgrp.crfVersionName);
// crfVersionStatusId
crfVersion.setStatus(Status.get(objgrp.crfVersionStatusId.intValue()));
// crfVersionStatusId
crfVersion.setStatusId(objgrp.crfVersionStatusId.intValue());
// .
// intValue
// (
// )
eventCRF.setCrfVersion(crfVersion);
ArrayList events = new ArrayList();
events.add(eventCRF);
// logger.info("///adding an event CRF..."
// + eventCRF.getInterviewerName());
// hmm, one to one relationship?
event.setEventCRFs(events);
// guard clause to see if it's in there already?
// not rly, the above is only used in auditlogging
// could fit in crf and crf version ids here, though
// FIXME def not one to one relationship, tbh, 03.08
String key = getStudyEventDataKey(/* studySubjectId.intValue() */
objev.studySubjectId.intValue(), /* studyEventDefinitionId.intValue() */
objev.studyEvenetDefinitionId.intValue(), /* sampleOrdinal.intValue()) */
objev.sampleOrdinal.intValue());
if (eventData == null) {
eventData = new HashMap();
}
StudyEventBean checkEvent = (StudyEventBean) eventData.get(key);
if (checkEvent == null) {
eventData.put(key, event);
// logger.info("###just CREATED key: " + key + " event: " +
// event.getName() + " int.name: " +
// eventCRF.getInterviewerName());
} else {
// OK - already saved
}
} else {
isfnd = true;
}
//
}
// for
// before return quick count
logger.debug("Number of entries in the eventData is:" + eventData.size());
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ExtractBean method getCRFStatus.
// below created to support CRF metadata, tbh
protected String getCRFStatus(int h, int i, int j) {
// return crfbean.getStatus().getName();
// return currentCRF.getStatus().getName();
StudyEventBean seb = getEvent(h, i, j);
ArrayList crfbeans = currentDef.getCrfs();
EventCRFBean eventCRF = null;
if (seb.getEventCRFs().size() > 0) {
eventCRF = (EventCRFBean) seb.getEventCRFs().get(0);
}
return eventCRF != null ? eventCRF.getStatus().getName() : "";
}
Aggregations