Changeset 901
- Timestamp:
- Sep 27, 2010, 5:04:47 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/RestController.groovy
r843 r901 42 42 */ 43 43 private def auth() { 44 44 45 credentials = BasicAuthentication.credentialsFromRequest(request) 45 46 requestUser = authService.authUser(credentials.u,credentials.p) … … 83 84 def getStudies = { 84 85 List studies = [] 86 def user = params.user 85 87 Study.findAllByOwner(requestUser).each { study -> 86 studies.push( [ 'externalStudyID': study.code, 'name':study.title ] )88 studies.push( [ 'externalStudyID': study.code, 'name':study.title, 'studyToken':study.code ] ) 87 89 } 88 90 render studies as JSON … … 114 116 * Provide a list of all assays for a given study 115 117 * 116 * Example call of the getAssays REST resource: http://localhost:8080/gscf/rest/getAssays?externalStudyID=PPSH&moduleURL=http://localhost:8182/sam 118 * Example call of the getAssays REST resource: 119 * http://localhost:8080/gscf/rest/getAssays?externalStudyID=PPSH&moduleURL=http://localhost:8182/sam 117 120 * 118 121 * @param externalStudyID String The external study id (code) of the target GSCF Study object 119 122 * @param moduleURL String The base URL of the calling dbNP module 120 * @return list of assays in the study as JSON object list, filtered to only contain assays for the specified module, with 'externalAssayID' and 'name' for each assay 123 * @return list of assays in the study as JSON object list, filtered to only contain assays 124 * for the specified module, with 'externalAssayID' and 'name' for each assay 121 125 */ 122 126 def getAssays = { 123 127 List assays = [] 124 if( params.externalStudyID ) { 125 def study = Study.find( "from Study as s where s.code=?", [params.externalStudyID]) 128 if( params.externalStudyID || params.studyToken ) { 129 def id = params.studyToken ?: params.externalStudyID 130 def study = Study.find( "from Study as s where s.code=?", [id] ) 126 131 if(study && study.owner == requestUser) study.assays.each{ assay -> 127 132 if (assay.module.url.equals(params.moduleURL)) { 128 def map = ['name':assay.name, 'externalAssayID':assay.externalAssayID ]133 def map = ['name':assay.name, 'externalAssayID':assay.externalAssayID, 'assayToken':assay.externalAssayID] 129 134 assays.push( map ) 130 135 } … … 167 172 168 173 169 /* this is just for testing! */ 170 /*def test = { 171 render( dbnp.rest.common.CommunicationManager.getQueryResultWithOperator("Insulin",">",200) ) 172 }*/ 174 175 176 177 /** 178 * REST resource for dbNP modules. 179 * 180 * @param studyToken String, the external identifier of the study 181 * @return List of all fields of this study 182 * @return 183 * 184 * Example REST call (without authentication): 185 * http://localhost:8080/gscf/rest/getStudy/study?studyToken=PPSH 186 * 187 * Returns the JSON object: 188 * {"title":"NuGO PPS human study","studyToken":"PPSH","startDate":"2008-01-13T23:00:00Z", 189 * "Description":"Human study performed at RRI; centres involved: RRI, IFR, TUM, Maastricht U.", 190 * "Objectives":null,"Consortium":null,"Cohort name":null,"Lab id":null,"Institute":null, 191 * "Study protocol":null} 192 */ 193 def getStudy = { 194 def items = [:] 195 if( params.studyToken ) { 196 def study = Study.find( "from Study as s where code=?",[params.studyToken]) 197 study.giveFields().each { field -> 198 def name = field.name 199 def value = study.getFieldValue( name ) 200 if(name=="code") { name = "studyToken" } 201 items[name] = value 202 } 203 } 204 render items as JSON 205 } 206 207 208 209 /** 210 * REST resource for dbNP modules. 211 * 212 * @param assayToken String, the external identifier of the study 213 * @return List of all fields of this assay 214 * 215 * Example REST call (without authentication): 216 * http://localhost:8080/gscf/rest/getAssay/assay?assayToken=PPS3_SAM 217 * 218 * Returns the JSON object: {"name":"Lipid profiling","module":{"class":"dbnp.studycapturing.AssayModule","id":1, 219 * "name":"SAM module for clinical data","platform":"clinical measurements","url":"http://sam.nmcdsp.org"}, 220 * "assayToken":"PPS3_SAM","Description":null} 221 */ 222 def getAssay = { 223 def items = [:] 224 if( params.assayToken ) { 225 def assay = Assay.find( "from Assay as a where externalAssayID=?",[params.assayToken]) 226 assay.giveFields().each { field -> 227 def name = field.name 228 def value = assay.getFieldValue( name ) 229 if(name=="externalAssayID") { name = "assayToken" } 230 items[name] = value 231 } 232 } 233 render items as JSON 234 } 235 236 237 238 /** 239 * REST resource for data modules. 240 * Username and password should be supplied via HTTP Basic Authentication. 241 * One specific sample of a given Assay. 242 * 243 * @param externalAssayID String (externalAssayID of some Assay in GSCF) 244 * @return As a JSON object list, for each sample in that assay: 245 * @return 'name' (Sample name, which is unique) 246 * @return 'material' (Sample material) 247 * @return 'subject' (The name of the subject from which the sample was taken) 248 * @return 'event' (the name of the template of the SamplingEvent describing the sampling) 249 * @return 'startTime' (the time the sample was taken relative to the start of the study, as a string) 250 * 251 * Example REST call (without authentication): 252 * http://localhost:8080/gscf/rest/getSample/sam?assayToken=PPS3_SAM&sampleToken=A30_B 253 * 254 * Returns the JSON object: 255 * {"subject":"A30","event":"Liver extraction","startTime":"1 week, 1 hour", 256 * "sampleToken":"A30_B","material":{"class":"dbnp.data.Term","id":6,"accession":"BTO:0000131", 257 * "name":"blood plasma","ontology":{"class":"Ontology","id":2}},"Remarks":null, 258 * "Text on vial":"T70.91709057820039","Sample measured volume":null} 259 */ 260 def getSample = { 261 def items = [:] 262 if( params.assayToken && params.sampleToken ) { 263 def assay = Assay.find( "from Assay as a where externalAssayID=?",[params.assayToken]) 264 assay.getSamples().each { sample -> 265 if( sample.name == params.sampleToken ) { 266 items = [ 267 'subject' : sample.parentSubject.name, 268 'event' : sample.parentEvent.template.name, 269 'startTime' : sample.parentEvent.getStartTimeString() 270 ] 271 sample.giveFields().each { field -> 272 def name = field.name 273 def value = sample.getFieldValue( name ) 274 if(name=="name") { name = "sampleToken" } 275 items[name] = value 276 } 277 } 278 } 279 } 280 render items as JSON 281 } 173 282 } -
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r897 r901 717 717 * domain fields of this entity 718 718 */ 719 def List<TemplateField> giveFields() {719 def public List<TemplateField> giveFields() { 720 720 return this.giveDomainFields() + this.giveTemplateFields(); 721 721 }
Note: See TracChangeset
for help on using the changeset viewer.