{ "info": { "author": "HealthSamurai", "author_email": "fhirbase.py@health-samurai.io", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Database :: Front-Ends", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "[![Build Status](https://travis-ci.org/fhirbase/fhirbase.py.svg?branch=master)](https://travis-ci.org/fhirbase/fhirbase.py)\n[![pypi](https://img.shields.io/pypi/v/fhirbase.svg)](https://pypi.python.org/pypi/fhirbase)\n\n# fhirbase.py\nFHIRBase connector for python.\nThis package provides wrapper over psycopg2 connection which\nprovides CRUD for resources in fhirbase.\n\n# Install\n```\npip install fhirbase\n```\n\n# Usage\nImport `fhirbase` and `psycopg2` libraries:\n```\nimport fhirbase\nimport psycopg2\n```\n\nCreate a connection using `psycopg2.connect`;\n\n```\nconnection = psycopg2.connect(\n dbname='postgres', user='postgres',\n host='localhost', port='5432')\n```\n\nCreate an instance of `FHIRBase`:\n```\nfb = fhribase.FHIRBase(connection)\n```\n\nNow you can use the following methods of `FHIRBase` instance:\n* `.execute(sql, params=None, commit=False)`\n* `.execute_without_result(sql, params=None, commit=False)`\n* `.row_to_resource(row)`\n\nCRUD methods work with [FHIR resources](https://www.hl7.org/fhir/resourcelist.html).\nResource represented as a dict with specified `resourceType` key as required key.\nThe following methods works with resource and returns resources.\n\n* `.create(resource, txid=None, commit=True)`\n* `.update(resource, txid=None, commit=True)`\n* `.delete(resource, txid=None, commit=True)`/`.delete(resource_type, id, txid=None, commit=True)`\n* `.read(resource)`/`.read(resource_type, id)`\n* `.list(sql, params=None)`\n\n# Methods\n\n### .execute\nExecutes sql with params.\n\nSyntax: `.execute(sql, params=None, commit=False)`\n\nReturns: context manager with cursor as context\n\nExample:\n```\nwith fb.execute('SELECT * FROM patient WHERE id=%s', ['id']) as cursor:\n print(cursor.fetchall())\n```\n\n### .execute_without_result\nExecutes sql with params.\n\nSyntax: `.execute_without_result(sql, params=None, commit=False)`\n\nReturns: nothing\n\nExample:\n```\nfb.execute_without_result('INSERT INTO transaction (resource) VALUES (%s)', ['{}'])\n```\n\n### `.row_to_resource`\nTransforms row raw from DB to resource.\n\nSyntax: `.row_to_resource(row)`\n\nReturns: resource representation (dict)\n\nExample:\n```\nfb.row_to_resource({\n 'resource': {'name': []},\n 'ts': 'ts',\n 'txid': 'txid',\n 'resource_type': 'Patient',\n 'meta': {'tag': 'created'},\n 'id': 'id',\n}))\n```\n\nwill return resource representation:\n\n```\n{\n 'id': 'id',\n 'meta': {'lastUpdated': 'ts', 'versionId': 'txid'},\n 'name': [],\n 'resourceType': 'Patient',\n}\n```\n\n### `.create`\nCreates resource.\nIf txid is not specified, new unique logical transaction id will be generated.\n\nSyntax: `.create(resource, txid=None, commit=True)`\n\nReturns: resource representation (dict)\n\nExample:\n```\nfb.create({\n 'resourceType': 'Patient',\n 'name': [{'text': 'John'}],\n})\n```\nreturns\n```\n{\n 'resourceType': 'Patient',\n 'id': 'UNIQUE ID',\n 'name': [{'text': 'John'}],\n 'meta': {'lastUpdated': 'timestamp', 'versionId': 'txid'},\n}\n```\n\n### `.update`\nUpdates resource.\nIf txid is not specified, new unique logical transaction id will be generated.\n\nKey `id` is required in `resource` argument.\n\nSyntax: `.update(resource, txid=None, commit=True)`\n\nReturns: resource representation (dict)\n\nExample:\n```\nfb.update({\n 'resourceType': 'Patient',\n 'id': 'id',\n 'name': [{'text': 'John'}],\n})\n```\n\nreturns\n\n```\n{\n 'resourceType': 'Patient',\n 'id': 'UNIQUE ID',\n 'name': [{'text': 'John'}],\n 'meta': {'lastUpdated': 'timestamp', 'versionId': 'txid'},\n}\n```\n\n\n### `.delete`\nDeletes resource.\nIf txid is not specified, new unique logical transaction id will be generated.\nKeys `id` and `resourceType` are required in `resource` argument in first variant of usage.\n\nSyntax: `.delete(resource, txid=None, commit=True)` or `.delete(resource_type, id, txid=None, commit=True)`\n\nReturns: nothing\n\nExample:\n```\nfb.delete({\n 'resourceType': 'Patient',\n 'id': 'id',\n})\n```\n\nor\n\n```\nfb.delete(resource_type='Patient', id='id')\n```\n\n\n### `.read`\nReads resource.\nKeys `id` and `resourceType` are required in `resource` argument in first variant of usage.\n\nSyntax: `.read(resource)` or `.read(resource_type, id)`\n\nReturns: resource representation (dict)\n\nExample:\n```\nfb.read({\n 'resourceType': 'Patient',\n 'id': 'id',\n})\n```\n\nor\n\n```\nfb.read(resource_type='Patient', id='id')\n```\n\n### `.list`\n\nExecutes SQL and returns iterator of resources.\nNote: sql query must return all fields of resource table.\n\nSyntax: `.list(sql, params)`\n\nReturns: iterator of resources\n\nExample:\n```\nfor patient in fb.list('SELECT * FROM patient'):\n print(patient)\n```\n\nor\n\n```\npatients = list(fb.list('SELECT * FROM patient'))\n```\n\n# Example application\nTo run example, just do:\n\n```\ndocker-compose build\ndocker-compose up -d\n```\nWait until db starting process will be completed, and run:\n\n```\ndocker-compose run --rm fhirbase fhirbase init 3.0.1\ndocker-compose run --rm fhirbasepy python examples/example.py\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/fhirbase/fhirbase.py", "keywords": "fhir,fhirbase", "license": "", "maintainer": "", "maintainer_email": "", "name": "fhirbase", "package_url": "https://pypi.org/project/fhirbase/", "platform": "", "project_url": "https://pypi.org/project/fhirbase/", "project_urls": { "Homepage": "http://github.com/fhirbase/fhirbase.py" }, "release_url": "https://pypi.org/project/fhirbase/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "fhirbase connector", "version": "0.0.1" }, "last_serial": 4240284, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "b62fd592b0130cd88c2cfebc7a0cb878", "sha256": "530408651a35a96e779ba2a2b22dc14eed1c47d026c296d300185ccf5574433f" }, "downloads": -1, "filename": "fhirbase-0.0.1.tar.gz", "has_sig": false, "md5_digest": "b62fd592b0130cd88c2cfebc7a0cb878", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5031, "upload_time": "2018-09-05T08:44:08", "url": "https://files.pythonhosted.org/packages/94/76/5f7cd40c23216d5bf21037ef225bce66e7a8c5c37f4ee9e4f0e4a287e80e/fhirbase-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b62fd592b0130cd88c2cfebc7a0cb878", "sha256": "530408651a35a96e779ba2a2b22dc14eed1c47d026c296d300185ccf5574433f" }, "downloads": -1, "filename": "fhirbase-0.0.1.tar.gz", "has_sig": false, "md5_digest": "b62fd592b0130cd88c2cfebc7a0cb878", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5031, "upload_time": "2018-09-05T08:44:08", "url": "https://files.pythonhosted.org/packages/94/76/5f7cd40c23216d5bf21037ef225bce66e7a8c5c37f4ee9e4f0e4a287e80e/fhirbase-0.0.1.tar.gz" } ] }