Search in sources :

Example 6 with StudySubject

use of org.akaza.openclinica.domain.datamap.StudySubject in project OpenClinica by OpenClinica.

the class StudySubjectProcessor method process.

@Override
public ProcessorEnum process(SubmissionContainer container) throws Exception {
    logger.info("Executing study subject processor.");
    String studySubjectOid = container.getSubjectContext().get("studySubjectOID");
    String embeddedStudySubjectId = getEmbeddedStudySubjectOid(container);
    int nextLabel = studySubjectDao.findTheGreatestLabel() + 1;
    Date currentDate = new Date();
    UserAccount rootUser = userAccountDao.findByUserId(1);
    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd.HHmmss");
    // Standard Participant Dashboard submission
    if (studySubjectOid != null) {
        StudySubject studySubject = studySubjectDao.findByOcOID(studySubjectOid);
        container.setSubject(studySubject);
        if (studySubject.getStatus() != Status.AVAILABLE) {
            container.getErrors().reject("value.incorrect.STATUS");
            throw new Exception("StudySubject status is not Available.");
        }
    // Embedded Study Subject ID in form.  An offline submission.
    } else if (embeddedStudySubjectId != null) {
        Study study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
        StudySubject embeddedStudySubject = studySubjectDao.findByLabelAndStudyOrParentStudy(embeddedStudySubjectId, study);
        //If Study Subject exists in current study and is available use that
        if (embeddedStudySubject != null && embeddedStudySubject.getStatus() == Status.AVAILABLE) {
            container.setSubject(embeddedStudySubject);
        //If it exists but is in the wrong status, throw an exception
        } else if (embeddedStudySubject != null && embeddedStudySubject.getStatus() != Status.AVAILABLE) {
            container.getErrors().reject("value.incorrect.STATUS");
            throw new Exception("Embedded StudySubject status is not Available");
        //If Study Subject exists in a parent/sibling study, create study subject with 'FIXME-<timestamp>' label to avoid data loss and mark it
        } else if (subjectExistsInParentSiblingStudy(embeddedStudySubjectId, study)) {
            String subjectLabel = "FIXME-" + dateFormatter.format(currentDate);
            Subject subject = createSubject(currentDate);
            StudySubject studySubject = createStudySubject(subjectLabel, subject, study, rootUser, currentDate, embeddedStudySubjectId);
            container.setSubject(studySubject);
        //Study Subject does not exist. Create it
        } else {
            Subject subject = createSubject(currentDate);
            StudySubject studySubject = createStudySubject(embeddedStudySubjectId, subject, study, rootUser, currentDate, null);
            container.setSubject(studySubject);
        }
    // Anonymous submission or offline submission with no embedded Study Subject ID
    } else {
        // create Subject & Study Subject
        Study study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
        Subject subject = createSubject(currentDate);
        StudySubject studySubject = createStudySubject(Integer.toString(nextLabel), subject, study, rootUser, currentDate, null);
        container.setSubject(studySubject);
    }
    return ProcessorEnum.PROCEED;
}
Also used : Study(org.akaza.openclinica.domain.datamap.Study) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) UserAccount(org.akaza.openclinica.domain.user.UserAccount) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) Subject(org.akaza.openclinica.domain.datamap.Subject)

Example 7 with StudySubject

use of org.akaza.openclinica.domain.datamap.StudySubject in project OpenClinica by OpenClinica.

the class StudySubjectProcessor method createStudySubject.

private StudySubject createStudySubject(String label, Subject subject, Study study, UserAccount rootUser, Date currentDate, String secondaryLabel) {
    StudySubject studySubject = new StudySubject();
    studySubject.setStudy(study);
    studySubject.setSubject(subject);
    studySubject.setStatus(Status.AVAILABLE);
    studySubject.setUserAccount(rootUser);
    studySubject.setEnrollmentDate(currentDate);
    studySubject.setDateCreated(currentDate);
    studySubject.setSecondaryLabel("");
    studySubject.setLabel(label);
    if (secondaryLabel != null && !secondaryLabel.equals(""))
        studySubject.setSecondaryLabel(secondaryLabel);
    String studySubjectOid = studySubjectDao.getValidOid(studySubject, new ArrayList<String>());
    studySubject.setOcOid(studySubjectOid);
    studySubject = studySubjectDao.saveOrUpdate(studySubject);
    return studySubject;
}
Also used : StudySubject(org.akaza.openclinica.domain.datamap.StudySubject)

Example 8 with StudySubject

use of org.akaza.openclinica.domain.datamap.StudySubject in project OpenClinica by OpenClinica.

the class OpenRosaServices method getUserXml.

private String getUserXml(ServletContext context) throws Exception {
    HashMap<String, String> value = getSubjectContextCacheValue(context);
    String studySubjectOid = value.get("studySubjectOID");
    StudySubject ssBean = ssDao.findByOcOID(studySubjectOid);
    StudyBean study = getStudy(ssBean.getStudy().getOc_oid());
    StudyBean parentStudy = getParentStudy(ssBean.getStudy().getOc_oid());
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element root = doc.createElement("root");
    doc.appendChild(root);
    List<UserAccount> users = userAccountDao.findNonRootNonParticipateUsersByStudyId(study.getId(), parentStudy.getId());
    for (UserAccount userAccount : users) {
        Element item = doc.createElement("item");
        Element userName = doc.createElement("user_name");
        userName.appendChild(doc.createTextNode(userAccount.getUserName()));
        Element firstName = doc.createElement("first_name");
        firstName.appendChild(doc.createTextNode(userAccount.getFirstName()));
        Element lastName = doc.createElement("last_name");
        lastName.appendChild(doc.createTextNode(userAccount.getLastName()));
        item.appendChild(userName);
        item.appendChild(firstName);
        item.appendChild(lastName);
        root.appendChild(item);
    }
    DOMSource dom = new DOMSource(doc);
    StringWriter writer = new StringWriter();
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.transform(dom, result);
    String userXml = writer.toString();
    return userXml;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) StringWriter(java.io.StringWriter) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) DocumentBuilder(javax.xml.parsers.DocumentBuilder) UserAccount(org.akaza.openclinica.domain.user.UserAccount)

Example 9 with StudySubject

use of org.akaza.openclinica.domain.datamap.StudySubject 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 10 with StudySubject

use of org.akaza.openclinica.domain.datamap.StudySubject 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)

Aggregations

StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)15 Study (org.akaza.openclinica.domain.datamap.Study)8 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)6 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)6 Date (java.util.Date)4 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)4 UserAccount (org.akaza.openclinica.domain.user.UserAccount)4 ArrayList (java.util.ArrayList)3 OdmClinicalDataBean (org.akaza.openclinica.bean.odmbeans.OdmClinicalDataBean)3 CrfVersion (org.akaza.openclinica.domain.datamap.CrfVersion)3 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)3 SimpleDateFormat (java.text.SimpleDateFormat)2 LinkedHashMap (java.util.LinkedHashMap)2 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)2 StringWriter (java.io.StringWriter)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1