{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Requirements\n", "\n", "- Installed git. More on how to use and install git can be found [here][git]. \n", "- A zip of the certificate. Particularly, you'll need the crt and key files.\n", "- A labkey access configuration file. A sample for [linux][linuxConfig] or [Windows][windowsConfig]. The file paths point to locations of extracted files from certificate zip on your disk.\n", "\n", "[git]: https://git-scm.com/\n", "[linuxConfig]: https://git0.fmf.uni-lj.si/studen/labkeyInterface/src/master/network-config-sample.json\n", "[windowsConfig]: https://git0.fmf.uni-lj.si/studen/labkeyInterface/src/master/network-config-sample.json" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "loadLibrary\n", "remoteSourcesURL https://git0.fmf.uni-lj.si/studen/nixSuite/raw/master/remoteResources/resources.json\n", "{'labkeyInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'irAEMM': {'url': 'https://git0.fmf.uni-lj.si/studen/iraemm/archive/master.zip', 'branch': 'master', 'modules': ['iraemmBrowser']}, 'SlicerLabkeyExtension': {'url': 'https://git0.fmf.uni-lj.si/studen/SlicerLabkeyExtension/archive/SlicerExtensionIndex.zip', 'branch': 'SlicerExtensionIndex', 'modules': ['labkeyBrowser']}, 'limfomiPET': {'url': 'https://git0.fmf.uni-lj.si/studen/limfomiPET/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser', 'segmentationBrowser']}, 'parseConfig': {'url': 'https://git0.fmf.uni-lj.si/studen/parseConfig/archive/master.zip', 'branch': 'master', 'modules': []}, 'orthancInterface': {'url': 'https://git0.fmf.uni-lj.si/studen/orthancInterface/archive/master.zip', 'branch': 'master', 'modules': []}, 'dynamicSPECT': {'url': 'https://git0.fmf.uni-lj.si/studen/dynamicSPECT/archive/master.zip', 'branch': 'master', 'modules': ['imageBrowser']}}\n", "{'url': 'https://git0.fmf.uni-lj.si/studen/labkeyInterface/archive/master.zip', 'branch': 'master', 'modules': []}\n", "File /home/studen/temp/labkeyInterface.zip: True\n" ] } ], "source": [ "#load required libraries\n", "import sys\n", "import os\n", "import chardet\n", "import json\n", "\n", "#you should get nixWrapper using an appropriate env\n", "#more details https://git0.fmf.uni-lj.si/studen/nixWrapper\n", "nixSuite=os.path.join(os.path.expanduser('~'),'software','src','nixSuite')\n", "sys.path.append(os.path.join(nixSuite,'wrapper'))\n", "import nixWrapper\n", "nixWrapper.loadLibrary('labkeyInterface')\n", "import labkeyInterface\n", "import labkeyDatabaseBrowser\n", "import labkeyFileBrowser\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "User: andrej studen CSRF: 02ab69b2d39a2791e287ea647dace30d\n" ] }, { "data": { "text/plain": [ "'02ab69b2d39a2791e287ea647dace30d'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#check connectivity. This checks the configuration in $HOME/.labkey/network.json, \n", "#where paths to certificates are stored\n", "net=labkeyInterface.labkeyInterface()\n", "#fconfig=os.path.join(os.path.expanduser('~'),'.labkey','network.json')\n", "fconfig=os.path.join(os.path.expanduser('~'),'.labkey','labkey-public.json')\n", "net.init(fconfig)\n", "#this reports the certificate used\n", "#print('Using: {}'.format(net.connectionConfig['SSL']['user']))\n", "#This gets a deafult CSRF code; It should report user name plus a long string of random hex numbers\n", "net.getCSRF()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'PCStageN': 'NX', '_labkeyurl_PCStageN': '/labkey/hypoAfrica/Study/list-details.view?listId=236&pk=1', 'Key': 2}\n", "{'PCStageN': 'N0', '_labkeyurl_PCStageN': '/labkey/hypoAfrica/Study/list-details.view?listId=236&pk=2', 'Key': 3}\n", "{'PCStageN': 'N1', '_labkeyurl_PCStageN': '/labkey/hypoAfrica/Study/list-details.view?listId=236&pk=3', 'Key': 4}\n" ] } ], "source": [ "db=labkeyDatabaseBrowser.labkeyDB(net)\n", "fb=labkeyFileBrowser.labkeyFileBrowser(net)\n", "#select a project\n", "schema='lists'\n", "project='hypoAfrica/Study'\n", "query='enumPCStageN'\n", "#queryOut='enumGIToxicity'\n", "#idFilter={'variable':'ParticipantId','value':'VUB_PA3','oper':'eq'}\n", "#empty filter\n", "qFilter=[]\n", "#qFilter can be a list of filters used in conjugation (logical AND)\n", "#qFilter=[idFilter]\n", "ds=db.selectRows(project,schema,query,qFilter)\n", "rows=ds['rows']\n", "lut={i+1:i+2 for i in range(len(rows))}\n", "for row in rows:\n", " #row as a dictionary\n", " #print(row)\n", " #update row\n", " #depending on field type adjust newValue\n", " #row['crfSponsorMode']='READ'\n", " #fn=row['formName']\n", " #lut={4:1,5:11,6:3,7:4,8:5,9:6,10:2}\n", " #for v in lut:\n", " # if fn==v:\n", " # row['formName']=lut[v]\n", " # break\n", " row['Key']=lut[int(row['Key'])]\n", " #print the new row\n", " print(row)\n", " #change the value of the field in database \n", " #if field is not in database, it will NOT be added and no changes will occur\n", " #st=db.modifyRows('insert',project,schema,queryOut,[row]) \n", " #print(st)\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "nix", "language": "python", "name": "nix" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }