Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Merge thehyve/cross_trial into thehyve/master
Browse files Browse the repository at this point in the history
Conflicts:
	TransmartCoreGrailsPlugin.groovy
	grails-app/conf/BuildConfig.groovy
	transmart-core-db-tests/TransmartCoreDbTestsGrailsPlugin.groovy
  • Loading branch information
cataphract committed Aug 12, 2014
2 parents 0f760c9 + 67aadb8 commit 557dba8
Show file tree
Hide file tree
Showing 47 changed files with 2,471 additions and 302 deletions.
25 changes: 22 additions & 3 deletions TransmartCoreGrailsPlugin.groovy
Expand Up @@ -19,9 +19,13 @@

import org.springframework.stereotype.Component
import org.transmartproject.db.accesscontrol.AccessControlChecks
import org.transmartproject.db.dataquery.clinical.InnerClinicalTabularResultFactory
import org.transmartproject.db.dataquery.clinical.variables.ClinicalVariableFactory
import org.transmartproject.db.dataquery.highdim.AbstractHighDimensionDataTypeModule
import org.transmartproject.db.http.BusinessExceptionResolver
import org.transmartproject.db.ontology.AcrossTrialsConceptsResourceDecorator
import org.transmartproject.db.ontology.AcrossTrialsOntologyTerm
import org.transmartproject.db.ontology.DefaultConceptsResource
import org.transmartproject.db.support.DatabasePortabilityService

class TransmartCoreGrailsPlugin {
Expand Down Expand Up @@ -68,11 +72,28 @@ A runtime dependency for tranSMART that implements the Core API
def doWithSpring = {
xmlns context:"http://www.springframework.org/schema/context"

def config = application.config

/* unless explicitly disabled, enable across trials functionality */
def haveAcrossTrials =
config.org.transmartproject.enableAcrossTrials != false

businessExceptionResolver(BusinessExceptionResolver)

accessControlChecks(AccessControlChecks)

clinicalVariableFactory(ClinicalVariableFactory)
clinicalVariableFactory(ClinicalVariableFactory) {
disableAcrossTrials = !haveAcrossTrials
}
innerClinicalTabularResultFactory(InnerClinicalTabularResultFactory)

if (haveAcrossTrials) {
conceptsResourceService(AcrossTrialsConceptsResourceDecorator) {
inner = new DefaultConceptsResource()
}
} else {
conceptsResourceService(DefaultConceptsResource)
}

context.'component-scan'('base-package': 'org.transmartproject.db.dataquery.highdim') {
context.'include-filter'(
Expand All @@ -86,8 +107,6 @@ A runtime dependency for tranSMART that implements the Core API
expression: Component.canonicalName)
}

// Config
def config = application.config
if (!config.org.transmartproject.i2b2.user_id) {
config.org.transmartproject.i2b2.user_id = 'i2b2'
}
Expand Down
6 changes: 3 additions & 3 deletions grails-app/conf/Config.groovy
Expand Up @@ -6,9 +6,9 @@ grails.databinding.trimStrings = false

///*
//Example configuration for using the reveng plugin
//grails.plugin.reveng.defaultSchema = 'DEAPP'
//grails.plugin.reveng.includeTables = ['DE_SUBJECT_METABOLOMICS_DATA', 'DE_METABOLITE_ANNOTATION']
//grails.plugin.reveng.packageName = 'org.transmartproject.db.dataquery.highdim.metabolite'
grails.plugin.reveng.defaultSchema = 'i2b2demodata'
grails.plugin.reveng.includeTables = ['modifier_dimension', 'modifier_metadata']
grails.plugin.reveng.packageName = 'org.transmartproject.db.i2b2data'
//*/

log4j = {
Expand Down
28 changes: 14 additions & 14 deletions grails-app/conf/DataSource.groovy
Expand Up @@ -5,20 +5,20 @@ hibernate {
}

// environment specific settings
//environments {
// development {
// dataSource {
// driverClassName = 'org.postgresql.Driver'
// url = 'jdbc:postgresql://localhost:5432/transmart'
// dialect = 'org.hibernate.dialect.PostgreSQLDialect'
//
environments {
development {
dataSource {
driverClassName = 'org.postgresql.Driver'
url = 'jdbc:postgresql://localhost:5433/transmart'
dialect = 'org.hibernate.dialect.PostgreSQLDialect'

// driverClassName = 'oracle.jdbc.driver.OracleDriver'
// url = 'jdbc:oracle:thin:@localhost:11521:CI'
// dialect = 'org.hibernate.dialect.Oracle10gDialect'
//
// username = 'biomart_user'
// password = 'biomart_user'
// dbCreate = 'none'
// }
// }
//}

username = 'biomart_user'
password = 'biomart_user'
dbCreate = 'none'
}
}
}
@@ -0,0 +1,47 @@
package org.transmartproject.db.ontology

class ModifierDimensionCoreDb {

String path
String code
String name
Long level
String studyId
String nodeType

// unused
// String modifierBlob
// Date updateDate
// Date downloadDate
// Date importDate
// Long uploadId

static mapping = {
table schema: 'i2b2demodata', name: 'modifier_dimension'
id name: 'path', generator: 'assigned'
version false

path column: 'modifier_path'
code column: 'modifier_cd'
name column: 'name_char'
level column: 'modifier_level'
studyId column: 'sourcesystem_cd'
nodeType column: 'modifier_node_type' // known values: {L, F}
}

static constraints = {
path maxSize: 700
code nullable: true, maxSize: 50
name nullable: true, maxSize: 2000
level nullable: true
studyId nullable: true, maxSize: 50
nodeType nullable: true, maxSize: 10

// unused:
// modifierBlob nullable: true
// updateDate nullable: true
// downloadDate nullable: true
// importDate nullable: true
// uploadId nullable: true
}
}
@@ -0,0 +1,69 @@
/*
* Copyright © 2013-2014 The Hyve B.V.
*
* This file is part of transmart-core-db.
*
* Transmart-core-db is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* transmart-core-db. If not, see <http://www.gnu.org/licenses/>.
*/

package org.transmartproject.db.ontology

/**
* View that joins {@link ModifierDimensionView} and
* {@link ModifierMetadataCoreDb}. It has to be done on a view because
* modifier_metadata inexplicably doesn't use modifier_dimension's primary key,
* though modifier_cd functions as a de facto second primary key.
*/
class ModifierDimensionView {

// it's a view!

String path
String code
String name
Long level
String studyId
String nodeType
String valueType
String unit
String visitInd = 'N'

static transients = ['visit']

Boolean visit

Boolean isVisit() {
visitInd == 'Y'
}

void setVisit(Boolean visit) {
visitInd == visit == null ? null :
visit ? 'Y' : 'N'
}

static mapping = {
table schema: 'i2b2demodata', name: 'modifier_dimension_view'
id name: 'path', generator: 'assigned'
version false

path column: 'modifier_path'
code column: 'modifier_cd'
name column: 'name_char'
level column: 'modifier_level'
studyId column: 'sourcesystem_cd'
nodeType column: 'modifier_node_type' // known values: {L, F}
valueType column: 'valtype_cd'
unit column: 'std_units'
}
}
@@ -0,0 +1,46 @@
package org.transmartproject.db.ontology

class ModifierMetadataCoreDb implements Serializable {

/* why the tables were designed in a way that this one has no reference
* modifier_dimension's primary key is beyond me.
* Add to that oddity that this table that it stores a boolean as a string
* and doesn't even have a primary key (though in this mapping I chose
* modifierCode as the primary key (the queries make it clear modifierCode
* must be unique) */
String code //id

String valueType
String unit
Character visitInd = 'N' as Character

static transients = ['visit']

Boolean visit

Boolean isVisit() {
visitInd == 'Y'
}

void setVisit(Boolean visit) {
visitInd == visit == null ? null :
visit ? 'Y' : 'N'
}

static mapping = {
table schema: 'i2b2demodata', name: 'modifier_metadata'
id generator: 'assigned', name: 'code'
version false

code column: 'modifier_cd'
valueType column: 'valtype_cd'
unit column: 'std_units'
}

static constraints = {
code maxSize: 50
valueType nullable: true, maxSize: 10
unit nullable: true, maxSize: 50
visitInd nullable: false
}
}
17 changes: 15 additions & 2 deletions grails-app/domain/org/transmartproject/db/user/User.groovy
Expand Up @@ -21,6 +21,7 @@ package org.transmartproject.db.user

import org.hibernate.FetchMode
import org.springframework.beans.factory.annotation.Autowired
import org.transmartproject.core.ontology.Study
import org.transmartproject.core.users.ProtectedOperation
import org.transmartproject.core.users.ProtectedResource
import org.transmartproject.db.accesscontrol.AccessControlChecks
Expand All @@ -44,7 +45,7 @@ class User extends PrincipalCoreDb implements org.transmartproject.core.users.Us
groups: Group
]

static transients = ['accessControlChecks']
static transients = ['accessControlChecks', 'admin', 'accessibleStudies']

static mapping = {
//table schema: 'searchapp', name: 'search_auth_user'
Expand Down Expand Up @@ -84,6 +85,11 @@ class User extends PrincipalCoreDb implements org.transmartproject.core.users.Us
//federatedId nullable: true, unique: true
}

/* not in api */
boolean isAdmin() {
roles.find { it.authority == RoleCoreDb.ROLE_ADMIN_AUTHORITY }
}

@Override
boolean canPerform(ProtectedOperation protectedOperation,
ProtectedResource protectedResource) {
Expand All @@ -95,7 +101,7 @@ class User extends PrincipalCoreDb implements org.transmartproject.core.users.Us
"$protectedResource")
}

if (roles.find { it.authority == RoleCoreDb.ROLE_ADMIN_AUTHORITY }) {
if (admin) {
/* administrators bypass all the checks */
log.debug "Bypassing check for $protectedOperation on " +
"$protectedResource for user $this because he is an " +
Expand All @@ -107,4 +113,11 @@ class User extends PrincipalCoreDb implements org.transmartproject.core.users.Us
protectedOperation,
protectedResource)
}

/* not in API */
Set<Study> getAccessibleStudies() {
def studies = accessControlChecks.getAccessibleStudiesForUser this
log.debug "User $this has access to studies: ${studies*.id}"
studies
}
}
Expand Up @@ -21,17 +21,19 @@ package org.transmartproject.db.clinical

import com.google.common.collect.Maps
import com.google.common.collect.Sets
import groovy.util.logging.Log4j
import org.springframework.beans.factory.annotation.Autowired
import org.transmartproject.core.dataquery.Patient
import org.transmartproject.core.dataquery.TabularResult
import org.transmartproject.core.dataquery.clinical.*
import org.transmartproject.core.exceptions.InvalidArgumentsException
import org.transmartproject.core.querytool.QueryResult
import org.transmartproject.db.dataquery.clinical.ClinicalDataTabularResult
import org.transmartproject.db.dataquery.clinical.TerminalConceptVariablesDataQuery
import org.transmartproject.db.dataquery.clinical.InnerClinicalTabularResultFactory
import org.transmartproject.db.dataquery.clinical.variables.ClinicalVariableFactory
import org.transmartproject.db.dataquery.clinical.variables.TerminalConceptVariable

@Log4j
class ClinicalDataResourceService implements ClinicalDataResource {

static transactional = false
Expand All @@ -41,6 +43,9 @@ class ClinicalDataResourceService implements ClinicalDataResource {
@Autowired
ClinicalVariableFactory clinicalVariableFactory

@Autowired
InnerClinicalTabularResultFactory innerResultFactory

@Override
ClinicalDataTabularResult retrieveData(List<QueryResult> queryResults,
List<ClinicalVariable> variables) {
Expand All @@ -62,6 +67,11 @@ class ClinicalDataResourceService implements ClinicalDataResource {
TabularResult<ClinicalVariableColumn, PatientRow> retrieveData(Set<Patient> patientCollection,
List<ClinicalVariable> variables) {

if (!variables) {
throw new InvalidArgumentsException(
'No variables passed to #retrieveData()')
}

def session = sessionFactory.openStatelessSession()

try {
Expand All @@ -72,18 +82,18 @@ class ClinicalDataResourceService implements ClinicalDataResource {
List<TerminalConceptVariable> flattenedVariables = []
flattenClinicalVariables(flattenedVariables, variables)

TerminalConceptVariablesDataQuery query =
new TerminalConceptVariablesDataQuery(
session: session,
patientIds: patientMap.keySet(),
clinicalVariables: flattenedVariables)
query.init()
def intermediateResults = []
if (!patientCollection.empty) {
intermediateResults = innerResultFactory.
createIntermediateResults(session,
patientCollection, flattenedVariables)
} else {
log.info("No patients passed to retrieveData() with" +
"variables $variables; will skip main queries")
}

new ClinicalDataTabularResult(
query.openResultSet(),
variables,
flattenedVariables,
patientMap)
session, intermediateResults, patientMap)
} catch (Throwable t) {
session.close()
throw t
Expand Down

0 comments on commit 557dba8

Please sign in to comment.