def available_schemata(context, request): """ Returns a list of available schemata for the given context Criteria for available schemata: * Must be configured for a study (i.e NOT patient/enrollment forms) * Must NOT be retracted GET parameters: schema -- (optional) only shows results for specific schema name (useful for searching for a schema's publish dates) term -- (optional) filters by schema title or publish date grouped -- (optional) groups all results by schema name """ db_session = request.db_session class SearchForm(Form): term = wtforms.StringField() schema = wtforms.StringField() grouped = wtforms.BooleanField() form = SearchForm(request.GET) form.validate() query = ( db_session.query(datastore.Schema) # only allow forms that are available to active studies .join(models.study_schema_table) .join(models.Study) .filter(datastore.Schema.retract_date == sa.null())) if form.schema.data: query = query.filter(datastore.Schema.name == form.schema.data) if form.term.data: wildcard = u'%' + form.term.data + u'%' query = query.filter( datastore.Schema.title.ilike(wildcard) | sa.cast(datastore.Schema.publish_date, sa.Unicode).ilike(wildcard)) query = ( query.order_by( datastore.Schema.title, datastore.Schema.publish_date.asc()) .limit(100)) if form.grouped.data: schemata = form2json(query) else: schemata = [version2json(i) for i in query] return { '__query__': form.data, 'schemata': schemata }
def available_schemata(context, request): """ Returns a list of available schemata for the given context Criteria for available schemata: * Must be configured for a study (i.e NOT patient/enrollment forms) * Must NOT be retracted GET parameters: schema -- (optional) only shows results for specific schema name (useful for searching for a schema's publish dates) term -- (optional) filters by schema title or publish date grouped -- (optional) groups all results by schema name """ db_session = request.db_session class SearchForm(Form): term = wtforms.StringField() schema = wtforms.StringField() grouped = wtforms.BooleanField() form = SearchForm(request.GET) form.validate() query = ( db_session.query(datastore.Schema) # only allow forms that are available to active studies .join(models.study_schema_table).join( models.Study).filter(datastore.Schema.retract_date == sa.null())) if form.schema.data: query = query.filter(datastore.Schema.name == form.schema.data) if form.term.data: wildcard = u'%' + form.term.data + u'%' query = query.filter( datastore.Schema.title.ilike(wildcard) | sa.cast(datastore.Schema.publish_date, sa.Unicode).ilike( wildcard)) query = (query.order_by(datastore.Schema.title, datastore.Schema.publish_date.asc()).limit(100)) if form.grouped.data: schemata = form2json(query) else: schemata = [version2json(i) for i in query] return {'__query__': form.data, 'schemata': schemata}
def available_schemata(context, request): """ Returns a listing of available schemata for the study The results will try to exclude schemata configured for patients, or schemata that is currently used by the context study (if editing). GET parameters: term -- (optional) filters by schema title or publish date schema -- (optional) only shows results for specific schema name (useful for searching for a schema's publish dates) grouped -- (optional) groups all results by schema name """ db_session = request.db_session class SearchForm(Form): term = wtforms.StringField() schema = wtforms.StringField() grouped = wtforms.BooleanField() form = SearchForm(request.GET) form.validate() query = ( db_session.query(datastore.Schema).filter( datastore.Schema.publish_date != sa.null()).filter( datastore.Schema.retract_date == sa.null()).filter( ~datastore.Schema.name.in_( # Exclude patient schemata db_session.query(datastore.Schema.name).join( models.patient_schema_table).subquery()))) if form.schema.data: query = query.filter(datastore.Schema.name == form.schema.data) if form.term.data: wildcard = u'%' + form.term.data + u'%' query = query.filter( datastore.Schema.title.ilike(wildcard) | sa.cast(datastore.Schema.publish_date, sa.Unicode).ilike( wildcard)) if isinstance(context, models.Study): # Filter out schemata that is already in use by the study if context.randomization_schema: query = query.filter( datastore.Schema.name != context.randomization_schema.name) if context.termination_schema: query = query.filter( datastore.Schema.name != context.termination_schema.name) query = query.filter(~datastore.Schema.id.in_( db_session.query(datastore.Schema.id).select_from( models.Study).filter(models.Study.id == context.id).join( models.Study.schemata).subquery())) query = (query.order_by(datastore.Schema.title, datastore.Schema.publish_date.asc()).limit(100)) return { '__query__': form.data, 'schemata': (form2json(query) if form.grouped.data else [version2json(i) for i in query]) }
def available_schemata(context, request): """ Returns a listing of available schemata for the study The results will try to exclude schemata configured for patients, or schemata that is currently used by the context study (if editing). GET parameters: term -- (optional) filters by schema title or publish date schema -- (optional) only shows results for specific schema name (useful for searching for a schema's publish dates) grouped -- (optional) groups all results by schema name """ db_session = request.db_session class SearchForm(Form): term = wtforms.StringField() schema = wtforms.StringField() grouped = wtforms.BooleanField() form = SearchForm(request.GET) form.validate() query = ( db_session.query(datastore.Schema) .filter(datastore.Schema.publish_date != sa.null()) .filter(datastore.Schema.retract_date == sa.null()) .filter(~datastore.Schema.name.in_( # Exclude patient schemata db_session.query(datastore.Schema.name) .join(models.patient_schema_table) .subquery()))) if form.schema.data: query = query.filter(datastore.Schema.name == form.schema.data) if form.term.data: wildcard = u'%' + form.term.data + u'%' query = query.filter( datastore.Schema.title.ilike(wildcard) | sa.cast(datastore.Schema.publish_date, sa.Unicode).ilike(wildcard)) if isinstance(context, models.Study): # Filter out schemata that is already in use by the study if context.randomization_schema: query = query.filter( datastore.Schema.name != context.randomization_schema.name) if context.termination_schema: query = query.filter( datastore.Schema.name != context.termination_schema.name) query = query.filter(~datastore.Schema.id.in_( db_session.query(datastore.Schema.id) .select_from(models.Study) .filter(models.Study.id == context.id) .join(models.Study.schemata) .subquery())) query = ( query.order_by( datastore.Schema.title, datastore.Schema.publish_date.asc()) .limit(100)) return { '__query__': form.data, 'schemata': (form2json(query) if form.grouped.data else [version2json(i) for i in query]) }