use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class FormLayoutDAO method create.
public EntityBean create(EntityBean eb) {
// "INSERT INTO CRF_VERSION (NAME, DESCRIPTION, CRF_ID, STATUS_ID,DATE_CREATED," +
// "OWNER_ID,REVISION_NOTES,OC_OID) "
// + "VALUES ('" + stripQuotes(version) + "','" + stripQuotes(versionDesc) + "'," +
// "(SELECT CRF_ID FROM CRF WHERE NAME='"
// + crfName + "'),1,NOW()," + ub.getId() + ",'" + stripQuotes(revisionNotes) + "','" + oid + "')";
// <sql>INSERT INTO CRF_VERSION (CRF_ID, STATUS_ID, NAME,
// DESCRIPTION, OWNER_ID,
// DATE_CREATED, REVISION_NOTES)
// VALUES (?,?,?,?,?,NOW(),?)</sql>
FormLayoutBean cvb = (FormLayoutBean) eb;
HashMap variables = new HashMap();
// variables.put(Integer.valueOf(2), cb.getLabel());
variables.put(Integer.valueOf(1), Integer.valueOf(cvb.getCrfId()));
variables.put(Integer.valueOf(2), Integer.valueOf(cvb.getStatus().getId()));
variables.put(Integer.valueOf(3), cvb.getName());
variables.put(Integer.valueOf(4), cvb.getDescription());
variables.put(Integer.valueOf(5), Integer.valueOf(cvb.getOwner().getId()));
variables.put(Integer.valueOf(6), cvb.getRevisionNotes());
variables.put(Integer.valueOf(7), getValidOid(cvb, cvb.getName(), cvb.getOid()));
variables.put(Integer.valueOf(8), cvb.getXform());
variables.put(Integer.valueOf(9), cvb.getXformName());
variables.put(Integer.valueOf(10), cvb.getUrl());
// am i the only one who runs their daos' unit tests after I change
// things, tbh?
this.execute(digester.getQuery("create"), variables);
if (isQuerySuccessful()) {
cvb.setActive(true);
}
return cvb;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
StudyDAO studyDao = new StudyDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
CRFDAO crfDao = new CRFDAO(dataSource);
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
if (study.getParentStudyId() < 1) {
// Is a study
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
} else {
// Is a site
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
}
Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
Map<Integer, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(studySubject.getId());
Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, crfById);
de.setUncompletedCRFs(al);
// de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
// studySubject));
de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayEventCRFs.
private List<DisplayEventCRFBean> getDisplayEventCRFs(List eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study, Set<Integer> nonEmptyEventCrf, Map<Integer, FormLayoutBean> formLayoutById, Map<Integer, CRFBean> crfById, Integer studyEventDefinitionId, List eventDefinitionCRFs) {
ArrayList<DisplayEventCRFBean> answer = new ArrayList<DisplayEventCRFBean>();
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int formLayoutId = ecb.getFormLayoutId();
FormLayoutBean flb = formLayoutById.get(formLayoutId);
ecb.setFormLayout(flb);
CRFBean cb = crfById.get(flb.getCrfId());
ecb.setCrf(cb);
EventDefinitionCRFBean edc = null;
Iterator it = eventDefinitionCRFs.iterator();
while (it.hasNext()) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
if (edcBean.getCrfId() == cb.getId()) {
edc = edcBean;
break;
}
}
// rules updated 112007 tbh
if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
ecb.setStage(DataEntryStage.LOCKED);
// we need to set a SED-wide flag here, because other edcs
// in this event can be filled in and change the status, tbh
} else if (status.equals(SubjectEventStatus.INVALID)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!flb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
}
// TODO need to refactor since this is similar to other code, tbh
if (edc != null) {
// System.out.println("edc is not null, need to set flags");
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventDefinitionCRF(edc);
// System.out.println("edc.isDoubleEntry()" +
// edc.isDoubleEntry() + ecb.getId());
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
if (dec.isLocked()) {
// System.out.println("*** found a locked DEC:
// "+edc.getCrfName());
}
if (nonEmptyEventCrf.contains(ecb.getId())) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
}
}
return answer;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method getFormLayoutRefs.
List<ElementRefBean> getFormLayoutRefs(FormDefBean formDef) {
CRFBean crfBean = crfdao.findByOid(formDef.getOid());
List<FormLayoutBean> formLayouts = fldao.findAllByCRFId(crfBean.getId());
List<ElementRefBean> elementRefs = new ArrayList<>();
ElementRefBean element;
for (FormLayoutBean formLayout : formLayouts) {
element = new ElementRefBean();
element.setName(formLayout.getName());
element.setUrl(formLayout.getUrl());
elementRefs.add(element);
}
return elementRefs;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class ListCRFServlet method processRequest.
/**
* Finds all the crfs
*
*/
@Override
public void processRequest() throws Exception {
if (currentStudy.getParentStudyId() > 0) {
addPageMessage(respage.getString("no_crf_available_study_is_a_site"));
forwardPage(Page.MENU_SERVLET);
return;
}
session.removeAttribute("version");
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
if (module.equalsIgnoreCase("admin") && !(ub.isSysAdmin() || ub.isTechAdmin())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
request.setAttribute(MODULE, module);
// if coming from change crf version -> display message
String crfVersionChangeMsg = fp.getString("isFromCRFVersionBatchChange");
if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
addPageMessage(crfVersionChangeMsg);
}
// for
String dir = SQLInitServlet.getField("filePath") + "crf" + File.separator + "new" + File.separator;
// crf
// version
// spreadsheet
logger.debug("found directory: " + dir);
CRFDAO cdao = new CRFDAO(sm.getDataSource());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
ArrayList crfs = (ArrayList) cdao.findAll();
for (int i = 0; i < crfs.size(); i++) {
CRFBean eb = (CRFBean) crfs.get(i);
logger.debug("crf id:" + eb.getId());
ArrayList versions = (ArrayList) fldao.findAllByCRF(eb.getId());
// check whether the speadsheet is available on the server
for (int j = 0; j < versions.size(); j++) {
FormLayoutBean cv = (FormLayoutBean) versions.get(j);
File file = new File(dir + eb.getId() + cv.getOid() + ".xls");
logger.debug("looking in " + dir + eb.getId() + cv.getOid() + ".xls");
if (file.exists()) {
cv.setDownloadable(true);
} else {
File file2 = new File(dir + eb.getId() + cv.getName() + ".xls");
logger.debug("initial failed, looking in " + dir + eb.getId() + cv.getName() + ".xls");
if (file2.exists()) {
cv.setDownloadable(true);
}
}
}
eb.setVersions(versions);
}
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allRows = ListCRFRow.generateRowsFromBeans(crfs);
String[] columns = { resword.getString("CRF_name"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("crf_oid"), resword.getString("versions"), resword.getString("date_created"), resword.getString("owner"), resword.getString("status"), resword.getString("download"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
// oid column
table.hideColumnLink(4);
// BWP 3281: make the "owner" column sortable; table.hideColumnLink(7);
table.hideColumnLink(8);
table.setQuery("ListCRF", new HashMap());
table.addLink(resword.getString("blank_CRF_template"), "DownloadVersionSpreadSheet?template=1");
// YW << add "Enterprise CRF Catalog" link
String crfCatalogField = "crfCatalog";
// table.addLink(resword.getString("openclinica_CRF_catalog"),
// SQLInitServlet.getEnterpriseField(crfCatalogField));
// YW >>
// TODO add i18n links to the above, tbh
table.addLink(resword.getString("create_a_new_CRF"), "CreateCRFVersion?module=" + module);
table.setRows(allRows);
table.computeDisplay();
request.setAttribute("table", table);
request.setAttribute("study", currentStudy);
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
panel.setSubmitDataModule(false);
panel.setExtractData(false);
panel.setCreateDataset(false);
if (crfs.size() > 0) {
setToPanel("CRFs", new Integer(crfs.size()).toString());
}
setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
forwardPage(Page.CRF_LIST);
}
Aggregations