use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.
the class ExtractBean method getMetadata.
/**
* Implements the Column algorithm in "Dataset Export Algorithms" Must be
* called after DatasetDAO.getDatasetData();
*/
public void getMetadata() {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(this.ds);
StudyGroupDAO studygroupDAO = new StudyGroupDAO(ds);
StudyGroupClassDAO studygroupclassDAO = new StudyGroupClassDAO(ds);
// SubjectGroupMapDAO subjectGroupMapDAO = new SubjectGroupMapDAO(ds);
studyGroupClasses = new ArrayList();
studyGroupMap = new HashMap();
studyGroupMaps = new HashMap<Integer, ArrayList>();
sedCrfColumns = new HashMap();
displayed = new HashMap();
sedCrfItemFormMetadataBeans = new HashMap();
studyEvents = seddao.findAllByStudy(study);
ArrayList finalStudyEvents = new ArrayList();
if (dataset.isShowSubjectGroupInformation()) {
// logger.info("found study id for maps: "+study.getId());
studyGroupMaps = studygroupDAO.findSubjectGroupMaps(study.getId());
// below is for a given subject; we need a data structure for
// all subjects
// studyGroupMap = studygroupDAO.findByStudySubject(currentSubject);
// problem: can't use currentSubject here, since it's not 'set up'
// properly
// how to get the current subject?
logger.info("found subject group ids: " + dataset.getSubjectGroupIds().toString());
// studyGroupClasses = dataset.getSubjectGroupIds();
for (int h = 0; h < dataset.getSubjectGroupIds().size(); h++) {
Integer groupId = (Integer) dataset.getSubjectGroupIds().get(h);
StudyGroupClassBean sgclass = (StudyGroupClassBean) studygroupclassDAO.findByPK(groupId.intValue());
// logger.info();
// hmm how to link groups to subjects though? only through
// subject group map
logger.info("found a studygroupclass bean: " + sgclass.getName());
studyGroupClasses.add(sgclass);
}
}
for (int i = 0; i < studyEvents.size(); i++) {
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) studyEvents.get(i);
if (!selectedSED(sed)) {
continue;
}
ArrayList CRFs = (ArrayList) cdao.findAllActiveByDefinition(sed);
ArrayList CRFsDisplayedInThisSED = new ArrayList();
for (int j = 0; j < CRFs.size(); j++) {
CRFBean cb = (CRFBean) CRFs.get(j);
if (!selectedSEDCRF(sed, cb)) {
continue;
} else {
CRFsDisplayedInThisSED.add(cb);
ArrayList CRFVersions = cvdao.findAllByCRFId(cb.getId());
for (int k = 0; k < CRFVersions.size(); k++) {
CRFVersionBean cvb = (CRFVersionBean) CRFVersions.get(k);
ArrayList Items = idao.findAllItemsByVersionId(cvb.getId());
// sort by ordinal/name
Collections.sort(Items);
for (int l = 0; l < Items.size(); l++) {
ItemBean ib = (ItemBean) Items.get(l);
if (selected(ib) && !getDisplayed(sed, cb, ib)) {
// logger.info("found at
// itemformmetadatadao: "+ib.getId()+",
// "+cvb.getId());
ItemFormMetadataBean ifmb = ifmDAO.findByItemIdAndCRFVersionId(ib.getId(), cvb.getId());
addColumn(sed, cb, ib);
addItemFormMetadataBeans(sed, cb, ifmb);
markDisplayed(sed, cb, ib);
}
}
}
}
// else
}
// for
sed.setCrfs(CRFsDisplayedInThisSED);
// make the setCrfs call "stick"
finalStudyEvents.add(sed);
}
this.studyEvents = finalStudyEvents;
}
use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.
the class ScoreCalculator method redoCalculations.
/**
* Re-do calculations if funcs include changed item(s) and funcs are not
* included in the current section. If calculation can not sucessfully redo,
* old value will be erased and "<erased>" will be saved in database. <br>
* The parameter 'itemdata' might be overwritten.
*
* @param itemGroupSizes
* @param items
* @param itemdata
* @param oldItemdata
* @param updatedData
* @param sectionId
* @return ArrayList<String> which records left_item_text of items who
* failed to be updated into database.
*/
public ArrayList<String> redoCalculations(HashMap<String, ItemBean> items, HashMap<String, String> itemdata, TreeSet<String> changedItems, HashMap<Integer, TreeSet<Integer>> itemOrdinals, int sectionId) {
ArrayList<String> updateFailedItems = new ArrayList<String>();
if (itemdata == null) {
logger.error("In ScoreCalculator redoCalculations(), itemdata is empty!");
errors.add("In ScoreCalculator redoCalculations(), 'itemdata' map is empty!");
return updateFailedItems;
}
if (changedItems == null) {
logger.error("In ScoreCalculator redoCalculations(), 'changeItems' set is empty!");
errors.add("In ScoreCalculator redoCalculations(), 'changeItems' set is empty!");
return updateFailedItems;
}
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
NumberFormat nf = NumberFormat.getInstance();
Parser parser = new Parser(items, itemdata);
try {
// for calculation type
List<ItemFormMetadataBean> derivedItemList = ifmdao.findAllByCRFVersionIdAndResponseTypeId(ecb.getCRFVersionId(), ResponseType.CALCULATION.getId());
if (derivedItemList.size() > 0) {
Collections.sort(derivedItemList);
for (ItemFormMetadataBean ifmb : derivedItemList) {
if (ifmb.getSectionId() != sectionId) {
ItemBean ib = (ItemBean) idao.findByPK(ifmb.getItemId());
ResponseOptionBean rob = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
int groupsize = 1;
if (itemOrdinals.containsKey(ib.getId())) {
groupsize = itemOrdinals.get(ib.getId()).size();
}
String value = "";
ArrayList<ScoreToken> parsedExp = new ArrayList<ScoreToken>();
for (int i = 0; i < groupsize; ++i) {
ItemDataBean idb = iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb.getItemId(), ecb.getId(), i + 1);
// is there any changed item
Parser p = new Parser(items, itemdata);
parsedExp = parser.parseScoreTokens(rob.getValue());
if (p.isChanged(changedItems, parsedExp)) {
StringBuffer err = new StringBuffer();
parsedExp = parser.assignVariables(parsedExp, i + 1);
// before, set "<erased>"
if (parser.getErrors().length() > 0) {
err.append(parser.getErrors());
if (idb.isActive()) {
idb.setValue("<erased>");
idb.setStatus(Status.UNAVAILABLE);
idb = (ItemDataBean) iddao.update(idb);
if (!idb.isActive()) {
String key = i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
updateFailedItems.add(key);
}
}
parser.setErrors(new StringBuffer());
} else // otherwise do calculation
{
try {
value = ScoreUtil.eval(parsedExp);
} catch (ScoreException se) {
logger.error(se.getMessage());
}
String exp = rob.getValue();
exp = exp.replace("##", ",");
if (writeToDB(ib, ifmb, idb, exp, value, err)) {
changedItems.add(ib.getName());
itemdata.put(ib.getId() + "_" + (i + 1), idb.getValue());
} else {
String key = i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
updateFailedItems.add(key);
}
}
if (err.length() > 0) {
String key = i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
errors.add("Item " + key + " contains calculation errors: " + err.toString());
}
}
}
}
}
}
List<ItemFormMetadataBean> itemList = ifmdao.findAllByCRFVersionIdAndResponseTypeId(ecb.getCRFVersionId(), ResponseType.GROUP_CALCULATION.getId());
if (itemList.size() > 0) {
Collections.sort(itemList);
for (ItemFormMetadataBean ifmb : itemList) {
if (ifmb.getSectionId() != sectionId) {
ItemBean ib = (ItemBean) idao.findByPK(ifmb.getItemId());
ResponseOptionBean rob = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
String value = "";
Parser p = new Parser(items, itemdata);
ArrayList<ScoreToken> parsedExp = parser.parseScoreTokens(rob.getValue());
if (p.isChanged(changedItems, parsedExp)) {
StringBuffer err = new StringBuffer();
parser.setErrors(err);
parsedExp = parser.assignVariables(parsedExp, itemOrdinals);
ItemDataBean idb = iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb.getItemId(), ecb.getId(), 1);
if (parser.getErrors().length() > 0) {
err.append(parser.getErrors());
if (idb.isActive()) {
idb.setValue("<erased>");
idb.setStatus(Status.UNAVAILABLE);
idb = (ItemDataBean) iddao.update(idb);
if (!idb.isActive()) {
updateFailedItems.add(ifmb.getLeftItemText());
}
}
} else {
try {
value = ScoreUtil.eval(parsedExp);
} catch (ScoreException se) {
logger.error(se.getMessage());
}
String exp = rob.getValue();
exp = exp.replace("##", ",");
if (writeToDB(ib, ifmb, idb, exp, value, err)) {
changedItems.add(ib.getName());
itemdata.put(ib.getId() + "_" + idb.getOrdinal(), idb.getValue());
} else {
updateFailedItems.add(ifmb.getLeftItemText());
}
}
if (err.length() > 0) {
errors.add("Item " + ifmb.getLeftItemText() + " contains calculation errors: " + err.toString());
}
}
}
}
}
} catch (OpenClinicaException e) {
logger.error(e.getMessage());
}
return updateFailedItems;
}
use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.
the class DeleteEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt(STUDY_SUB_ID, true);
int eventCRFId = fp.getInt(EVENT_CRF_ID);
String action = request.getParameter("action");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_delete"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
ArrayList<ItemDataBean> itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.DELETE_EVENT_CRF);
} else {
logger.info("submit to delete the event CRF from event");
// OC-6303 Deleting Event CRF resets Show / Hide logic
// delete records from DynamicItemForm and DynamicItemGroup
// getDynamicsItemFormMetadataDao().delete(eventCRFId);
// getDynamicsItemGroupMetadataDao().delete(eventCRFId);
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.RESET);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
for (ItemDataBean itemdata : itemData) {
// OC-6343 Rule behaviour must be reset if an Event CRF is deleted
// delete the records from ruleActionRunLogDao
List<RuleActionRunLogBean> ruleActionRunLog = getRuleActionRunLogDao().findAllItemData(itemdata.getId());
if (ruleActionRunLog.size() != 0) {
getRuleActionRunLogDao().delete(itemdata.getId());
}
// OC-6344 Notes & Discrepancies must be set to "closed" when event CRF is deleted
// parentDiscrepancyNoteList is the list of the parent DNs records only
ArrayList<DiscrepancyNoteBean> parentDiscrepancyNoteList = getDnDao().findParentNotesOnlyByItemData(itemdata.getId());
for (DiscrepancyNoteBean parentDiscrepancyNote : parentDiscrepancyNoteList) {
if (parentDiscrepancyNote.getResolutionStatusId() != 4) {
// if the DN's resolution status is
// not set to Closed
String description = resword.getString("dn_auto-closed_description");
String detailedNotes = resword.getString("dn_auto_closed_detailed_notes");
// create new DN record , new DN Map record , also update the parent record
createDiscrepancyNoteBean(description, detailedNotes, itemdata.getId(), study, ub, parentDiscrepancyNote);
}
}
iddao = new ItemDataDAO(sm.getDataSource());
ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
ItemDataBean idBean = (ItemDataBean) iddao.findByPK(itemdata.getId());
ItemFormMetadataBean ifmBean = ifmdao.findByItemIdAndCRFVersionId(idBean.getItemId(), crfVersionId);
// Updating Dn_item_data_map actovated column into false for the existing DNs
ArrayList<DiscrepancyNoteBean> dnBeans = getDnDao().findExistingNotesForItemData(itemdata.getId());
if (dnBeans.size() != 0) {
DiscrepancyNoteBean dnBean = new DiscrepancyNoteBean();
dnBean.setEntityId(itemdata.getId());
dnBean.setActivated(false);
getDnDao().updateDnMapActivation(dnBean);
}
// Default Values are not addressed
itemdata.setValue("");
itemdata.setOldStatus(itemdata.getStatus());
itemdata.setOwner(ub);
itemdata.setStatus(Status.AVAILABLE);
itemdata.setUpdater(ub);
iddao.updateUser(itemdata);
iddao.update(itemdata);
}
// OC-6291 event_crf status change
eventCRF.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
ecdao.update(eventCRF);
if (event.getSubjectEventStatus().isCompleted() || event.getSubjectEventStatus().isSigned()) {
event.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
event.setUpdater(ub);
sedao = new StudyEventDAO(sm.getDataSource());
sedao.update(event);
}
String emailBody = respage.getString("the_event_CRF") + cb.getName() + respage.getString("has_been_deleted_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_deleted_from_the_event_cont");
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.
the class CreateCRFVersionServlet method isResponseValid.
private ItemBean isResponseValid(HashMap items, CRFVersionBean version) {
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO metadao = new ItemFormMetadataDAO(sm.getDataSource());
Set names = items.keySet();
Iterator it = names.iterator();
while (it.hasNext()) {
String name = (String) it.next();
ItemBean oldItem = (ItemBean) idao.findByNameAndCRFId(name, version.getCrfId());
ItemBean item = (ItemBean) items.get(name);
if (oldItem.getId() > 0) {
// found same item in DB
ArrayList metas = metadao.findAllByItemId(oldItem.getId());
for (int i = 0; i < metas.size(); i++) {
ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(i);
ResponseSetBean rsb = ifmb.getResponseSet();
if (hasDifferentOption(rsb, item.getItemMeta().getResponseSet()) != null) {
return item;
}
}
}
}
return null;
}
use of org.akaza.openclinica.dao.submit.ItemFormMetadataDAO in project OpenClinica by OpenClinica.
the class ViewEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int eventCRFId = fp.getInt("id", true);
int studySubId = fp.getInt("studySubId", true);
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
SectionDAO secdao = new SectionDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
} else {
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
CRFBean crf = cdao.findByVersionId(eventCRF.getCRFVersionId());
request.setAttribute("crf", crf);
ArrayList sections = secdao.findAllByCRFVersionId(eventCRF.getCRFVersionId());
for (int j = 0; j < sections.size(); j++) {
SectionBean section = (SectionBean) sections.get(j);
ArrayList itemData = iddao.findAllByEventCRFId(eventCRFId);
ArrayList displayItemData = new ArrayList();
for (int i = 0; i < itemData.size(); i++) {
ItemDataBean id = (ItemDataBean) itemData.get(i);
DisplayItemBean dib = new DisplayItemBean();
ItemBean item = (ItemBean) idao.findByPK(id.getItemId());
ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), eventCRF.getCRFVersionId());
item.setItemMeta(ifm);
dib.setItem(item);
dib.setData(id);
dib.setMetadata(ifm);
displayItemData.add(dib);
}
section.setItems(displayItemData);
}
request.setAttribute("sections", sections);
request.setAttribute("studySubId", new Integer(studySubId).toString());
forwardPage(Page.VIEW_EVENT_CRF);
}
}
Aggregations