Search in sources :

Example 6 with CrfVersion

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;
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) Date(java.util.Date)

Example 7 with CrfVersion

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);
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) Date(java.util.Date) EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) Item(org.akaza.openclinica.domain.datamap.Item) FileItem(org.apache.commons.fileupload.FileItem) ResponseEntity(org.springframework.http.ResponseEntity) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) UserAccount(org.akaza.openclinica.domain.user.UserAccount) PFormCache(org.akaza.openclinica.web.pform.PFormCache)

Example 8 with CrfVersion

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;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TreeSet(java.util.TreeSet) Set(java.util.Set) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ItemGroup(org.akaza.openclinica.domain.datamap.ItemGroup) DocumentBuilder(javax.xml.parsers.DocumentBuilder) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion) StringReader(java.io.StringReader)

Example 9 with CrfVersion

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;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Errors(org.springframework.validation.Errors) Study(org.akaza.openclinica.domain.datamap.Study) StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion)

Example 10 with CrfVersion

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();
}
Also used : Query(org.hibernate.query.Query) CrfVersion(org.akaza.openclinica.domain.datamap.CrfVersion)

Aggregations

CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)11 Date (java.util.Date)5 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)4 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)4 Study (org.akaza.openclinica.domain.datamap.Study)3 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)3 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)3 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)2 Item (org.akaza.openclinica.domain.datamap.Item)2 Query (org.hibernate.query.Query)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Errors (org.springframework.validation.Errors)2 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 CrfBean (org.akaza.openclinica.domain.datamap.CrfBean)1 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)1