use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class DataImportService method submitData.
public ArrayList<String> submitData(ODMContainer odmContainer, DataSource dataSource, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, Map<Integer, String> importedCRFStatuses) throws Exception {
boolean discNotesGenerated = false;
ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
itemDataDao.setFormatDates(false);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
StringBuffer auditMsg = new StringBuffer();
int eventCrfBeanId = -1;
EventCRFBean eventCrfBean = null;
ArrayList<Integer> eventCrfInts;
ItemDataBean itemDataBean;
CrfBusinessLogicHelper crfBusinessLogicHelper = new CrfBusinessLogicHelper(dataSource);
for (DisplayItemBeanWrapper wrapper : displayItemBeanWrappers) {
boolean resetSDV = false;
logger.debug("right before we check to make sure it is savable: " + wrapper.isSavable());
if (wrapper.isSavable()) {
eventCrfInts = new ArrayList<Integer>();
logger.debug("wrapper problems found : " + wrapper.getValidationErrors().toString());
if (wrapper.getDisplayItemBeans() != null && wrapper.getDisplayItemBeans().size() == 0) {
return getReturnList("fail", "", "No items to submit. Please check your XML.");
}
for (DisplayItemBean displayItemBean : wrapper.getDisplayItemBeans()) {
eventCrfBeanId = displayItemBean.getData().getEventCRFId();
eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCrfBeanId);
logger.debug("found value here: " + displayItemBean.getData().getValue());
logger.debug("found status here: " + eventCrfBean.getStatus().getName());
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.debug("just tried to find item data bean on item name " + displayItemBean.getItem().getName());
itemDataBean.setUpdatedDate(new Date());
itemDataBean.setUpdater(userBean);
itemDataBean.setValue(displayItemBean.getData().getValue());
// set status?
itemDataDao.update(itemDataBean);
logger.debug("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.debug("created: " + displayItemBean.getData().getItemId());
itemDataBean = itemDataDao.findByItemIdAndEventCRFIdAndOrdinal(displayItemBean.getItem().getId(), eventCrfBean.getId(), displayItemBean.getData().getOrdinal());
// logger.debug("found: id " + itemDataBean2.getId() + " name " + itemDataBean2.getName());
displayItemBean.getData().setId(itemDataBean.getId());
}
ItemDAO idao = new ItemDAO(dataSource);
ItemBean ibean = (ItemBean) idao.findByPK(displayItemBean.getData().getItemId());
// logger.debug("*** checking for validation errors: " + ibean.getName());
String itemOid = displayItemBean.getItem().getOid() + "_" + wrapper.getStudyEventRepeatKey() + "_" + displayItemBean.getData().getOrdinal() + "_" + wrapper.getStudySubjectOid();
// wrapper.getValidationErrors().toString());
if (wrapper.getValidationErrors().containsKey(itemOid)) {
ArrayList<String> messageList = (ArrayList<String>) wrapper.getValidationErrors().get(itemOid);
for (String message : messageList) {
DiscrepancyNoteBean parentDn = createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, null, userBean, dataSource, studyBean);
createDiscrepancyNote(ibean, message, eventCrfBean, displayItemBean, parentDn.getId(), userBean, dataSource, studyBean);
discNotesGenerated = true;
logger.debug("*** created disc note with message: " + message);
auditMsg.append(wrapper.getStudySubjectOid() + ": " + ibean.getOid() + ": " + message + "---");
// split by this ? later, tbh
// displayItemBean);
}
}
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, userBean, true);
} else {
crfBusinessLogicHelper.markCRFComplete(eventCrfBean, userBean, true);
}
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, userBean.getId(), eventCrfBean.getId());
}
}
if (!discNotesGenerated) {
return getReturnList("success", "", auditMsg.toString());
} else {
return getReturnList("warn", "", auditMsg.toString());
}
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class GenerateExtractFileService method createSPSSFile.
/**
* createSPSSFile, added by tbh, 01/2009
*
* @param db
* @param eb
* @param currentstudyid
* @param parentstudy
* @return
*/
public HashMap<String, Integer> createSPSSFile(DatasetBean db, ExtractBean eb2, StudyBean currentStudy, StudyBean parentStudy, long sysTimeBegin, String generalFileDir, SPSSReportBean answer, String generalFileDirCopy, UserAccountBean userBean) {
setUpResourceBundles();
String SPSSFileName = db.getName() + "_data_spss.dat";
String DDLFileName = db.getName() + "_ddl_spss.sps";
String ZIPFileName = db.getName() + "_spss";
SPSSVariableNameValidator svnv = new SPSSVariableNameValidator();
answer.setDatFileName(SPSSFileName);
// DatasetDAO dsdao = new DatasetDAO(ds);
// create the extract bean here, tbh
// ExtractBean eb = this.generateExtractBean(db, currentStudy,
// parentStudy);
// eb = dsdao.getDatasetData(eb, currentStudy.getId(),
// parentStudy.getId());
// eb.getMetadata();
// eb.computeReport(answer);
// set up items here to get
answer.setItems(eb2.getItemNames());
// itemMetadata
// set up response sets for each item here
ItemDAO itemdao = new ItemDAO(ds);
ItemFormMetadataDAO imfdao = new ItemFormMetadataDAO(ds);
ArrayList items = answer.getItems();
for (int i = 0; i < items.size(); i++) {
DisplayItemHeaderBean dih = (DisplayItemHeaderBean) items.get(i);
ItemBean item = dih.getItem();
ArrayList metas = imfdao.findAllByItemId(item.getId());
// for (int h = 0; h < metas.size(); h++) {
// ItemFormMetadataBean ifmb = (ItemFormMetadataBean)
// metas.get(h);
// logger.info("group name found:
// "+ifmb.getGroupLabel());
// }
// logger.info("crf versionname" +
// meta.getCrfVersionName());
item.setItemMetas(metas);
}
HashMap eventDescs = new HashMap<String, String>();
eventDescs = eb2.getEventDescriptions();
eventDescs.put("SubjID", resword.getString("study_subject_ID"));
eventDescs.put("ProtocolID", resword.getString("protocol_ID_site_ID"));
eventDescs.put("DOB", resword.getString("date_of_birth"));
eventDescs.put("YOB", resword.getString("year_of_birth"));
eventDescs.put("Gender", resword.getString("gender"));
answer.setDescriptions(eventDescs);
ArrayList generatedReports = new ArrayList<String>();
try {
// YW <<
generatedReports.add(answer.getMetadataFile(svnv, eb2).toString());
generatedReports.add(answer.getDataFile().toString());
// YW >>
} catch (IndexOutOfBoundsException i) {
generatedReports.add(answer.getMetadataFile(svnv, eb2).toString());
logger.debug("throw the error here");
}
long sysTimeEnd = System.currentTimeMillis() - sysTimeBegin;
ArrayList titles = new ArrayList();
// YW <<
titles.add(DDLFileName);
titles.add(SPSSFileName);
// YW >>
// create new createFile method that accepts array lists to
// put into zip files
int fId = this.createFile(ZIPFileName, titles, generalFileDir, generatedReports, db, sysTimeEnd, ExportFormatBean.TXTFILE, true, userBean);
if (!"".equals(generalFileDirCopy)) {
int fId2 = this.createFile(ZIPFileName, titles, generalFileDirCopy, generatedReports, db, sysTimeEnd, ExportFormatBean.TXTFILE, false, userBean);
}
// return DDLFileName;
HashMap answerMap = new HashMap<String, Integer>();
answerMap.put(DDLFileName, new Integer(fId));
return answerMap;
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class DatasetDAO method initialDatasetData.
/**
* Initialize itemMap, itemIds, itemDefCrf and groupIds for a DatasetBean
*
* @param db
* @return
* @author ywang (Feb., 2008)
*/
public DatasetBean initialDatasetData(int datasetId) {
ItemDAO idao = new ItemDAO(ds);
DatasetBean db = (DatasetBean) findByPK(datasetId);
String sql = db.getSQLStatement();
sql = sql.split("study_event_definition_id in")[1];
String[] ss = sql.split("and item_id in");
String sedIds = ss[0];
String[] sss = ss[1].split("and");
String itemIds = sss[0];
this.setDefinitionCrfItemTypesExpected();
logger.debug("begin to execute GetDefinitionCrfItemSql");
ArrayList alist = select(getDefinitionCrfItemSql(sedIds, itemIds));
Iterator it = alist.iterator();
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
ItemBean ib = (ItemBean) idao.getEntityFromHashMap(row);
Integer defId = (Integer) row.get("sed_id");
String defName = (String) row.get("sed_name");
String crfName = (String) row.get("crf_name");
Integer itemId = ib.getId();
String key = defId + "_" + itemId;
if (!db.getItemMap().containsKey(key)) {
ib.setSelected(true);
ib.setDefName(defName);
ib.setCrfName(crfName);
ib.setDatasetItemMapKey(key);
// contains study_event_definition_ids
if (!db.getEventIds().contains(defId)) {
db.getEventIds().add(defId);
}
db.getItemIds().add(itemId);
db.getItemDefCrf().add(ib);
db.getItemMap().put(key, ib);
}
}
db.setSubjectGroupIds(getGroupIds(db.getId()));
return db;
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class CreateCRFVersionServlet method isItemSame.
/**
* Checks whether the item with same name has the same other fields: units, phi_status if no, they are two different
* items, cannot have the same same
*
* @param items
* items from excel
* @return the items found
*/
private ArrayList isItemSame(HashMap items, CRFVersionBean version) {
ItemDAO idao = new ItemDAO(sm.getDataSource());
ArrayList diffItems = new ArrayList();
Set names = items.keySet();
Iterator it = names.iterator();
while (it.hasNext()) {
String name = (String) it.next();
ItemBean newItem = (ItemBean) idao.findByNameAndCRFId(name, version.getCrfId());
ItemBean item = (ItemBean) items.get(name);
if (newItem.getId() > 0) {
if (!item.getUnits().equalsIgnoreCase(newItem.getUnits()) || item.isPhiStatus() != newItem.isPhiStatus() || item.getDataType().getId() != newItem.getDataType().getId() || !item.getDescription().equalsIgnoreCase(newItem.getDescription())) {
logger.debug("found two items with same name but different units/phi/datatype/description");
diffItems.add(newItem);
}
}
}
return diffItems;
}
use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.
the class ViewNoteServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
Locale locale = LocaleResolver.getLocale(request);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
dndao.setFetchMapping(true);
int noteId = fp.getInt(NOTE_ID, true);
DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);
String entityType = note.getEntityType();
if (note.getEntityId() > 0 && !entityType.equals("")) {
if (!StringUtil.isBlank(entityType)) {
if ("itemData".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(note.getEntityId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
note.setEntityValue(itemData.getValue());
note.setEntityName(item.getName());
//Mantis Issue 5165. It should be itemData.getId() instead of item.getId()
note.setEntityId(itemData.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
note.setCrfName(crf.getName());
} else if ("studySub".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(note.getEntityId());
note.setStudySub(ssub);
// System.out.println("column" + note.getColumn());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
if (!StringUtil.isBlank(note.getColumn())) {
if ("enrollment_date".equalsIgnoreCase(note.getColumn())) {
if (ssub.getEnrollmentDate() != null) {
note.setEntityValue(dateFormatter.format(ssub.getEnrollmentDate()));
}
note.setEntityName(resword.getString("enrollment_date"));
} else if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
}
}
} else if ("subject".equalsIgnoreCase(entityType)) {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(note.getEntityId());
StudySubjectBean ssub = new StudySubjectBean();
ssub.setLabel(sub.getUniqueIdentifier());
note.setStudySub(ssub);
if (!StringUtil.isBlank(note.getColumn())) {
if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(note.getColumn())) {
note.setEntityName(resword.getString("unique_identifier"));
note.setEntityValue(sub.getUniqueIdentifier());
}
}
} else if ("studyEvent".equalsIgnoreCase(entityType)) {
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(note.getEntityId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
if (!StringUtil.isBlank(note.getColumn())) {
if ("location".equalsIgnoreCase(note.getColumn())) {
request.setAttribute("entityValue", se.getLocation());
request.setAttribute("entityName", resword.getString("location"));
note.setEntityName(resword.getString("location"));
note.setEntityValue(se.getLocation());
} else if ("date_start".equalsIgnoreCase(note.getColumn())) {
if (se.getDateStarted() != null) {
note.setEntityValue(dateFormatter.format(se.getDateStarted()));
}
note.setEntityName(resword.getString("start_date"));
} else if ("date_end".equalsIgnoreCase(note.getColumn())) {
if (se.getDateEnded() != null) {
note.setEntityValue(dateFormatter.format(se.getDateEnded()));
}
note.setEntityName(resword.getString("end_date"));
}
}
} else if ("eventCrf".equalsIgnoreCase(entityType)) {
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(note.getEntityId());
StudySubjectBean ssub = (StudySubjectBean) new StudySubjectDAO(sm.getDataSource()).findByPK(ec.getStudySubjectId());
note.setStudySub(ssub);
StudyEventBean event = (StudyEventBean) new StudyEventDAO(sm.getDataSource()).findByPK(ec.getStudyEventId());
note.setEvent(event);
if (!StringUtil.isBlank(note.getColumn())) {
if ("date_interviewed".equals(note.getColumn())) {
if (ec.getDateInterviewed() != null) {
note.setEntityValue(dateFormatter.format(ec.getDateInterviewed()));
}
note.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(note.getColumn())) {
note.setEntityValue(ec.getInterviewerName());
note.setEntityName(resword.getString("interviewer_name"));
}
}
}
}
}
// Mantis Issue 8495.
if (note.getStudyId() != currentStudy.getId()) {
if (currentStudy.getParentStudyId() > 0) {
if (currentStudy.getId() != note.getStudySub().getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
} else {
// The SubjectStudy is not belong to currentstudy and current study is not a site.
StudyDAO studydao = new StudyDAO(sm.getDataSource());
Collection sites;
sites = studydao.findOlnySiteIdsByStudy(currentStudy);
if (!sites.contains(note.getStudySub().getStudyId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
}
}
// Check end
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);
Date lastUpdatedDate = note.getCreatedDate();
UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId == 0) { note = n; note.setLastUpdator((UserAccountBean)
* udao.findByPK(n.getOwnerId()));
* note.setLastDateUpdated(n.getCreatedDate()); lastUpdatedDate =
* note.getLastDateUpdated(); lastUpdator = note.getLastUpdator(); } }
*/
// BWP 3029 >> This algorithm needs to be changed to properly set
// the parent note's status and updated date
// First sort the notes on their ID; this will put the parent note
// first; and
// the note with the latest status and updated date last
java.util.Collections.sort(notes);
DiscrepancyNoteBean lastChild = notes.get(notes.size() - 1);
lastUpdatedDate = lastChild.getCreatedDate();
lastUpdator = (UserAccountBean) udao.findByPK(lastChild.getOwnerId());
note.setLastUpdator(lastUpdator);
note.setLastDateUpdated(lastUpdatedDate);
note.setUpdatedDate(lastUpdatedDate);
for (DiscrepancyNoteBean dnBean : notes) {
if (dnBean.getParentDnId() > 0) {
note.getChildren().add(dnBean);
}
}
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId > 0) { note.getChildren().add(n);
*
* if (!n.getCreatedDate().before(lastUpdatedDate)) { lastUpdatedDate =
* n.getCreatedDate(); lastUpdator = (UserAccountBean)
* udao.findByPK(n.getOwnerId()); note.setLastUpdator(lastUpdator);
* note.setLastDateUpdated(lastUpdatedDate);
* note.setResolutionStatusId(n.getResolutionStatusId());
* note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId())); } } }
*/
note.setNumChildren(note.getChildren().size());
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
request.setAttribute(DIS_NOTE, note);
forwardPage(Page.VIEW_SINGLE_NOTE);
}
Aggregations