source: trunk/grails-app/controllers/SandboxController.groovy @ 924

Last change on this file since 924 was 924, checked in by tabma, 9 years ago
  • Sandbox update to OAuth
  • Property svn:keywords set to Date Author Rev
File size: 2.2 KB
Line 
1import dbnp.studycapturing.*
2import dbnp.clinicaldata.ClinicalFloatData
3import dbnp.clinicaldata.ClinicalMeasurement
4
5// The sandbox is meant for internal communication over code examples etc.
6
7class SandboxController {
8
9        def clinicalDataLayerService
10        def oauthService
11
12        def index = {
13
14                // Get the example study in a lazy way
15                def st = Study.get(1)
16                println st.title
17                println st.subjects
18                def fieldsAll = st.giveSubjectTemplates().asList().first().fields
19        def f = fieldsAll[0]
20        println fieldsAll.class
21            println f.class
22      f.each {
23        println "" + it + "-" + it.class
24      }
25      //println st.giveAllFields()
26
27                // This is a way to iterate over the fields in your controller
28                // And print them to the console
29                // Most of the time, you would just iterate over them in the view using <g:each>
30                // See also views/sandbox/index.gsp
31                f.each { field ->
32                        println field.name + "(" + field.type + ")"
33                }
34
35                //Let's get a certain field for a certain subject
36                /*def subject = st.subjects.get(1)
37
38                if (subject) {
39                println st.template.getSubjectFieldType('Age')
40                println subject.getFieldValue('Genotype')
41                subject.setFieldValue('Genotype','wildtype')
42                println subject.getFieldValue('Genotype')
43                subject.setFieldValue('name','hallo')
44                println subject.name }*/
45
46
47                // Demonstration of querying mechanism
48                //println "Features available for first assay of PPSH study: " + clinicalDataLayerService.getFeaturesQuantitative(Study.findByCode("PPSH").assays*.id[0])
49                //println "LDL feature value for two subjects: " + clinicalDataLayerService.getDataQuantitative('LDL',1,['A1_B','A3_B'] as String[])
50
51                // Specify which variables we want to be available in the controller (implicit return statement)
52                [fields: f, subjects: st.subjects, studyInstance: st, subject: Subject.findByName('A1')]
53        }
54
55        def oauth = {           
56            def secret = session.oauthToken.secret
57            def response = oauthService.accessResource('http://www.myexperiment.org/whoami.xml', 'myExperiment',
58                           [key: session.oauthToken.key, secret: session.oauthToken.secret], 'GET')
59            render ("Calling whoami from myExperiment [key:" + key + ", secret:"+secret+"]")
60            render ("Response: " + response)
61
62        }
63
64
65}
Note: See TracBrowser for help on using the repository browser.