use of org.akaza.openclinica.dao.rule.RuleDAO in project OpenClinica by OpenClinica.
the class StudyModuleController method handleMainPage.
@RequestMapping(method = RequestMethod.GET)
public ModelMap handleMainPage(HttpServletRequest request, HttpServletResponse response) {
ModelMap map = new ModelMap();
// Todo need something to reset panel from all the Spring Controllers
StudyInfoPanel panel = new StudyInfoPanel();
UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
if (!mayProceed(request)) {
try {
response.sendRedirect(request.getContextPath() + "/MainMenu?message=authentication_failed");
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
panel.reset();
request.getSession().setAttribute("panel", panel);
// setUpSidebar(request);
ResourceBundleProvider.updateLocale(LocaleResolver.getLocale(request));
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
eventDefinitionCRFDao = new EventDefinitionCRFDAO(dataSource);
studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
crfDao = new CRFDAO(dataSource);
studyGroupClassDao = new StudyGroupClassDAO(dataSource);
studyDao = new StudyDAO(dataSource);
userDao = new UserAccountDAO(dataSource);
ruleDao = new RuleDAO(dataSource);
StudyModuleStatus sms = studyModuleStatusDao.findByStudyId(currentStudy.getId());
if (sms == null) {
sms = new StudyModuleStatus();
sms.setStudyId(currentStudy.getId());
}
int crfCount = crfDao.findAllByStudy(currentStudy.getId()).size();
int crfWithEventDefinition = crfDao.findAllActiveByDefinitions(currentStudy.getId()).size();
int totalCrf = crfCount + crfWithEventDefinition;
// int eventDefinitionCount = eventDefinitionCRFDao.findAllActiveByStudy(currentStudy).size();
int eventDefinitionCount = studyEventDefinitionDao.findAllActiveByStudy(currentStudy).size();
int subjectGroupCount = studyGroupClassDao.findAllActiveByStudy(currentStudy).size();
// List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByStudy(currentStudy);
// ruleSets = ruleSetService.filterByStatusEqualsAvailableOnlyRuleSetRules(ruleSets);
int ruleCount = ruleSetService.getCountByStudy(currentStudy);
int siteCount = studyDao.findOlnySiteIdsByStudy(currentStudy).size();
int userCount = userDao.findAllUsersByStudy(currentStudy.getId()).size();
Collection childStudies = studyDao.findAllByParent(currentStudy.getId());
Map childStudyUserCount = new HashMap();
for (Object sb : childStudies) {
StudyBean childStudy = (StudyBean) sb;
childStudyUserCount.put(childStudy.getName(), userDao.findAllUsersByStudy(childStudy.getId()).size());
}
if (sms.getCrf() == 0) {
sms.setCrf(StudyModuleStatus.NOT_STARTED);
}
if (sms.getCrf() != 3 && totalCrf > 0) {
sms.setCrf(StudyModuleStatus.IN_PROGRESS);
}
if (sms.getEventDefinition() == 0) {
sms.setEventDefinition(StudyModuleStatus.NOT_STARTED);
}
if (sms.getEventDefinition() != 3 && eventDefinitionCount > 0) {
sms.setEventDefinition(StudyModuleStatus.IN_PROGRESS);
}
if (sms.getSubjectGroup() == 0) {
sms.setSubjectGroup(StudyModuleStatus.NOT_STARTED);
}
if (sms.getSubjectGroup() != 3 && subjectGroupCount > 0) {
sms.setSubjectGroup(StudyModuleStatus.IN_PROGRESS);
}
if (sms.getRule() == 0) {
sms.setRule(StudyModuleStatus.NOT_STARTED);
}
if (sms.getRule() != 3 && ruleCount > 0) {
sms.setRule(StudyModuleStatus.IN_PROGRESS);
}
if (sms.getSite() == 0) {
sms.setSite(StudyModuleStatus.NOT_STARTED);
}
if (sms.getSite() != 3 && siteCount > 0) {
sms.setSite(StudyModuleStatus.IN_PROGRESS);
}
if (sms.getUsers() == 0) {
sms.setUsers(StudyModuleStatus.NOT_STARTED);
}
if (sms.getUsers() != 3 && userCount > 0) {
sms.setUsers(StudyModuleStatus.IN_PROGRESS);
}
map.addAttribute(sms);
map.addAttribute("crfCount", totalCrf);
map.addAttribute("eventDefinitionCount", eventDefinitionCount);
map.addAttribute("subjectGroupCount", subjectGroupCount);
map.addAttribute("ruleCount", ruleCount);
map.addAttribute("siteCount", siteCount);
map.addAttribute("userCount", userCount);
map.addAttribute("childStudyUserCount", childStudyUserCount);
map.addAttribute("studyId", currentStudy.getId());
map.addAttribute("currentStudy", currentStudy);
// Load Participate registration information
String portalURL = CoreResources.getField("portalURL");
map.addAttribute("portalURL", portalURL);
if (portalURL != null && !portalURL.equals("")) {
String participateOCStatus = currentStudy.getStudyParameterConfig().getParticipantPortal();
ParticipantPortalRegistrar registrar = new ParticipantPortalRegistrar();
Authorization pManageAuthorization = registrar.getAuthorization(currentStudy.getOid());
String participateStatus = "";
String url = "";
try {
URL pManageUrl = new URL(portalURL);
if (pManageAuthorization != null && pManageAuthorization.getAuthorizationStatus() != null && pManageAuthorization.getAuthorizationStatus().getStatus() != null)
participateStatus = pManageAuthorization.getAuthorizationStatus().getStatus();
map.addAttribute("participateURL", pManageUrl);
map.addAttribute("participateOCStatus", participateOCStatus);
map.addAttribute("participateStatus", participateStatus);
if (pManageAuthorization != null && pManageAuthorization.getStudy() != null && pManageAuthorization.getStudy().getHost() != null && !pManageAuthorization.getStudy().getHost().equals("")) {
url = pManageUrl.getProtocol() + "://" + pManageAuthorization.getStudy().getHost() + "." + pManageUrl.getHost() + ((pManageUrl.getPort() > 0) ? ":" + String.valueOf(pManageUrl.getPort()) : "");
}
} catch (MalformedURLException e) {
logger.error(e.getMessage());
logger.error(ExceptionUtils.getStackTrace(e));
}
map.addAttribute("participateURLDisplay", url);
map.addAttribute("participateURLFull", url + "/#/login");
}
// Load Randomization information
String moduleManager = CoreResources.getField("moduleManager");
map.addAttribute("moduleManager", moduleManager);
if (moduleManager != null && !moduleManager.equals("")) {
String randomizationOCStatus = currentStudy.getStudyParameterConfig().getRandomization();
RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
SeRandomizationDTO randomization = null;
try {
randomization = randomizationRegistrar.getCachedRandomizationDTOObject(currentStudy.getOid(), true);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String randomizationStatus = "";
URL randomizeUrl = null;
if (randomization != null && randomization.getStatus() != null) {
randomizationStatus = randomization.getStatus();
if (randomization.getUrl() != null) {
try {
randomizeUrl = new URL(randomization.getUrl());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
map.addAttribute("randomizeURL", randomizeUrl);
map.addAttribute("randomizationOCStatus", randomizationOCStatus);
map.addAttribute("randomizationStatus", randomizationStatus);
}
// @pgawade 13-April-2011- #8877: Added the rule designer URL
if (null != coreResources) {
map.addAttribute("ruleDesignerURL", coreResources.getField("designer.url"));
map.addAttribute("contextPath", getContextPath(request));
logMe("before checking getHostPath url = " + request.getRequestURL());
// JN: for the eclinicalhosting the https is not showing up in the request path, going for a fix of taking
// the hostpath from sysurl
// map.addAttribute("hostPath", getHostPath(request));
map.addAttribute("hostPath", getHostPathFromSysUrl(coreResources.getField("sysURL.base"), request.getContextPath()));
map.addAttribute("path", "pages/studymodule");
}
// UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
request.setAttribute("userBean", userBean);
ArrayList statusMap = Status.toStudyUpdateMembersList();
// statusMap.add(Status.PENDING);
request.setAttribute("statusMap", statusMap);
if (currentStudy.getParentStudyId() > 0) {
StudyBean parentStudy = (StudyBean) studyDao.findByPK(currentStudy.getParentStudyId());
request.setAttribute("parentStudy", parentStudy);
}
ArrayList pageMessages = new ArrayList();
if (request.getSession().getAttribute("pageMessages") != null) {
pageMessages.addAll((ArrayList) request.getSession().getAttribute("pageMessages"));
request.setAttribute("pageMessages", pageMessages);
request.getSession().removeAttribute("pageMessages");
}
ArrayList regMessages = new ArrayList();
if (request.getSession().getAttribute(REG_MESSAGE) != null) {
regMessages.addAll((ArrayList) request.getSession().getAttribute(REG_MESSAGE));
request.setAttribute(REG_MESSAGE, regMessages);
request.getSession().removeAttribute(REG_MESSAGE);
}
return map;
}
Aggregations