1 | <g:if test="${studyList*.subjects?.flatten()?.size()==0}"> |
---|
2 | No subjects in the selected studies |
---|
3 | </g:if> |
---|
4 | <g:else> |
---|
5 | <table> |
---|
6 | <thead> |
---|
7 | <tr> |
---|
8 | <g:if test="${multipleStudies}"> |
---|
9 | <th></th> |
---|
10 | </g:if> |
---|
11 | <g:each in="${new dbnp.studycapturing.Subject().giveDomainFields()}" var="field"> |
---|
12 | <th>${field}</th> |
---|
13 | </g:each> |
---|
14 | |
---|
15 | <% |
---|
16 | // Determine a union of the fields for all different |
---|
17 | // subjects in all studies. In order to show a proper list. |
---|
18 | // We want every field to appear just once, |
---|
19 | // so the list is filtered for unique values |
---|
20 | subjectTemplates = studyList*.giveSubjectTemplates()?.flatten().unique() |
---|
21 | if( !subjectTemplates ) { |
---|
22 | subjectTemplates = []; |
---|
23 | subjectFields = []; |
---|
24 | } else { |
---|
25 | subjectFields = subjectTemplates*.fields?.flatten().unique() |
---|
26 | if( !subjectFields ) { |
---|
27 | subjectFields = []; |
---|
28 | } |
---|
29 | } |
---|
30 | |
---|
31 | /* |
---|
32 | * These lines are rewritten because |
---|
33 | * performance sucked |
---|
34 | * |
---|
35 | * // These took about 9 seconds (for 31 subjects and |
---|
36 | * allSubjects = studyList*.subjects?.flatten() |
---|
37 | * |
---|
38 | * subjectFields = subjectFields.findAll { subjectField -> |
---|
39 | * ( true in allSubjects.collect { subject -> subject.fieldExists( subjectField.name ) && subject.getFieldValue( subjectField.name ) != null }.flatten() ) |
---|
40 | * } |
---|
41 | */ |
---|
42 | |
---|
43 | // Filter out all fields that are left blank for all subjects |
---|
44 | allSubjects = studyList*.subjects?.flatten() |
---|
45 | |
---|
46 | showSubjectFields = [] |
---|
47 | subjectFields.each { subjectField -> |
---|
48 | for( subject in allSubjects ) |
---|
49 | { |
---|
50 | // If the field is filled for this subject, we have to |
---|
51 | // show the field and should not check any other |
---|
52 | // subjects (hence the break) |
---|
53 | if( subject.fieldExists( subjectField.name ) && subject.getFieldValue( subjectField.name ) ) { |
---|
54 | showSubjectFields << subjectField; |
---|
55 | break; |
---|
56 | } |
---|
57 | } |
---|
58 | } |
---|
59 | %> |
---|
60 | |
---|
61 | <g:each in="${showSubjectFields}" var="field"> |
---|
62 | <th>${field}</th> |
---|
63 | </g:each> |
---|
64 | |
---|
65 | </tr> |
---|
66 | </thead> |
---|
67 | |
---|
68 | <g:set var="i" value="${1}" /> |
---|
69 | |
---|
70 | <g:each in="${studyList}" var="studyInstance"> |
---|
71 | <g:each in="${studyInstance.subjects}" var="subject" status="j"> |
---|
72 | <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> |
---|
73 | <g:if test="${multipleStudies && j==0}"> |
---|
74 | <td class="studytitle" rowspan="${studyInstance.subjects?.size()}"> |
---|
75 | ${studyInstance.title} |
---|
76 | </td> |
---|
77 | </g:if> |
---|
78 | <g:each in="${subject.giveDomainFields()}" var="field"> |
---|
79 | <td><wizard:showTemplateField field="${field}" entity="${subject}" /></td> |
---|
80 | </g:each> |
---|
81 | |
---|
82 | <g:each in="${showSubjectFields}" var="field"> |
---|
83 | <td> |
---|
84 | <g:if test="${subject.fieldExists(field.name)}"> |
---|
85 | <wizard:showTemplateField field="${field}" entity="${subject}" /> |
---|
86 | </g:if> |
---|
87 | <g:else> |
---|
88 | N/A |
---|
89 | </g:else> |
---|
90 | </td> |
---|
91 | </g:each> |
---|
92 | |
---|
93 | </tr> |
---|
94 | <g:set var="i" value="${i + 1}" /> |
---|
95 | </g:each> |
---|
96 | </g:each> |
---|
97 | </table> |
---|
98 | </g:else> |
---|