Changeset 812
- Timestamp:
- Aug 16, 2010, 6:04:00 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BootStrap.groovy
r793 r812 40 40 BootStrapStudies.addExampleStudies() 41 41 } 42 43 println "Finished adding templates and studies" 42 44 } 43 45 … … 51 53 TemplateEntity.getField(Sample.domainFields, 'material').ontologies = [Ontology.getOrCreateOntologyByNcboId(1005)] 52 54 55 println "Registering SAM REST methods" 53 56 // register methods for accessing SAM's Rest services 54 57 if (grails.util.GrailsUtil.environment == GrailsApplication.ENV_PRODUCTION) { … … 59 62 } 60 63 CommunicationManager.registerRestWrapperMethodsSAMtoGSCF() 64 65 println "Done with BootStrap" 61 66 } 62 67 -
trunk/grails-app/conf/BootStrapStudies.groovy
r806 r812 231 231 def evS = new SamplingEvent( 232 232 startTime: 3600 +7 * 24 * 3600, 233 endTime: 3600 +7 * 24 * 3600,234 233 template: liverSamplingEventTemplate, 235 234 sampleTemplate: humanTissueSampleTemplate) … … 238 237 def evS4 = new SamplingEvent( 239 238 startTime: 3600 +7 * 24 * 3600, 240 endTime: 3600 +7 * 24 * 3600,241 239 template: liverSamplingEventTemplate, 242 240 sampleTemplate: humanTissueSampleTemplate) … … 314 312 .setFieldValue("Cage", "" + (int)(x/2)) 315 313 314 // We have to save the subject first, otherwise the parentEvent property of the sample cannot be set 315 // (this is possibly a Grails or Hibernate bug) 316 316 mouseStudy.addToSubjects(currentSubject) 317 .with { if (!validate()) { errors.each { println it} } else save()}317 currentSubject.with { if (!validate()) { errors.each { println it} } else save()} 318 318 319 319 // Add subject to appropriate EventGroup … … 333 333 template: humanBloodSampleTemplate, 334 334 parentSubject: currentSubject, 335 parentEvent: x > 40 ? evS4 : evS335 parentEvent: evS //x > 40 ? evS4 : evS 336 336 ); 337 mouseStudy.addToSamples(currentSample) 338 currentSample.with { if (!validate()) { errors.each { println it} } else save()} 337 339 currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) ) 338 mouseStudy.addToSamples(currentSample).with { if (!validate()) { errors.each { println it} } else save()}339 340 } 340 341 … … 388 389 def bloodSamplingEvent = new SamplingEvent( 389 390 startTime: 3 * 24 * 3600 + 30 * 3600, 390 endTime: 3 * 24 * 3600 + 30 * 3600,391 391 template: bloodSamplingEventTemplate, 392 392 sampleTemplate: humanBloodSampleTemplate) … … 411 411 .setFieldValue("BMI", 20 + Math.random() * 10F) 412 412 413 humanStudy.addToSubjects(currentSubject) 414 currentSubject.with { if (!validate()) { errors.each { println it} } else save()} 415 413 416 rootGroup.addToSubjects currentSubject 414 417 rootGroup.save() … … 421 424 parentEvent: bloodSamplingEvent 422 425 ); 426 427 humanStudy.addToSamples(currentSample) 428 currentSample.with { if (!validate()) { errors.each { println it} } else save()} 423 429 currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) ) 424 425 humanStudy.addToSubjects(currentSubject).addToSamples(currentSample)426 .with { if (!validate()) { errors.each { println it} } else save()}427 430 } 428 431 … … 431 434 humanStudy.addToEventGroups rootGroup 432 435 433 436 println ".adding persons and saving PPSH study..." 434 437 // Add persons to study 435 438 def studyperson3 = new StudyPerson( person: person1, role: role2 ) 436 437 439 humanStudy 438 440 .addToPersons( studyperson3 ) … … 440 442 .with { if (!validate()) { errors.each { println it} } else save()} 441 443 442 // Add clinical data ==> to be moved to SAM 443 444 def lipidAssay = new dbnp.clinicaldata.ClinicalAssay( 445 name: 'Lipid profile', 446 approved: true 447 ).with { if (!validate()) { errors.each { println it} } else save()} 448 449 def ldlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( 450 name: 'LDL', 451 unit: 'mg/dL', 452 type: dbnp.data.FeatureType.QUANTITATIVE, 453 referenceValues: '100 mg/dL', 454 detectableLimit: 250, 455 isDrug: false, isIntake: true, inSerum: true 456 ).with { if (!validate()) { errors.each { println it} } else save()} 457 458 def hdlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( 459 name: 'HDL', 460 unit: 'mg/dL', 461 type: dbnp.data.FeatureType.QUANTITATIVE, 462 referenceValues: '50 mg/dL', 463 detectableLimit: 100, 464 isDrug: false, isIntake: true, inSerum: true 465 ).with { if (!validate()) { errors.each { println it} } else save()} 466 467 lipidAssay.addToMeasurements ldlMeasurement 468 lipidAssay.addToMeasurements hdlMeasurement 469 470 def lipidAssayInstance = new dbnp.clinicaldata.ClinicalAssayInstance( 471 assay: lipidAssay 472 ).with { if (!validate()) { errors.each { println it} } else save()} 473 474 humanStudy.samples*.each { 475 new dbnp.clinicaldata.ClinicalFloatData( 476 assay: lipidAssayInstance, 477 measurement: ldlMeasurement, 478 sample: it.name, 479 value: Math.round(Math.random()*ldlMeasurement.detectableLimit) 480 ).with { if (!validate()) { errors.each { println it} } else save()} 481 482 new dbnp.clinicaldata.ClinicalFloatData( 483 assay: lipidAssayInstance, 484 measurement: hdlMeasurement, 485 sample: it.name, 486 value: Math.round(Math.random()*hdlMeasurement.detectableLimit) 487 ).with { if (!validate()) { errors.each { println it} } else save()} 488 } 489 490 // Add assay to study capture module 491 444 println ".adding assay references to mouse example study..." 445 446 // Add SAM assay references 492 447 def clinicalModule = new AssayModule( 493 448 name: 'SAM module for clinical data', … … 510 465 mouseStudy.save() 511 466 512 lipidAssayRef.with { if (!validate()) { errors.each { println it} } else save()} 467 //lipidAssayRef.with { if (!validate()) { errors.each { println it} } else save()} 468 469 println ".adding assay references to human example study..." 513 470 514 471 def glucoseAssay2Ref = new Assay( … … 524 481 ) 525 482 526 humanStudy.addToAssays(glucoseAssay2Ref)527 humanStudy.addToAssays(glucoseAssay3Ref)528 humanStudy.save()529 530 483 humanStudy.samples*.each { 531 484 glucoseAssay2Ref.addToSamples(it) … … 533 486 } 534 487 535 glucoseAssay2Ref.with { if (!validate()) { errors.each { println it} } else save()} 536 glucoseAssay3Ref.with { if (!validate()) { errors.each { println it} } else save()} 488 489 humanStudy.addToAssays(glucoseAssay2Ref) 490 humanStudy.addToAssays(glucoseAssay3Ref) 491 humanStudy.save() 492 println "Saving" 493 //glucoseAssay2Ref.with { if (!validate()) { errors.each { println it} } else save()} 494 //glucoseAssay3Ref.with { if (!validate()) { errors.each { println it} } else save()} 537 495 538 496 } -
trunk/grails-app/controllers/dbnp/studycapturing/TemplateController.groovy
r397 r812 1 /** 2 * TemplateController Controler 3 * 4 * An overview of 5 * 6 * @author Kees van Bochove 7 * @since 20100726 8 * @package dbnp.studycapturing 9 * 10 * Revision information: 11 * $Rev$ 12 * $Author$ 13 * $Date$ 14 */ 1 15 package dbnp.studycapturing 2 /** 3 * 888 888 888 888 8888888888 8888888b. 8888888888 4 * 888 o 888 888 888 888 888 Y88b 888 5 * 888 d8b 888 888 888 888 888 888 888 6 * 888 d888b 888 8888888888 8888888 888 d88P 8888888 7 * 888d88888b888 888 888 888 8888888P" 888 8 * 88888P Y88888 888 888 888 888 T88b 888 9 * 8888P Y8888 888 888 888 888 T88b 888 10 * 888P Y888 888 888 8888888888 888 T88b 8888888888 11 * 12 * 8888888 .d8888b. 88888888888 888 888 8888888888 13 * 888 d88P Y88b 888 888 888 888 14 * 888 Y88b. 888 888 888 888 15 * 888 "Y888b. 888 8888888888 8888888 16 * 888 "Y88b. 888 888 888 888 17 * 888 "888 888 888 888 888 18 * 888 Y88b d88P 888 888 888 888 19 * 8888888 "Y8888P" 888 888 888 8888888888 20 * 21 * 888888 d8888 888 888 d8888 8888888b. .d88888b. .d8888b. 22 * "88b d88888 888 888 d88888 888 "Y88b d88P" "Y88b d88P Y88b 23 * 888 d88P888 888 888 d88P888 888 888 888 888 888 888 24 * 888 d88P 888 Y88b d88P d88P 888 888 888 888 888 888 25 * 888 d88P 888 Y88b d88P d88P 888 888 888 888 888 888 26 * 888 d88P 888 Y88o88P d88P 888 888 888 888 888 888 888 27 * 88P d8888888888 Y888P d8888888888 888 .d88P Y88b. .d88P Y88b d88P 28 * 888 d88P 888 Y8P d88P 888 8888888P" "Y88888P" "Y8888P" 29 * .d88P 30 * .d88P" 31 * 888P" 32 * 33 * .d8888b. 888 .d8888b. 888 .d8888b. 888 34 * d88P Y88b 888 d88P Y88b 888 d88P Y88b 888 35 * .d88P 888 .d88P 888 .d88P 888 36 * .d88P" 888 .d88P" 888 .d88P" 888 37 * 888" 888 888" 888 888" 888 38 * 888 Y8P 888 Y8P 888 Y8P 39 * " " " 40 * 888 888 888 888 888 888 41 * 42 * 43 * TODO: add PROPER class and method documentation, just like have 44 * agreed upon hundreds of times!!!! 45 */ 16 46 17 class TemplateController { 47 18 def scaffold = Template -
trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy
r784 r812 12 12 13 13 // A Sample always belongs to one study. 14 static belongsTo = [parent : Study ]14 static belongsTo = [parent : Study, parentSubject : Subject, parentEvent : SamplingEvent] 15 15 16 16 // A Sample optionally has a parent Subject from which it was taken, this Subject should be in the same parent study. 17 SubjectparentSubject17 //long parentSubject 18 18 19 19 // Also, it has a parent SamplingEvent describing the actual sampling, also within the same parent study. 20 SamplingEvent parentEvent 20 // Strange enough, we need to define parentEvent as a long here, otherwise the SamplingEvent gets serialized into the database (?!!) 21 //long parentEvent 21 22 22 23 String name // should be unique with respect to the parent study (which can be inferred) -
trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy
r803 r812 89 89 return samples == null ? [] : samples 90 90 } 91 92 def String toString() { 93 return fieldExists('Description') ? getFieldValue('Description') : "" 94 } 95 91 96 } -
trunk/grails-app/domain/dbnp/studycapturing/Study.groovy
r811 r812 237 237 } 238 238 239 // remove event from the study 239 // Delete the samples that have this sampling event as parent 240 this.samples.findAll { it.parentEvent.equals(samplingEvent) }.each { 241 // This should remove the sample itself too, because of the cascading belongsTo relation 242 this.removeFromSamples(it) 243 // But apparently it needs an explicit delete() too 244 it.delete() 245 msg += ", sample '${it.name}' was deleted" 246 } 247 248 // Remove event from the study 249 // This should remove the event group itself too, because of the cascading belongsTo relation 240 250 this.removeFromSamplingEvents(samplingEvent) 251 // But apparently it needs an explicit delete() too 252 // (Which can be verified by outcommenting this line, then SampleTests.testDeleteViaParentSamplingEvent fails 253 samplingEvent.delete() 241 254 242 255 return msg … … 300 313 // ------- 301 314 302 println ".removing sample '${it.name}' from study '${this. name}'"315 println ".removing sample '${it.name}' from study '${this.title}'" 303 316 msg += ", sample '${it.name}' was deleted" 304 317 this.removeFromSamples( it ) … … 321 334 322 335 // remove the eventGroup from the study 323 println ".remove eventGroup '${eventGroup.name}' from study '${this. name}'"336 println ".remove eventGroup '${eventGroup.name}' from study '${this.title}'" 324 337 this.removeFromEventGroups(eventGroup) 325 338 -
trunk/test/integration/gscf/SampleTests.groovy
r774 r812 8 8 import dbnp.studycapturing.TemplateFieldType 9 9 import dbnp.studycapturing.Subject 10 import dbnp.studycapturing.EventGroup 10 11 11 12 /** … … 32 33 final String testSamplingEventTemplateName = "Blood extraction" 33 34 final long testSamplingEventTime = 34534534L 35 final long testSamplingEventDuration = 1000L 36 final String testEventGroupName = "Test Group" 34 37 35 38 … … 45 48 assert samplingEventTemplate 46 49 50 // Look up sample template 51 def sampleTemplate = Template.findByName(testSampleTemplateName) 52 assert sampleTemplate 53 47 54 // Create parent sampling event 48 55 def samplingEvent = new SamplingEvent( 49 56 startTime: testSamplingEventTime, 50 endTime: testSamplingEventTime, 51 template: samplingEventTemplate 57 duration: testSamplingEventDuration, 58 template: samplingEventTemplate, 59 sampleTemplate: sampleTemplate 52 60 ) 53 61 … … 62 70 assert samplingEvent.validate() 63 71 assert samplingEvent.save(flush:true) 64 65 // Look up sample template66 def sampleTemplate = Template.findByName(testSampleTemplateName)67 assert sampleTemplate68 72 69 73 // Create sample with the retrieved study as parent … … 93 97 94 98 void testSave() { 99 95 100 // Try to retrieve the sample and make sure it's the same 96 101 def sampleDB = Sample.findByName(testSampleName) … … 101 106 assert sampleDB.parentEvent.startTime.equals(testSamplingEventTime) 102 107 108 println "The sample has parentEvent ${sampleDB.parentEvent.encodeAsHTML()}" 103 109 // A sample without a name should not be saveable 104 110 sampleDB.name = null … … 157 163 assert !study.subjects.contains(subject) 158 164 159 assert !Subject.findByName( testSampleName)165 assert !Subject.findByName(subject.name) 160 166 assert !Sample.findByName(testSampleName) 161 167 162 168 assert Subject.count() == 0 169 assert Sample.count() == 0 170 171 } 172 173 void testDeleteViaParentSamplingEvent() { 174 175 def sampleDB = Sample.findByName(testSampleName) 176 assert sampleDB 177 178 // Retrieve the parent study 179 def study = Study.findByTitle(testStudyName) 180 assert study 181 182 def event = sampleDB.parentEvent 183 assert event 184 185 // Use the deleteSamplingEvent method 186 def msg = study.deleteSamplingEvent(event) 187 println msg 188 assert study.save() 189 190 assert !study.samplingEvents.contains(event) 191 192 assert !SamplingEvent.findByStartTime(testSamplingEventTime) 193 assert !Sample.findByName(testSampleName) 194 195 assert SamplingEvent.count() == 0 196 assert Sample.count() == 0 197 198 } 199 200 void testDeleteViaParentEventGroup() { 201 202 def sampleDB = Sample.findByName(testSampleName) 203 assert sampleDB 204 205 // Retrieve the parent study 206 def study = Study.findByTitle(testStudyName) 207 assert study 208 209 // Retrieve the sample's sampling event 210 def event = sampleDB.parentEvent 211 assert event 212 213 // Create a subject and add it at the sample's parent 214 def subject = SubjectTests.createSubject(study) 215 assert subject 216 sampleDB.parentSubject = subject 217 assert sampleDB.validate() 218 assert sampleDB.save() 219 220 // Create an event group in this study with the sample's sampling event 221 def group = new EventGroup( 222 name: testEventGroupName 223 ) 224 study.addToEventGroups(group) 225 group.addToSubjects(subject) 226 group.addToSamplingEvents(event) 227 assert study.eventGroups.find { it.name == group.name} 228 assert group.validate() 229 assert study.save() 230 231 // Use the deleteSamplingEvent method 232 def msg = study.deleteEventGroup(group) 233 println msg 234 assert study.save() 235 236 assert !study.eventGroups.contains(group) 237 assert !EventGroup.findByName(testEventGroupName) 238 assert !Sample.findByName(testSampleName) 239 240 assert EventGroup.count() == 0 163 241 assert Sample.count() == 0 164 242
Note: See TracChangeset
for help on using the changeset viewer.