use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class FormLayoutDao method findByFormLayoutId.
public FormLayout findByFormLayoutId(int formLayoutId) {
String query = "from " + getDomainClassName() + " form_layout where form_layout.formLayoutId = :formlayoutid ";
Query q = getCurrentSession().createQuery(query);
q.setParameter("formlayoutid", formLayoutId);
return (FormLayout) q.uniqueResult();
}
use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class OdmImportServiceImpl method saveOrUpdateCrfAndFormLayouts.
private void saveOrUpdateCrfAndFormLayouts(String crfOid, List<OCodmComplexTypeDefinitionFormLayoutDef> formLayoutDefs, Form[] fmCrfs, UserAccount userAccount, Study study, String crfName) {
DataBinder dataBinder = new DataBinder(new FormLayout());
Errors errors = dataBinder.getBindingResult();
StudyBean currentStudy = new StudyBean();
currentStudy.setId(study.getStudyId());
UserAccountBean ub = new UserAccountBean();
ub.setId(userAccount.getUserId());
ub.setActiveStudyId(currentStudy.getId());
for (Form crf : fmCrfs) {
if (crf.getOcoid().equals(crfOid)) {
ExecuteIndividualCrfObject eicObj = new ExecuteIndividualCrfObject(crf, formLayoutDefs, errors, currentStudy, ub, true, null);
xformService.executeIndividualCrf(eicObj);
}
}
}
use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class XformMetaDataService method createCRFMetaData.
@Transactional
public FormLayout createCRFMetaData(CrfMetaDataObject cmdObject) throws Exception {
CrfVersion crfVersion = null;
FormLayout formLayout = null;
CrfBean crfBean = null;
Section section = null;
crfBean = (CrfBean) crfDao.findByOcOID(cmdObject.crf.getOcoid());
if (crfBean != null) {
crfBean.setUpdateId(cmdObject.ub.getId());
crfBean.setDateUpdated(new Date());
crfBean = crfDao.saveOrUpdate(crfBean);
formLayout = formLayoutDao.findByOcOID(cmdObject.version.getOcoid());
if (formLayout == null) {
formLayout = new FormLayout();
formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
formLayout = formLayoutDao.saveOrUpdate(formLayout);
}
crfVersion = crfVersionDao.findAllByCrfId(crfBean.getCrfId()).get(0);
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
} else {
crfBean = new CrfBean();
crfBean = populateCrf(crfBean, cmdObject);
Integer crfId = (Integer) crfDao.save(crfBean);
crfBean.setCrfId(crfId);
// Create new Form Layout
formLayout = new FormLayout();
formLayout = populateFormLayout(formLayout, crfBean, cmdObject);
formLayout = formLayoutDao.saveOrUpdate(formLayout);
// Create new CRF Version
crfVersion = new CrfVersion();
crfVersion = populateCrfVersion(crfBean, crfVersion, cmdObject);
crfVersion = crfVersionDao.saveOrUpdate(crfVersion);
// Create Section
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
if (section == null) {
section = new Section();
section = populateCrfVersion(section, crfVersion, cmdObject);
sectionDao.saveOrUpdate(section);
section = sectionDao.findByCrfVersionOrdinal(crfVersion.getCrfVersionId(), 1);
}
}
createGroups(cmdObject.container, crfBean, crfVersion, formLayout, section, cmdObject.ub, cmdObject.errors);
if (cmdObject.errors.hasErrors()) {
logger.error("Encounter validation errors while saving CRF. Rolling back transaction.");
throw new RuntimeException("Encountered validation errors while saving CRF.");
}
return formLayout;
}
use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class XformMetaDataService method saveFormMetadata.
public void saveFormMetadata(ExecuteIndividualCrfObject eicObj, FormVersion version, XformContainer container, OCodmComplexTypeDefinitionFormLayoutDef formLayoutDef, List<String> fileLinks) {
try {
try {
FormLayout formLayout = createCRFMetaData(new CrfMetaDataObject(eicObj.form, version, container, eicObj.getCurrentStudy(), eicObj.ub, eicObj.errors, formLayoutDef.getURL()));
saveFormArtifactsInOCDataDirectory(fileLinks, eicObj.form.getOcoid(), version.getOcoid());
saveMediaFiles(fileLinks, eicObj.form.getOcoid(), formLayout);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (RuntimeException e) {
logger.error("Error encountered while saving CRF: " + e.getMessage());
logger.error(ExceptionUtils.getStackTrace(e));
if (!eicObj.errors.hasErrors())
throw e;
}
}
use of org.akaza.openclinica.domain.datamap.FormLayout 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);
}
Aggregations