use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean 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.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class ImportCRFDataService method fetchEventCRFStatuses.
/*
* purpose: Build a map of EventCRFs and the statuses they should have postimport. Assumes EventCRFs have been
* created for "Not Started" forms.
*/
public void fetchEventCRFStatuses(ODMContainer odmContainer, HashMap<Integer, String> importedCRFStatuses) {
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);
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));
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);
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if (!importedCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
importedCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
}
}
}
}
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class StudyInfoPanel method generateDatasetTree.
private ArrayList generateDatasetTree(ExtractBean eb, DatasetBean db) {
ArrayList displayData = new ArrayList();
ArrayList seds = eb.getStudyEvents();
for (int i = 0; i < seds.size(); i++) {
// second, iterate through seds
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
String repeating = "";
if (sed.isRepeating()) {
repeating = " (Repeating) ";
}
// if repeating:
// change string to (Repeating)
displayData.add(new StudyInfoPanelLine("Study Event Definition", sed.getName() + repeating, true, false));
ArrayList crfs = sed.getCrfs();
for (int j = 0; j < crfs.size(); j++) {
CRFBean cb = (CRFBean) crfs.get(j);
if (j < crfs.size() - 1 && crfs.size() > 1) {
displayData.add(new StudyInfoPanelLine("CRF", cb.getName() + " <b>" + ExtractBean.getSEDCRFCode(i + 1, j + 1) + "</b>", false, false));
} else {
// last crf
displayData.add(new StudyInfoPanelLine("CRF", cb.getName() + " <b>" + ExtractBean.getSEDCRFCode(i + 1, j + 1) + "</b>", false, true));
}
// third, iterate through crf versions
}
}
return displayData;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class CrfBusinessLogicHelper method markCRFComplete.
/**
* The following methods are for 'mark CRF complete' Note that we will also wrap Study Event status changes in this
* code, possibly split out in a later release, tbh 06/2008
*
* @return
*/
public boolean markCRFComplete(EventCRFBean ecb, UserAccountBean ub, boolean inTransaction) throws Exception {
DataEntryStage stage = ecb.getStage();
EventCRFDAO eventCrfDao = new EventCRFDAO(ds);
ItemDataDAO itemDataDao = new ItemDataDAO(ds);
StudyDAO sdao = new StudyDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudyBean study = sdao.findByStudySubjectId(ecb.getStudySubjectId());
EventDefinitionCRFBean edcb = getEventDefinitionCrfByStudyEventAndCrfVersion(ecb, study);
// StudyEventDAO studyEventDao = new StudyEventDAO(ds);
// StudyEventBean studyEventBean = (StudyEventBean)
// studyEventDao.findByPK(ecb.getStudyEventId());
// Status studyEventStatus = studyEventBean.getStatus();
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(ds);
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) studyEventDefinitionDao.findByPK(edcb.getStudyEventDefinitionId());
CRFDAO crfDao = new CRFDAO(ds);
ArrayList crfs = (ArrayList) crfDao.findAllActiveByDefinition(sedBean);
sedBean.setCrfs(crfs);
// request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN,
// ecb);
// request.setAttribute(INPUT_EVENT_CRF_ID, new
// Integer(ecb.getId()));
logger.debug("inout_event_crf_id:" + ecb.getId());
logger.debug("inout_study_event_def_id:" + sedBean.getId());
Status newStatus = ecb.getStatus();
DataEntryStage newStage = ecb.getStage();
boolean ide = true;
newStatus = Status.UNAVAILABLE;
// ecb.setUpdaterId(ub.getId());
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecb.setDateCompleted(new Date());
ecb.setDateValidateCompleted(new Date());
/*
* //for the non-reviewed sections, no item data in DB yet, need to //create them if
* (!isEachSectionReviewedOnce()) { boolean canSave = saveItemsToMarkComplete(newStatus); if (canSave == false){
* addPageMessage("You may not mark this Event CRF complete, because there are some required entries which have
* not been filled out."); return false; } }
*/
ecb.setStatus(newStatus);
ecb.setStage(newStage);
ecb = (EventCRFBean) eventCrfDao.update(ecb);
logger.debug("just updated event crf id: " + ecb.getId());
// note the below statement only updates the DATES, not the STATUS
eventCrfDao.markComplete(ecb, ide);
// update all the items' status to complete
itemDataDao.updateStatusByEventCRF(ecb, newStatus);
// change status for study event
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
seb.setUpdatedDate(new Date());
seb.setUpdater(ub);
// updates with Pauls observation from bug:2488:
// 1. If there is only one CRF in the event (whether the CRF was
// required or not), and data was imported for it, the status of the
// event should be Completed.
//
logger.debug("sed bean get crfs get size: " + sedBean.getCrfs().size());
logger.debug("edcb get crf id: " + edcb.getCrfId() + " version size? " + edcb.getVersions().size());
logger.debug("ecb get crf id: " + ecb.getCrf().getId());
logger.debug("ecb get crf version id: " + ecb.getCRFVersionId());
if (sedBean.getCrfs().size() == 1) {
// && edcb.getCrfId() ==
// ecb.getCrf().getId()) {
seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
logger.info("just set subj event status to -- COMPLETED --");
} else // removing sedBean.getCrfs().size() > 1 &&
if (areAllRequired(seb, study) && !areAllCompleted(seb, study)) {
seb.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
logger.info("just set subj event status to -- DATAENTRYSTARTED --");
} else // removing sedBean.getCrfs().size() > 1 &&
if (!areAllRequired(seb, study)) {
if (areAllRequiredCompleted(seb, study)) {
seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
logger.info("just set subj event status to -- 3completed3 --");
} else {
seb.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
logger.info("just set subj event status to -- DATAENTRYSTARTED --");
}
} else if (noneAreRequired(seb, study)) {
seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
logger.info("just set subj event status to -- 5completed5 --");
}
logger.debug("just set subj event status, final status is " + seb.getSubjectEventStatus().getName());
logger.debug("final overall status is " + seb.getStatus().getName());
seb = (StudyEventBean) sedao.update(seb, inTransaction);
return true;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class CrfBusinessLogicHelper method markCRFStarted.
/**
* The following methods are for 'mark CRF Started' Note that we will also wrap Study Event status changes in this
* code, possibly split out in a later release, tbh 06/2008
*
* @return
*/
public boolean markCRFStarted(EventCRFBean ecb, UserAccountBean ub, boolean inTransaction) throws Exception {
EventCRFDAO eventCrfDao = new EventCRFDAO(ds);
StudyDAO sdao = new StudyDAO(ds);
StudyBean study = sdao.findByStudySubjectId(ecb.getStudySubjectId());
EventDefinitionCRFBean edcb = getEventDefinitionCrfByStudyEventAndCrfVersion(ecb, study);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(ds);
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) studyEventDefinitionDao.findByPK(edcb.getStudyEventDefinitionId());
CRFDAO crfDao = new CRFDAO(ds);
ArrayList crfs = (ArrayList) crfDao.findAllActiveByDefinition(sedBean);
sedBean.setCrfs(crfs);
logger.debug("inout_event_crf_id:" + ecb.getId());
logger.debug("inout_study_event_def_id:" + sedBean.getId());
Status newStatus = Status.AVAILABLE;
DataEntryStage newStage = ecb.getStage();
ecb.setUpdater(ub);
ecb.setUpdatedDate(new Date());
ecb.setStatus(newStatus);
ecb.setStage(newStage);
ecb = (EventCRFBean) eventCrfDao.update(ecb);
logger.debug("just updated event crf id: " + ecb.getId());
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
if (seb.getSubjectEventStatus().isScheduled() || seb.getSubjectEventStatus().isNotScheduled() || seb.getSubjectEventStatus().isDE_Started()) {
// change status for study event
seb.setUpdatedDate(new Date());
seb.setUpdater(ub);
seb.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
seb = (StudyEventBean) sedao.update(seb, inTransaction);
}
return true;
}
Aggregations