source: trunk/grails-app/conf/BootStrap.groovy @ 269

Last change on this file since 269 was 269, checked in by keesvb, 13 years ago

upgraded to webflow plugin 1.2.1, added templates to BootStrap?, changed some code to get list_extended back up but it's still not working

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