Skip to content

Commit

Permalink
Merge pull request #1266 from kkrumlian/3.14
Browse files Browse the repository at this point in the history
Correcting study subject label auto generation algorithm , Looks good
  • Loading branch information
jkeremian committed Jan 18, 2018
2 parents e710806 + e763f49 commit 425de43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ private String getOid(StudySubject studySubject) {
}

public int findTheGreatestLabelByStudy(Integer studyId) {
List<StudySubject> allStudySubjects = findAllByStudy(studyId);
getSessionFactory().getStatistics().logSummary();
String query = "from " + getDomainClassName() + " do where (do.study.studyId = :studyid or do.study.study.studyId = :studyid)";

org.hibernate.Query q = getCurrentSession().createQuery(query);
q.setInteger("studyid", studyId);
List<StudySubject> allStudySubjects = (ArrayList<StudySubject>) q.list();

int greatestLabel = 0;
for (StudySubject subject:allStudySubjects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public void process(SubmissionContainer container) throws Exception {
} else {
// create Subject & Study Subject
Study study = studyDao.findByOcOID(container.getSubjectContext().get("studyOID"));
int nextLabel = studySubjectDao.findTheGreatestLabelByStudy(study.getStudyId()) + 1;
// Need to pass parent study Id if this is a site
Integer studyId = study.getStudy() != null ? study.getStudy().getStudyId() : study.getStudyId();
int nextLabel = studySubjectDao.findTheGreatestLabelByStudy(studyId) + 1;
Subject subject = createSubject(currentDate, rootUser);
StudySubject studySubject = createStudySubject(Integer.toString(nextLabel), subject, study,rootUser,currentDate, null);
container.setSubject(studySubject);
Expand Down

0 comments on commit 425de43

Please sign in to comment.