use of org.akaza.openclinica.domain.datamap.FormLayout 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.FormLayout in project OpenClinica by OpenClinica.
the class FSItemProcessor method processFieldSubmissionGroupItems.
private void processFieldSubmissionGroupItems(ArrayList<HashMap> listOfUploadFilePaths, Node repeatNode, Node itemNode, SubmissionContainer container, ItemGroup itemGroup) throws Exception {
String itemName;
Integer itemOrdinal = 1;
String itemValue;
// Node repeatGroupNode = itemNode.getParentNode();
if (repeatNode != null) {
final NamedNodeMap attributes = repeatNode.getAttributes();
// check to see if groupNode has any enketo attributes
for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) {
if (attributes.item(attrIndex).getNodeName().equals(ENKETO_ORDINAL)) {
logger.debug("found enketo attribute");
logger.debug(attributes.item(attrIndex).getNodeName());
logger.debug(attributes.item(attrIndex).getNodeValue());
itemOrdinal = new Integer(attributes.item(attrIndex).getNodeValue());
}
}
} else {
itemOrdinal = 1;
}
FormLayout formLayout = container.getFormLayout();
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
container.setCrfVersion(crfVersion);
Item item = null;
ItemGroupMetadata igm = null;
if (container.getRequestType() == FieldRequestTypeEnum.DELETE_FIELD) {
List<ItemGroupMetadata> igms = itemGroupMetadataDao.findByItemGroupCrfVersion(itemGroup.getItemGroupId(), crfVersion.getCrfVersionId());
for (ItemGroupMetadata ig : igms) {
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(ig.getItem().getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
// ItemData existingItemData = lookupFieldItemData(itemGroup, itemOrdinal, container);
if (existingItemData != null) {
existingItemData.setDeleted(true);
existingItemData.setValue("");
existingItemData.setOldStatus(existingItemData.getStatus());
existingItemData.setUserAccount(container.getUser());
existingItemData.setStatus(Status.AVAILABLE);
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setInstanceId(container.getInstanceId());
existingItemData = itemDataDao.saveOrUpdate(existingItemData);
resetSdvStatus(container);
// Close discrepancy notes
closeItemDiscrepancyNotes(container, existingItemData);
}
}
return;
}
// igm = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
// Item loop
QueryServiceHelperBean helperBean = new QueryServiceHelperBean();
if (queryService.getQueryAttribute(helperBean, itemNode) != null) {
queryService.process(helperBean, container, itemNode, itemOrdinal);
} else if (shouldProcessItemNode(itemNode)) {
itemName = itemNode.getNodeName().trim();
itemValue = itemNode.getTextContent();
item = itemDao.findByNameCrfId(itemNode.getNodeName(), crfVersion.getCrf().getCrfId());
if (item == null) {
logger.error("Failed to lookup item: '" + itemName + "'. Continuing with submission.");
}
ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
// Convert space separated Enketo multiselect values to comma separated OC multiselect values
Integer responseTypeId = itemFormMetadata.getResponseSet().getResponseType().getResponseTypeId();
if (responseTypeId == 3 || responseTypeId == 7) {
itemValue = itemValue.replaceAll(" ", ",");
}
if (responseTypeId == 4) {
/*
* for (HashMap uploadFilePath : listOfUploadFilePaths) {
* if ((boolean) uploadFilePath.containsKey(itemValue) && itemValue != "") {
* itemValue = (String) uploadFilePath.get(itemValue);
* break;
* }
* }
*/
FormLayoutMedia media = formLayoutMediaDao.findByEventCrfIdAndFileName(container.getEventCrf().getEventCrfId(), itemValue);
if (media == null) {
media = new FormLayoutMedia();
}
media.setName(itemValue);
media.setFormLayout(formLayout);
media.setEventCrfId(container.getEventCrf().getEventCrfId());
media.setPath("/" + container.getStudy().getOc_oid() + "/");
formLayoutMediaDao.saveOrUpdate(media);
}
ItemData newItemData = createItemData(item, itemValue, itemOrdinal, container);
Errors itemErrors = validateItemData(newItemData, item, responseTypeId);
if (itemErrors.hasErrors()) {
container.getErrors().addAllErrors(itemErrors);
throw new Exception("Item validation error. Rolling back submission changes.");
}
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(item.getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
if (existingItemData == null) {
newItemData.setStatus(Status.UNAVAILABLE);
itemDataDao.saveOrUpdate(newItemData);
resetSdvStatus(container);
} else if (existingItemData.getValue().equals(newItemData.getValue())) {
} else {
// Existing item. Value changed. Update existing value.
existingItemData.setInstanceId(container.getInstanceId());
existingItemData.setValue(newItemData.getValue());
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setDateUpdated(new Date());
itemDataDao.saveOrUpdate(existingItemData);
resetSdvStatus(container);
}
}
}
use of org.akaza.openclinica.domain.datamap.FormLayout 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. ***");
}
}
use of org.akaza.openclinica.domain.datamap.FormLayout in project OpenClinica by OpenClinica.
the class OpenRosaServices method getForm.
@GET
@Path("/{studyOID}/form")
@Produces(MediaType.TEXT_XML)
public XFormList getForm(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formID") String uniqueId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
// print logback's internal status
StatusPrinter.print(lc);
if (!mayProceedPreview(studyOID))
return null;
String flavor = getQuerySet(uniqueId);
String formLayoutOid = getFormLayoutOid(uniqueId);
FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
CrfBean crf = crfDao.findById(formLayout.getCrf().getCrfId());
String xformOutput = "";
String directoryPath = Utils.getCrfMediaFilePath(crf.getOcOid(), formLayout.getOcOid());
File dir = new File(directoryPath);
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
if (flavor.equals(QUERY_FLAVOR) && child.getName().endsWith(QUERY_SUFFIX) || flavor.equals(NO_FLAVOR) && child.getName().endsWith(NO_SUFFIX)) {
xformOutput = new String(Files.readAllBytes(Paths.get(child.getPath())));
break;
}
}
}
XFormList formList = null;
try {
formList = new XFormList();
XForm form = new XForm(crf, formLayout);
// TODO Uncomment this before checking in
if (StringUtils.isNotEmpty(xformOutput)) {
form.setHash(DigestUtils.md5Hex(xformOutput));
}
String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
List<FormLayoutMedia> mediaList = formLayoutMediaDao.findByFormLayoutIdForNoteTypeMedia(formLayout.getFormLayoutId());
if (flavor.equals(QUERY_FLAVOR)) {
form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + formLayout.getOcOid() + QUERY);
form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + formLayout.getOcOid() + QUERY);
form.setFormID(formLayout.getOcOid() + QUERY);
} else {
form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + formLayout.getOcOid());
form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + formLayout.getOcOid());
}
formList.add(form);
} catch (Exception e) {
LOGGER.error(e.getMessage());
LOGGER.error(ExceptionUtils.getStackTrace(e));
// return "<Error>" + e.getMessage() + "</Error>";
}
return formList;
}
use of org.akaza.openclinica.domain.datamap.FormLayout 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 uniqueId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
if (!mayProceedPreview(studyOID))
return null;
XFormList formList = null;
try {
if (StringUtils.isEmpty(uniqueId)) {
List<CrfBean> crfs = crfDao.findAll();
List<FormLayout> formLayouts = formLayoutDao.findAll();
formList = new XFormList();
for (CrfBean crf : crfs) {
for (FormLayout formLayout : formLayouts) {
if (formLayout.getCrf().getCrfId() == crf.getCrfId()) {
XForm form = new XForm(crf, formLayout);
// TODO: Need to generate hash based on contents of
// XForm. Will be done in a later story.
// TODO: For now all XForms get a date based hash to
// trick Enketo into always downloading
// TODO: them.
String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + formLayout.getOcOid());
List<FormLayoutMedia> mediaList = formLayoutMediaDao.findByFormLayoutIdForNoteTypeMedia(formLayout.getFormLayoutId());
if (mediaList != null && mediaList.size() > 0) {
form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + formLayout.getOcOid());
}
formList.add(form);
}
}
}
} else {
formList = getForm(request, response, studyOID, uniqueId, authorization, context);
}
// 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>";
}
}
Aggregations