from labkey.utils import create_server_context from labkey.query import select_rows, QueryFilter print("Create a server context") server_context = create_server_context('idri.labkey.com', 'Formulations') ssr = select_rows(server_context, 'Samples', 'Formulations') print("select_rows: There are " + str(len(ssr['rows'])) + " rows.") ssr = select_rows(server_context, 'Samples', 'Formulations', filter_array=[ QueryFilter('Batch', 'QF', filter_type=QueryFilter.Types.CONTAINS) ]) print("select_rows: There are " + str(len(ssr['rows'])) + " filtered rows.")
# validate call is made as expected expected_args = expected_kwargs.pop('expected_args') mock_post.assert_called_once_with(*expected_args, **expected_kwargs) configs = { 'protocol': 'https://' , 'server': 'my_testServer:8080' , 'context_path': 'testPath' , 'project_path': 'testProject/subfolder' } schema = 'testSchema' query = 'testQuery' server_context = create_server_context(configs['server'], configs['project_path'], configs['context_path']) class TestDeleteRows(unittest.TestCase): def setUp(self): self.configs = configs.copy() self.service = MockDeleteRows(**self.configs) self.expected_kwargs = { 'expected_args': [self.service.get_server_url()] , 'data': '{"queryName": "' + query + '", "rows": "{id:1234}", "schemaName": "' + schema + '"}' , 'headers': {u'Content-Type': u'application/json'} , 'timeout': 30 } rows = '{id:1234}'
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Sample to get a batch from labkey.utils import create_server_context from labkey.experiment import load_batch print("Create a server context") project_name = 'ModuleAssayTest' # Project folder name server_context = create_server_context('localhost:8080', project_name, 'labkey', use_ssl=False) print("Load an Assay batch from the server") assay_id = 2809 # provide one from your server batch_id = 120 # provide one from your server run_group = load_batch(server_context, assay_id, batch_id) if run_group is not None: print("Batch Id: " + str(run_group.id)) print("Created By: " + run_group.created_by)
from __future__ import unicode_literals from labkey.utils import create_server_context from labkey.exceptions import RequestError, QueryNotFoundError, ServerContextError, ServerNotFoundError from labkey.query import select_rows, update_rows, Pagination, QueryFilter, \ insert_rows, delete_rows, execute_sql from requests.exceptions import Timeout import copy print("Create a server context") labkey_server = 'localhost:8080' project_name = 'moduleAssayTest' # Project folder name contextPath = 'labkey' server_context = create_server_context(labkey_server, project_name, contextPath, use_ssl=False) schema = 'lists' table = 'Demographics' column1 = 'Group Assignment' column2 = 'Participant ID' ################### # Test basic select_rows ################### result = select_rows(server_context, schema, table) if result is not None: print(result['rows'][0]) print("select_rows: There are " + str(result['rowCount']) + " rows.") else:
from __future__ import unicode_literals from labkey.utils import create_server_context from labkey.exceptions import RequestError, QueryNotFoundError, ServerContextError, ServerNotFoundError from labkey.query import select_rows, update_rows, Pagination, QueryFilter, \ insert_rows, delete_rows, truncate_table, execute_sql from requests.exceptions import Timeout import copy print("Create a server context") labkey_server = 'localhost:8080' project_name = 'ModuleAssayTest' # Project folder name context_path = 'labkey' server_context = create_server_context(labkey_server, project_name, context_path, use_ssl=False) schema = 'lists' table = 'Demographics' column1 = 'Group Assignment' column2 = 'Participant ID' ################### # Test basic select_rows ################### result = select_rows(server_context, schema, table) if result is not None: print(result['rows'][0]) print("select_rows: There are " + str(result['rowCount']) + " rows.") else:
""" Examples using the Experiment.py API Sample code to submit a single batch of Assay data containing a run with three rows of data """ from labkey.utils import create_server_context from labkey.experiment import save_batch, Batch, Run assay_id = 2809 # provide one from your server. rowid from the URL query parameters print("Create a server context") project_name = 'ModuleAssayTest' server_context = create_server_context('localhost:8080', project_name, 'labkey', use_ssl=False) # Run data rows dataRows = [ { # ColumnName : Value "SampleId": "Monkey 1", "TimePoint": "2008/11/02 11:22:33", "DoubleData": 4.5, "HiddenData": "another data point" }, { "SampleId": "Monkey 2", "TimePoint": "2008/11/02 14:00:01", "DoubleData": 3.1,
context = SSL.Context(SSL.SSLv23_METHOD) # Get REDCap params from config file rc_api_url = config.rcparams['rc_api_url'] rc_base_url = config.rcparams['rc_base_url'] rc_refer_pid = config.rcparams['ndd_rc_refer_pid'] rc_refer_apikey = config.rcparams['ndd_rc_refer_apikey'] rc_data_pid = config.rcparams['ndd_rc_data_pid'] rc_data_apikey = config.rcparams['ndd_rc_data_apikey'] rc_sample_pid = config.rcparams['ndd_rc_sample_pid'] rc_sample_apikey = config.rcparams['ndd_rc_sample_apikey'] # Initialize LK properties from config file and create server context where queries will be executed labkey_server = config.lkparams['labkey_server'] project_name = config.lkparams['project_name'] context_path = config.lkparams['context_path'] use_ssl = config.lkparams['use_ssl'] server_context = create_server_context(labkey_server, project_name, context_path, use_ssl) app = Flask(__name__) app.config['SERVER_NAME']=config.flaskparams['servname'] app.config['PREFERRRED_URL_SCHEME']='https' cors = CORS(app, resources={r'/*': {'origins': originspermitted}}) # Pull RedCap metadata that will be used in various routes dd_refer = NDDdb.getMetaData(rc_api_url, rc_refer_apikey, 'family_members') dd_data = NDDdb.getMetaData(rc_api_url, rc_data_apikey, 'family_members') dd_refer.set_index(keys='field_name', drop = False, inplace = True, verify_integrity = True) dd_data.set_index(keys='field_name', drop = False, inplace = True, verify_integrity = True) # Relation map for LabKey updates reln_map = NDDdb.parseChoiceMap(dd_data.loc['demo_relation','select_choices_or_calculations'], CHOICEPATTERN, ALTPATTERN)