use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.
the class CrfVersionDao method findByCrfVersionId.
public CrfVersion findByCrfVersionId(int crf_version_id) {
String query = "from " + getDomainClassName() + " crf_version where crf_version.crfVersionId = :crfversionid ";
Query q = getCurrentSession().createQuery(query);
q.setParameter("crfversionid", crf_version_id);
return (CrfVersion) q.uniqueResult();
}
use of org.akaza.openclinica.domain.datamap.CrfVersion 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.CrfVersion in project OpenClinica by OpenClinica.
the class OpenRosaSubmissionService method processRequest.
@Transactional
public void processRequest(Study study, HashMap<String, String> subjectContext, String requestBody, Errors errors, Locale locale, ArrayList<HashMap> listOfUploadFilePaths, SubmissionContainer.FieldRequestTypeEnum requestType) throws Exception {
// Execute save as Hibernate transaction to avoid partial imports
CrfVersion crfVersion = crfVersionDao.findByOcOID(subjectContext.get("crfVersionOID"));
String requestPayload = parseSubmission(requestBody, crfVersion);
runAsTransaction(study, requestPayload, subjectContext, errors, locale, listOfUploadFilePaths, requestType);
}
use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.
the class OpenRosaSubmissionController method createEventCrf.
private EventCrf createEventCrf(FormLayout formLayout, StudyEvent studyEvent, StudySubject studySubject, UserAccount user) {
EventCrf eventCrf = new EventCrf();
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
Date currentDate = new Date();
eventCrf.setAnnotations("");
eventCrf.setDateCreated(currentDate);
eventCrf.setCrfVersion(crfVersion);
eventCrf.setFormLayout(formLayout);
eventCrf.setInterviewerName("");
eventCrf.setDateInterviewed(null);
eventCrf.setUserAccount(user);
eventCrf.setStatusId(org.akaza.openclinica.domain.Status.AVAILABLE.getCode());
// setCompletionStatusId(1);
eventCrf.setCompletionStatus(completionStatusDao.findByCompletionStatusId(1));
eventCrf.setStudySubject(studySubject);
eventCrf.setStudyEvent(studyEvent);
eventCrf.setValidateString("");
eventCrf.setValidatorAnnotations("");
eventCrf.setUpdateId(user.getUserId());
eventCrf.setDateUpdated(new Date());
eventCrf.setValidatorId(0);
eventCrf.setOldStatusId(0);
eventCrf.setSdvUpdateId(0);
eventCrf = eventCrfDao.saveOrUpdate(eventCrf);
logger.debug("*********CREATED EVENT CRF");
return eventCrf;
}
use of org.akaza.openclinica.domain.datamap.CrfVersion 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);
}
}
}
Aggregations