Welcome to fhirpath-guillotina’s documentation!

Introduction

https://img.shields.io/pypi/v/fhirpath_guillotina.svg https://img.shields.io/travis/nazrulworld/fhirpath_guillotina.svg Documentation Status Test Coverage

A guillotina framework powered fhirpath provider. Full battery included to use fhirpath more efficiently.

If you don’t know about FHIR® and HL7®, Please have a look here.

Quickstart

  1. Make sure fhirpath_guillotina is added as addon in your guillotina configure file.

  2. Make sure elasticsearch server configured properly.

  3. Make sure you have FHIR resource contenttypes registered (see example bellow).

  4. Make sure you have FHIR resources mapping (correct version) for elasticsearch.

Example: Add Contents:

>>> from fhirpath_guillotina.field import FhirField

class IOrganization(IFhirContent, IContentIndex):
    index_field(
        "organization_resource",
        type="object",
        field_mapping=fhir_resource_mapping("Organization"),
        fhirpath_enabled=True,
        resource_type="Organization",
        fhir_release=FHIR_VERSION.R4,
    )
    index_field("org_type", type="keyword")
    org_type = TextLine(title="Organization Type", required=False)
    organization_resource = FhirField(
        title="Organization Resource", resource_type="Organization", fhir_release="R4"
    )


@configure.contenttype(type_name="Organization", schema=IOrganization)
class Organization(Folder):
    """ """

    index(schemas=[IOrganization], settings={})
    resource_type = "Organization"

Example Search:

>>> from guillotina.component import query_utility
>>> from fhirpath.interfaces import ISearchContextFactory
>>> from fhirpath.interfaces import IFhirSearch
>>> search_context = query_utility(ISearchContextFactory).get(
...    resource_type="Organization"
... )
>>> search_tool = query_utility(IFhirSearch)
>>> params = (
...     ("active", "true"),
...     ("_lastUpdated", "2010-05-28T05:35:56+00:00"),
...     ("_profile", "http://hl7.org/fhir/Organization"),
...     ("identifier", "urn:oid:2.16.528.1|91654"),
...     ("type", "http://hl7.org/fhir/organization-type|prov"),
...     ("address-postalcode", "9100 AA")
... )
>>> fhir_bundle = await search_tool(params, context=search_context)
>>> fhir_bundle.total == len(fhir_bundle.entry)

Example FhirPath Query:

>>> from fhirpath.interfaces import IElasticsearchEngineFactory
>>> from guillotina.component import query_utility
>>> from fhirpath.enums import SortOrderType
>>> from fhirpath.fql import Q_
>>> from fhirpath.fql import T_
>>> from fhirpath.fql import V_
>>> from fhirpath.fql import sort_
>>> engine = query_utility(IElasticsearchEngineFactory).get()
>>> query_builder = Q_(resource="Organization", engine=engine)
>>> query_builder = (
...        query_builder.where(T_("Organization.active") == V_("true"))
...        .where(T_("Organization.meta.lastUpdated", "2010-05-28T05:35:56+00:00"))
...        .sort(sort_("Organization.meta.lastUpdated", SortOrderType.DESC))
...        .limit(20)
...    )
>>> query_result = query_builder(async_result=True)
>>> result = query_result.fetchall()
>>> result.header.total == 100
True
>>> len(result.body) == 20
True
>>> async for resource in query_result:
...     assert resource.resource_type == "Organization"

Credits

This package skeleton was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

Installation

Stable release

To install fhirpath-guillotina, run this command in your terminal:

$ pip install fhirpath_guillotina

This is the preferred method to install fhirpath-guillotina, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for fhirpath-guillotina can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/nazrulworld/fhirpath_guillotina

Or download the tarball:

$ curl  -OL https://github.com/nazrulworld/fhirpath_guillotina/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

To use fhirpath-guillotina in a project:

import fhirpath_guillotina

fhirpath_guillotina

fhirpath_guillotina package

Submodules

fhirpath_guillotina.engine module

class fhirpath_guillotina.engine.ElasticsearchConnection(conn)[source]

Bases: fhirpath.connectors.factory.es.ElasticsearchConnection

Elasticsearch Connection

async count(index, compiled_query)[source]
async fetch(index, compiled_query)[source]

xxx: must have use scroll+slice https://stackoverflow.com/questions/43211387/what-does-elasticsearch-automatic-slicing-do https://stackoverflow.com/questions/50376713/elasticsearch-scroll-api-with-multi-threading

classmethod from_url(url: str)[source]
async scroll(scroll_id, scroll='30s')[source]
async server_info()[source]
class fhirpath_guillotina.engine.ElasticsearchEngine(fhir_release, conn_factory, dialect_factory)[source]

Bases: fhirpath.engine.es.ElasticsearchEngine

Elasticsearch Engine

build_security_query(query)[source]
calculate_field_index_name(resource_type=None, index_config=None)[source]

1.) xxx: should be cached

async execute(query, unrestricted=False, query_type=<EngineQueryType.DML: 'DML'>)[source]
extract_hits(selects, hits, container)[source]
static field_index_config_from_factory(factory, resource_type=None)[source]
async get_index_name(container=None)[source]
get_mapping(resource_type=None, index_config=None)[source]
async process_raw_result(rawresult, selects)[source]
wrapped_with_bundle(result)[source]

fhirpath_guillotina.field module

class fhirpath_guillotina.field.DefaultFhirFieldSchemaSerializer(field, schema, request)[source]

Bases: guillotina.json.serialize_schema_field.DefaultSchemaFieldSerializer

property field_type
class fhirpath_guillotina.field.FhirField(resource_class=None, resource_interface=None, resource_type=None, fhir_release=None, **kw)[source]

Bases: guillotina.schema._field.Object

FhirResource also known as FHIR field is the schema field derrived from z3c.form’s field.

It takes all initilial arguments those are derrived from standard schema field, with additionally model, resource_type and resource_interface

Note

field name must be start with lowercase name of FHIR Resource.

ensure_fhir_abstract(klass)[source]
from_dict(dict_value)[source]
from_unicode(str_val)[source]
class fhirpath_guillotina.field.FhirFieldValue(obj: NewType.<locals>.new_type = None)[source]

Bases: object

FhirResourceValue is a proxy class for holding any object derrived from fhir.resources.resource.Resource

foreground_origin()[source]

Return the original object of FHIR model that is proxied!

patch(patch_data)[source]
stringify(prettify=False)[source]
fhirpath_guillotina.field.fhir_field_deserializer(fhirfield, value, context=None)[source]
fhirpath_guillotina.field.fhir_field_from_resource_type(resource_type: str, cache: bool = True) → Optional[dict][source]
fhirpath_guillotina.field.fhir_field_from_schema(schema: <InterfaceClass zope.interface.Interface>, resource_type: str = None) → Optional[fhirpath_guillotina.field.FhirField][source]
fhirpath_guillotina.field.fhir_field_value_serializer(value)[source]

fhirpath_guillotina.helpers module

fhirpath_guillotina.helpers.parse_json_str(str_val: str) → Optional[dict][source]

fhirpath_guillotina.interfaces module

Module where all interfaces, events and exceptions live.

fhirpath_guillotina.utilities module

class fhirpath_guillotina.utilities.ElasticsearchEngineFactory[source]

Bases: object

get(fhir_release=None)[source]
class fhirpath_guillotina.utilities.FhirSearch[source]

Bases: object

create_context(resource_type, fhir_release=None, unrestricted=False)[source]
class fhirpath_guillotina.utilities.SearchContextFactory[source]

Bases: object

get(resource_type, fhir_release=None, unrestricted=False)[source]
fhirpath_guillotina.utilities.create_engine(fhir_release=None)[source]
fhirpath_guillotina.utilities.default_settings()[source]

Module contents

fhirpath_guillotina.includeme(root)[source]

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/nazrulworld/fhirpath_guillotina/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

fhirpath-guillotina could always use more documentation, whether as part of the official fhirpath-guillotina docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/nazrulworld/fhirpath_guillotina/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up fhirpath_guillotina for local development.

  1. Fork the fhirpath_guillotina repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/fhirpath_guillotina.git
    
  3. Install your local copy into a virtualenv. Assuming you have pipenv installed, this is how you set up your fork for local development:

    $ cd fhirpath_guillotina/
    $ pipenv install --dev -e .[test]
    $ pipenv shell
    $ pytest tests
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ make lint
    $ pytest tests
    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  6. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  7. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

  3. The pull request should work for Python 3.7, 3.8, and optionally for PyPy. Check https://travis-ci.org/nazrulworld/fhirpath_guillotina/pull_requests and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ pytest tests.test_fhirpath_guillotina

Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:

$ bumpversion patch # possible: major / minor / patch
$ git push
$ git push --tags

Travis will then deploy to PyPI if tests pass.

Credits

Development Lead

Contributors

None yet. Why not be the first?

History

0.4.0 (2020-05-16)

Improvements

  • supports fhirpath 0.6.1 or later version.

  • supports guillotina 5.3.x but not 6.x.x

0.3.0 (2019-11-13)

Improvements

  • supports https://pypi.org/project/fhirpath/ 0.4.0 or later version.

0.2.0 (2019-10-10)

0.1.0 (2019-08-24)

  • First release on PyPI. [nazrulworld]

Indices and tables