use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class UrlRewriteServlet method getOpenClinicaResourceFromURL.
/**
* Method to parse the request URL parameters and get the respective
* database identifiers
*
* @param URLPath
* - example "S_CPCS/320999/SE_CPCS%5B1%5D/F_CPCS_1"
* @param queryString
* - example
* "format=html&mode=view&tabId=1&exitTo=ViewStudySubject"
* @return
*/
public OpenClinicaResource getOpenClinicaResourceFromURL(String URLPath) /*
* ,
* String
* queryString
*/
{
OpenClinicaResource openClinicaResource = new OpenClinicaResource();
if ((null != URLPath) && (!URLPath.equals(""))) {
if (URLPath.contains("/")) {
String[] tokens = URLPath.split("/");
if (tokens.length != 0) {
String URLParamValue = "";
StudyDAO stdao = new StudyDAO(getDataSource());
StudySubjectDAO ssubdao = new StudySubjectDAO(getDataSource());
StudyEventDefinitionDAO sedefdao = new StudyEventDefinitionDAO(getDataSource());
CRFDAO crfdao = new CRFDAO(getDataSource());
CRFVersionDAO crfvdao = new CRFVersionDAO(getDataSource());
ItemDAO idao = new ItemDAO(getDataSource());
ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
StudyEventDAO sedao = new StudyEventDAO(getDataSource());
StudyBean study = null;
StudySubjectBean subject = null;
StudyEventDefinitionBean sed = null;
CRFBean c = null;
CRFVersionBean cv = null;
ItemBean item = null;
ItemGroupBean ig = null;
StudyEventBean studyEvent = null;
Integer studySubjectId = 0;
Integer eventDefId = 0;
Integer eventRepeatKey = 0;
for (int i = 0; i < tokens.length; i++) {
// when interpreting these request URL parameters, the
// assumption is that the position of
// each type of parameters will be fixed. Meaning, study
// OID is always going to be at the start
// followed by StudySubjectKey followed by study event
// definition OID followed by
// study event repeat key followed by form OID followed
// by item group OID followed by
// item group repeat key followed by item OID
// It can also be done based on the start of OID value
// (example study OID presently
// starts with 'S_' but we will have to change it if we
// change the method of generating
// oID values in future.
URLParamValue = tokens[i].trim();
//System.out.println("URLParamValue::"+URLParamValue);
logger.info("URLPAramValue::" + URLParamValue);
if ((null != URLParamValue) && (!URLParamValue.equals(""))) {
switch(i) {
case 0:
{
// study OID
study = stdao.findByOid(URLParamValue);
//validate study OID
if (study == null) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_study_oid"));
return openClinicaResource;
} else {
openClinicaResource.setStudyOID(URLParamValue);
if (null != study) {
openClinicaResource.setStudyID(study.getId());
}
}
break;
}
case 1:
{
// StudySubjectKey
subject = ssubdao.findByOidAndStudy(URLParamValue, study.getId());
//validate subject OID
if (subject == null) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_subject_oid"));
return openClinicaResource;
} else {
openClinicaResource.setStudySubjectOID(URLParamValue);
if (null != subject) {
studySubjectId = subject.getId();
openClinicaResource.setStudySubjectID(studySubjectId);
}
}
break;
}
case 2:
{
// study event definition OID
// separate study event OID and study event
// repeat key
String seoid = "";
String eventOrdinal = "";
if (URLParamValue.contains("%5B") && URLParamValue.contains("%5D")) {
seoid = URLParamValue.substring(0, URLParamValue.indexOf("%5B"));
openClinicaResource.setStudyEventDefOID(seoid);
eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("%5B") + 3, URLParamValue.indexOf("%5D"));
} else if (URLParamValue.contains("[") && URLParamValue.contains("]")) {
seoid = URLParamValue.substring(0, URLParamValue.indexOf("["));
logger.info("seoid" + seoid);
openClinicaResource.setStudyEventDefOID(seoid);
eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("[") + 1, URLParamValue.indexOf("]"));
logger.info("eventOrdinal::" + eventOrdinal);
} else {
//event ordinal not specified
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("event_ordinal_not_specified"));
return openClinicaResource;
}
if ((null != seoid) && (null != study)) {
sed = sedefdao.findByOidAndStudy(seoid, study.getId(), study.getParentStudyId());
//validate study event oid
if (null == sed) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_event_oid"));
return openClinicaResource;
} else {
eventDefId = sed.getId();
openClinicaResource.setStudyEventDefID(eventDefId);
}
}
if (null != eventRepeatKey) {
eventRepeatKey = Integer.parseInt(eventOrdinal.trim());
//validate the event ordinal specified exists in database
studyEvent = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(subject.getId(), sed.getId(), eventRepeatKey);
//this method return new StudyEvent (not null) even if no studyEvent can be found
if (null == studyEvent || studyEvent.getId() == 0) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_event_ordinal"));
return openClinicaResource;
} else {
openClinicaResource.setStudyEventRepeatKey(eventRepeatKey);
}
}
break;
}
case 3:
{
// form OID
openClinicaResource.setFormVersionOID(URLParamValue);
//validate the crf version oid
cv = crfvdao.findByOid(URLParamValue);
if (cv == null) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("invalid_crf_oid"));
return openClinicaResource;
} else {
openClinicaResource.setFormVersionID(cv.getId());
//validate if crf is removed
if (cv.getStatus().equals(Status.DELETED)) {
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("removed_crf"));
return openClinicaResource;
} else {
if (null != study) {
// cv =
// crfvdao.findByCrfVersionOidAndStudy(URLParamValue,
// study.getId());
// if (null != cv) {
// openClinicaResource.setFormVersionID(cv.getId());
// openClinicaResource.setFormID(cv.getCrfId());
// }
HashMap studySubjectCRFDataDetails = sedao.getStudySubjectCRFData(study, studySubjectId, eventDefId, URLParamValue, eventRepeatKey);
if ((null != studySubjectCRFDataDetails) && (studySubjectCRFDataDetails.size() != 0)) {
if (studySubjectCRFDataDetails.containsKey("event_crf_id")) {
openClinicaResource.setEventCrfId((Integer) studySubjectCRFDataDetails.get("event_crf_id"));
}
if (studySubjectCRFDataDetails.containsKey("event_definition_crf_id")) {
openClinicaResource.setEventDefinitionCrfId((Integer) studySubjectCRFDataDetails.get("event_definition_crf_id"));
}
if (studySubjectCRFDataDetails.containsKey("study_event_id")) {
openClinicaResource.setStudyEventId((Integer) studySubjectCRFDataDetails.get("study_event_id"));
}
} else {
//no data was found in the database for the combination of parameters in the RESTful URL. There are 2 possible reasons:
//a. The data entry is not started yet for this event CRF. As of OpenClinica 3.1.3 we have not implemented the
// RESTful URL functionality in this case.
//b. The form version OID entered in the URL could be different than the one used in the data entry
openClinicaResource.setInValid(true);
openClinicaResource.getMessages().add(resexception.getString("either_no_data_for_crf_or_data_entry_not_started"));
return openClinicaResource;
}
}
}
}
break;
}
case 4:
{
// item group OID
// separate item group OID and item group
// repeat key
String igoid = "";
String igRepeatKey = "";
if (URLParamValue.contains("[")) {
igoid = URLParamValue.substring(1, URLParamValue.indexOf("["));
igRepeatKey = URLParamValue.substring(URLParamValue.indexOf("["), URLParamValue.indexOf("}]"));
}
if ((null != igoid) && (null != cv)) {
ig = igdao.findByOidAndCrf(URLParamValue, cv.getCrfId());
if (null != ig) {
openClinicaResource.setItemGroupID(ig.getId());
}
}
if (null != igRepeatKey) {
openClinicaResource.setItemGroupRepeatKey(Integer.parseInt(igRepeatKey));
}
break;
}
case 5:
{
// item = idao.find
break;
}
}
// switch end
}
}
}
}
}
return openClinicaResource;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class VerifyImportedCRFDataServlet method processRequest.
@Override
@SuppressWarnings(value = "unchecked")
public void processRequest() throws Exception {
ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(sm.getDataSource());
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
resetPanel();
panel.setStudyInfoShown(false);
panel.setOrderedData(true);
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"));
if ("confirm".equalsIgnoreCase(action)) {
List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
logger.info("Size of displayItemBeanWrappers : " + displayItemBeanWrappers.size());
forwardPage(Page.VERIFY_IMPORT_CRF_DATA);
}
if ("save".equalsIgnoreCase(action)) {
// setup ruleSets to run if applicable
RuleSetServiceInterface ruleSetService = (RuleSetServiceInterface) SpringServletAccess.getApplicationContext(context).getBean("ruleSetService");
List<ImportDataRuleRunnerContainer> containers = this.ruleRunSetup(sm.getDataSource(), currentStudy, ub, ruleSetService);
List<DisplayItemBeanWrapper> displayItemBeanWrappers = (List<DisplayItemBeanWrapper>) session.getAttribute("importedData");
// System.out.println("Size of displayItemBeanWrappers : " +
// displayItemBeanWrappers.size());
HashMap<Integer, String> importedCRFStatuses = (HashMap<Integer, String>) session.getAttribute("importedCRFStatuses");
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = new EventCRFBean();
// TODO : tom , the wrapper object has all the necessary data -
// as you see we check the
// is to see if this data is Savable if it is then we go ahead
// and save it. if not we discard.
// So the change needs to happen here , instead of discarding we
// need to file discrepancy notes
// and save the data. If you look in the
// Page.VERIFY_IMPORT_CRF_DATA jsp file you can see how I am
// pulling the errors. and use that in the same way.
logger.info("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
ArrayList<Integer> eventCrfInts = new ArrayList<Integer>();
// wrapper.getValidationErrors().toString());
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.info("found value here: " + displayItemBean.getData().getValue());
logger.info("found status here: " + eventCrfBean.getStatus().getName());
// System.out.println("found event crf bean name here: "
// +
// eventCrfBean.getEventName()+" id "+eventCrfBean.getId
// ());
// SO, items can be created in a wrapper which is set to
// overwrite
// we get around this by checking the bean first, to
// make sure it's not null
ItemDataBean itemDataBean = new ItemDataBean();
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
if (wrapper.isOverwrite() && itemDataBean.getStatus() != null) {
if (!itemDataBean.getValue().equals(displayItemBean.getData().getValue()))
resetSDV = true;
logger.info("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(ub);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.info("updated: " + itemDataBean.getItemId());
// need to set pk here in order to create dn
displayItemBean.getData().setId(itemDataBean.getId());
} else {
resetSDV = true;
itemDataDao.create(displayItemBean.getData());
logger.info("created: " + displayItemBean.getData().getItemId() + "event CRF ID = " + eventCrfBean.getId() + "CRF VERSION ID =" + eventCrfBean.getCRFVersionId());
// does this dao function work for repeating
// events/groups?
// ItemDataBean itemDataBean =
// itemDataDao.findByEventCRFIdAndItemName(
// eventCrfBean,
// displayItemBean.getItem().getName());
ItemDataBean itemDataBean2 = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
logger.info("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean2.getId());
}
// logger.info("created item data bean:
// "+displayItemBean.getData().getId());
// logger.info("created:
// "+displayItemBean.getData().getName());
// logger.info("continued:
// "+displayItemBean.getData().getItemId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.info("continued2: getName " +
// ibean.getName());
// System.out.println("*** checking for validation errors: "
// + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList messageList = (ArrayList) wrapper.getValidationErrors().get(itemOid);
// could it be more than one? tbh 08/2008
for (int iter = 0; iter < messageList.size(); iter++) {
String message = (String) messageList.get(iter);
DiscrepancyNoteBean parentDn = ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, ub, sm.getDataSource(), currentStudy);
ImportSpringJob.createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), ub, sm.getDataSource(), currentStudy);
// System.out.println("*** created disc note with message: "
// + message);
// displayItemBean);
}
}
// "+displayItemBean.getDbData().getName());
if (!eventCrfInts.contains(new Integer(eventCrfBean.getId()))) {
String eventCRFStatus = importedCRFStatuses.get(new Integer(eventCrfBean.getId()));
if (eventCRFStatus != null && eventCRFStatus.equals(DataEntryStage.INITIAL_DATA_ENTRY.getName()) && eventCrfBean.getStatus().isAvailable()) {
crfBusinessLogicHelper.markCRFStarted(eventCrfBean, ub);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
}
eventCrfInts.add(new Integer(eventCrfBean.getId()));
}
}
// Reset the SDV status if item data has been changed or added
if (eventCrfBean != null && resetSDV)
eventCrfDao.setSDVStatus(false, ub.getId(), eventCrfBean.getId());
// end of item datas, tbh
// crfBusinessLogicHelper.markCRFComplete(eventCrfBean, ub);
// System .out.println("*** just updated event crf bean: "+
// eventCrfBean.getId());
// need to update the study event status as well, tbh
// crfBusinessLogicHelper.updateStudyEvent(eventCrfBean,
// ub);
// above should do it for us, tbh 08/2008
}
}
addPageMessage(respage.getString("data_has_been_successfully_import"));
addPageMessage(this.ruleActionWarnings(this.runRules(currentStudy, ub, containers, ruleSetService, ExecutionMode.SAVE)));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// replaced tbh, 06/2009
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class CellFactoryPrintDecorator method addUnits.
public Element addUnits(Element tdCell, DisplayItemBean displayBean) {
if (displayBean == null) {
return tdCell;
}
ItemBean itemBean = displayBean.getItem();
if (itemBean == null) {
return tdCell;
}
StringBuilder units = new StringBuilder(displayBean.getItem().getUnits());
if (units.length() < 1) {
return tdCell;
}
Element spanElement = new Element("span");
spanElement.setAttribute("style", "float:left;clear:both");
// surround units with parentheses
units = units.insert(0, "(");
units = units.append(")");
spanElement.addContent(" " + units.toString());
tdCell.addContent(spanElement);
return tdCell;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method createDisplaySectionWithItemGroups.
/**
* Create a DisplaySectionBean with a list of ItemGroupBeans. NOTE:
* unGrouped Items are not included
*
* @param study
* The StudyBean
* @param sectionId
* The Section ID associated with the Items, which end up
* providing the content of the tables.
* @param crfVersionId
* The CRF version ID associated with the Items.
* @param studyEventId
* The Study Event ID associated with the CRF Version ID.
* @param sm
* A SessionManager, from which DataSources are acquired for the
* DAO objects.
* @return A DisplaySectionBean.
*/
public DisplaySectionBean createDisplaySectionWithItemGroups(StudyBean study, int sectionId, EventCRFBean eventCrfBean, int studyEventId, SessionManager sm, int eventDefinitionCRFId, ServletContext context) {
DisplaySectionBean dBean = new DisplaySectionBean();
ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
ItemDAO itemDao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(sm.getDataSource());
List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(sectionId);
// all items associated with the section, including those not in a group
List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
try {
allMetas = metaDao.findAllBySectionId(sectionId);
} catch (OpenClinicaException oce) {
logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
}
// Collections.sort(allMetas);
if (arrList.isEmpty())
return dBean;
// Find out whether there are any checkboxes/radios/select elements
// and if so, get any null values
// associated with them
List<String> nullValuesList = new ArrayList<String>();
boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
// "+eventDefinitionCRFId);
if (eventDefinitionCRFId <= 0) {
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, studyEventId, eventCrfBean.getCRFVersionId());
eventDefinitionCRFId = edcBean.getId();
}
// "+eventDefinitionCRFId);
if (itemsHaveChecksRadios && eventDefinitionCRFId > 0) {
// method returns null values as a List<String>
nullValuesList = this.getNullValuesByEventCRFDefId(eventDefinitionCRFId, sm.getDataSource());
}
// Get the items associated with each group
List<ItemBean> itBeans;
List<DisplayItemBean> displayItems;
List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
DisplayItemGroupBean displayItemGBean;
for (ItemGroupBean itemGroup : arrList) {
itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
if (!metadata.isEmpty()) {
// for a given crf version, all the items in the same group
// have the same group metadata
// so we can get one of them and set metadata for the group
ItemGroupMetadataBean meta = metadata.get(0);
itemGroup.setMeta(meta);
}
// include arrayList parameter until I determine difference in
// classes
displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), eventCrfBean, sectionId, nullValuesList, context);
displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
displayFormBeans.add(displayItemGBean);
}
// We still have to sort these display item group beans on their
// ItemGroupMetadataBean?
// then number their ordinals accordingly
Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {
public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
}
});
// Now provide the display item group beans with an ordinal
int digOrdinal = 0;
for (DisplayItemGroupBean digBean : displayFormBeans) {
digBean.setOrdinal(++digOrdinal);
}
dBean.setDisplayFormGroups(displayFormBeans);
return dBean;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class FormBeanUtil method getDisplayBeansFromItems.
public static List<DisplayItemBean> getDisplayBeansFromItems(List<ItemBean> itemBeans, DataSource dataSource, EventCRFBean eventCrfBean, int sectionId, EventDefinitionCRFBean edcb, int test, ServletContext context) {
//int test is for method overloading.
List<DisplayItemBean> disBeans = new ArrayList<DisplayItemBean>();
if (itemBeans == null || itemBeans.isEmpty())
return disBeans;
ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
DisplayItemBean displayBean;
ItemFormMetadataBean meta;
for (ItemBean iBean : itemBeans) {
displayBean = new DisplayItemBean();
displayBean.setEventDefinitionCRF(edcb);
meta = metaDao.findByItemIdAndCRFVersionId(iBean.getId(), eventCrfBean.getCRFVersionId());
ItemDataBean itemDataBean = itemDataDao.findByItemIdAndEventCRFId(iBean.getId(), eventCrfBean.getId());
if (meta.getSectionId() == sectionId) {
displayBean.setItem(iBean);
displayBean.setMetadata(runDynamicsCheck(meta, eventCrfBean, itemDataBean, context));
displayBean.setData(itemDataBean);
// << tbh 05/2010
disBeans.add(displayBean);
}
}
Collections.sort(disBeans);
return disBeans;
}
Aggregations