use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class PrintDataEntryServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
boolean isSubmitted = false;
int eventCRFId = fp.getInt("ecId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb;
SectionDAO sdao = new SectionDAO(getDataSource());
ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
String age = "";
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
if (eventCRFId == 0) {
ecb = new EventCRFBean();
// super.ecb.setCRFVersionId(sb.getCRFVersionId());
} else {
EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
// Get all the SectionBeans attached to this ECB
ArrayList sects = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
// super.sb = sb;
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
// This is the StudySubjectBean
StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
// This is the SubjectBean
SubjectDAO subjectDao = new SubjectDAO(getDataSource());
int subjectId = sub.getSubjectId();
int studyId = sub.getStudyId();
SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setStudyEventDefinition(sed);
// Let us process the age
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
// YW 11-16-2007 enrollment-date is used for computing age
age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
}
// Get the study then the parent study
StudyDAO studydao = new StudyDAO(getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("studyTitle", parentStudy.getName() + " - " + study.getName());
} else {
request.setAttribute("studyTitle", study.getName());
}
request.setAttribute("studySubject", sub);
request.setAttribute("subject", subject);
request.setAttribute("studyEvent", se);
request.setAttribute("age", age);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
// Get the section beans from super
sectionBeans = super.getAllDisplayBeans(request);
}
// Find out whether the sections involve groups
ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
// CRF VERSION ID WILL BE 0 IF "ecId" IS NOT IN THE QUERYSTRING
int crfVersionId = ecb.getCRFVersionId();
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
boolean sectionsHaveGroups = false;
if (itemGroupBeans.size() > 0) {
sectionsHaveGroups = true;
// get a DisplaySectionBean for each section of the CRF, sort them,
// then
// dispatch the request to a print JSP. the constructor for this
// handler takes
// a boolean value depending on whether an event or data is involved
// or not
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(true, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionId);
handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
request.setAttribute("crfVersionBean", crfverBean);
CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that an event and/or data is involved
request.setAttribute("dataInvolved", "true");
}
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("EventCRFBean", ecb);
// We do not need most of these attributes if groups are involved
if (!sectionsHaveGroups) {
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
request.setAttribute("allSections", sectionBeans);
request.setAttribute("displayAll", "1");
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute("sec", sb);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
} else {
// end if(! sectionsHaveGroups)
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
}
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class PrintAllSiteEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
// The PrintDataEntry servlet handles this parameter
int siteId = fp.getInt("siteId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(getDataSource());
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
ArrayList<SectionBean> allSectionBeans;
StudyDAO studyDao = new StudyDAO(getDataSource());
StudyBean site = (StudyBean) studyDao.findByPK(siteId);
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
seds = sedao.findAllByStudy(site);
// ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
CRFDAO cdao = new CRFDAO(getDataSource());
boolean isSubmitted = false;
ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
for (StudyEventDefinitionBean sed : seds) {
int defId = sed.getId();
edcs.addAll(edcdao.findAllByDefinitionAndSiteIdAndParentStudyId(defId, siteId, site.getParentStudyId()));
}
Map eventDefinitionDefaultVersions = new LinkedHashMap();
Map eventDefinitionEventDefCrf = new LinkedHashMap<StudyEventDefinitionBean, EventDefinitionCRFBean>();
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = edcs.get(i);
if (!edc.getStatus().equals(Status.AVAILABLE)) {
continue;
}
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());
StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
edc.setDefaultVersionName(defaultVersion.getName());
if (defaultVersion.getStatus().isAvailable()) {
List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
if (list == null)
list = new ArrayList();
list.add(defaultVersion);
eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
eventDefinitionEventDefCrf.put(studyEventDefinitionBean, edc);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
SectionDAO sdao = new SectionDAO(getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
Map sedCrfBeans = null;
for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
if (sedCrfBeans == null)
sedCrfBeans = new LinkedHashMap();
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
if (itemGroupBeans.size() > 0) {
// get a DisplaySectionBean for each section of the CRF, sort
// them, then
// dispatch the request to a print JSP. The constructor for this
// handler takes
// a boolean value depending on whether data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionBean.getId());
//handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
request.setAttribute("crfVersionBean", crfverBean);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setDisplaySectionBeans(displaySectionBeans);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setGrouped(true);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
continue;
}
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionBean.getId());
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) eventDefinitionEventDefCrf.get(sedBean);
request.setAttribute(EVENT_DEF_CRF_BEAN, edcBean);
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
sectionBeans = super.getAllDisplayBeans(request);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setGrouped(false);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
}
}
StudyBean parentStudy = (StudyBean) studyDao.findByPK(site.getParentStudyId());
String studyName = parentStudy.getName();
String siteName = site.getName();
request.setAttribute("sedCrfBeans", sedCrfBeans);
request.setAttribute("studyName", studyName);
request.setAttribute("site", siteName);
forwardPage(Page.VIEW_ALL_SITE_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class PrintCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
// The PrintDataEntry servlet handles this parameter
int eventCRFId = fp.getInt("ecId");
//JN:The following were the the global variables, moved as local.
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
// EventDefinitionCRFDao findByStudyEventIdAndCRFVersionId(int
// studyEventId, int crfVersionId)
SectionDAO sdao = new SectionDAO(getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
CRFDAO crfDao = new CRFDAO(getDataSource());
ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
// The existing application doesn't print null values, even if they are
// defined in the event definition
int crfVersionId = fp.getInt("id", true);
boolean isSubmitted = false;
if (crfVersionId == 0) {
addPageMessage(respage.getString("please_choose_a_crf_to_view_details"), request);
forwardPage(Page.CRF_LIST_SERVLET, request, response);
} else {
// BWP 2/7/2008>> Find out if the CRF has grouped tables, and if so,
// use
// that dedicated JSP
ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
if (itemGroupBeans.size() > 0) {
// get a DisplaySectionBean for each section of the CRF, sort
// them, then
// dispatch the request to a print JSP. The constructor for this
// handler takes
// a boolean value depending on whether data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionId);
handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
request.setAttribute("crfVersionBean", crfverBean);
CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
// request.setAttribute("displaySection",displaySection);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
// IllegalStateException
return;
}
//JN:Revisit ME
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionId);
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
// super.sb = sb;
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
request.setAttribute(INPUT_EVENT_CRF, ecb);
sectionBeans = super.getAllDisplayBeans(request);
}
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
request.setAttribute("allSections", sectionBeans);
request.setAttribute("displayAllCRF", "1");
request.setAttribute(BEAN_DISPLAY, dsb);
request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
request.setAttribute("sec", sb);
request.setAttribute("EventCRFBean", ecb);
forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method buildInstance.
// method
/**
* @param model
* @param crfVersion
* @param crfSections
* @return
* @throws Exception
*/
private String buildInstance(Model model, FormLayoutBean formLayout, CRFVersionBean crfVersion, ArrayList<SectionBean> crfSections) throws Exception {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder build = docFactory.newDocumentBuilder();
Document doc = build.newDocument();
Element crfElement = doc.createElement(formLayout.getOid());
crfElement.setAttribute("id", formLayout.getOid());
doc.appendChild(crfElement);
crfElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:jr", "http://openrosa.org/javarosa");
for (SectionBean section : crfSections) {
Element sectionSubTitle = doc.createElement("SECTION_" + section.getId() + ".SUBTITLE");
Element sectionInstructions = doc.createElement("SECTION_" + section.getId() + ".INSTRUCTIONS");
Element sectionElm = doc.createElement("SECTION_" + section.getLabel().replaceAll("\\W", "_"));
crfElement.appendChild(sectionSubTitle);
crfElement.appendChild(sectionInstructions);
crfElement.appendChild(sectionElm);
}
ArrayList<ItemGroupBean> itemGroupBeans = getItemGroupBeansByFormLayout(formLayout);
for (ItemGroupBean itemGroupBean : itemGroupBeans) {
ItemGroupMetadataBean itemGroupMetadataBean = getItemGroupMetadataByGroup(itemGroupBean, crfVersion);
String repeatGroupMin = itemGroupMetadataBean.getRepeatNum().toString();
Boolean isrepeating = itemGroupMetadataBean.isRepeatingGroup();
Element groupElement = doc.createElement(itemGroupBean.getOid());
if (isrepeating) {
groupElement.setTextContent(repeatGroupMin);
groupElement.setAttribute("jr:template", "");
Element hiddenOrdinalItem = doc.createElement("OC.REPEAT_ORDINAL");
groupElement.appendChild(hiddenOrdinalItem);
}
crfElement.appendChild(groupElement);
idao = new ItemDAO(dataSource);
ArrayList<ItemBean> items = (ArrayList<ItemBean>) idao.findAllItemsByGroupIdOrdered(itemGroupBean.getId(), crfVersion.getId());
for (ItemBean item : items) {
ItemFormMetadataBean itemMetaData = getItemFormMetadata(item, crfVersion);
if (itemMetaData.getHeader() != null && !itemMetaData.getHeader().equals("")) {
Element header = doc.createElement(item.getOid() + ".HEADER");
groupElement.appendChild(header);
}
if (itemMetaData.getHeader() != null && !itemMetaData.getSubHeader().equals("")) {
Element subHeader = doc.createElement(item.getOid() + ".SUBHEADER");
groupElement.appendChild(subHeader);
}
Element question = doc.createElement(item.getOid());
groupElement.appendChild(question);
}
// end of item
}
// end of group
// add meta
Element meta = doc.createElement("meta");
// add instanceId
Element instanceId = doc.createElement("instanceID");
meta.appendChild(instanceId);
crfElement.appendChild(meta);
TransformerFactory transformFactory = TransformerFactory.newInstance();
Transformer transformer = transformFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
return writer.toString();
}
use of org.akaza.openclinica.bean.submit.ItemGroupBean in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method getItemGroupBeans.
@SuppressWarnings({ "rawtypes", "unchecked" })
private ArrayList<ItemGroupBean> getItemGroupBeans(SectionBean section) throws Exception {
ArrayList<ItemGroupBean> itemGroupBeans = null;
igdao = new ItemGroupDAO(dataSource);
itemGroupBeans = (ArrayList<ItemGroupBean>) igdao.findGroupBySectionId(section.getId());
return itemGroupBeans;
}
Aggregations