use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ImportCRFDataService method validateStudyMetadata.
/*
* meant to answer the following questions 3.a. is that study subject in that study? 3.b. is that study event def in
* that study? 3.c. is that site in that study? 3.d. is that crf version in that study event def? 3.e. are those
* item groups in that crf version? 3.f. are those items in that item group?
*/
public List<String> validateStudyMetadata(ODMContainer odmContainer, int currentStudyId) {
List<String> errors = new ArrayList<String>();
MessageFormat mf = new MessageFormat("");
// throw new OpenClinicaException(mf.format(arguments), "");
try {
StudyDAO studyDAO = new StudyDAO(ds);
String studyOid = odmContainer.getCrfDataPostImportContainer().getStudyOID();
StudyBean studyBean = studyDAO.findByOid(studyOid);
if (studyBean == null) {
mf.applyPattern(respage.getString("your_study_oid_does_not_reference_an_existing"));
Object[] arguments = { studyOid };
errors.add(mf.format(arguments));
// errors.add("Your Study OID " + studyOid + " does not
// reference an existing Study or Site in the database. Please
// check it and try again.");
// throw an error here because getting the ID would be difficult
// otherwise
logger.debug("unknown study OID");
throw new OpenClinicaException("Unknown Study OID", "");
} else if (studyBean.getId() != currentStudyId) {
mf.applyPattern(respage.getString("your_current_study_is_not_the_same_as"));
Object[] arguments = { studyBean.getName() };
//
// errors.add("Your current study is not the same as the Study "
// + studyBean.getName()
// + ", for which you are trying to enter data. Please log out
// of your current study and into the study for which the data
// is keyed.");
errors.add(mf.format(arguments));
}
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
ItemGroupDAO itemGroupDAO = new ItemGroupDAO(ds);
ItemDAO itemDAO = new ItemDAO(ds);
if (subjectDataBeans != null) {
// report all available errors, tbh
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
String oid = subjectDataBean.getSubjectOID();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(oid, studyBean.getId());
if (studySubjectBean == null) {
mf.applyPattern(respage.getString("your_subject_oid_does_not_reference"));
Object[] arguments = { oid };
errors.add(mf.format(arguments));
// errors.add("Your Subject OID " + oid + " does not
// reference an existing Subject in the Study.");
logger.debug("logged an error with subject oid " + oid);
}
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
if (studyEventDataBeans != null) {
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
String sedOid = studyEventDataBean.getStudyEventOID();
StudyEventDefinitionBean studyEventDefintionBean = studyEventDefinitionDAO.findByOidAndStudy(sedOid, studyBean.getId(), studyBean.getParentStudyId());
if (studyEventDefintionBean == null) {
mf.applyPattern(respage.getString("your_study_event_oid_for_subject_oid"));
Object[] arguments = { sedOid, oid };
errors.add(mf.format(arguments));
// errors.add("Your Study Event OID " + sedOid +
// " for Subject OID " + oid
// + " does not reference an existing Study
// Event in the Study.");
logger.debug("logged an error with se oid " + sedOid + " and subject oid " + oid);
}
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
if (formDataBeans != null) {
for (FormDataBean formDataBean : formDataBeans) {
String formOid = formDataBean.getFormOID();
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formOid);
// right now just check nulls
if (crfVersionBeans != null) {
for (CRFVersionBean crfVersionBean : crfVersionBeans) {
if (crfVersionBean == null) {
mf.applyPattern(respage.getString("your_crf_version_oid_for_study_event_oid"));
Object[] arguments = { formOid, sedOid };
errors.add(mf.format(arguments));
// errors.add("Your CRF Version
// OID " + formOid + " for Study
// Event OID " + sedOid
// + " does not reference a
// proper CRF Version in that
// Study Event.");
logger.debug("logged an error with form " + formOid + " and se oid " + sedOid);
}
}
} else {
mf.applyPattern(respage.getString("your_crf_version_oid_did_not_generate"));
Object[] arguments = { formOid };
errors.add(mf.format(arguments));
// errors.add("Your CRF Version OID " +
// formOid
// + " did not generate any results in
// the database. Please check it and try
// again.");
}
ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
if (itemGroupDataBeans != null) {
for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
String itemGroupOID = itemGroupDataBean.getItemGroupOID();
List<ItemGroupBean> itemGroupBeans = itemGroupDAO.findAllByOid(itemGroupOID);
if (itemGroupBeans != null) {
logger.debug("number of item group beans: " + itemGroupBeans.size());
logger.debug("item group oid: " + itemGroupOID);
for (ItemGroupBean itemGroupBean : itemGroupBeans) {
if (itemGroupBean == null) {
mf.applyPattern(respage.getString("your_item_group_oid_for_form_oid"));
Object[] arguments = { itemGroupOID, formOid };
errors.add(mf.format(arguments));
// errors.add("Your Item
// Group OID " +
// itemGroupOID + " for
// Form OID " + formOid
// + " does not
// reference a proper
// Item Group in that
// CRF Version.");
}
}
} else {
mf.applyPattern(respage.getString("the_item_group_oid_did_not"));
Object[] arguments = { itemGroupOID };
errors.add(mf.format(arguments));
// errors.add("The Item Group
// OID " + itemGroupOID
// + " did not generate any
// results in the database,
// please check it and try
// again.");
}
ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
if (itemDataBeans != null) {
for (ImportItemDataBean itemDataBean : itemDataBeans) {
String itemOID = itemDataBean.getItemOID();
List<ItemBean> itemBeans = itemDAO.findByOid(itemOID);
if (itemBeans != null) {
logger.debug("found itembeans: ");
for (ItemBean itemBean : itemBeans) {
if (itemBean == null) {
mf.applyPattern(respage.getString("your_item_oid_for_item_group_oid"));
Object[] arguments = { itemOID, itemGroupOID };
errors.add(mf.format(arguments));
// errors.add(
// "Your
// Item OID " +
// itemOID + "
// for Item
// Group OID " +
// itemGroupOID
// + " does not
// reference a
// proper Item
// in the Item
// Group.");
} else {
logger.debug("found " + itemBean.getOid() + ", passing");
}
}
}
}
} else {
mf.applyPattern(respage.getString("the_item_group_oid_did_not_contain_item_data"));
Object[] arguments = { itemGroupOID };
errors.add(mf.format(arguments));
// errors.add("The Item Group
// OID " + itemGroupOID
// + " did not contain any Item
// Data in the XML file, please
// check it and try again.");
}
}
} else {
mf.applyPattern(respage.getString("your_study_event_contains_no_form_data"));
Object[] arguments = { sedOid };
errors.add(mf.format(arguments));
// errors.add("Your Study Event " +
// sedOid
// + " contains no Form Data, or the
// Form OIDs are incorrect. Please check
// it and try again.");
}
}
}
}
}
}
}
} catch (OpenClinicaException oce) {
} catch (NullPointerException npe) {
logger.debug("found a nullpointer here");
}
// if errors == null you pass, if not you fail
return errors;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class ImportCRFDataService method eventCRFStatusesValid.
/*
* purpose: returns false if any of the forms/EventCRFs fail the UpsertOnBean rules.
*/
public boolean eventCRFStatusesValid(ODMContainer odmContainer, UserAccountBean ub) {
ArrayList<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
ArrayList<Integer> eventCRFBeanIds = new ArrayList<Integer>();
EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
StudyDAO studyDAO = new StudyDAO(ds);
StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
UpsertOnBean upsert = odmContainer.getCrfDataPostImportContainer().getUpsertOn();
// If Upsert bean is not present, create one with default settings
if (upsert == null)
upsert = new UpsertOnBean();
String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
StudyBean studyBean = studyDAO.findByOid(studyOID);
ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
for (SubjectDataBean subjectDataBean : subjectDataBeans) {
ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
// locked
if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.STOPPED)) {
return true;
}
for (FormDataBean formDataBean : formDataBeans) {
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
for (CRFVersionBean crfVersionBean : crfVersionBeans) {
ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
// event crf, yet.
if (eventCrfBeans.isEmpty()) {
logger.debug(" found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED))) {
if (!upsert.isNotStarted())
return false;
}
}
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if (!(ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) && upsert.isDataEntryStarted()) && !(ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && upsert.isDataEntryComplete()))
return false;
}
}
}
}
}
return true;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class StudyEventDAO method findCRFsByStudyEvent.
public HashMap findCRFsByStudyEvent(StudyEventBean seb) {
// Soon-to-be-depreciated, replaced by find crfs by study, tbh 11-26
// returns a hashmap of crfs + arraylist of crfversions,
// for creating a checkbox list of crf versions all collected by
// the study event primary key, tbh
HashMap crfs = new HashMap();
this.setCRFTypesExpected();
HashMap variables = new HashMap();
variables.put(Integer.valueOf(1), Integer.valueOf(seb.getStudyEventDefinitionId()));
ArrayList alist = this.select(digester.getQuery("findCRFsByStudyEvent"), variables);
Iterator it = alist.iterator();
CRFDAO cdao = new CRFDAO(this.ds);
CRFVersionDAO cvdao = new CRFVersionDAO(this.ds);
while (it.hasNext()) {
HashMap answers = (HashMap) it.next();
logger.warn("***First CRF ID: " + answers.get("crf_id"));
logger.warn("***Next CRFVersion ID: " + answers.get("crf_version_id"));
// here's the logic:
// grab a crf,
// iterate through crfs in hashmap,
// if one matches, grab it;
// take a look at its arraylist of versions;
// if there is no version correlating, add it;
// else, add the crf with a fresh arraylist + one version.
// how long could this take to run???
CRFBean cbean = (CRFBean) cdao.findByPK(((Integer) answers.get("crf_id")).intValue());
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(((Integer) answers.get("crf_version_id")).intValue());
Set se = crfs.entrySet();
boolean found = false;
boolean versionFound = false;
for (Iterator itse = se.iterator(); itse.hasNext(); ) {
Map.Entry me = (Map.Entry) itse.next();
CRFBean checkCrf = (CRFBean) me.getKey();
if (checkCrf.getId() == cbean.getId()) {
found = true;
ArrayList oldList = (ArrayList) me.getValue();
Iterator itself = oldList.iterator();
while (itself.hasNext()) {
CRFVersionBean cvbCheck = (CRFVersionBean) itself.next();
if (cvbCheck.getId() == cvb.getId()) {
versionFound = true;
}
}
// end of iteration through versions
if (!versionFound) {
oldList.add(cvb);
crfs.put(cbean, oldList);
}
// end of adding new version to old crf
}
// end of check to see if current crf is in list
}
// end of iterating
if (!found) {
// add new crf here with version
// CRFVersionBean cvb = (CRFVersionBean)cvdao.findByPK(
// ((Integer)answers.get("crf_version_id")).intValue());
ArrayList newList = new ArrayList();
newList.add(cvb);
crfs.put(cbean, newList);
}
}
return crfs;
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method populateUncompletedCRFsWithCRFAndVersions.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void populateUncompletedCRFsWithCRFAndVersions(ArrayList<DisplayEventDefinitionCRFBean> uncompletedEventDefinitionCRFs, Map<Integer, CRFVersionBean> crfVersionById, Map<Integer, CRFBean> crfById) {
CRFVersionDAO crfVersionDao = new CRFVersionDAO(dataSource);
int size = uncompletedEventDefinitionCRFs.size();
for (int i = 0; i < size; i++) {
DisplayEventDefinitionCRFBean dedcrf = uncompletedEventDefinitionCRFs.get(i);
// CRFBean cb = (CRFBean)
// crfDao.findByPK(dedcrf.getEdc().getCrfId());
CRFBean cb = crfById.get(dedcrf.getEdc().getCrfId());
dedcrf.getEdc().setCrf(cb);
ArrayList<CRFVersionBean> theVersions = (ArrayList<CRFVersionBean>) crfVersionDao.findAllActiveByCRF(dedcrf.getEdc().getCrfId());
ArrayList<CRFVersionBean> versions = new ArrayList<CRFVersionBean>();
HashMap<String, CRFVersionBean> crfVersionIds = new HashMap<String, CRFVersionBean>();
for (int j = 0; j < theVersions.size(); j++) {
CRFVersionBean crfVersion = theVersions.get(j);
crfVersionIds.put(String.valueOf(crfVersion.getId()), crfVersion);
}
if (!dedcrf.getEdc().getSelectedVersionIds().equals("")) {
String[] kk = dedcrf.getEdc().getSelectedVersionIds().split(",");
for (String string : kk) {
if (crfVersionIds.get(string) != null) {
versions.add(crfVersionIds.get(string));
}
}
} else {
versions = theVersions;
}
dedcrf.getEdc().setVersions(versions);
uncompletedEventDefinitionCRFs.set(i, dedcrf);
}
}
use of org.akaza.openclinica.dao.submit.CRFVersionDAO 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);
// OC-12177 added to fix displaying DDE workflow status
eventCRF.setValidatorId(0);
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
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);
}
}
}
Aggregations