Search in sources :

Example 1 with Subject

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

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

the class StudySubjectProcessor method createSubject.

private Subject createSubject(Date currentDate) {
    UserAccount rootUser = userAccountDao.findByUserId(1);
    Subject subject = new Subject();
    subject.setUserAccount(rootUser);
    subject.setStatus(Status.AVAILABLE);
    subject.setDobCollected(false);
    subject.setDateCreated(currentDate);
    subject.setUniqueIdentifier("");
    subject = subjectDao.saveOrUpdate(subject);
    return subject;
}
Also used : UserAccount(org.akaza.openclinica.domain.user.UserAccount) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) Subject(org.akaza.openclinica.domain.datamap.Subject)

Aggregations

StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)2 Subject (org.akaza.openclinica.domain.datamap.Subject)2 UserAccount (org.akaza.openclinica.domain.user.UserAccount)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Study (org.akaza.openclinica.domain.datamap.Study)1