use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.
the class EventProcessor 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(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 OpenRosaSubmissionController method markComplete.
// @RequestMapping(value = "/{studyOID}/fieldsubmission/complete", method = RequestMethod.POST)
public ResponseEntity<String> markComplete(HttpServletRequest request, HttpServletResponse response, @PathVariable("studyOID") String studyOID, @RequestParam(FORM_CONTEXT) String ecid) throws Exception {
HashMap<String, String> subjectContext = null;
PFormCache cache = PFormCache.getInstance(context);
subjectContext = cache.getSubjectContext(ecid);
int studyEventDefinitionID = Integer.valueOf(subjectContext.get("studyEventDefinitionID"));
int userAccountID = Integer.valueOf(subjectContext.get("userAccountID"));
String studySubjectOID = subjectContext.get("studySubjectOID");
String formLayoutOID = subjectContext.get("formLayoutOID");
int studyEventOrdinal = Integer.valueOf(subjectContext.get("studyEventOrdinal"));
UserAccount userAccount = userAccountDao.findById(userAccountID);
StudySubject studySubject = studySubjectDao.findByOcOID(studySubjectOID);
Study study = studyDao.findByOcOID(studyOID);
StudyEventDefinition sed = studyEventDefinitionDao.findById(studyEventDefinitionID);
FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOID);
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
StudyEvent studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinalTransactional(sed.getOc_oid(), studyEventOrdinal, studySubject.getStudySubjectId());
EventCrf eventCrf = eventCrfDao.findByStudyEventIdStudySubjectIdFormLayoutId(studyEvent.getStudyEventId(), studySubject.getStudySubjectId(), formLayout.getFormLayoutId());
if (eventCrf == null) {
eventCrf = createEventCrf(formLayout, studyEvent, studySubject, userAccount);
List<Item> items = itemDao.findAllByCrfVersion(crfVersion.getCrfVersionId());
createItemData(items.get(0), "", eventCrf, userAccount);
}
eventCrf.setStatusId(org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode());
eventCrf.setUserAccount(userAccount);
eventCrf.setUpdateId(userAccount.getUserId());
eventCrf.setDateUpdated(new Date());
eventCrfDao.saveOrUpdate(eventCrf);
List<EventCrf> eventCrfs = eventCrfDao.findByStudyEventIdStudySubjectId(studyEvent.getStudyEventId(), studySubject.getOcOid());
List<EventDefinitionCrf> eventDefinitionCrfs = eventDefinitionCrfDao.findAvailableByStudyEventDefStudy(sed.getStudyEventDefinitionId(), study.getStudyId());
int count = 0;
for (EventCrf evCrf : eventCrfs) {
if (evCrf.getStatusId() == org.akaza.openclinica.domain.Status.UNAVAILABLE.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.DELETED.getCode() || evCrf.getStatusId() == org.akaza.openclinica.domain.Status.AUTO_DELETED.getCode()) {
for (EventDefinitionCrf eventDefinitionCrf : eventDefinitionCrfs) {
if (eventDefinitionCrf.getCrf().getCrfId() == evCrf.getFormLayout().getCrf().getCrfId()) {
count++;
break;
}
}
}
}
if (count == eventDefinitionCrfs.size()) {
studyEvent.setSubjectEventStatusId(SubjectEventStatus.COMPLETED.getCode());
studyEvent.setUserAccount(userAccount);
studyEventDao.saveOrUpdate(studyEvent);
} else if (studyEvent.getSubjectEventStatusId() == SubjectEventStatus.SCHEDULED.getCode()) {
studyEvent.setSubjectEventStatusId(SubjectEventStatus.DATA_ENTRY_STARTED.getCode());
studyEvent.setUserAccount(userAccount);
studyEventDao.saveOrUpdate(studyEvent);
}
String responseMessage = "<OpenRosaResponse xmlns=\"http://openrosa.org/http/response\">" + "<message>success</message>" + "</OpenRosaResponse>";
return new ResponseEntity<String>(responseMessage, HttpStatus.CREATED);
}
use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.
the class ItemProcessor method process.
public ProcessorEnum process(SubmissionContainer container) throws Exception {
logger.info("Executing Item Processor.");
if (container.isFieldSubmissionFlag()) {
return ProcessorEnum.PROCEED;
}
ArrayList<HashMap> listOfUploadFilePaths = container.getListOfUploadFilePaths();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(container.getRequestBody()));
Document doc = db.parse(is);
String itemName;
String itemValue;
String groupNodeName = "";
NodeList instanceNodeList = doc.getElementsByTagName("instance");
// Instance loop
for (int i = 0; i < instanceNodeList.getLength(); i = i + 1) {
Node instanceNode = instanceNodeList.item(i);
if (instanceNode instanceof Element) {
NodeList crfNodeList = instanceNode.getChildNodes();
// Form loop
for (int j = 0; j < crfNodeList.getLength(); j = j + 1) {
Node crfNode = crfNodeList.item(j);
if (crfNode instanceof Element) {
CrfVersion crfVersion = container.getCrfVersion();
HashMap<Integer, Set<Integer>> groupOrdinalMapping = new HashMap<Integer, Set<Integer>>();
NodeList groupNodeList = crfNode.getChildNodes();
// Group loop
for (int k = 0; k < groupNodeList.getLength(); k = k + 1) {
Node groupNode = groupNodeList.item(k);
if (groupNode instanceof Element && !groupNode.getNodeName().startsWith("SECTION_")) {
groupNodeName = groupNode.getNodeName();
ItemGroup itemGroup = lookupItemGroup(groupNodeName, crfVersion);
if (itemGroup == null) {
logger.error("Failed to lookup item group: '" + groupNodeName + "'. Continuing with submission.");
continue;
}
processGroupItems(listOfUploadFilePaths, groupOrdinalMapping, groupNode, itemGroup, container);
}
}
// Delete rows that have been removed
removeDeletedRows(groupOrdinalMapping, container);
}
}
}
}
return ProcessorEnum.PROCEED;
}
use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.
the class EventProcessor method process.
public ProcessorEnum process(SubmissionContainer container) throws Exception {
logger.info("Executing Event Processor.");
Errors errors = container.getErrors();
StudySubject studySubject = container.getSubject();
StudyEventDefinition studyEventDefinition = studyEventDefinitionDao.findByStudyEventDefinitionId(Integer.valueOf(container.getSubjectContext().get("studyEventDefinitionID")));
FormLayout formLayout = formLayoutDao.findByOcOID(container.getSubjectContext().get("formLayoutOID"));
container.setFormLayout(formLayout);
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
container.setCrfVersion(crfVersion);
boolean isAnonymous = false;
if (container.getSubjectContext().get("studySubjectOID") == null)
isAnonymous = true;
// Create study event if it doesn't exist
if (isAnonymous)
processAnonymous(container, errors, studySubject, studyEventDefinition);
else
processParticipant(container, errors, studySubject, studyEventDefinition);
// TODO: May need to move this to a new processor that runs at the end
// Update the EventCrf and StudyEvent to the proper status.
// Don't do it in the initial save so it will have the expected audit trail entries.
Study study = null;
if (container.getSubjectContext().get("studyOID") != null)
study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
else
study = container.getStudy();
container.setEventCrf(updateEventCrf(container.getEventCrf(), study, studySubject, container.getUser(), isAnonymous));
container.setStudyEvent(updateStudyEvent(container.getStudyEvent(), studyEventDefinition, study, studySubject, container.getUser(), isAnonymous));
return ProcessorEnum.PROCEED;
}
use of org.akaza.openclinica.domain.datamap.CrfVersion in project OpenClinica by OpenClinica.
the class CrfVersionDao method findByOcOID.
public CrfVersion findByOcOID(String OCOID) {
getSessionFactory().getStatistics().logSummary();
Query q = getCurrentSession().createQuery(findByOcIdQuery);
q.setParameter("OCOID", OCOID);
return (CrfVersion) q.uniqueResult();
}
Aggregations