1 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
2 | import grails.util.GrailsUtil |
---|
3 | import dbnp.studycapturing.* |
---|
4 | |
---|
5 | import dbnp.data.Ontology |
---|
6 | import dbnp.data.Term |
---|
7 | import java.text.SimpleDateFormat |
---|
8 | |
---|
9 | /** |
---|
10 | * Application Bootstrapper |
---|
11 | * @Author Jeroen Wesbeek |
---|
12 | * @Since 20091021 |
---|
13 | * |
---|
14 | * Revision information: |
---|
15 | * $Rev: 239 $ |
---|
16 | * $Author: keesvb $ |
---|
17 | * $Date: 2010-03-05 15:46:29 +0000 (vr, 05 mrt 2010) $ |
---|
18 | */ |
---|
19 | class BootStrap { |
---|
20 | def init = {servletContext -> |
---|
21 | // define timezone |
---|
22 | System.setProperty('user.timezone', 'CET') |
---|
23 | |
---|
24 | if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) { |
---|
25 | printf("development bootstrapping....\n\n"); |
---|
26 | |
---|
27 | // ontologies |
---|
28 | def speciesOntology = new Ontology( |
---|
29 | name: 'NCBI Taxonomy', |
---|
30 | shortName: 'Taxon', |
---|
31 | url: 'http://www.obofoundry.org/cgi-bin/detail.cgi?id=ncbi_taxonomy' |
---|
32 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
33 | |
---|
34 | def humanBodyOntology = new Ontology( |
---|
35 | name: 'Foundational Model of Anatomy', |
---|
36 | shortName: 'HumanBody', |
---|
37 | url: 'http://bioportal.bioontology.org/ontologies/39966' |
---|
38 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
39 | |
---|
40 | // terms |
---|
41 | def mouseTerm = new Term( |
---|
42 | name: 'Mus musculus', |
---|
43 | ontology: speciesOntology, |
---|
44 | accession: '10090' |
---|
45 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
46 | def humanTerm = new Term( |
---|
47 | name: 'Homo sapiens', |
---|
48 | ontology: speciesOntology, |
---|
49 | accession: '9606' |
---|
50 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
51 | |
---|
52 | def bloodTerm = new Term( |
---|
53 | name: 'Portion of blood', |
---|
54 | ontology: humanBodyOntology, |
---|
55 | accession: '9670' |
---|
56 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
57 | |
---|
58 | def madmaxOntology = new Ontology( |
---|
59 | name: 'Madmax ontology', |
---|
60 | shortName: 'MDMX', |
---|
61 | url: 'madmax.bioinformatics.nl' |
---|
62 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
63 | |
---|
64 | def treatmentTerm = new Term( |
---|
65 | name: 'ExperimentalProtocol', |
---|
66 | ontology: madmaxOntology, |
---|
67 | accession: 'P-MDMXGE-264' |
---|
68 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
69 | |
---|
70 | def dietProtocol = new Protocol( |
---|
71 | name: 'Diet treatment Protocol NuGO PPS3 leptin module', |
---|
72 | reference: treatmentTerm |
---|
73 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
74 | |
---|
75 | def boostProtocol = new Protocol( |
---|
76 | name: 'Boost treatment Protocol NuGO PPS3 leptin module', |
---|
77 | reference: treatmentTerm |
---|
78 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
79 | |
---|
80 | def fastingProtocol = new Protocol( |
---|
81 | name: 'Fasting', |
---|
82 | reference: treatmentTerm |
---|
83 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
84 | |
---|
85 | |
---|
86 | // ParameterStringListItems |
---|
87 | def oil10= new ParameterStringListItem( |
---|
88 | name: '10% fat (palm oil)' |
---|
89 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
90 | def oil45= new ParameterStringListItem( |
---|
91 | name: '45% fat (palm oil)' |
---|
92 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
93 | def vehicle= new ParameterStringListItem( |
---|
94 | name: 'Vehicle' |
---|
95 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
96 | def leptin= new ParameterStringListItem( |
---|
97 | name: 'Leptin' |
---|
98 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
99 | |
---|
100 | |
---|
101 | dietProtocol |
---|
102 | .addToParameters(new ProtocolParameter( |
---|
103 | name: 'Diet', |
---|
104 | type: ProtocolParameterType.STRINGLIST, |
---|
105 | listEntries: [oil10,oil45])) |
---|
106 | .save() |
---|
107 | |
---|
108 | boostProtocol |
---|
109 | .addToParameters(new ProtocolParameter( |
---|
110 | name: 'Compound', |
---|
111 | type: ProtocolParameterType.STRINGLIST, |
---|
112 | listEntries: [vehicle,leptin])) |
---|
113 | .save() |
---|
114 | |
---|
115 | fastingProtocol |
---|
116 | .addToParameters(new ProtocolParameter( |
---|
117 | name: 'Fasting period', |
---|
118 | type: ProtocolParameterType.STRING)) |
---|
119 | .save() |
---|
120 | |
---|
121 | |
---|
122 | // sampling event protocols |
---|
123 | |
---|
124 | def liverSamplingProtocol = new Protocol( |
---|
125 | name: 'Liver sampling' |
---|
126 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
127 | |
---|
128 | liverSamplingProtocol |
---|
129 | .addToParameters(new ProtocolParameter( |
---|
130 | name: 'Sample weight', |
---|
131 | unit: 'mg', |
---|
132 | type: ProtocolParameterType.FLOAT)) |
---|
133 | .save() |
---|
134 | |
---|
135 | def bloodSamplingProtocol = new Protocol( |
---|
136 | name: 'Liver sampling' |
---|
137 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
138 | |
---|
139 | bloodSamplingProtocol |
---|
140 | .addToParameters(new ProtocolParameter( |
---|
141 | name: 'Sample volume', |
---|
142 | unit: 'ml', |
---|
143 | type: ProtocolParameterType.FLOAT)) |
---|
144 | .save() |
---|
145 | |
---|
146 | // create system user |
---|
147 | |
---|
148 | /*def systemUser = userService.createUser(InstanceGenerator.user( |
---|
149 | username: 'system', |
---|
150 | pass: 'system', |
---|
151 | passConfirm: 'system', |
---|
152 | enabled: true |
---|
153 | ))*/ |
---|
154 | |
---|
155 | |
---|
156 | def genderField = new TemplateField( |
---|
157 | name: 'Gender',type: TemplateFieldType.STRINGLIST, |
---|
158 | listEntries: [new TemplateFieldListItem(name:'Male'),new TemplateFieldListItem(name: 'Female')]) |
---|
159 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
160 | |
---|
161 | def ageField = new TemplateField( |
---|
162 | name: 'Age',type: TemplateFieldType.INTEGER) |
---|
163 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
164 | |
---|
165 | // Nutritional study template |
---|
166 | |
---|
167 | def studyTemplate = new Template( |
---|
168 | name: 'Nutritional study', entity: dbnp.studycapturing.Study |
---|
169 | ).addToFields(new TemplateField( |
---|
170 | name: 'NuGO Code',type: TemplateFieldType.STRING) |
---|
171 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
172 | |
---|
173 | |
---|
174 | // Mouse template |
---|
175 | def mouseTemplate = new Template( |
---|
176 | name: 'Mouse', entity: dbnp.studycapturing.Subject |
---|
177 | ).addToFields(new TemplateField( |
---|
178 | name: 'Genotype',type: TemplateFieldType.STRINGLIST, |
---|
179 | listEntries: [new TemplateFieldListItem(name:'C57/Bl6j'),new TemplateFieldListItem(name:'wild type')])) |
---|
180 | .addToFields(genderField) |
---|
181 | .addToFields(ageField) |
---|
182 | .addToFields(new TemplateField( |
---|
183 | name: 'Cage',type: TemplateFieldType.INTEGER)) |
---|
184 | .addToFields(new TemplateField( |
---|
185 | name: 'Some double', type: TemplateFieldType.DOUBLE)) |
---|
186 | .addToFields(new TemplateField( |
---|
187 | name: 'Some ontology', type: TemplateFieldType.ONTOLOGYTERM)) |
---|
188 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
189 | |
---|
190 | // Human template |
---|
191 | def humanTemplate = new Template( |
---|
192 | name: 'Human', entity: dbnp.studycapturing.Subject) |
---|
193 | .addToFields(genderField) |
---|
194 | .addToFields(ageField) |
---|
195 | .addToFields(new TemplateField( |
---|
196 | name: 'DOB',type: TemplateFieldType.DATE)) |
---|
197 | .addToFields(new TemplateField( |
---|
198 | name: 'Height',type: TemplateFieldType.DOUBLE)) |
---|
199 | .addToFields(new TemplateField( |
---|
200 | name: 'Weight',type: TemplateFieldType.DOUBLE)) |
---|
201 | .addToFields(new TemplateField( |
---|
202 | name: 'BMI',type: TemplateFieldType.DOUBLE)) |
---|
203 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
204 | |
---|
205 | //events |
---|
206 | def eventDiet = new EventDescription( |
---|
207 | name: 'Diet treatment', |
---|
208 | description: 'Diet treatment (fat percentage)', |
---|
209 | classification: treatmentTerm, |
---|
210 | protocol: dietProtocol, |
---|
211 | isSamplingEvent: false |
---|
212 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
213 | |
---|
214 | def eventBoost = new EventDescription( |
---|
215 | name: 'Boost treatment', |
---|
216 | description: 'Boost treatment (leptin or vehicle)', |
---|
217 | classification: treatmentTerm, |
---|
218 | protocol: boostProtocol, |
---|
219 | isSamplingEvent: false |
---|
220 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
221 | |
---|
222 | def samplingEvent = new EventDescription( |
---|
223 | name: 'Liver extraction', |
---|
224 | description: 'Liver sampling for transcriptomics arrays', |
---|
225 | protocol: liverSamplingProtocol, |
---|
226 | isSamplingEvent: true |
---|
227 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
228 | |
---|
229 | def bloodSamplingEventDescription = new EventDescription( |
---|
230 | name: 'Blood extraction', |
---|
231 | description: 'Blood extraction targeted at lipid assays', |
---|
232 | protocol: bloodSamplingProtocol, |
---|
233 | isSamplingEvent: true |
---|
234 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
235 | |
---|
236 | |
---|
237 | def fastingTreatment = new EventDescription( |
---|
238 | name: 'Fasting treatment', |
---|
239 | description: 'Fasting Protocol NuGO PPSH', |
---|
240 | protocol: fastingProtocol, |
---|
241 | isSamplingEvent: false |
---|
242 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
243 | |
---|
244 | println('Adding PPS3 study...') |
---|
245 | |
---|
246 | // studies |
---|
247 | def exampleStudy = new Study( |
---|
248 | template: studyTemplate, |
---|
249 | title:"NuGO PPS3 mouse study leptin module", |
---|
250 | code:"PPS3_leptin_module", |
---|
251 | researchQuestion:"Leptin etc.", |
---|
252 | description:"C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet. After 1 week 10 mice that received a low fat diet were given an IP leptin challenge and 10 mice of the low-fat group received placebo injections. The same procedure was performed with mice that were fed the high-fat diet. After 4 weeks the procedure was repeated. In total 80 mice were culled.", |
---|
253 | ecCode:"2007117.c", |
---|
254 | startDate: Date.parse('yyyy-MM-dd','2007-12-11') |
---|
255 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
256 | |
---|
257 | def evLF = new Event( |
---|
258 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
259 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
260 | eventDescription: eventDiet, |
---|
261 | parameterStringValues: ['Diet':'10% fat (palm oil)'] |
---|
262 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
263 | |
---|
264 | def evHF = new Event( |
---|
265 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
266 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
267 | eventDescription: eventDiet, |
---|
268 | parameterStringValues: ['Diet':'45% fat (palm oil)'] |
---|
269 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
270 | |
---|
271 | def evBV = new Event( |
---|
272 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
273 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
274 | eventDescription: eventBoost, |
---|
275 | parameterStringValues: ['Compound':'Vehicle'] |
---|
276 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
277 | |
---|
278 | def evBL = new Event( |
---|
279 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
280 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
281 | eventDescription: eventBoost, |
---|
282 | parameterStringValues: ['Compound':'Leptin'] |
---|
283 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
284 | |
---|
285 | def evLF4 = new Event( |
---|
286 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
287 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
288 | eventDescription: eventDiet, |
---|
289 | parameterStringValues: ['Diet':'10% fat (palm oil)'] |
---|
290 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
291 | |
---|
292 | def evHF4 = new Event( |
---|
293 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
294 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
295 | eventDescription: eventDiet, |
---|
296 | parameterStringValues: ['Diet':'45% fat (palm oil)'] |
---|
297 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
298 | |
---|
299 | def evBV4 = new Event( |
---|
300 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
301 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
302 | eventDescription: eventBoost, |
---|
303 | parameterStringValues: ['Compound':'Vehicle'] |
---|
304 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
305 | |
---|
306 | def evBL4 = new Event( |
---|
307 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
308 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
309 | eventDescription: eventBoost, |
---|
310 | parameterStringValues: ['Compound':'Leptin'] |
---|
311 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
312 | |
---|
313 | def evS = new SamplingEvent( |
---|
314 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
315 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
316 | eventDescription: samplingEvent, |
---|
317 | parameterFloatValues: ['Sample weight':5F] |
---|
318 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
319 | |
---|
320 | def evS4 = new SamplingEvent( |
---|
321 | startTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
322 | endTime: Date.parse('yyyy-MM-dd','2008-02-04'), |
---|
323 | eventDescription: samplingEvent, |
---|
324 | parameterFloatValues: ['Sample weight':5F] |
---|
325 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
326 | |
---|
327 | // Add events to study |
---|
328 | exampleStudy |
---|
329 | .addToEvents(evLF) |
---|
330 | .addToEvents(evHF) |
---|
331 | .addToEvents(evBV) |
---|
332 | .addToEvents(evBL) |
---|
333 | .addToEvents(evLF4) |
---|
334 | .addToEvents(evHF4) |
---|
335 | .addToEvents(evBV4) |
---|
336 | .addToEvents(evBL4) |
---|
337 | .addToSamplingEvents(evS) |
---|
338 | .addToSamplingEvents(evS4) |
---|
339 | .save() |
---|
340 | |
---|
341 | def LFBV1 = new EventGroup(name:"10% fat + vehicle for 1 week") |
---|
342 | .addToEvents(evLF) |
---|
343 | .addToEvents(evBV) |
---|
344 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
345 | |
---|
346 | def LFBL1 = new EventGroup(name:"10% fat + leptin for 1 week") |
---|
347 | .addToEvents(evLF) |
---|
348 | .addToEvents(evBL) |
---|
349 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
350 | |
---|
351 | def HFBV1 = new EventGroup(name:"45% fat + vehicle for 1 week") |
---|
352 | .addToEvents(evHF) |
---|
353 | .addToEvents(evBV) |
---|
354 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
355 | |
---|
356 | def HFBL1 = new EventGroup(name:"45% fat + leptin for 1 week") |
---|
357 | .addToEvents(evHF) |
---|
358 | .addToEvents(evBL) |
---|
359 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
360 | |
---|
361 | def LFBV4 = new EventGroup(name:"10% fat + vehicle for 4 weeks") |
---|
362 | .addToEvents(evLF4) |
---|
363 | .addToEvents(evBV4) |
---|
364 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
365 | |
---|
366 | def LFBL4 = new EventGroup(name:"10% fat + leptin for 4 weeks") |
---|
367 | .addToEvents(evLF4) |
---|
368 | .addToEvents(evBL4) |
---|
369 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
370 | |
---|
371 | def HFBV4 = new EventGroup(name:"45% fat + vehicle for 4 weeks") |
---|
372 | .addToEvents(evHF4) |
---|
373 | .addToEvents(evBV4) |
---|
374 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
375 | |
---|
376 | def HFBL4 = new EventGroup(name:"45% fat + leptin for 4 weeks") |
---|
377 | .addToEvents(evHF4) |
---|
378 | .addToEvents(evBL4) |
---|
379 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
380 | |
---|
381 | |
---|
382 | |
---|
383 | def x=1 |
---|
384 | 80.times { |
---|
385 | def currentSubject = new Subject( |
---|
386 | name: "A" + x++, |
---|
387 | species: mouseTerm, |
---|
388 | template: mouseTemplate, |
---|
389 | ) |
---|
390 | .setFieldValue("Gender", "Male") |
---|
391 | .setFieldValue("Genotype", "C57/Bl6j") |
---|
392 | .setFieldValue("Age", 17) |
---|
393 | .setFieldValue("Cage", (int)(x/2)) |
---|
394 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
395 | |
---|
396 | exampleStudy.addToSubjects(currentSubject) |
---|
397 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
398 | |
---|
399 | // Add subject to appropriate EventGroup |
---|
400 | if (x > 70) { HFBL4.addToSubjects(currentSubject).save() } |
---|
401 | else if (x > 60) { HFBV4.addToSubjects(currentSubject).save() } |
---|
402 | else if (x > 50) { LFBL4.addToSubjects(currentSubject).save() } |
---|
403 | else if (x > 40) { LFBV4.addToSubjects(currentSubject).save() } |
---|
404 | else if (x > 30) { HFBL1.addToSubjects(currentSubject).save() } |
---|
405 | else if (x > 20) { HFBV1.addToSubjects(currentSubject).save() } |
---|
406 | else if (x > 10) { LFBL1.addToSubjects(currentSubject).save() } |
---|
407 | else { LFBV1.addToSubjects(currentSubject).save() } |
---|
408 | |
---|
409 | } |
---|
410 | |
---|
411 | // Add EventGroups to study |
---|
412 | exampleStudy |
---|
413 | .addToEventGroups(LFBV1) |
---|
414 | .addToEventGroups(LFBL1) |
---|
415 | .addToEventGroups(HFBV1) |
---|
416 | .addToEventGroups(HFBL1) |
---|
417 | .addToEventGroups(LFBV4) |
---|
418 | .addToEventGroups(LFBL4) |
---|
419 | .addToEventGroups(HFBV4) |
---|
420 | .addToEventGroups(HFBL4) |
---|
421 | .save() |
---|
422 | |
---|
423 | println 'Adding PPSH study' |
---|
424 | |
---|
425 | def humanStudy = new Study( |
---|
426 | template: studyTemplate, |
---|
427 | title:"NuGO PPS human study", |
---|
428 | code:"PPSH", |
---|
429 | researchQuestion:"How much are fasting plasma and urine metabolite levels affected by prolonged fasting ?", |
---|
430 | description:"Human study", |
---|
431 | ecCode:"unknown", |
---|
432 | startDate: Date.parse('yyyy-MM-dd','2009-01-01') |
---|
433 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
434 | |
---|
435 | def fastingEvent = new Event( |
---|
436 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
437 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
438 | eventDescription: fastingTreatment, |
---|
439 | parameterStringValues: ['Fasting period':'8h']); |
---|
440 | |
---|
441 | def bloodSamplingEvent = new SamplingEvent( |
---|
442 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
443 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
444 | eventDescription: bloodSamplingEventDescription, |
---|
445 | parameterFloatValues: ['Sample volume':4.5F]); |
---|
446 | |
---|
447 | def rootGroup = new EventGroup(name: 'Root group'); |
---|
448 | rootGroup.addToEvents fastingEvent |
---|
449 | rootGroup.addToEvents bloodSamplingEvent |
---|
450 | rootGroup.save() |
---|
451 | |
---|
452 | def y=1 |
---|
453 | 11.times { |
---|
454 | def currentSubject = new Subject( |
---|
455 | name: "" + y++, |
---|
456 | species: humanTerm, |
---|
457 | template: humanTemplate) |
---|
458 | .setFieldValue("Gender", (boolean)(x/2) ? "Male" : "Female") |
---|
459 | .setFieldValue("DOB", new java.text.SimpleDateFormat("dd-mm-yy").parse("01-02-19"+(10+(int)(Math.random()*80)))) |
---|
460 | .setFieldValue("Age", 30) |
---|
461 | .setFieldValue("Height",Math.random()*2F) |
---|
462 | .setFieldValue("Weight",Math.random()*150F) |
---|
463 | .setFieldValue("BMI",20 + Math.random()*10F) |
---|
464 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
465 | |
---|
466 | def currentSample = new Sample( |
---|
467 | name: currentSubject.name + '_B', |
---|
468 | material: bloodTerm, |
---|
469 | parentSubject: currentSubject, |
---|
470 | parentEvent: bloodSamplingEvent); |
---|
471 | |
---|
472 | rootGroup.addToSubjects currentSubject |
---|
473 | rootGroup.save() |
---|
474 | |
---|
475 | humanStudy.addToSubjects(currentSubject) |
---|
476 | .addToSamples(currentSample) |
---|
477 | .addToEventGroups rootGroup |
---|
478 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
479 | } |
---|
480 | |
---|
481 | humanStudy.addToEventGroups(rootGroup).save() |
---|
482 | |
---|
483 | // new Study(title:"example",code:"Excode",researchQuestion:"ExRquestion",description:"Exdescription",ecCode:"ExecCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save() |
---|
484 | // new Study(title:"testAgain",code:"testcode",researchQuestion:"testRquestion",description:"testdescription",ecCode:"testCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save() |
---|
485 | // new Study(title:"Exampletest",code:"Examplecode",researchQuestion:"ExampleRquestion",description:"Exampledescription",ecCode:"ExampleecCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save() |
---|
486 | |
---|
487 | // Add clinical data |
---|
488 | |
---|
489 | def lipidAssay = new dbnp.clinicaldata.ClinicalAssay( |
---|
490 | name: 'Lipid profile', |
---|
491 | approved: true |
---|
492 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
493 | |
---|
494 | def ldlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( |
---|
495 | name: 'LDL', |
---|
496 | unit: 'mg/dL', |
---|
497 | type: dbnp.data.FeatureType.QUANTITATIVE, |
---|
498 | referenceValues: '100 mg/dL', |
---|
499 | detectableLimit: 250, |
---|
500 | isDrug: false, isIntake: true, inSerum: true |
---|
501 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
502 | |
---|
503 | def hdlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( |
---|
504 | name: 'HDL', |
---|
505 | unit: 'mg/dL', |
---|
506 | type: dbnp.data.FeatureType.QUANTITATIVE, |
---|
507 | referenceValues: '50 mg/dL', |
---|
508 | detectableLimit: 100, |
---|
509 | isDrug: false, isIntake: true, inSerum: true |
---|
510 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
511 | |
---|
512 | lipidAssay.addToMeasurements ldlMeasurement |
---|
513 | lipidAssay.addToMeasurements hdlMeasurement |
---|
514 | |
---|
515 | def lipidAssayInstance = new dbnp.clinicaldata.ClinicalAssayInstance( |
---|
516 | assay: lipidAssay |
---|
517 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
518 | |
---|
519 | humanStudy.samples*.each { |
---|
520 | new dbnp.clinicaldata.ClinicalFloatData( |
---|
521 | assay: lipidAssayInstance, |
---|
522 | measurement: ldlMeasurement, |
---|
523 | sample: it.name, |
---|
524 | value: Math.round(Math.random()*ldlMeasurement.detectableLimit) |
---|
525 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
526 | |
---|
527 | new dbnp.clinicaldata.ClinicalFloatData( |
---|
528 | assay: lipidAssayInstance, |
---|
529 | measurement: hdlMeasurement, |
---|
530 | sample: it.name, |
---|
531 | value: Math.round(Math.random()*hdlMeasurement.detectableLimit) |
---|
532 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
533 | } |
---|
534 | |
---|
535 | // Add assay to study capture module |
---|
536 | |
---|
537 | def clinicalModule = new AssayModule( |
---|
538 | name: 'Clinical data', |
---|
539 | type: AssayType.CLINICAL_DATA, |
---|
540 | platform: 'clinical measurements', |
---|
541 | url: 'http://localhost:8080/gscf' |
---|
542 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
543 | |
---|
544 | def lipidAssayRef = new Assay( |
---|
545 | name: 'Lipid profiling', |
---|
546 | module: clinicalModule, |
---|
547 | externalAssayId: lipidAssayInstance.id |
---|
548 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
549 | |
---|
550 | humanStudy.samples*.each { |
---|
551 | lipidAssayRef.addToSamples(it) |
---|
552 | } |
---|
553 | lipidAssayRef.save() |
---|
554 | |
---|
555 | humanStudy.addToAssays(lipidAssayRef); |
---|
556 | humanStudy.save() |
---|
557 | |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | def destroy = { |
---|
562 | } |
---|
563 | } |
---|