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;
}
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;
}
Aggregations