use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class ResolveDiscrepancyServlet method prepareRequestForResolution.
public boolean prepareRequestForResolution(HttpServletRequest request, DataSource ds, StudyBean currentStudy, DiscrepancyNoteBean note, boolean isCompleted) throws Exception {
String entityType = note.getEntityType().toLowerCase();
int id = note.getEntityId();
if ("subject".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(id, currentStudy);
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
request.setAttribute("studySubId", String.valueOf(ssb.getId()));
} else if ("studysub".equalsIgnoreCase(entityType)) {
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
} else if ("eventcrf".equalsIgnoreCase(entityType)) {
request.setAttribute("editInterview", "1");
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(id);
request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
// If the request is passed along to ViewSectionDataEntryServlet,
// that code needs
// an event crf id; the (ecb.getId()+"") is necessary because
// FormProcessor throws
// a ClassCastException without the casting to a String
request.setAttribute(ViewSectionDataEntryServlet.EVENT_CRF_ID, ecb.getId() + "");
} else if ("studyevent".equalsIgnoreCase(entityType)) {
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(id);
request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.STUDY_SUBJECT_ID, String.valueOf(seb.getStudySubjectId()));
} else // this is for item data
if ("itemdata".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemDataBean idb = (ItemDataBean) iddao.findByPK(id);
ItemBean item = (ItemBean) idao.findByPK(idb.getItemId());
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO<>(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
FormLayoutDAO fldao = new FormLayoutDAO(ds);
FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(ecb.getFormLayoutId());
StudyEventDAO sedao = new StudyEventDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(ds);
ItemFormMetadataBean ifmb = ifmdao.findByItemIdAndCRFVersionId(idb.getItemId(), ecb.getFormLayoutId());
ItemGroupMetadataBean igmBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(idb.getItemId(), ecb.getCRFVersionId());
ItemGroupDAO igdao = new ItemGroupDAO<>(ds);
ItemGroupBean igBean = (ItemGroupBean) igdao.findByPK(igmBean.getItemGroupId());
int repeatOrdinal = idb.getOrdinal();
ItemDataBean idata = null;
if (idb != null && idb.isDeleted()) {
return false;
}
if (igmBean.isRepeatingGroup() && repeatOrdinal > 1) {
List<ItemGroupMetadataBean> igms = igmdao.findMetaByGroupAndCrfVersion(igBean.getId(), ecb.getCRFVersionId());
for (int i = 0; i < idb.getOrdinal(); i++) {
for (ItemGroupMetadataBean igm : igms) {
idata = iddao.findByItemIdAndEventCRFIdAndOrdinal(igm.getItemId(), ecb.getId(), i + 1);
if (idata != null && idata.isDeleted()) {
repeatOrdinal--;
break;
}
}
}
}
EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// Cache the subject context for use during xform submission
PFormCache cache = PFormCache.getInstance(context);
PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
subjectContext.setStudySubjectOid(ssb.getOid());
subjectContext.setStudyEventDefinitionId(seb.getStudyEventDefinitionId());
subjectContext.setOrdinal(seb.getSampleOrdinal());
subjectContext.setFormLayoutOid(formLayout.getOid());
subjectContext.setUserAccountId(ub.getId());
subjectContext.setItemName(item.getName() + COMMENT);
subjectContext.setItemRepeatOrdinal(repeatOrdinal);
subjectContext.setItemInRepeatingGroup(igmBean.isRepeatingGroup());
subjectContext.setItemRepeatGroupName(igBean.getLayoutGroupPath());
String contextHash = cache.putSubjectContext(subjectContext);
String formUrl = null;
if (ecb.getId() > 0) {
formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, currentStudy.getOid(), null, null, QUERY_FLAVOR);
} else {
formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, currentStudy.getOid(), QUERY_FLAVOR);
}
int hashIndex = formUrl.lastIndexOf("#");
String part1 = formUrl;
String part2 = "";
if (hashIndex != -1) {
part1 = formUrl.substring(0, hashIndex);
part2 = formUrl.substring(hashIndex);
}
request.setAttribute(EnketoFormServlet.FORM_URL1, part1);
request.setAttribute(EnketoFormServlet.FORM_URL2, part2);
}
return true;
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class RemoveStudyEventServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// studyEventId
int studyEventId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (studyEventId == 0) {
addPageMessage(respage.getString("please_choose_a_SE_to_remove"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studySub.getStudyId());
request.setAttribute("study", study);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
//
// if (!event.getStatus().equals(Status.AVAILABLE)) {
// addPageMessage(respage.getString("this_event_is_not_available_for_this_study")
// + " "
// +
// respage.getString("please_contact_sysadmin_for_more_information"));
// request.setAttribute("id", new
// Integer(studySubId).toString());
// forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
// return;
// }
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all crfs in the definition
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllByEventDefinitionId(study, sed.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(getDisplayEventCRFs(eventCRFs, eventDefinitionCRFs));
request.setAttribute("displayEvent", de);
forwardPage(Page.REMOVE_STUDY_EVENT);
} else {
logger.info("submit to remove the event from study");
// remove event from study
event.setStatus(Status.DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
// remove all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
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.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
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.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
String emailBody = respage.getString("the_event") + " " + event.getStudyEventDefinition().getName() + " " + respage.getString("has_been_removed_from_the_subject_record_for") + " " + studySub.getLabel() + " " + respage.getString("in_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class RemoveStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
// studySubjectId
String studySubIdString = request.getParameter("id");
String subIdString = request.getParameter("subjectId");
String studyIdString = request.getParameter("studyId");
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_a_study_subject_to_remove"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
int subjectId = Integer.valueOf(subIdString.trim()).intValue();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
checkRoleByUserAndStudy(ub, study.getParentStudyId(), study.getId());
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (!studySub.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_is_not_available_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
}
request.setAttribute("subject", subject);
request.setAttribute("study", study);
request.setAttribute("studySub", studySub);
request.setAttribute("events", displayEvents);
forwardPage(Page.REMOVE_STUDY_SUBJECT);
} else {
logger.info("submit to remove the subject from study");
// remove subject from study
studySub.setStatus(Status.DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
subdao.update(studySub);
// remove all study events
// remove all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < displayEvents.size(); j++) {
DisplayStudyEventBean dispEvent = displayEvents.get(j);
StudyEventBean event = dispEvent.getStudyEvent();
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.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
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.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getName() + " " + respage.getString("has_been_removed_from_the_study") + study.getName() + ".";
addPageMessage(emailBody);
// try{
// sendEmail(emailBody);
// }catch(Exception ex){
// addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
// }
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class ReassignStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt("id");
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_reassign"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
} else {
StudySubjectBean studySub = (StudySubjectBean) ssdao.findByPK(studySubId);
int subjectId = studySub.getSubjectId();
request.setAttribute("studySub", studySub);
SubjectBean subject = (SubjectBean) subdao.findByPK(subjectId);
request.setAttribute("subject", subject);
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
if (StringUtil.isBlank(action)) {
ArrayList studies = null;
DisplayStudyBean displayStudy = new DisplayStudyBean();
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
if (study.getParentStudyId() > 0) {
// current in site
studies = (ArrayList) sdao.findAllByParent(study.getParentStudyId());
StudyBean parent = (StudyBean) sdao.findByPK(study.getParentStudyId());
displayStudy.setParent(parent);
// studies.add(parent);
displayStudy.setChildren(studies);
} else {
studies = (ArrayList) sdao.findAllByParent(study.getId());
displayStudy.setParent(study);
displayStudy.setChildren(studies);
// studies.add(study);
}
// request.setAttribute("studies", studies);
request.setAttribute("displayStudy", displayStudy);
forwardPage(Page.REASSIGN_STUDY_SUBJECT);
} else {
int studyId = fp.getInt("studyId");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_site_to_reassign_the_subject"));
forwardPage(Page.REASSIGN_STUDY_SUBJECT);
return;
}
StudyBean st = (StudyBean) sdao.findByPK(studyId);
if ("confirm".equalsIgnoreCase(action)) {
StudySubjectBean sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabel(studySub.getLabel(), studyId, studySub.getId());
if (sub1.getId() > 0) {
addPageMessage(respage.getString("the_study_subject_ID_used_by_another_in_study_site"));
forwardPage(Page.REASSIGN_STUDY_SUBJECT);
return;
}
// YW << comment out this message
// if (groupMaps.size() > 0) {
// addPageMessage("Warning: This subject has Group data
// assoicated with current study,"
// + "the group data will be lost if it is reassigned to
// another study.");
// }
// YW >>
request.setAttribute("newStudy", st);
forwardPage(Page.REASSIGN_STUDY_SUBJECT_CONFIRM);
} else {
logger.info("submit to reassign the subject");
studySub.setUpdatedDate(new Date());
studySub.setUpdater(ub);
studySub.setStudyId(studyId);
ssdao.update(studySub);
for (int i = 0; i < groupMaps.size(); i++) {
SubjectGroupMapBean sgm = (SubjectGroupMapBean) groupMaps.get(i);
sgm.setUpdatedDate(new Date());
sgm.setUpdater(ub);
sgm.setStatus(Status.DELETED);
sgmdao.update(sgm);
}
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("subject_reassigned"));
Object[] arguments = { studySub.getLabel(), st.getName() };
addPageMessage(mf.format(arguments));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
}
use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO in project OpenClinica by OpenClinica.
the class RestoreEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// eventCRFId
int eventCRFId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_restore"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
// YW 11-07-2007, an event CRF could not be restored if its study
// subject has been removed
Status s = studySub.getStatus();
if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
addPageMessage(resword.getString("event_CRF") + resterm.getString("could_not_be") + resterm.getString("restored") + "." + respage.getString("study_subject_has_been_deleted"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
// YW
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (!eventCRF.getStatus().equals(Status.DELETED) && !eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
addPageMessage(respage.getString("this_event_CRF_avilable_for_study") + " " + " " + respage.getString("please_contact_sysadmin_for_more_information"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.RESTORE_EVENT_CRF);
} else {
logger.info("submit to restore the event CRF from study");
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// restore all the item data
for (int a = 0; a < itemData.size(); a++) {
ItemDataBean item = (ItemDataBean) itemData.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_event_CRF") + cb.getName() + " " + respage.getString("has_been_restored_to_the_event") + " " + event.getStudyEventDefinition().getName() + ".";
addPageMessage(emailBody);
sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
Aggregations