use of org.akaza.openclinica.service.pmanage.SeRandomizationDTO in project OpenClinica by OpenClinica.
the class RandomizeActionProcessor method mayProceed.
private boolean mayProceed(String studyOid) throws Exception {
boolean accessPermission = false;
StudyBean siteStudy = getStudy(studyOid);
StudyBean study = getParentStudy(studyOid);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(ds);
StudyParameterValueBean pStatus = spvdao.findByHandleAndStudy(study.getId(), "randomization");
randomizationRegistrar = new RandomizationRegistrar();
SeRandomizationDTO seRandomizationDTO = randomizationRegistrar.getCachedRandomizationDTOObject(study.getOid().toString(), false);
String randomizationStatusFromOCUI = seRandomizationDTO.getStatus();
// enabled , disabled
String randomizationStatusFromOC = pStatus.getValue().toString();
// available , pending , frozen , locked
String studyStatus = study.getStatus().getName().toString();
// available , pending , frozen , locked
String siteStatus = siteStudy.getStatus().getName().toString();
System.out.println("randomizationStatusFromOCUI: " + randomizationStatusFromOCUI + " randomizationStatusFromOC: " + randomizationStatusFromOC + " studyStatus: " + studyStatus + " siteStatus: " + siteStatus);
logger.info("randomizationStatusFromOCUI: " + randomizationStatusFromOCUI + " randomizationStatusFromOC: " + randomizationStatusFromOC + " studyStatus: " + studyStatus + " siteStatus: " + siteStatus);
if (randomizationStatusFromOC.equalsIgnoreCase("enabled") && studyStatus.equalsIgnoreCase("available") && siteStatus.equalsIgnoreCase("available") && randomizationStatusFromOCUI.equalsIgnoreCase("ACTIVE")) {
accessPermission = true;
}
return accessPermission;
}
use of org.akaza.openclinica.service.pmanage.SeRandomizationDTO in project OpenClinica by OpenClinica.
the class ViewStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_view"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if (currentStudy.getId() != studyId && currentStudy.getParentStudyId() != studyId) {
checkRoleByUserAndStudy(ub, studyId, 0);
}
String viewFullRecords = fp.getString("viewFull");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
StudyConfigService scs = new StudyConfigService(sm.getDataSource());
study = scs.setParametersForStudy(study);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String randomizationStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "randomization").getValue();
String participantStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "participantPortal").getValue();
if (participantStatusInOC == "")
participantStatusInOC = "disabled";
if (randomizationStatusInOC == "")
randomizationStatusInOC = "disabled";
RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
SeRandomizationDTO seRandomizationDTO = randomizationRegistrar.getCachedRandomizationDTOObject(study.getOid(), false);
if (seRandomizationDTO != null && seRandomizationDTO.getStatus().equalsIgnoreCase("ACTIVE") && randomizationStatusInOC.equalsIgnoreCase("enabled")) {
study.getStudyParameterConfig().setRandomization("enabled");
} else {
study.getStudyParameterConfig().setRandomization("disabled");
}
;
ParticipantPortalRegistrar participantPortalRegistrar = new ParticipantPortalRegistrar();
String pStatus = participantPortalRegistrar.getCachedRegistrationStatus(study.getOid(), session);
if (participantPortalRegistrar != null && pStatus.equalsIgnoreCase("ACTIVE") && participantStatusInOC.equalsIgnoreCase("enabled")) {
study.getStudyParameterConfig().setParticipantPortal("enabled");
} else {
study.getStudyParameterConfig().setParticipantPortal("disabled");
}
;
request.setAttribute("studyToView", study);
if ("yes".equalsIgnoreCase(viewFullRecords)) {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList sites = new ArrayList();
ArrayList userRoles = new ArrayList();
ArrayList subjects = new ArrayList();
if (this.currentStudy.getParentStudyId() > 0 && this.currentRole.getRole().getId() > 3) {
sites.add(this.currentStudy);
userRoles = udao.findAllUsersByStudy(currentStudy.getId());
subjects = ssdao.findAllByStudy(currentStudy);
} else {
sites = (ArrayList) sdao.findAllByParent(studyId);
userRoles = udao.findAllUsersByStudy(studyId);
subjects = ssdao.findAllByStudy(study);
}
// find all subjects in the study, include ones in sites
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList displayStudySubs = new ArrayList();
// for (int i = 0; i < subjects.size(); i++) {
// StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
// // find all events
// ArrayList events = sedao.findAllByStudySubject(studySub);
//
// // find all eventcrfs for each event
// EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
//
// DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
// dssb.setStudyEvents(events);
// dssb.setStudySubject(studySub);
// displayStudySubs.add(dssb);
// }
// find all events in the study, include ones in sites
ArrayList definitions = seddao.findAllByStudy(study);
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean def = (StudyEventDefinitionBean) definitions.get(i);
ArrayList crfs = (ArrayList) edcdao.findAllActiveParentsByEventDefinitionId(def.getId());
def.setCrfNum(crfs.size());
}
String moduleManager = CoreResources.getField("moduleManager");
request.setAttribute("moduleManager", moduleManager);
String portalURL = CoreResources.getField("portalURL");
request.setAttribute("portalURL", portalURL);
request.setAttribute("config", study);
request.setAttribute("sitesToView", sites);
request.setAttribute("siteNum", sites.size() + "");
request.setAttribute("userRolesToView", userRoles);
request.setAttribute("userNum", userRoles.size() + "");
// request.setAttribute("subjectsToView", displayStudySubs);
// request.setAttribute("subjectNum", subjects.size() + "");
request.setAttribute("definitionsToView", definitions);
request.setAttribute("defNum", definitions.size() + "");
forwardPage(Page.VIEW_FULL_STUDY);
} else {
forwardPage(Page.VIEW_STUDY);
}
}
}
use of org.akaza.openclinica.service.pmanage.SeRandomizationDTO in project OpenClinica by OpenClinica.
the class RandomizeService method getRandomizationCode.
// Rest Call to OCUI to get Randomization
public String getRandomizationCode(EventCRFBean eventCrfBean, List<StratificationFactorBean> stratificationFactorBeans, RuleSetBean ruleSet) throws JSONException {
StudySubjectDAO ssdao = new StudySubjectDAO<>(ds);
StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eventCrfBean.getStudySubjectId());
// study subject oid
String identifier = ssBean.getOid();
StudyDAO sdao = new StudyDAO<>(ds);
StudyBean sBean = (StudyBean) sdao.findByPK(ssBean.getStudyId());
// site or study oid
String siteIdentifier = sBean.getOid();
// site or study name
String name = sBean.getName();
UserAccountDAO udao = new UserAccountDAO(ds);
int userId = 0;
if (eventCrfBean.getUpdaterId() == 0) {
userId = eventCrfBean.getOwnerId();
} else {
userId = eventCrfBean.getUpdaterId();
}
UserAccountBean uBean = (UserAccountBean) udao.findByPK(userId);
String user = uBean.getName();
// sBean should be parent study
// put randomization object in cache
StudyBean study = getParentStudy(sBean.getOid());
SeRandomizationDTO randomization = null;
try {
randomization = getCachedRandomizationDTOObject(study.getOid(), false);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String randomiseUrl = randomization.getUrl();
String username = randomization.getUsername();
String password = randomization.getPassword();
String timezone = "America/New_York";
// String randomiseUrl = "https://evaluation.sealedenvelope.com/redpill/seti2";
// String username = "oc";
// String password = "secret";
HttpHeaders headers = createHeaders(username, password);
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// retrieve json object if Randomization exist ,otherwise return a null object
JSONObject jsonRandObject = retrieveARandomisation(randomiseUrl, ssBean, headers);
if (jsonRandObject != null) {
return (String) jsonRandObject.get("code");
} else {
// if Site identifier exists ,then update otherwise create new Site identifier
addOrUpdateASite(randomiseUrl, sBean, headers, timezone);
// send for Randomization
JSONObject jsonRandomisedObject = randomiseSubject(randomiseUrl, ssBean, sBean, headers, user, stratificationFactorBeans, eventCrfBean, ruleSet);
if (jsonRandomisedObject != null)
return (String) jsonRandomisedObject.get("code");
else
return "";
}
}
use of org.akaza.openclinica.service.pmanage.SeRandomizationDTO 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;
}
use of org.akaza.openclinica.service.pmanage.SeRandomizationDTO in project OpenClinica by OpenClinica.
the class SystemController method getRandomizeModule.
public HashMap<String, Object> getRandomizeModule(StudyBean studyBean) {
StudyParameterValueBean spvBean = getParticipateMod(studyBean, "randomization");
String ocRandomizeStatus = "";
if (spvBean.isActive()) {
// enabled , disabled
ocRandomizeStatus = spvBean.getValue().toString();
}
SeRandomizationDTO seRandomizationDTO = null;
String ocuiRandomizeStatus = "";
URL randomizeUrl = null;
HashMap<String, String> mapMetadata = new HashMap<>();
if (ocRandomizeStatus.equals("enabled")) {
try {
RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
seRandomizationDTO = randomizationRegistrar.getRandomizationDTOObject(studyBean.getOid());
if (seRandomizationDTO != null && seRandomizationDTO.getStatus() != null) {
ocuiRandomizeStatus = seRandomizationDTO.getStatus();
if (seRandomizationDTO.getUrl() != null) {
randomizeUrl = new URL(seRandomizationDTO.getUrl());
}
mapMetadata.put("Randomize URL", randomizeUrl == null ? "" : randomizeUrl.toString());
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
HashMap<String, Object> mapRandomize = new HashMap<>();
mapRandomize.put("enabled", ocRandomizeStatus.equals("enabled") ? "True" : "False");
mapRandomize.put("status", ocuiRandomizeStatus.equals("") ? "INACTIVE" : ocuiRandomizeStatus);
mapRandomize.put("metadata", mapMetadata);
HashMap<String, Object> mapModule = new HashMap<>();
mapModule.put("Randomize", mapRandomize);
return mapModule;
}
Aggregations