use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.
the class ExpressionService method getStudyEventFromOID.
public StudyEvent getStudyEventFromOID(String oid) {
Integer subjectId = expressionWrapper.getStudySubjectId();
StudyEvent studyEvent = null;
if (oid.contains("[")) {
int leftBracketIndex = oid.indexOf("[");
int rightBracketIndex = oid.indexOf("]");
int ordinal = Integer.valueOf(oid.substring(leftBracketIndex + 1, rightBracketIndex));
studyEvent = getStudyEventFromDb(oid.substring(0, leftBracketIndex), ordinal, subjectId);
} else
studyEvent = getStudyEventFromDb(oid, 1, subjectId);
return studyEvent;
}
use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.
the class EnketoFormServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormLayoutDao formLayoutDao = (FormLayoutDao) SpringServletAccess.getApplicationContext(context).getBean("formLayoutDao");
StudyEventDao studyEventDao = (StudyEventDao) SpringServletAccess.getApplicationContext(context).getBean("studyEventDaoDomain");
EnketoUrlService enketoUrlService = (EnketoUrlService) SpringServletAccess.getApplicationContext(context).getBean("enketoUrlService");
EnketoCredentials enketoCredentials = (EnketoCredentials) SpringServletAccess.getApplicationContext(context).getBean("enketoCredentials");
String originatingPage = request.getParameter(ORIGINATING_PAGE);
String formLayoutId = request.getParameter(FORM_LAYOUT_ID);
String studyEventId = request.getParameter(STUDY_EVENT_ID);
String eventCrfId = request.getParameterValues(EVENT_CRF_ID)[0];
String formUrl = null;
StudyEvent studyEvent = studyEventDao.findByStudyEventId(Integer.valueOf(studyEventId));
FormLayout formLayout = formLayoutDao.findById(Integer.valueOf(formLayoutId));
// Cache the subject context for use during xform submission
PFormCache cache = PFormCache.getInstance(context);
PFormCacheSubjectContextEntry subjectContext = new PFormCacheSubjectContextEntry();
subjectContext.setStudySubjectOid(studyEvent.getStudySubject().getOcOid());
subjectContext.setStudyEventDefinitionId(studyEvent.getStudyEventDefinition().getStudyEventDefinitionId());
subjectContext.setOrdinal(studyEvent.getSampleOrdinal());
subjectContext.setFormLayoutOid(formLayout.getOcOid());
subjectContext.setUserAccountId(ub.getId());
String contextHash = cache.putSubjectContext(subjectContext);
Study study = enketoCredentials.getParentStudy(currentStudy.getOid());
if (Integer.valueOf(eventCrfId) > 0) {
formUrl = enketoUrlService.getEditUrl(contextHash, subjectContext, study.getOc_oid(), formLayout, studyEvent, QUERY_FLAVOR);
} else {
formUrl = enketoUrlService.getInitialDataEntryUrl(contextHash, subjectContext, study.getOc_oid(), 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(FORM_URL1, part1);
request.setAttribute(FORM_URL2, part2);
// request.setAttribute(FORM_URL, "https://enke.to/i/::widgets?a=b");
request.setAttribute(ORIGINATING_PAGE, originatingPage);
forwardPage(Page.ENKETO_FORM_SERVLET);
}
use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.
the class BatchCRFMigrationController method executeMigrationAction.
public void executeMigrationAction(HelperObject helperObject, EventCRFBean eventCRFBean) {
Session session = helperObject.getSession();
EventCrf eventCrf = helperObject.getEventCrfDao().findById(eventCRFBean.getId());
StudyEvent studyEvent = helperObject.getStudyEventDao().findById(eventCRFBean.getStudyEventId());
FormLayout formLayout = helperObject.getFormLayoutDao().findById(helperObject.getTargetCrfVersionBean().getId());
StudySubject studySubject = helperObject.getStudySubjectDao().findById(eventCRFBean.getStudySubjectId());
eventCrf.setSdvStatus(false);
eventCrf.setDateUpdated(new Date());
eventCrf.setSdvUpdateId(helperObject.getUserAccountBean().getId());
eventCrf.setUpdateId(helperObject.getUserAccountBean().getId());
eventCrf.setFormLayout(formLayout);
session.saveOrUpdate(eventCrf);
String status_before_update = null;
SubjectEventStatus eventStatus = null;
if (studySubject.getStatus() == Status.SIGNED) {
status_before_update = auditDao().findLastStatus("study_subject", studySubject.getStudySubjectId(), "8");
if (status_before_update != null && status_before_update.length() == 1) {
int subject_status = Integer.parseInt(status_before_update);
Status status = Status.getByCode(subject_status);
studySubject.setStatus(status);
}
studySubject.setUpdateId(helperObject.getUserAccountBean().getId());
session.saveOrUpdate(studySubject);
}
studyEvent.setUpdateId(helperObject.getUserAccountBean().getId());
studyEvent.setDateUpdated(new Date());
status_before_update = auditDao().findLastStatus("study_event", studyEvent.getStudyEventId(), "8");
if (status_before_update != null && status_before_update.length() == 1) {
int status = Integer.parseInt(status_before_update);
eventStatus = SubjectEventStatus.get(status);
studyEvent.setSubjectEventStatusId(eventStatus.getId());
}
session.saveOrUpdate(studyEvent);
}
use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.
the class EventProcessor method createStudyEvent.
private StudyEvent createStudyEvent(StudySubject studySubject, StudyEventDefinition studyEventDefinition, Integer ordinal, UserAccount user) {
Date currentDate = new Date();
StudyEvent studyEvent = new StudyEvent();
studyEvent.setStudySubject(studySubject);
studyEvent.setStudyEventDefinition(studyEventDefinition);
studyEvent.setSampleOrdinal(ordinal);
studyEvent.setStatusId(Status.AVAILABLE.getCode());
studyEvent.setUserAccount(user);
studyEvent.setDateStart(currentDate);
studyEvent.setSubjectEventStatusId(SubjectEventStatus.SCHEDULED.getCode());
studyEvent.setStartTimeFlag(false);
studyEvent.setEndTimeFlag(false);
studyEvent.setDateCreated(currentDate);
studyEvent.setLocation("");
StudyEventChangeDetails changeDetails = new StudyEventChangeDetails(true, true);
StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
studyEventDao.saveOrUpdateTransactional(container);
studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefinition.getOc_oid(), ordinal, studySubject.getStudySubjectId());
return studyEvent;
}
use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.
the class EventProcessor method processAnonymous.
private void processAnonymous(SubmissionContainer container, Errors errors, StudySubject studySubject, StudyEventDefinition studyEventDefinition) throws Exception {
// Integer.valueOf(container.getSubjectContext().get("studyEventOrdinal"));
Integer ordinal = 1;
Integer maxExistingOrdinal = studyEventDao.findMaxOrdinalByStudySubjectStudyEventDefinition(studySubject.getStudySubjectId(), studyEventDefinition.getStudyEventDefinitionId());
FormLayout formLayout = formLayoutDao.findByOcOID(container.getSubjectContext().get("formLayoutOID"));
while (ordinal <= maxExistingOrdinal + 1) {
StudyEvent existingStudyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefinition.getOc_oid(), ordinal, studySubject.getStudySubjectId());
if (existingStudyEvent == null) {
container.setStudyEvent(createStudyEvent(studySubject, studyEventDefinition, ordinal, container.getUser()));
container.setEventCrf(createEventCrf(formLayout, container.getStudyEvent(), container.getSubject(), container.getUser()));
break;
} else if (!existingStudyEvent.getStatusId().equals(Status.AVAILABLE.getCode()) || (!existingStudyEvent.getSubjectEventStatusId().equals(SubjectEventStatus.SCHEDULED.getCode()) && !existingStudyEvent.getSubjectEventStatusId().equals(SubjectEventStatus.NOT_SCHEDULED.getCode()) && !existingStudyEvent.getSubjectEventStatusId().equals(SubjectEventStatus.DATA_ENTRY_STARTED.getCode()))) {
if (studyEventDefinition.getRepeating()) {
ordinal++;
continue;
} else {
errors.reject("Existing StudyEvent is not Available and EventDef is not repeating");
logger.info("*** Existing StudyEvent is not Available and EventDef is not repeating ***");
throw new Exception("*** Existing StudyEvent is not Available and EventDef is not repeating ***");
}
} else {
EventCrf existingEventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdCrfId(existingStudyEvent.getStudyEventId(), container.getSubject().getStudySubjectId(), formLayout.getCrf().getCrfId());
if (existingEventCrf == null) {
container.setStudyEvent(existingStudyEvent);
container.setEventCrf(createEventCrf(formLayout, container.getStudyEvent(), container.getSubject(), container.getUser()));
break;
} else {
List<ItemData> itemDataList = itemDataDao.findByEventCrfId(existingEventCrf.getEventCrfId());
if (existingEventCrf.getStatusId().equals(Status.AVAILABLE.getCode()) && itemDataList.size() == 0) {
container.setStudyEvent(existingStudyEvent);
container.setEventCrf(existingEventCrf);
break;
} else if (studyEventDefinition.getRepeating()) {
ordinal++;
continue;
} else {
errors.reject("Existing EventCRF is not usable and EventDef is not repeating");
logger.info("*** Existing EventCRF is not usable and EventDef is not repeating ***");
throw new Exception("*** Existing EventCRF is not usable and EventDef is not repeating ***");
}
}
}
}
if (container.getStudyEvent() == null || container.getEventCrf() == null) {
errors.reject("Unable to identify StudyEvent or EventCrf.");
logger.info("*** Unable to identify StudyEvent or EventCrf. ***");
throw new Exception("*** Unable to identify StudyEvent or EventCrf. ***");
}
}
Aggregations