4903 |
10 Jul 18 |
olle |
1 |
package net.sf.basedb.meludi.dao; |
4903 |
10 Jul 18 |
olle |
2 |
|
4903 |
10 Jul 18 |
olle |
3 |
import java.util.ArrayList; |
4903 |
10 Jul 18 |
olle |
4 |
import java.util.List; |
4903 |
10 Jul 18 |
olle |
5 |
|
4903 |
10 Jul 18 |
olle |
6 |
import org.json.simple.JSONObject; |
4903 |
10 Jul 18 |
olle |
7 |
|
4903 |
10 Jul 18 |
olle |
8 |
import net.sf.basedb.core.AnnotationSimpleRestriction; |
4903 |
10 Jul 18 |
olle |
9 |
import net.sf.basedb.core.AnnotationType; |
4903 |
10 Jul 18 |
olle |
10 |
import net.sf.basedb.core.DbControl; |
4903 |
10 Jul 18 |
olle |
11 |
import net.sf.basedb.core.Include; |
4903 |
10 Jul 18 |
olle |
12 |
import net.sf.basedb.core.InvalidDataException; |
4903 |
10 Jul 18 |
olle |
13 |
import net.sf.basedb.core.ItemQuery; |
4903 |
10 Jul 18 |
olle |
14 |
import net.sf.basedb.core.Operator; |
4903 |
10 Jul 18 |
olle |
15 |
import net.sf.basedb.core.PermissionDeniedException; |
4903 |
10 Jul 18 |
olle |
16 |
import net.sf.basedb.core.Sample; |
4903 |
10 Jul 18 |
olle |
17 |
import net.sf.basedb.core.SessionControl; |
4903 |
10 Jul 18 |
olle |
18 |
import net.sf.basedb.core.Type; |
4903 |
10 Jul 18 |
olle |
19 |
import net.sf.basedb.core.query.Annotations; |
4903 |
10 Jul 18 |
olle |
20 |
import net.sf.basedb.core.query.Expressions; |
4903 |
10 Jul 18 |
olle |
21 |
import net.sf.basedb.core.query.Hql; |
4903 |
10 Jul 18 |
olle |
22 |
import net.sf.basedb.core.query.Orders; |
4903 |
10 Jul 18 |
olle |
23 |
import net.sf.basedb.core.query.Restrictions; |
4903 |
10 Jul 18 |
olle |
24 |
import net.sf.basedb.meludi.JsonUtil; |
4903 |
10 Jul 18 |
olle |
25 |
import net.sf.basedb.meludi.Meludi; |
4903 |
10 Jul 18 |
olle |
26 |
import net.sf.basedb.meludi.ReservedItems; |
4903 |
10 Jul 18 |
olle |
27 |
import net.sf.basedb.util.MD5; |
4903 |
10 Jul 18 |
olle |
28 |
import net.sf.basedb.util.Values; |
4903 |
10 Jul 18 |
olle |
29 |
|
4903 |
10 Jul 18 |
olle |
30 |
/** |
4903 |
10 Jul 18 |
olle |
Class for loading information that is related to FFPE block items. |
4903 |
10 Jul 18 |
olle |
32 |
|
4903 |
10 Jul 18 |
olle |
@author olle |
4903 |
10 Jul 18 |
olle |
@since 1.6.0 |
4903 |
10 Jul 18 |
olle |
35 |
*/ |
4903 |
10 Jul 18 |
olle |
36 |
public class FfpeBlock |
4903 |
10 Jul 18 |
olle |
37 |
extends MeludiItem<Sample> |
4903 |
10 Jul 18 |
olle |
38 |
{ |
4903 |
10 Jul 18 |
olle |
39 |
|
4903 |
10 Jul 18 |
olle |
40 |
/** |
4954 |
31 Aug 18 |
olle |
Find all FFPE block information. |
4954 |
31 Aug 18 |
olle |
This method will check for {@link Subtype#FFPE_BLOCK} |
4954 |
31 Aug 18 |
olle |
samples. |
4954 |
31 Aug 18 |
olle |
@since 1.6.0 |
4954 |
31 Aug 18 |
olle |
45 |
*/ |
4954 |
31 Aug 18 |
olle |
46 |
public static List<FfpeBlock> findAll(DbControl dc) |
4954 |
31 Aug 18 |
olle |
47 |
{ |
4954 |
31 Aug 18 |
olle |
// Look for an FFPE block item. |
4954 |
31 Aug 18 |
olle |
49 |
ItemQuery<Sample> ffpeBlockQuery = Sample.getQuery(); |
4954 |
31 Aug 18 |
olle |
50 |
Subtype.FFPE_BLOCK.addFilter(dc, ffpeBlockQuery); |
4954 |
31 Aug 18 |
olle |
51 |
ffpeBlockQuery.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
4954 |
31 Aug 18 |
olle |
52 |
ffpeBlockQuery.order(Orders.asc(Hql.property("name"))); |
4954 |
31 Aug 18 |
olle |
53 |
|
4954 |
31 Aug 18 |
olle |
54 |
List<Sample> tmp = ffpeBlockQuery.list(dc); |
4954 |
31 Aug 18 |
olle |
55 |
List<FfpeBlock> ffpeBlockList = new ArrayList<FfpeBlock>(tmp.size()); |
4954 |
31 Aug 18 |
olle |
56 |
for (Sample s : tmp) |
4954 |
31 Aug 18 |
olle |
57 |
{ |
4954 |
31 Aug 18 |
olle |
58 |
ffpeBlockList.add(new FfpeBlock(s)); |
4954 |
31 Aug 18 |
olle |
59 |
} |
4954 |
31 Aug 18 |
olle |
60 |
return ffpeBlockList; |
4954 |
31 Aug 18 |
olle |
61 |
} |
4954 |
31 Aug 18 |
olle |
62 |
|
4954 |
31 Aug 18 |
olle |
63 |
/** |
4903 |
10 Jul 18 |
olle |
Find all FFPE block information by case name. |
4903 |
10 Jul 18 |
olle |
This method will check for {@link Subtype#FFPE_BLOCK} |
4903 |
10 Jul 18 |
olle |
samples with a CASE_ID annotation matching the case name. |
4903 |
10 Jul 18 |
olle |
@since 1.6.0 |
4903 |
10 Jul 18 |
olle |
68 |
*/ |
4903 |
10 Jul 18 |
olle |
69 |
public static List<FfpeBlock> findAllByCaseName(DbControl dc, String name) |
4903 |
10 Jul 18 |
olle |
70 |
{ |
4903 |
10 Jul 18 |
olle |
// Look for an FFPE block item with the given case ID as annotation. |
4903 |
10 Jul 18 |
olle |
72 |
String caseId = name; |
4903 |
10 Jul 18 |
olle |
73 |
AnnotationType caseIdType = Annotationtype.CASE_ID.load(dc); |
4903 |
10 Jul 18 |
olle |
74 |
ItemQuery<Sample> ffpeBlockQuery = Sample.getQuery(); |
4903 |
10 Jul 18 |
olle |
75 |
Subtype.FFPE_BLOCK.addFilter(dc, ffpeBlockQuery); |
4903 |
10 Jul 18 |
olle |
76 |
ffpeBlockQuery.restrict(new AnnotationSimpleRestriction(null, caseIdType, Operator.EQ, caseId, true, false)); |
4903 |
10 Jul 18 |
olle |
77 |
ffpeBlockQuery.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
4903 |
10 Jul 18 |
olle |
78 |
ffpeBlockQuery.order(Orders.asc(Hql.property("name"))); |
4903 |
10 Jul 18 |
olle |
79 |
|
4903 |
10 Jul 18 |
olle |
80 |
List<Sample> tmp = ffpeBlockQuery.list(dc); |
4903 |
10 Jul 18 |
olle |
81 |
List<FfpeBlock> ffpeBlockList = new ArrayList<FfpeBlock>(tmp.size()); |
4903 |
10 Jul 18 |
olle |
82 |
for (Sample s : tmp) |
4903 |
10 Jul 18 |
olle |
83 |
{ |
4903 |
10 Jul 18 |
olle |
84 |
ffpeBlockList.add(new FfpeBlock(s)); |
4903 |
10 Jul 18 |
olle |
85 |
} |
4903 |
10 Jul 18 |
olle |
86 |
return ffpeBlockList; |
4903 |
10 Jul 18 |
olle |
87 |
} |
4903 |
10 Jul 18 |
olle |
88 |
|
4903 |
10 Jul 18 |
olle |
89 |
/** |
4903 |
10 Jul 18 |
olle |
Find an FFPE block item with the given external ID. |
4903 |
10 Jul 18 |
olle |
@return An FFPE block item, or null if not found. |
4903 |
10 Jul 18 |
olle |
@since 1.6.0 |
4903 |
10 Jul 18 |
olle |
93 |
*/ |
4903 |
10 Jul 18 |
olle |
94 |
public static FfpeBlock findByExternalId(DbControl dc, String externalId) |
4903 |
10 Jul 18 |
olle |
95 |
{ |
4903 |
10 Jul 18 |
olle |
96 |
FfpeBlock item = null; |
4903 |
10 Jul 18 |
olle |
97 |
|
4903 |
10 Jul 18 |
olle |
98 |
ItemQuery<Sample> query = Sample.getQuery(); |
4903 |
10 Jul 18 |
olle |
99 |
Subtype.FFPE_BLOCK.addFilter(dc, query); |
4903 |
10 Jul 18 |
olle |
100 |
query.restrict(Restrictions.eq(Hql.property("externalId"), Expressions.string(externalId))); |
4903 |
10 Jul 18 |
olle |
101 |
query.order(Orders.desc(Hql.property("name"))); |
4903 |
10 Jul 18 |
olle |
102 |
query.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
4903 |
10 Jul 18 |
olle |
103 |
|
4903 |
10 Jul 18 |
olle |
104 |
List<Sample> items = query.list(dc); |
4903 |
10 Jul 18 |
olle |
105 |
/* |
4903 |
10 Jul 18 |
olle |
if (items.size() > 1) |
4903 |
10 Jul 18 |
olle |
107 |
{ |
4903 |
10 Jul 18 |
olle |
throw new InvalidDataException( |
4903 |
10 Jul 18 |
olle |
"More than one FFPE block item with the external id '" + externalId + "' was found. " + |
4903 |
10 Jul 18 |
olle |
"This wizard can't be used until that is corrected."); |
4903 |
10 Jul 18 |
olle |
111 |
} |
4903 |
10 Jul 18 |
olle |
112 |
*/ |
4903 |
10 Jul 18 |
olle |
113 |
if (items.size() == 1) |
4903 |
10 Jul 18 |
olle |
114 |
{ |
4903 |
10 Jul 18 |
olle |
115 |
item = new FfpeBlock(items.get(0)); |
4903 |
10 Jul 18 |
olle |
116 |
} |
4903 |
10 Jul 18 |
olle |
117 |
return item; |
4903 |
10 Jul 18 |
olle |
118 |
} |
4903 |
10 Jul 18 |
olle |
119 |
|
4903 |
10 Jul 18 |
olle |
120 |
|
4903 |
10 Jul 18 |
olle |
121 |
/** |
4903 |
10 Jul 18 |
olle |
Find all FFPE block information linked with a patient. A patient can have any |
4903 |
10 Jul 18 |
olle |
number of FFPE block items. |
4903 |
10 Jul 18 |
olle |
124 |
*/ |
4903 |
10 Jul 18 |
olle |
125 |
public static List<FfpeBlock> findByPatient(DbControl dc, Patient patient) |
4903 |
10 Jul 18 |
olle |
126 |
{ |
4903 |
10 Jul 18 |
olle |
127 |
ItemQuery<Sample> ffpeBlockQuery = patient.getBioSource().getSamples(); |
4903 |
10 Jul 18 |
olle |
128 |
Subtype.FFPE_BLOCK.addFilter(dc, ffpeBlockQuery); |
4903 |
10 Jul 18 |
olle |
129 |
ffpeBlockQuery.include(Include.ALL); |
4903 |
10 Jul 18 |
olle |
130 |
ffpeBlockQuery.order(Orders.asc(Hql.property("name"))); |
4903 |
10 Jul 18 |
olle |
131 |
List<Sample> tmp = ffpeBlockQuery.list(dc); |
4903 |
10 Jul 18 |
olle |
132 |
List<FfpeBlock> ffpeBlock = new ArrayList<FfpeBlock>(tmp.size()); |
4903 |
10 Jul 18 |
olle |
133 |
for (Sample s : tmp) |
4903 |
10 Jul 18 |
olle |
134 |
{ |
4903 |
10 Jul 18 |
olle |
135 |
ffpeBlock.add(new FfpeBlock(s)); |
4903 |
10 Jul 18 |
olle |
136 |
} |
4903 |
10 Jul 18 |
olle |
137 |
return ffpeBlock; |
4903 |
10 Jul 18 |
olle |
138 |
} |
4903 |
10 Jul 18 |
olle |
139 |
|
4903 |
10 Jul 18 |
olle |
140 |
/** |
4903 |
10 Jul 18 |
olle |
Find blood information by PAD number. This method will check for |
4903 |
10 Jul 18 |
olle |
{@link Subtype#FFPE_BLOCK} samples annotated with PadNumber=name. |
4903 |
10 Jul 18 |
olle |
<p> |
4903 |
10 Jul 18 |
olle |
144 |
|
4903 |
10 Jul 18 |
olle |
@param dc DbControl The DbControl to use to connect to the database. |
4903 |
10 Jul 18 |
olle |
@param name String The PAD number to find an FFPE sample for. |
4903 |
10 Jul 18 |
olle |
@return FFPE An FFPE block item with the input PAD number, or null if not found. |
4903 |
10 Jul 18 |
olle |
@since 1.6.0 |
4903 |
10 Jul 18 |
olle |
149 |
*/ |
4903 |
10 Jul 18 |
olle |
150 |
public static FfpeBlock findByPadNumber(DbControl dc, String name) |
4903 |
10 Jul 18 |
olle |
151 |
{ |
4903 |
10 Jul 18 |
olle |
152 |
FfpeBlock ffpeBlock = null; |
4903 |
10 Jul 18 |
olle |
153 |
|
4903 |
10 Jul 18 |
olle |
// Return null if input PAD number is null or empty string. |
4903 |
10 Jul 18 |
olle |
155 |
if (name == null || name.equals("")) |
4903 |
10 Jul 18 |
olle |
156 |
{ |
4903 |
10 Jul 18 |
olle |
157 |
return null; |
4903 |
10 Jul 18 |
olle |
158 |
} |
4903 |
10 Jul 18 |
olle |
159 |
|
4903 |
10 Jul 18 |
olle |
// Look for an FFPE block sample with annotation BloodRccidNumber=name |
4903 |
10 Jul 18 |
olle |
161 |
ItemQuery<Sample> ffpeBlockQuery = Sample.getQuery(); |
4903 |
10 Jul 18 |
olle |
162 |
Subtype.FFPE_BLOCK.addFilter(dc, ffpeBlockQuery); |
4903 |
10 Jul 18 |
olle |
163 |
ffpeBlockQuery.restrict(new AnnotationSimpleRestriction(null, Annotationtype.PAD.load(dc), Operator.EQ, name, true, false)); |
4903 |
10 Jul 18 |
olle |
164 |
|
4903 |
10 Jul 18 |
olle |
165 |
List<Sample> ffpeBlockSamples = ffpeBlockQuery.list(dc); |
4903 |
10 Jul 18 |
olle |
166 |
|
4903 |
10 Jul 18 |
olle |
167 |
/* |
4903 |
10 Jul 18 |
olle |
// ...if more than one is found, something is incorrectly registered... abort |
4903 |
10 Jul 18 |
olle |
if (ffpeBlockSamples.size() > 1) |
4903 |
10 Jul 18 |
olle |
170 |
{ |
4903 |
10 Jul 18 |
olle |
throw new InvalidDataException( |
4903 |
10 Jul 18 |
olle |
"Found " + ffpeBlockSamples.size() + " FFPE block samples with same PAD number (" + name + |
4903 |
10 Jul 18 |
olle |
"). This wizard can't be used until that is corrected."); |
4903 |
10 Jul 18 |
olle |
174 |
} |
4903 |
10 Jul 18 |
olle |
175 |
*/ |
4903 |
10 Jul 18 |
olle |
176 |
|
4903 |
10 Jul 18 |
olle |
177 |
if (ffpeBlockSamples.size() == 1) |
4903 |
10 Jul 18 |
olle |
178 |
{ |
4903 |
10 Jul 18 |
olle |
179 |
ffpeBlock = new FfpeBlock(ffpeBlockSamples.get(0)); |
4903 |
10 Jul 18 |
olle |
180 |
} |
4903 |
10 Jul 18 |
olle |
181 |
|
4903 |
10 Jul 18 |
olle |
182 |
return ffpeBlock; |
4903 |
10 Jul 18 |
olle |
183 |
} |
4903 |
10 Jul 18 |
olle |
184 |
|
4903 |
10 Jul 18 |
olle |
185 |
/** |
4903 |
10 Jul 18 |
olle |
Generate the next auto-generated FFPE block name. This method will search all FFPE block item |
4903 |
10 Jul 18 |
olle |
samples starting with the given prefix and find the one with the highest numeric |
4903 |
10 Jul 18 |
olle |
suffix. The returned name is the found FFPE block + 1. |
4903 |
10 Jul 18 |
olle |
@since 2.5 |
4903 |
10 Jul 18 |
olle |
190 |
*/ |
4903 |
10 Jul 18 |
olle |
191 |
public static String generateNextName(DbControl dc, String prefix, Subtype subtype) |
4903 |
10 Jul 18 |
olle |
192 |
{ |
4903 |
10 Jul 18 |
olle |
193 |
ItemQuery<Sample> ffpeBlockQuery = Sample.getQuery(); |
4903 |
10 Jul 18 |
olle |
194 |
if (subtype != null) subtype.addFilter(dc, ffpeBlockQuery); |
4903 |
10 Jul 18 |
olle |
195 |
ffpeBlockQuery.restrict(Restrictions.rlike(Hql.property("name"), Expressions.string("^" + prefix + "[0-9]*$"))); |
4903 |
10 Jul 18 |
olle |
196 |
ffpeBlockQuery.order(Orders.desc(Hql.property("name"))); |
4903 |
10 Jul 18 |
olle |
197 |
ffpeBlockQuery.setMaxResults(1); |
4903 |
10 Jul 18 |
olle |
198 |
ffpeBlockQuery.include(Include.ALL); |
4903 |
10 Jul 18 |
olle |
199 |
List<Sample> ffpeBlock = ffpeBlockQuery.list(dc); |
4903 |
10 Jul 18 |
olle |
200 |
String name = null; |
4903 |
10 Jul 18 |
olle |
201 |
if (ffpeBlock.size() == 0) |
4903 |
10 Jul 18 |
olle |
202 |
{ |
4903 |
10 Jul 18 |
olle |
// First FFPE block sample should not have any numeric suffix |
4903 |
10 Jul 18 |
olle |
204 |
name = prefix; |
4903 |
10 Jul 18 |
olle |
205 |
} |
4903 |
10 Jul 18 |
olle |
206 |
else |
4903 |
10 Jul 18 |
olle |
207 |
{ |
4903 |
10 Jul 18 |
olle |
208 |
String suffix = ffpeBlock.get(0).getName().substring(prefix.length()); |
4903 |
10 Jul 18 |
olle |
209 |
int nextSuffix = Values.getInt(suffix, 1) + 1; |
4903 |
10 Jul 18 |
olle |
210 |
name = prefix + nextSuffix; |
4903 |
10 Jul 18 |
olle |
211 |
} |
4903 |
10 Jul 18 |
olle |
212 |
return name; |
4903 |
10 Jul 18 |
olle |
213 |
} |
4903 |
10 Jul 18 |
olle |
214 |
|
4903 |
10 Jul 18 |
olle |
// Reserve external ids for 5 minutes |
4903 |
10 Jul 18 |
olle |
216 |
private static final ReservedItems<Integer> RESERVED_EXTERNAL_IDS = new ReservedItems<Integer>(300); |
4903 |
10 Jul 18 |
olle |
217 |
|
4903 |
10 Jul 18 |
olle |
218 |
/** |
4903 |
10 Jul 18 |
olle |
Generate the next auto-generated external ID. This method will search all FFPE block items |
4903 |
10 Jul 18 |
olle |
starting with the given prefix and find the one with the highest numeric suffix. |
4903 |
10 Jul 18 |
olle |
The returned string is the found FFPE block + 1. This method uses the |
4903 |
10 Jul 18 |
olle |
{@link ReservedItems} to make sure that the same id is not generated |
4903 |
10 Jul 18 |
olle |
twice. |
4903 |
10 Jul 18 |
olle |
@since 1.6.0 |
4903 |
10 Jul 18 |
olle |
225 |
*/ |
4903 |
10 Jul 18 |
olle |
226 |
public static String generateNextExternalId(DbControl dc, String prefix) |
4903 |
10 Jul 18 |
olle |
227 |
{ |
4903 |
10 Jul 18 |
olle |
228 |
ItemQuery<Sample> ffpeBlockQuery = Sample.getQuery(); |
4903 |
10 Jul 18 |
olle |
229 |
Subtype.BLOOD.addFilter(dc, ffpeBlockQuery); |
4903 |
10 Jul 18 |
olle |
230 |
ffpeBlockQuery.restrict(Restrictions.rlike(Hql.property("externalId"), Expressions.string("^" + prefix + "[0-9]+$"))); |
4903 |
10 Jul 18 |
olle |
231 |
ffpeBlockQuery.order(Orders.desc(Hql.property("externalId"))); |
4903 |
10 Jul 18 |
olle |
232 |
ffpeBlockQuery.setMaxResults(1); |
4903 |
10 Jul 18 |
olle |
233 |
ffpeBlockQuery.include(Include.ALL); |
4903 |
10 Jul 18 |
olle |
234 |
List<Sample> ffpeBlock = ffpeBlockQuery.list(dc); |
4903 |
10 Jul 18 |
olle |
235 |
|
4903 |
10 Jul 18 |
olle |
236 |
int nextExternalNumber = 1; |
4903 |
10 Jul 18 |
olle |
237 |
if (ffpeBlock.size() > 0) |
4903 |
10 Jul 18 |
olle |
238 |
{ |
4903 |
10 Jul 18 |
olle |
239 |
String externalNumber = ffpeBlock.get(0).getExternalId().substring(prefix.length()); |
4903 |
10 Jul 18 |
olle |
240 |
nextExternalNumber = Integer.parseInt(externalNumber) + 1; |
4903 |
10 Jul 18 |
olle |
241 |
} |
4903 |
10 Jul 18 |
olle |
242 |
int maxExternalNumber = 100+nextExternalNumber; |
4903 |
10 Jul 18 |
olle |
243 |
while (!RESERVED_EXTERNAL_IDS.reserve(nextExternalNumber)) |
4903 |
10 Jul 18 |
olle |
244 |
{ |
4903 |
10 Jul 18 |
olle |
245 |
nextExternalNumber++; |
4903 |
10 Jul 18 |
olle |
246 |
if (nextExternalNumber == maxExternalNumber) |
4903 |
10 Jul 18 |
olle |
247 |
{ |
4903 |
10 Jul 18 |
olle |
248 |
throw new RuntimeException("Failed to generate an external ID after 100 tries"); |
4903 |
10 Jul 18 |
olle |
249 |
} |
4903 |
10 Jul 18 |
olle |
250 |
} |
4903 |
10 Jul 18 |
olle |
251 |
String externalId = prefix + MD5.leftPad(Integer.toString(nextExternalNumber), '0', 6); |
4903 |
10 Jul 18 |
olle |
252 |
return externalId; |
4903 |
10 Jul 18 |
olle |
253 |
} |
4903 |
10 Jul 18 |
olle |
254 |
|
4903 |
10 Jul 18 |
olle |
255 |
/** |
4903 |
10 Jul 18 |
olle |
Load an FFPE block sample given the exact name of the item. |
4903 |
10 Jul 18 |
olle |
@since 1.6.0 |
4903 |
10 Jul 18 |
olle |
258 |
*/ |
4903 |
10 Jul 18 |
olle |
259 |
public static FfpeBlock getByName(DbControl dc, String name) |
4903 |
10 Jul 18 |
olle |
260 |
{ |
4903 |
10 Jul 18 |
olle |
261 |
FfpeBlock ffpeBlock = null; |
4903 |
10 Jul 18 |
olle |
262 |
|
4903 |
10 Jul 18 |
olle |
// Look for an FFPE block with the given name |
4903 |
10 Jul 18 |
olle |
264 |
ItemQuery<Sample> ffpeBlockQuery = Sample.getQuery(); |
4903 |
10 Jul 18 |
olle |
265 |
Subtype.FFPE_BLOCK.addFilter(dc, ffpeBlockQuery); |
4903 |
10 Jul 18 |
olle |
266 |
ffpeBlockQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", name, Type.STRING))); |
4903 |
10 Jul 18 |
olle |
267 |
|
4903 |
10 Jul 18 |
olle |
268 |
List<Sample> ffpeBlockSamples = ffpeBlockQuery.list(dc); |
4903 |
10 Jul 18 |
olle |
269 |
|
4903 |
10 Jul 18 |
olle |
270 |
/* |
4903 |
10 Jul 18 |
olle |
// ...if more than one is found, something is incorrectly registered... abort |
4903 |
10 Jul 18 |
olle |
if (ffpeBlockSamples.size() > 1) |
4903 |
10 Jul 18 |
olle |
273 |
{ |
4903 |
10 Jul 18 |
olle |
throw new InvalidDataException( |
4903 |
10 Jul 18 |
olle |
"Found " + ffpeBlockSamples.size() + " FFPE block samples with the same name (" + name + |
4903 |
10 Jul 18 |
olle |
"). This wizard can't be used until that is corrected."); |
4903 |
10 Jul 18 |
olle |
277 |
} |
4903 |
10 Jul 18 |
olle |
278 |
*/ |
4903 |
10 Jul 18 |
olle |
279 |
|
4903 |
10 Jul 18 |
olle |
280 |
if (ffpeBlockSamples.size() == 1) |
4903 |
10 Jul 18 |
olle |
281 |
{ |
4903 |
10 Jul 18 |
olle |
282 |
ffpeBlock = new FfpeBlock(ffpeBlockSamples.get(0)); |
4903 |
10 Jul 18 |
olle |
283 |
} |
4903 |
10 Jul 18 |
olle |
284 |
|
4903 |
10 Jul 18 |
olle |
285 |
return ffpeBlock; |
4903 |
10 Jul 18 |
olle |
286 |
} |
4903 |
10 Jul 18 |
olle |
287 |
|
4903 |
10 Jul 18 |
olle |
288 |
public static FfpeBlock getById(DbControl dc, int itemId) |
4903 |
10 Jul 18 |
olle |
289 |
{ |
4903 |
10 Jul 18 |
olle |
290 |
Sample s = Sample.getById(dc, itemId); |
4903 |
10 Jul 18 |
olle |
291 |
return s == null ? null : new FfpeBlock(s); |
4903 |
10 Jul 18 |
olle |
292 |
} |
4903 |
10 Jul 18 |
olle |
293 |
|
4903 |
10 Jul 18 |
olle |
294 |
private FfpeBlock(Sample sample) |
4903 |
10 Jul 18 |
olle |
295 |
{ |
4903 |
10 Jul 18 |
olle |
296 |
super(sample); |
4903 |
10 Jul 18 |
olle |
297 |
} |
4903 |
10 Jul 18 |
olle |
298 |
|
4903 |
10 Jul 18 |
olle |
299 |
|
4903 |
10 Jul 18 |
olle |
300 |
/** |
4903 |
10 Jul 18 |
olle |
Get the real sample that represents this case in BASE. |
4903 |
10 Jul 18 |
olle |
302 |
*/ |
4903 |
10 Jul 18 |
olle |
303 |
public Sample getSample() |
4903 |
10 Jul 18 |
olle |
304 |
{ |
4903 |
10 Jul 18 |
olle |
305 |
return getItem(); |
4903 |
10 Jul 18 |
olle |
306 |
} |
4903 |
10 Jul 18 |
olle |
307 |
|
4903 |
10 Jul 18 |
olle |
308 |
private JSONObject jsonWell; |
4903 |
10 Jul 18 |
olle |
309 |
|
4903 |
10 Jul 18 |
olle |
310 |
@SuppressWarnings("unchecked") |
4903 |
10 Jul 18 |
olle |
311 |
@Override |
4903 |
10 Jul 18 |
olle |
312 |
protected void initJSON(JSONObject json) |
4903 |
10 Jul 18 |
olle |
313 |
{ |
4903 |
10 Jul 18 |
olle |
314 |
super.initJSON(json); |
4903 |
10 Jul 18 |
olle |
315 |
if (jsonWell != null) json.put("bioWell", jsonWell); |
4903 |
10 Jul 18 |
olle |
316 |
} |
4903 |
10 Jul 18 |
olle |
317 |
|
4903 |
10 Jul 18 |
olle |
318 |
/** |
4903 |
10 Jul 18 |
olle |
Load information about the plate and location the current FFPE block |
4903 |
10 Jul 18 |
olle |
is located on. |
4903 |
10 Jul 18 |
olle |
321 |
*/ |
4903 |
10 Jul 18 |
olle |
322 |
public JSONObject loadBioPlateLocation() |
4903 |
10 Jul 18 |
olle |
323 |
{ |
4903 |
10 Jul 18 |
olle |
324 |
if (jsonWell == null) |
4903 |
10 Jul 18 |
olle |
325 |
{ |
4903 |
10 Jul 18 |
olle |
326 |
jsonWell = JsonUtil.getBioWellAsJSON(getItem().getBioWell(), true); |
4903 |
10 Jul 18 |
olle |
327 |
} |
4903 |
10 Jul 18 |
olle |
328 |
return jsonWell; |
4903 |
10 Jul 18 |
olle |
329 |
} |
4903 |
10 Jul 18 |
olle |
330 |
|
4903 |
10 Jul 18 |
olle |
331 |
/** |
4903 |
10 Jul 18 |
olle |
Verify that the patient has given their permission to participate in the |
4903 |
10 Jul 18 |
olle |
study. Due to the order that things get registered, a non-existing "Consent" |
4903 |
10 Jul 18 |
olle |
annotation is accepted. If the annotation exists the answer must be "Yes", |
4903 |
10 Jul 18 |
olle |
or an exception is thrown. |
4903 |
10 Jul 18 |
olle |
336 |
*/ |
4903 |
10 Jul 18 |
olle |
337 |
public void verifyConsent(DbControl dc, Annotationtype consentType) |
4903 |
10 Jul 18 |
olle |
338 |
{ |
4903 |
10 Jul 18 |
olle |
339 |
if (consentType == null) |
4903 |
10 Jul 18 |
olle |
340 |
{ |
4903 |
10 Jul 18 |
olle |
341 |
consentType = Annotationtype.CONSENT; |
4903 |
10 Jul 18 |
olle |
342 |
} |
4903 |
10 Jul 18 |
olle |
343 |
String consent = (String)consentType.getAnnotationValue(dc, getItem()); |
4903 |
10 Jul 18 |
olle |
344 |
if (consent != null && !consent.equals("Yes")) |
4903 |
10 Jul 18 |
olle |
345 |
{ |
4903 |
10 Jul 18 |
olle |
346 |
throw new PermissionDeniedException("The case (" + getName() + |
4903 |
10 Jul 18 |
olle |
347 |
") has not agreed to participate in the study."); |
4903 |
10 Jul 18 |
olle |
348 |
} |
4903 |
10 Jul 18 |
olle |
349 |
|
4903 |
10 Jul 18 |
olle |
350 |
} |
4903 |
10 Jul 18 |
olle |
351 |
} |