use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class EnterDataForStudyEventServlet method getDisplayEventCRFs.
/**
* Each of the event CRFs with its corresponding CRFBean. Then generates a
* list of DisplayEventCRFBeans, one for each event CRF.
*
* @param eventCRFs
* The list of event CRFs for this study event.
* @param eventDefinitionCRFs
* The list of event definition CRFs for this study event.
* @return The list of DisplayEventCRFBeans for this study event.
*/
private ArrayList getDisplayEventCRFs(ArrayList eventCRFs, ArrayList eventDefinitionCRFs, SubjectEventStatus status) {
ArrayList answer = new ArrayList();
HashMap definitionsByCRFId = new HashMap();
int i;
for (i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
definitionsByCRFId.put(new Integer(edc.getCrfId()), edc);
}
CRFDAO cdao = new CRFDAO(sm.getDataSource());
FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
logger.debug("0. found event crf bean: " + ecb.getName());
// populate the event CRF with its crf bean
int crfVersionId = ecb.getFormLayoutId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
logger.debug("1. found crf bean: " + cb.getName());
ecb.setCrf(cb);
FormLayoutBean cvb = (FormLayoutBean) fldao.findByPK(crfVersionId);
logger.debug("2. found crf version bean: " + cvb.getName());
ecb.setFormLayout(cvb);
logger.debug("found subj event status: " + status.getName() + " cb status: " + cb.getStatus().getName() + " cvb status: " + cvb.getStatus().getName());
// below added tbh 092007
boolean invalidate = false;
if (status.isLocked()) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (status.isInvalid()) {
ecb.setStage(DataEntryStage.LOCKED);
// invalidate = true;
} else if (!cb.getStatus().equals(Status.AVAILABLE)) {
logger.debug("got to the CB version of the logic");
ecb.setStage(DataEntryStage.LOCKED);
// invalidate= true;
} else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
logger.debug("got to the CVB version of the logic");
ecb.setStage(DataEntryStage.LOCKED);
// invalidate = true;
}
logger.debug("found ecb stage of " + ecb.getStage().getName());
// above added tbh, 092007-102007
try {
// event crf collection will pull up events that have
// been started, but contain no data
// this creates problems if we remove CRFs from
// event definitions
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) definitionsByCRFId.get(new Integer(cb.getId()));
logger.debug("3. found event def crf bean: " + edcb.getName());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setFlags(ecb, ub, currentRole, edcb.isDoubleEntry());
ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
if (!idata.isEmpty()) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
} catch (NullPointerException npe) {
logger.debug("5. got to NPE on this time around!");
}
}
return answer;
}
use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class EnterDataForStudyEventServlet method getDisplayEventCRFs.
/**
* Generate a list of DisplayEventCRFBean objects for a study event. Some of
* the DisplayEventCRFBeans will represent uncompleted Event CRFs; others
* will represent Event CRFs which are in initial data entry, have completed
* initial data entry, are in double data entry, or have completed double
* data entry.
*
* The list is sorted using the DisplayEventCRFBean's compareTo method (that
* is, using the event definition crf bean's ordinal value.) Also, the
* setFlags method of each DisplayEventCRFBean object will have been called
* once.
*
* @param studyEvent
* The study event for which we want the Event CRFs.
* @param ecdao
* An EventCRFDAO from which to grab the study event's Event
* CRFs.
* @param edcdao
* An EventDefinitionCRFDAO from which to grab the Event CRF
* Definitions which apply to the study event.
* @return A list of DisplayEventCRFBean objects releated to the study
* event, ordered by the EventDefinitionCRF ordinal property, and
* with flags already set.
*/
public static ArrayList getDisplayEventCRFs(StudyEventBean studyEvent, EventCRFDAO ecdao, EventDefinitionCRFDAO edcdao, FormLayoutDAO fldao, UserAccountBean user, StudyUserRoleBean surb) {
ArrayList answer = new ArrayList();
HashMap indexByCRFId = new HashMap();
ArrayList eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
ArrayList eventDefinitionCRFs = edcdao.findAllByEventDefinitionId(studyEvent.getStudyEventDefinitionId());
// TODO: map this out to another function
ArrayList crfVersions = (ArrayList) fldao.findAll();
HashMap crfIdByCRFVersionId = new HashMap();
for (int i = 0; i < crfVersions.size(); i++) {
FormLayoutBean cvb = (FormLayoutBean) crfVersions.get(i);
crfIdByCRFVersionId.put(new Integer(cvb.getId()), new Integer(cvb.getCrfId()));
}
// put the event definition crfs inside DisplayEventCRFs
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
DisplayEventCRFBean decb = new DisplayEventCRFBean();
decb.setEventDefinitionCRF(edcb);
answer.add(decb);
indexByCRFId.put(new Integer(edcb.getCrfId()), new Integer(answer.size() - 1));
}
// attach EventCRFs to the DisplayEventCRFs
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
Integer crfVersionId = new Integer(ecb.getFormLayoutId());
if (crfIdByCRFVersionId.containsKey(crfVersionId)) {
Integer crfId = (Integer) crfIdByCRFVersionId.get(crfVersionId);
if (crfId != null && indexByCRFId.containsKey(crfId)) {
Integer indexObj = (Integer) indexByCRFId.get(crfId);
if (indexObj != null) {
int index = indexObj.intValue();
if (index > 0 && index < answer.size()) {
DisplayEventCRFBean decb = (DisplayEventCRFBean) answer.get(index);
decb.setEventCRF(ecb);
answer.set(index, decb);
}
}
}
}
}
for (int i = 0; i < answer.size(); i++) {
DisplayEventCRFBean decb = (DisplayEventCRFBean) answer.get(i);
decb.setFlags(decb.getEventCRF(), user, surb, decb.getEventDefinitionCRF().isDoubleEntry());
answer.set(i, decb);
}
return answer;
}
use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method getDisplayEventCRFs.
/**
* Each of the event CRFs with its corresponding CRFBean. Then generates a
* list of DisplayEventCRFBeans, one for each event CRF.
*
* @param eventCRFs
* The list of event CRFs for this study event.
* @return The list of DisplayEventCRFBeans for this study event.
*/
public static ArrayList getDisplayEventCRFs(StudyBean study, DataSource ds, ArrayList eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status) {
ArrayList answer = new ArrayList();
// HashMap definitionsById = new HashMap();
int i;
/*
* for (i = 0; i < eventDefinitionCRFs.size(); i++) {
* EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
* eventDefinitionCRFs.get(i); definitionsById.put(new
* Integer(edc.getStudyEventDefinitionId()), edc); }
*/
StudyEventDAO sedao = new StudyEventDAO(ds);
CRFDAO cdao = new CRFDAO(ds);
CRFVersionDAO cvdao = new CRFVersionDAO(ds);
ItemDataDAO iddao = new ItemDataDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
for (i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int crfVersionId = ecb.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
ecb.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
ecb.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = ecb.getStudyEventId();
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
// EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
// definitionsById.get(new Integer(
// studyEventDefinitionId));
// fix problem of the above code(commented out), find the correct
// edc, note that on definitionId can be related to multiple
// eventdefinitioncrfBeans
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
// rules updated 112007 tbh
if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
ecb.setStage(DataEntryStage.LOCKED);
// we need to set a SED-wide flag here, because other edcs
// in this event can be filled in and change the status, tbh
} else if (status.equals(SubjectEventStatus.INVALID)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
}
// TODO need to refactor since this is similar to other code, tbh
if (edc != null) {
// System.out.println("edc is not null, need to set flags");
DisplayEventCRFBean dec = new DisplayEventCRFBean();
// System.out.println("edc.isDoubleEntry()" +
// edc.isDoubleEntry() + ecb.getId());
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
// if (dec.isLocked()) {
// System.out.println("*** found a locked DEC: " + edc.getCrfName());
// }
ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
if (!idata.isEmpty()) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
}
}
return answer;
}
Aggregations