Changeset 224
- Timestamp:
- Mar 2, 2010, 6:10:52 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BootStrap.groovy
r212 r224 123 123 124 124 // create system user 125 /* 126 def systemUser = userService.createUser(InstanceGenerator.user(125 126 /*def systemUser = userService.createUser(InstanceGenerator.user( 127 127 username: 'system', 128 128 pass: 'system', 129 129 passConfirm: 'system', 130 130 enabled: true 131 )) 132 */133 134 def genderField = new Template SubjectField(131 ))*/ 132 133 134 def genderField = new TemplateField( 135 135 name: 'Gender',type: TemplateFieldType.STRINGLIST, 136 136 listEntries: ['Male','Female']) 137 137 .with { if (!validate()) { errors.each { println it} } else save()} 138 def ageField = new Template SubjectField(138 def ageField = new TemplateField( 139 139 name: 'Age',type: TemplateFieldType.INTEGER) 140 140 .with { if (!validate()) { errors.each { println it} } else save()} … … 142 142 // Mouse template 143 143 def mouseTemplate = new Template( 144 name: 'Mouse' 145 ).addTo SubjectFields(new TemplateSubjectField(144 name: 'Mouse', entity: dbnp.studycapturing.Subject 145 ).addToFields(new TemplateField( 146 146 name: 'Genotype',type: TemplateFieldType.STRINGLIST, 147 147 listEntries: ['C57/Bl6j','wild type'])) 148 .addTo SubjectFields(genderField)149 .addTo SubjectFields(ageField)150 .addTo SubjectFields(new TemplateSubjectField(148 .addToFields(genderField) 149 .addToFields(ageField) 150 .addToFields(new TemplateField( 151 151 name: 'Cage',type: TemplateFieldType.INTEGER)) 152 .addTo SubjectFields(new TemplateSubjectField(152 .addToFields(new TemplateField( 153 153 name: 'Some double', type: TemplateFieldType.DOUBLE)) 154 .addTo SubjectFields(new TemplateSubjectField(154 .addToFields(new TemplateField( 155 155 name: 'Some ontology', type: TemplateFieldType.ONTOLOGYTERM)) 156 156 .with { if (!validate()) { errors.each { println it} } else save()} … … 158 158 // Human template 159 159 def humanTemplate = new Template( 160 name: 'Human' )161 .addTo SubjectFields(genderField)162 .addTo SubjectFields(ageField)163 .addTo SubjectFields(new TemplateSubjectField(160 name: 'Human', entity: dbnp.studycapturing.Subject) 161 .addToFields(genderField) 162 .addToFields(ageField) 163 .addToFields(new TemplateField( 164 164 name: 'DOB',type: TemplateFieldType.DATE)) 165 .addTo SubjectFields(new TemplateSubjectField(165 .addToFields(new TemplateField( 166 166 name: 'Height',type: TemplateFieldType.DOUBLE)) 167 .addTo SubjectFields(new TemplateSubjectField(167 .addToFields(new TemplateField( 168 168 name: 'Weight',type: TemplateFieldType.DOUBLE)) 169 .addTo SubjectFields(new TemplateSubjectField(169 .addToFields(new TemplateField( 170 170 name: 'BMI',type: TemplateFieldType.DOUBLE)) 171 171 .with { if (!validate()) { errors.each { println it} } else save()} … … 245 245 println 'Adding PPSH study' 246 246 247 def humanStudy = new Study(247 def humanStudy = new Study( 248 248 title:"NuGO PPS human study", 249 249 code:"PPSH", … … 291 291 eventDescription: bloodSamplingEvent, 292 292 parameterFloatValues: ['Sample volume':4.5F]) 293 .addToSamples(new Sample( 294 name: currentSubject.name + '_B', 295 material: bloodTerm 296 )) 297 ).with { if (!validate()) { errors.each { println it} } else save()} 293 ) 294 .addToSamples(new Sample( 295 name: currentSubject.name + '_B', 296 material: bloodTerm) 297 ) 298 .with { if (!validate()) { errors.each { println it} } else save()} 298 299 } 299 300 … … 334 335 ).with { if (!validate()) { errors.each { println it} } else save()} 335 336 336 humanStudy. giveSamples()*.each {337 humanStudy.samples*.each { 337 338 new dbnp.clinicaldata.ClinicalFloatData( 338 339 assay: lipidAssayInstance, … … 365 366 ).with { if (!validate()) { errors.each { println it} } else save()} 366 367 367 humanStudy. giveSamples()*.each {368 humanStudy.samples*.each { 368 369 lipidAssayRef.addToSamples(it) 369 370 } … … 372 373 humanStudy.addToAssays(lipidAssayRef); 373 374 humanStudy.save() 375 374 376 } 375 377 } -
trunk/grails-app/domain/dbnp/studycapturing/Sample.groovy
r190 r224 9 9 static searchable = true 10 10 11 // TODO: should Sample also carry a reference to its parent study, 12 // or should this be inferred via the parent SamplingEvent? 11 13 12 14 13 String name // should be unique with respect to the parent study (which can be inferred) 15 14 Term material 16 // don't we need a member that describes the quantity of the sample? 15 // don't we need a member that describes the quantity of the sample? --> should be in the templates 17 16 18 17 static constraints = { -
trunk/grails-app/domain/dbnp/studycapturing/Study.groovy
r212 r224 20 20 Date lastUpdated 21 21 Date startDate 22 Template template23 22 24 23 static hasMany = [ … … 29 28 events: Event, 30 29 samplingEvents: SamplingEvent, 30 samples: Sample, 31 31 assays: Assay, 32 32 persons: StudyPerson, … … 50 50 } 51 51 52 def giveAllFields() {53 return template.studyFields;54 }55 56 def giveSamples() {57 return samplingEvents*.samples;58 }59 52 } -
trunk/grails-app/domain/dbnp/studycapturing/Subject.groovy
r212 r224 13 13 class Subject extends TemplateEntity implements Serializable { 14 14 static searchable = true 15 Template template16 15 String name 17 16 Term species -
trunk/grails-app/domain/dbnp/studycapturing/Template.groovy
r212 r224 12 12 */ 13 13 class Template implements Serializable { 14 14 15 String name 16 Class entity 15 17 //nimble.User owner 16 18 17 static hasMany = [ studyFields: TemplateStudyField, subjectFields: TemplateSubjectField]19 static hasMany = [fields: TemplateField] 18 20 19 21 static constraints = { 20 name(unique: true) 22 name(unique:['entity']) 23 21 24 } 22 25 … … 30 33 * @return The type (static member of TemplateFieldType) of the field, or null of the field does not exist 31 34 */ 32 def TemplateFieldType get SubjectFieldType(String fieldName) {33 def field = subjectFields.find {35 def TemplateFieldType getFieldType(String fieldName) { 36 def field = fields.find { 34 37 it.name == fieldName 35 38 } 36 39 field?.type 37 40 } 41 42 def getFieldsByType(TemplateFieldType fieldType) { 43 def result = fields.findAll { 44 it.type == fieldType 45 } 46 return result; 47 } 38 48 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r212 r224 2 2 3 3 import dbnp.data.Term 4 import org.codehaus.groovy.runtime.NullObject 4 5 5 6 class TemplateEntity { 6 7 8 Template template 9 7 10 Map templateStringFields 11 Map templateStringListFields 8 12 Map templateIntegerFields 9 13 Map templateFloatFields … … 13 17 14 18 static hasMany = [ 15 templateStringFields: String, // stores both STRING and STRINGLIST items (latter should be checked against the list) 19 templateStringFields: String, 20 templateStringListFields: TemplateFieldListItem, 16 21 templateIntegerFields: int, 17 22 templateFloatFields: float, … … 31 36 */ 32 37 def getFieldValue(String fieldName) { 33 TemplateFieldType fieldType = template.get SubjectFieldType(fieldName)38 TemplateFieldType fieldType = template.getFieldType(fieldName) 34 39 if (!fieldType) throw new NoSuchFieldException("Field name ${fieldName} not recognized") 35 40 switch(fieldType) { 36 41 case [TemplateFieldType.STRING, TemplateFieldType.STRINGLIST]: 37 42 return templateStringFields[fieldName] 43 case [TemplateFieldType.STRINGLIST]: 44 return templateStringListFields[fieldName] 38 45 case TemplateFieldType.INTEGER: 39 46 return templateIntegerFields[fieldName] … … 52 59 53 60 def setFieldValue(String fieldName, value) { 54 this.properties.each { println it}55 61 if (this.properties.containsKey(fieldName)) { 56 62 this[fieldName] = value 57 63 } 58 else if (templateStringFields.containsKey(fieldName) && value.class == String) { 59 this.templateStringFields[fieldName] = value 60 } 61 else if (templateIntegerFields.containsKey(fieldName) && value.class == Integer) { 62 this.templateIntegerFields[fieldName] = value 63 } 64 else if (templateFloatFields.containsKey(fieldName) && value.class == Float) { 65 this.templateFloatFields[fieldName] = value 66 } 67 else if (templateDoubleFields.containsKey(fieldName) && value.class == Double) { 68 this.templateDoubleFields[fieldName] = value 69 } 70 else if (templateDateFields.containsKey(fieldName) && value.class == Date) { 71 this.templateDateFields[fieldName] = value 72 } 73 else if (templateTermFields.containsKey(fieldName) && value.class == Term) { 74 this.templateTermFields[fieldName] = value 64 else 65 if (template == null) { 66 throw new NoSuchFieldException("Field ${fieldName} not found in class properties") 75 67 } 76 68 else { 77 println "Field ${fieldName} not found" 69 if (templateStringFields.containsKey(fieldName) && value.class == String) { 70 this.templateStringFields[fieldName] = value 71 } 72 if (templateStringListFields.containsKey(fieldName) && value.class == TemplateFieldListItem) { 73 this.templateStringFields[fieldName] = value 74 } 75 else if (templateIntegerFields.containsKey(fieldName) && value.class == Integer) { 76 this.templateIntegerFields[fieldName] = value 77 } 78 else if (templateFloatFields.containsKey(fieldName) && value.class == Float) { 79 this.templateFloatFields[fieldName] = value 80 } 81 else if (templateDoubleFields.containsKey(fieldName) && value.class == Double) { 82 this.templateDoubleFields[fieldName] = value 83 } 84 else if (templateDateFields.containsKey(fieldName) && value.class == Date) { 85 this.templateDateFields[fieldName] = value 86 } 87 else if (templateTermFields.containsKey(fieldName) && value.class == Term) { 88 this.templateTermFields[fieldName] = value 89 } 90 else { 91 throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields") 92 } 78 93 } 79 94 } 80 95 96 def Set<TemplateField> giveFields() { 97 return this.template.fields; 98 } 99 100 @Override 101 void setTemplate(Template newTemplate) { 102 103 // Contrary to expectation, this method does not cause an infinite loop but calls the super method 104 // whereas super.setTemplate(newTemplate) leads to errors concerning NullObject values 105 this.template = newTemplate 106 107 // TODO: initialize all template fields with the necessary keys and null values 108 109 println "Setting template " + newTemplate 110 /*if (template == null || template instanceof NullObject) {} else{ // negation doesn't seem to work well 111 def stringFields = template.getFieldsByType(TemplateFieldType.STRINGLIST) 112 println stringFields*.name 113 if (stringFields.size() > 0) { 114 templateStringFields = new HashMap<String,String>() 115 templateStringFields.keyset.add stringFields*.name; 116 println templateStringFields 117 } 118 }*/ 119 } 120 81 121 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy
r190 r224 9 9 * $Date$ 10 10 */ 11 abstractclass TemplateField implements Serializable {11 class TemplateField implements Serializable { 12 12 String name 13 13 TemplateFieldType type … … 15 15 16 16 static hasMany = [listEntries : String] // to store the entries to choose from when the type is 'item from predefined list' 17 //TODO: make TemplateFieldListItem and make a convenience setter for a string array 17 18 18 19 static constraints = {
Note: See TracChangeset
for help on using the changeset viewer.