use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class AnonymousFormControllerV2 method getEnketoForm.
/**
* @api {post} /pages/api/v2/anonymousform/form Retrieve anonymous form URL
* @apiName getEnketoForm
* @apiPermission Module participate - enabled
* @apiVersion 3.8.0
* @apiParam {String} studyOid Study Oid
* @apiParam {String} submissionUri Submission Url
* @apiGroup Form
* @apiDescription Retrieve anonymous form url.
* @apiParamExample {json} Request-Example:
* {
* "studyOid": "S_BL101",
* "submissionUri": "abcde"
* }
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "url": "http://localhost:8006/::YYYi?iframe=true&ecid=abb764d026830e98b895ece6d9dcaf3c5e817983cc00a4ebfaabcb6c3700b4d5",
* "offline": "false"
* }
*/
@RequestMapping(value = "/form", method = RequestMethod.POST)
public ResponseEntity<AnonymousUrlResponse> getEnketoForm(@RequestBody HashMap<String, String> map) throws Exception {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
EventDefinitionCrfTagService tagService = (EventDefinitionCrfTagService) SpringServletAccess.getApplicationContext(context).getBean("eventDefinitionCrfTagService");
String formUrl = null;
String studyOid = map.get("studyOid");
if (!mayProceed(studyOid))
return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
String submissionUri = map.get("submissionUri");
if (submissionUri != "" && submissionUri != null) {
StudyBean study = getStudy(studyOid);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(dataSource);
ArrayList<EventDefinitionCRFBean> edcBeans = edcdao.findAllSubmissionUriAndStudyId(submissionUri, study.getId());
if (edcBeans.size() != 0) {
EventDefinitionCRFBean edcBean = edcBeans.get(0);
CRFDAO crfdao = new CRFDAO(dataSource);
CRFVersionDAO cvdao = new CRFVersionDAO(dataSource);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
CRFVersionBean crfVersionBean = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
CRFBean crf = (CRFBean) crfdao.findByPK(crfVersionBean.getCrfId());
StudyBean sBean = (StudyBean) sdao.findByPK(edcBean.getStudyId());
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
String tagPath = sedBean.getOid() + "." + crf.getOid();
boolean isOffline = tagService.getEventDefnCrfOfflineStatus(2, tagPath, true);
String offline = null;
if (isOffline)
offline = "true";
else
offline = "false";
formUrl = createAnonymousEnketoUrl(sBean.getOid(), crfVersionBean, edcBean, isOffline);
AnonymousUrlResponse anonResponse = new AnonymousUrlResponse(formUrl, offline, crf.getName(), crfVersionBean.getDescription());
return new ResponseEntity<AnonymousUrlResponse>(anonResponse, org.springframework.http.HttpStatus.OK);
} else {
return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
}
} else {
return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
}
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class SDVUtil method getCRFName.
public String getCRFName(int crfVersionId) {
CRFVersionDAO cRFVersionDAO = new CRFVersionDAO(dataSource);
CRFDAO cRFDAO = new CRFDAO(dataSource);
CRFVersionBean versionBean = (CRFVersionBean) cRFVersionDAO.findByPK(crfVersionId);
if (versionBean != null) {
CRFBean crfBean = (CRFBean) cRFDAO.findByPK(versionBean.getCrfId());
if (crfBean != null)
return crfBean.getName();
}
return "";
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class OpenRosaServices method getFormList.
/**
* @api {get} /rest2/openrosa/:studyOID/formList Get Form List
* @apiName getFormList
* @apiPermission admin
* @apiVersion 3.8.0
* @apiParam {String} studyOID Study Oid.
* @apiGroup Form
* @apiDescription Retrieves a listing of the available OpenClinica forms.
* @apiParamExample {json} Request-Example:
* {
* "studyOid": "S_SAMPLTE",
* }
* @apiSuccessExample {xml} Success-Response:
* HTTP/1.1 200 OK
* {
* <xforms xmlns="http://openrosa.org/xforms/xformsList">
* <xform>
* <formID>F_FIRSTFORM_1</formID>
* <name>First Form</name>
* <majorMinorVersion>1</majorMinorVersion>
* <version>1</version>
* <hash>8678370cd92814d4e3216d58d821403f</hash>
* <downloadUrl>http://oc1.openclinica.com/OpenClinica-web/rest2/openrosa/S_SAMPLTE/formXml?
* formId=F_FIRSTFORM_1</downloadUrl>
* </xform>
* <xform>
* <formID>F_SECONDFORM_1</formID>
* <name>Second Form</name>
* <majorMinorVersion>1</majorMinorVersion>
* <version>1</version>
* <hash>7ee60d1c6516b730bbe9bdbd7cad942f</hash>
* <downloadUrl>http://oc1.openclinica.com/OpenClinica-web/rest2/openrosa/S_SAMPLTE/formXml?
* formId=F_SECONDFORM_1</downloadUrl>
* </xform>
* </xforms>
*/
@GET
@Path("/{studyOID}/formList")
@Produces(MediaType.TEXT_XML)
public String getFormList(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formID") String crfOID, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
StudyDAO sdao = new StudyDAO(getDataSource());
StudyBean study = sdao.findByOid(studyOID);
CRFDAO cdao = new CRFDAO(getDataSource());
Collection<CRFBean> crfs = cdao.findAll();
CRFVersionDAO cVersionDao = new CRFVersionDAO(getDataSource());
Collection<CRFVersionBean> crfVersions = cVersionDao.findAll();
CrfVersionMediaDao mediaDao = (CrfVersionMediaDao) SpringServletAccess.getApplicationContext(context).getBean("crfVersionMediaDao");
try {
XFormList formList = new XFormList();
for (CRFBean crf : crfs) {
for (CRFVersionBean version : crfVersions) {
if (version.getCrfId() == crf.getId()) {
XForm form = new XForm(crf, version);
// TODO: them.
if (version.getXformName() != null) {
form.setHash(DigestUtils.md5Hex(version.getXform()));
} else {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
form.setHash(DigestUtils.md5Hex(String.valueOf(cal.getTimeInMillis())));
}
String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + version.getOid());
List<CrfVersionMedia> mediaList = mediaDao.findByCrfVersionId(version.getId());
if (mediaList != null && mediaList.size() > 0) {
form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + version.getOid());
}
formList.add(form);
}
}
}
// Create the XML formList using a Castor mapping file.
XMLContext xmlContext = new XMLContext();
Mapping mapping = xmlContext.createMapping();
mapping.loadMapping(getCoreResources().getURL("openRosaFormListMapping.xml"));
xmlContext.addMapping(mapping);
Marshaller marshaller = xmlContext.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.setWriter(writer);
marshaller.marshal(formList);
// Set response headers
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
Date currentDate = new Date();
cal.setTime(currentDate);
SimpleDateFormat format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss zz");
format.setCalendar(cal);
response.setHeader("Content-Type", "text/xml; charset=UTF-8");
response.setHeader("Date", format.format(currentDate));
response.setHeader("X-OpenRosa-Version", "1.0");
return writer.toString();
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.error(ExceptionUtils.getStackTrace(e));
return "<Error>" + e.getMessage() + "</Error>";
}
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class OpenRosaXmlGenerator method buildForm.
/**
* @param formId
* @return
* @throws Exception
*/
public String buildForm(String formId) throws Exception {
try {
CRFVersionDAO versionDAO = new CRFVersionDAO(dataSource);
CRFVersionBean crfVersion = versionDAO.findByOid(formId);
CRFDAO crfDAO = new CRFDAO(dataSource);
CRFBean crf = (CRFBean) crfDAO.findByPK(crfVersion.getCrfId());
CRFVersionMetadataUtil metadataUtil = new CRFVersionMetadataUtil(dataSource);
ArrayList<SectionBean> crfSections = metadataUtil.retrieveFormMetadata(crfVersion);
StringWriter writer = new StringWriter();
IOUtils.copy(getClass().getResourceAsStream("/properties/xform_template.xml"), writer, "UTF-8");
String xform = writer.toString();
Html html = buildJavaXForm(xform);
int sectionCount = mapBeansToDTO(html, crf, crfVersion, crfSections);
if (sectionCount > 1)
setFormPaging(html);
String xformMinusInstance = buildStringXForm(html);
String preInstance = xformMinusInstance.substring(0, xformMinusInstance.indexOf("<instance>"));
String instance = buildInstance(html.getHead().getModel(), crfVersion, crfSections);
String nodeset = xformMinusInstance.substring(xformMinusInstance.indexOf("</instance>") + "</instance>".length());
// add nodeset for instanceId
String postInstance = "<bind calculate=\"concat('uuid:', uuid())\" nodeset=\"/" + crfVersion.getOid() + "/meta/instanceID\" readonly=\"true()\" type=\"string\"/>" + nodeset;
logger.debug(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
System.out.println(preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance);
return preInstance + "<instance>\n" + instance + "\n</instance>" + postInstance;
} catch (Exception e) {
log.error(e.getMessage());
log.error(ExceptionUtils.getStackTrace(e));
throw new Exception(e);
}
}
use of org.akaza.openclinica.bean.admin.CRFBean 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;
}
Aggregations