- Timestamp:
- Nov 17, 2010, 11:34:09 AM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BootStrapTemplates.groovy
r1118 r1153 39 39 40 40 def ageField = new TemplateField( 41 name: 'Age',type: TemplateFieldType. INTEGER,entity: Subject,unit: 'years',comment: 'Either include age at the start of the study or date of birth (if known)')41 name: 'Age',type: TemplateFieldType.LONG,entity: Subject,unit: 'years',comment: 'Either include age at the start of the study or date of birth (if known)') 42 42 .with { if (!validate()) { errors.each { println it} } else save()} 43 43 … … 90 90 .addToFields(genderField) 91 91 .addToFields(new TemplateField( 92 name: 'Age', type: TemplateFieldType. INTEGER, entity: Subject, unit: 'weeks', comment: 'Age at start of study'))92 name: 'Age', type: TemplateFieldType.LONG, entity: Subject, unit: 'weeks', comment: 'Age at start of study')) 93 93 .addToFields(new TemplateField( 94 94 name: 'Age type',type: TemplateFieldType.STRINGLIST,entity: Subject, … … 97 97 name: 'Cage',type: TemplateFieldType.STRING,entity: Subject,comment:'Indicate the cage used for housing (type and/or size)')) 98 98 .addToFields(new TemplateField( 99 name: '#Mice in cage',type: TemplateFieldType. INTEGER,entity: Subject,comment:'If known, indicate the number of mice per cage'))100 .addToFields(new TemplateField( 101 name: 'Litter size',type: TemplateFieldType. INTEGER,entity: Subject,comment:'If known, indicate the litter size of the litter from which the subject originates'))99 name: '#Mice in cage',type: TemplateFieldType.LONG,entity: Subject,comment:'If known, indicate the number of mice per cage')) 100 .addToFields(new TemplateField( 101 name: 'Litter size',type: TemplateFieldType.LONG,entity: Subject,comment:'If known, indicate the litter size of the litter from which the subject originates')) 102 102 .addToFields(new TemplateField( 103 103 name: 'Weight', type: TemplateFieldType.DOUBLE, unit: 'gram',entity: Subject,comment:'If known indicate the weight of the subject in grams at the start of the study')) … … 120 120 name: 'Race',type: TemplateFieldType.STRING,entity: Subject, comment:'If known and of interest the ethnic group can be indicated')) 121 121 .addToFields(new TemplateField( 122 name: 'Waist circumference',type: TemplateFieldType. FLOAT, unit: 'cm',entity: Subject, comment:'The waist circumference is measured just above the hip bone. Indicate the measure at the start of the study.'))123 .addToFields(new TemplateField( 124 name: 'Hip circumference',type: TemplateFieldType. FLOAT, unit: 'cm',entity: Subject, comment:'The hip circumference is measured at the level of the two bony prominences front of the hips. Indicate the measure at the start of the study.'))125 .addToFields(new TemplateField( 126 name: 'Systolic blood pressure',type: TemplateFieldType. FLOAT, unit: 'mmHg',entity: Subject, comment:'Indicate the levels at the start of the study in mmHG'))127 .addToFields(new TemplateField( 128 name: 'Diastolic blood pressure',type: TemplateFieldType. FLOAT, unit: 'mmHg',entity: Subject, comment:'Indicate the levels at the start of the study in mmHG'))129 .addToFields(new TemplateField( 130 name: 'Heart rate',type: TemplateFieldType. FLOAT, unit: 'beats/min',entity: Subject, comment:'Indicate the heart rate at the start of in study in beats per minute'))122 name: 'Waist circumference',type: TemplateFieldType.DOUBLE, unit: 'cm',entity: Subject, comment:'The waist circumference is measured just above the hip bone. Indicate the measure at the start of the study.')) 123 .addToFields(new TemplateField( 124 name: 'Hip circumference',type: TemplateFieldType.DOUBLE, unit: 'cm',entity: Subject, comment:'The hip circumference is measured at the level of the two bony prominences front of the hips. Indicate the measure at the start of the study.')) 125 .addToFields(new TemplateField( 126 name: 'Systolic blood pressure',type: TemplateFieldType.DOUBLE, unit: 'mmHg',entity: Subject, comment:'Indicate the levels at the start of the study in mmHG')) 127 .addToFields(new TemplateField( 128 name: 'Diastolic blood pressure',type: TemplateFieldType.DOUBLE, unit: 'mmHg',entity: Subject, comment:'Indicate the levels at the start of the study in mmHG')) 129 .addToFields(new TemplateField( 130 name: 'Heart rate',type: TemplateFieldType.DOUBLE, unit: 'beats/min',entity: Subject, comment:'Indicate the heart rate at the start of in study in beats per minute')) 131 131 .addToFields(new TemplateField( 132 132 name: 'Run-in-food',type: TemplateFieldType.TEXT,entity: Subject, comment:'If defined, give a short description of the food used before the measurements')) … … 158 158 name: 'Sample measured weight', 159 159 unit: 'mg', 160 type: TemplateFieldType. FLOAT,160 type: TemplateFieldType.DOUBLE, 161 161 entity: Sample 162 162 ) … … 175 175 name: 'Sample measured volume', 176 176 unit: 'ml', 177 type: TemplateFieldType. FLOAT,177 type: TemplateFieldType.DOUBLE, 178 178 entity: Sample 179 179 ) … … 270 270 name: 'Growth protocol', entity: Subject, type: TemplateFieldType.TEXT)) 271 271 .addToFields(new TemplateField( 272 name: 'Position X', entity: Subject, type: TemplateFieldType. FLOAT))273 .addToFields(new TemplateField( 274 name: 'Position Y', entity: Subject, type: TemplateFieldType. FLOAT))272 name: 'Position X', entity: Subject, type: TemplateFieldType.DOUBLE)) 273 .addToFields(new TemplateField( 274 name: 'Position Y', entity: Subject, type: TemplateFieldType.DOUBLE)) 275 275 .addToFields(new TemplateField( 276 276 name: 'Block', entity: Subject, type: TemplateFieldType.STRING)) 277 277 .addToFields(new TemplateField( 278 name: 'Temperature at day', entity: Subject, type: TemplateFieldType. FLOAT))279 .addToFields(new TemplateField( 280 name: 'Temperature at night', entity: Subject, type: TemplateFieldType. FLOAT))278 name: 'Temperature at day', entity: Subject, type: TemplateFieldType.DOUBLE)) 279 .addToFields(new TemplateField( 280 name: 'Temperature at night', entity: Subject, type: TemplateFieldType.DOUBLE)) 281 281 .addToFields(new TemplateField( 282 282 name: 'Photo period', entity: Subject, type: TemplateFieldType.STRING)) … … 343 343 name: 'Block', type: TemplateFieldType.STRING, entity: Subject)) 344 344 .addToFields(new TemplateField( 345 name: 'Position X', type: TemplateFieldType. FLOAT, entity: Subject))346 .addToFields(new TemplateField( 347 name: 'Position Y', type: TemplateFieldType. FLOAT, entity: Subject))348 .addToFields(new TemplateField( 349 name: 'Temperature at day', type: TemplateFieldType. FLOAT, entity: Subject))350 .addToFields(new TemplateField( 351 name: 'Temperature at night', type: TemplateFieldType. FLOAT, entity: Subject))345 name: 'Position X', type: TemplateFieldType.DOUBLE, entity: Subject)) 346 .addToFields(new TemplateField( 347 name: 'Position Y', type: TemplateFieldType.DOUBLE, entity: Subject)) 348 .addToFields(new TemplateField( 349 name: 'Temperature at day', type: TemplateFieldType.DOUBLE, entity: Subject)) 350 .addToFields(new TemplateField( 351 name: 'Temperature at night', type: TemplateFieldType.DOUBLE, entity: Subject)) 352 352 .addToFields(new TemplateField( 353 353 name: 'Photo period', type: TemplateFieldType.STRING, entity: Subject)) … … 502 502 unit: 'mg', 503 503 entity: SamplingEvent, 504 type: TemplateFieldType. FLOAT504 type: TemplateFieldType.DOUBLE 505 505 ) 506 506 ) … … 520 520 entity: SamplingEvent, 521 521 unit: 'ml', 522 type: TemplateFieldType. FLOAT522 type: TemplateFieldType.DOUBLE 523 523 ) 524 524 ) … … 539 539 unit: 'ul', 540 540 entity: SamplingEvent, 541 type: TemplateFieldType. FLOAT541 type: TemplateFieldType.DOUBLE 542 542 ) 543 543 ) -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r1111 r1153 25 25 Map templateTextFields = [:] 26 26 Map templateStringListFields = [:] 27 Map templateIntegerFields = [:]28 Map templateFloatFields = [:]29 27 Map templateDoubleFields = [:] 30 28 Map templateDateFields = [:] … … 45 43 templateTextFields : String, 46 44 templateStringListFields: TemplateFieldListItem, 47 templateIntegerFields : int,48 templateFloatFields : float,49 45 templateDoubleFields : double, 50 46 templateDateFields : Date, … … 148 144 error = true 149 145 errors.rejectValue( 150 'template IntegerFields',146 'templateStringFields', 151 147 'templateEntity.typeMismatch.templateFieldListItem', 152 148 [key, value.class] as Object[], … … 158 154 return (!error) 159 155 }) 160 templateIntegerFields(validator: { fields, obj, errors ->161 def error = false162 fields.each { key, value ->163 if (value && value.class != Integer) {164 try {165 fields[key] = (value as Integer)166 } catch (Exception e) {167 error = true168 errors.rejectValue(169 'templateIntegerFields',170 'templateEntity.typeMismatch.integer',171 [key, value.class] as Object[],172 'Property {0} must be of type Integer and is currently of type {1}'173 )174 }175 }176 }177 return (!error)178 })179 templateFloatFields(validator: { fields, obj, errors ->180 def error = false181 fields.each { key, value ->182 if (value && value.class != Float) {183 try {184 fields[key] = (value as Float)185 } catch (Exception e) {186 error = true187 errors.rejectValue(188 'templateFloatFields',189 'templateEntity.typeMismatch.float',190 [key, value.class] as Object[],191 'Property {0} must be of type Float and is currently of type {1}'192 )193 }194 }195 }196 return (!error)197 })198 156 templateDoubleFields(validator: { fields, obj, errors -> 199 157 def error = false 200 158 fields.each { key, value -> 159 // Double field should accept Doubles and Floats 201 160 if (value && value.class != Double) { 202 try { 203 fields[key] = (value as Double) 204 } catch (Exception e) { 205 error = true 206 errors.rejectValue( 207 'templateDoubleFields', 208 'templateEntity.typeMismatch.double', 209 [key, value.class] as Object[], 210 'Property {0} must be of type Double and is currently of type {1}' 211 ) 161 if(value.class == Float) { 162 fields[key] = value.toDouble(); 163 } else { 164 try { 165 fields[key] = (value as Double) 166 } catch (Exception e) { 167 error = true 168 errors.rejectValue( 169 'templateDoubleFields', 170 'templateEntity.typeMismatch.double', 171 [key, value.class] as Object[], 172 'Property {0} must be of type Double and is currently of type {1}' 173 ) 174 } 212 175 } 213 176 } … … 370 333 def error = false 371 334 fields.each { key, value -> 372 if (value && value.class != Long) { 373 try { 374 fields[key] = Long.parseLong(value.trim()) 375 } catch (Exception e) { 376 error = true 377 errors.rejectValue( 378 'templateLongFields', 379 'templateEntity.typeMismatch.long', 380 [key, value.class] as Object[], 381 'Property {0} must be of type Long and is currently of type {1}' 382 ) 335 // Long field should accept Longs and Integers 336 if (value && value.class != Long ) { 337 if( value.class == Integer ) { 338 fields[key] = value.toLong(); 339 } else { 340 try { 341 fields[key] = Long.parseLong(value.trim()) 342 } catch (Exception e) { 343 error = true 344 errors.rejectValue( 345 'templateLongFields', 346 'templateEntity.typeMismatch.long', 347 [key, value.class] as Object[], 348 'Property {0} must be of type Long and is currently of type {1}' 349 ) 350 } 383 351 } 384 352 } … … 403 371 case TemplateFieldType.STRINGLIST: 404 372 return templateStringListFields 405 case TemplateFieldType.INTEGER:406 return templateIntegerFields407 373 case TemplateFieldType.DATE: 408 374 return templateDateFields … … 411 377 case TemplateFieldType.FILE: 412 378 return templateFileFields 413 case TemplateFieldType.FLOAT:414 return templateFloatFields415 379 case TemplateFieldType.DOUBLE: 416 380 return templateDoubleFields … … 645 609 // Magic setter for LONG fields 646 610 if (field.type == TemplateFieldType.LONG && value && value.class == String) { 647 // TODO, check for invalids? 648 value = Long.parseLong(value.trim()) 611 // A check for invalidity is done in the validator of these fields. For that 612 // reason, we just try to parse it here. If it fails, the validator will also 613 // fail. 614 try { 615 value = Long.parseLong(value.trim()) 616 } catch( Exception e ) {} 649 617 } 650 618 … … 661 629 // the value to 0, otherwise, setting it to NULL 662 630 switch (field.type.toString()) { 663 case [ 'INTEGER', 'FLOAT','DOUBLE', 'RELTIME', 'LONG']:631 case [ 'DOUBLE', 'RELTIME', 'LONG']: 664 632 this[field.name] = 0; 665 633 break; -
trunk/grails-app/domain/dbnp/studycapturing/TemplateFieldType.groovy
r1056 r1153 10 10 */ 11 11 public enum TemplateFieldType implements Serializable { 12 STRING('String','Text', ' '), // string13 TEXT('Long string', 'Text', ' '), // text14 INTEGER('Integer number', 'Numerical', '1'), // integer15 FLOAT('Floating-point number', 'Numerical', '1.0'), // float16 DOUBLE(' Double precision floating-point number', 'Numerical', '1.0'),// double12 STRING('String','Text', 'max 255 chars'), // string 13 TEXT('Long string', 'Text', 'unlimited'), // text 14 //INTEGER('Integer number', 'Numerical', '1'), // integer 15 //FLOAT('Floating-point number', 'Numerical', '1.0'), // float 16 DOUBLE('Floating point number', 'Numerical', '1.0'), // double 17 17 STRINGLIST('List of items', 'Text', ''), // string list 18 18 ONTOLOGYTERM('Ontology Reference', 'Other', ''), // ontology reference … … 23 23 TEMPLATE('Template', 'Other', ''), // template 24 24 MODULE('Module', 'Other', ''), // third party connected module, 25 LONG(' Long number', 'Numerical', '100')// long25 LONG('Integer number', 'Numerical', '100') // long 26 26 // TODO: add a timezone-aware date type to use for study start date 27 27 … … 40 40 41 41 static list() { 42 [STRING, TEXT, INTEGER, FLOAT,DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE, MODULE, LONG]42 [STRING, TEXT, DOUBLE, STRINGLIST, ONTOLOGYTERM, DATE, RELTIME, FILE, BOOLEAN, TEMPLATE, MODULE, LONG] 43 43 } 44 44 … … 47 47 case [STRING, TEXT]: 48 48 return "" 49 case INTEGER:50 return Integer.MIN_VALUE51 case FLOAT:52 return Float.NaN53 49 case DOUBLE: 54 50 return Double.MIN_VALUE -
trunk/grails-app/views/templateEditor/template.gsp
r1136 r1153 95 95 <% /* NB: this empty field should always be the last in the list! */ %> 96 96 <li class="empty ui-state-default" <g:if test="${template.fields?.size() > 0 }">style='display: none;'</g:if>>This template does not yet contain any fields. Drag a field to this list or use the 'Add field button'.</li> 97 <input type="text" name="xxxas">98 97 </ol> 99 98 </div>
Note: See TracChangeset
for help on using the changeset viewer.