use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class FormLayoutDAO method create.
public EntityBean create(EntityBean eb) {
// "INSERT INTO CRF_VERSION (NAME, DESCRIPTION, CRF_ID, STATUS_ID,DATE_CREATED," +
// "OWNER_ID,REVISION_NOTES,OC_OID) "
// + "VALUES ('" + stripQuotes(version) + "','" + stripQuotes(versionDesc) + "'," +
// "(SELECT CRF_ID FROM CRF WHERE NAME='"
// + crfName + "'),1,NOW()," + ub.getId() + ",'" + stripQuotes(revisionNotes) + "','" + oid + "')";
// <sql>INSERT INTO CRF_VERSION (CRF_ID, STATUS_ID, NAME,
// DESCRIPTION, OWNER_ID,
// DATE_CREATED, REVISION_NOTES)
// VALUES (?,?,?,?,?,NOW(),?)</sql>
FormLayoutBean cvb = (FormLayoutBean) eb;
HashMap variables = new HashMap();
// variables.put(Integer.valueOf(2), cb.getLabel());
variables.put(Integer.valueOf(1), Integer.valueOf(cvb.getCrfId()));
variables.put(Integer.valueOf(2), Integer.valueOf(cvb.getStatus().getId()));
variables.put(Integer.valueOf(3), cvb.getName());
variables.put(Integer.valueOf(4), cvb.getDescription());
variables.put(Integer.valueOf(5), Integer.valueOf(cvb.getOwner().getId()));
variables.put(Integer.valueOf(6), cvb.getRevisionNotes());
variables.put(Integer.valueOf(7), getValidOid(cvb, cvb.getName(), cvb.getOid()));
variables.put(Integer.valueOf(8), cvb.getXform());
variables.put(Integer.valueOf(9), cvb.getXformName());
variables.put(Integer.valueOf(10), cvb.getUrl());
// am i the only one who runs their daos' unit tests after I change
// things, tbh?
this.execute(digester.getQuery("create"), variables);
if (isQuerySuccessful()) {
cvb.setActive(true);
}
return cvb;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
StudyDAO studyDao = new StudyDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
CRFDAO crfDao = new CRFDAO(dataSource);
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
if (study.getParentStudyId() < 1) {
// Is a study
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
} else {
// Is a site
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
}
Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
Map<Integer, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(studySubject.getId());
Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, crfById);
de.setUncompletedCRFs(al);
// de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
// studySubject));
de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayEventCRFs.
private List<DisplayEventCRFBean> getDisplayEventCRFs(List eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study, Set<Integer> nonEmptyEventCrf, Map<Integer, FormLayoutBean> formLayoutById, Map<Integer, CRFBean> crfById, Integer studyEventDefinitionId, List eventDefinitionCRFs) {
ArrayList<DisplayEventCRFBean> answer = new ArrayList<DisplayEventCRFBean>();
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int formLayoutId = ecb.getFormLayoutId();
FormLayoutBean flb = formLayoutById.get(formLayoutId);
ecb.setFormLayout(flb);
CRFBean cb = crfById.get(flb.getCrfId());
ecb.setCrf(cb);
EventDefinitionCRFBean edc = null;
Iterator it = eventDefinitionCRFs.iterator();
while (it.hasNext()) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
if (edcBean.getCrfId() == cb.getId()) {
edc = edcBean;
break;
}
}
// 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 (!flb.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();
dec.setEventDefinitionCRF(edc);
// 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());
}
if (nonEmptyEventCrf.contains(ecb.getId())) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
}
}
return answer;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class ImportCRFDataService method fetchEventCRFStatuses.
/*
* purpose: Build a map of EventCRFs and the statuses they should have post-import. Assumes EventCRFs have been
* created for "Not Started" forms.
*/
public HashMap<Integer, String> fetchEventCRFStatuses(ODMContainer odmContainer) {
HashMap<Integer, String> eventCRFStatuses = new HashMap<Integer, String>();
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) {
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(ds);
ArrayList<FormLayoutBean> formLayoutBeans = formLayoutDAO.findAllByOid(formDataBean.getFormOID());
for (FormLayoutBean formLayoutBean : formLayoutBeans) {
ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectFormLayout(studyEventBean, studySubjectBean, formLayoutBean);
for (EventCRFBean ecb : eventCrfBeans) {
Integer ecbId = new Integer(ecb.getId());
if (!eventCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
eventCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
}
}
}
}
}
}
return eventCRFStatuses;
}
use of org.akaza.openclinica.bean.submit.FormLayoutBean in project OpenClinica by OpenClinica.
the class ResolveDiscrepancyServlet method prepareRequestForResolution.
public boolean prepareRequestForResolution(HttpServletRequest request, DataSource ds, StudyBean currentStudy, DiscrepancyNoteBean note, boolean isCompleted) throws Exception {
String entityType = note.getEntityType().toLowerCase();
int id = note.getEntityId();
if ("subject".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudySubjectBean ssb = ssdao.findBySubjectIdAndStudy(id, currentStudy);
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
request.setAttribute("studySubId", String.valueOf(ssb.getId()));
} else if ("studysub".equalsIgnoreCase(entityType)) {
request.setAttribute("action", "show");
request.setAttribute("id", String.valueOf(note.getEntityId()));
} else if ("eventcrf".equalsIgnoreCase(entityType)) {
request.setAttribute("editInterview", "1");
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(id);
request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
// If the request is passed along to ViewSectionDataEntryServlet,
// that code needs
// an event crf id; the (ecb.getId()+"") is necessary because
// FormProcessor throws
// a ClassCastException without the casting to a String
request.setAttribute(ViewSectionDataEntryServlet.EVENT_CRF_ID, ecb.getId() + "");
} else if ("studyevent".equalsIgnoreCase(entityType)) {
StudyEventDAO sedao = new StudyEventDAO(ds);
StudyEventBean seb = (StudyEventBean) sedao.findByPK(id);
request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.EVENT_ID, String.valueOf(id));
request.setAttribute(UpdateStudyEventServlet.STUDY_SUBJECT_ID, String.valueOf(seb.getStudySubjectId()));
} else // this is for item data
if ("itemdata".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(ds);
ItemDAO idao = new ItemDAO(ds);
ItemDataBean idb = (ItemDataBean) iddao.findByPK(id);
ItemBean item = (ItemBean) idao.findByPK(idb.getItemId());
ItemGroupMetadataDAO igmdao = new ItemGroupMetadataDAO<>(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventCRFBean ecb = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
FormLayoutDAO fldao = new FormLayoutDAO(ds);
FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(ecb.getFormLayoutId());
StudyEventDAO sedao = new StudyEventDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssb = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(ds);
ItemFormMetadataBean ifmb = ifmdao.findByItemIdAndCRFVersionId(idb.getItemId(), ecb.getFormLayoutId());
ItemGroupMetadataBean igmBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(idb.getItemId(), ecb.getCRFVersionId());
ItemGroupDAO igdao = new ItemGroupDAO<>(ds);
ItemGroupBean igBean = (ItemGroupBean) igdao.findByPK(igmBean.getItemGroupId());
int repeatOrdinal = idb.getOrdinal();
ItemDataBean idata = null;
if (idb != null && idb.isDeleted()) {
return false;
}
if (igmBean.isRepeatingGroup() && repeatOrdinal > 1) {
List<ItemGroupMetadataBean> igms = igmdao.findMetaByGroupAndCrfVersion(igBean.getId(), ecb.getCRFVersionId());
for (int i = 0; i < idb.getOrdinal(); i++) {
for (ItemGroupMetadataBean igm : igms) {
idata = iddao.findByItemIdAndEventCRFIdAndOrdinal(igm.getItemId(), ecb.getId(), i + 1);
if (idata != null && idata.isDeleted()) {
repeatOrdinal--;
break;
}
}
}
}
EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
// Cache the subject context for use during xform submission
PFormCache cache = PFormCache.getInstance(context);
PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
subjectContext.setStudySubjectOid(ssb.getOid());
subjectContext.setStudyEventDefinitionId(seb.getStudyEventDefinitionId());
subjectContext.setOrdinal(seb.getSampleOrdinal());
subjectContext.setFormLayoutOid(formLayout.getOid());
subjectContext.setUserAccountId(ub.getId());
subjectContext.setItemName(item.getName() + COMMENT);
subjectContext.setItemRepeatOrdinal(repeatOrdinal);
subjectContext.setItemInRepeatingGroup(igmBean.isRepeatingGroup());
subjectContext.setItemRepeatGroupName(igBean.getLayoutGroupPath());
String contextHash = cache.putSubjectContext(subjectContext);
String formUrl = null;
if (ecb.getId() > 0) {
formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, currentStudy.getOid(), null, null, QUERY_FLAVOR);
} else {
formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, currentStudy.getOid(), QUERY_FLAVOR);
}
int hashIndex = formUrl.lastIndexOf("#");
String part1 = formUrl;
String part2 = "";
if (hashIndex != -1) {
part1 = formUrl.substring(0, hashIndex);
part2 = formUrl.substring(hashIndex);
}
request.setAttribute(EnketoFormServlet.FORM_URL1, part1);
request.setAttribute(EnketoFormServlet.FORM_URL2, part2);
}
return true;
}
Aggregations