google-fhir-r4


Namegoogle-fhir-r4 JSON
Version 0.11.0 PyPI version JSON
download
home_pagehttps://github.com/google/fhir-py
SummaryComponents for working with FHIR R4.
upload_time2024-07-15 21:51:28
maintainerNone
docs_urlNone
authorGoogle LLC
requires_python<3.12,>=3.8
licenseApache 2.0
keywords google fhir python healthcare
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Protocol buffer conversion, validation and utilities for FHIR R4 resources.

Users in interested in analyzing FHIR data should reference the
`google.fhir.views` package. This library contains underlying capabilities to
work with FHIR data represented in protocol buffers in PYthon code.

## FHIR JSON to and from Protocol Buffers
The `json_format` package supports converting FHIR protocol buffers to and
from the FHIR JSON format. Here are some simple examples:

```py
from google.fhir.r4 import json_format
from google.fhir.r4.proto.core.resources import patient_pb2

patient_json = """
{
  "resourceType" : "Patient",
  "id" : "example",
  "name" : [{
    "use" : "official",
    "family" : "Roosevelt",
    "given" : ["Franklin", "Delano"]
  }]
}
"""

# Read the JSON as a proto:
patient = json_format.json_fhir_string_to_proto(patient_json, patient_pb2.Patient)

# Get the FHIR JSON representation of the proto:
json_format.print_fhir_to_json_string(patient)
```

## FHIRPath support
FHIRPath is the basis of the `google-fhir-views` logic, but can also be used
directly against FHIR protos themselves. Here is an example:

```py
from google.fhir.r4 import fhir_path
from google.fhir.r4 import r4_package
from google.fhir.core.fhir_path import context

# Create the FHIRPath context for use.
fhir_path_context = context.LocalFhirPathContext(r4_package.load_base_r4())

# Compile the FHIRPath expressions for evaluation. This validates the FHIRPath and returns
# an optimized structure that can be efficiently evaluated over protocol buffers.
# The compiled expression is typically created once and reused for many following invocations.
expr = fhir_path.compile_expression('Patient', fhir_path_context, "name.where(use = 'official').family")

# Now we evaluate the expression on the given resource.
result = expr.evaluate(patient)

# Check to see if the result matched anything.
if result.has_value():
  # Gets the result as protocol buffer messages.
  result_as_messages = result.messages
  # Converts the result to a simple string, if applicable.
  result_as_simple_string = result.as_string()
```

The library also supports a fluent Python builder for creating FHIRPath expressions,
which is used extensively in the `google.fhir.views` package. Here is
the above string being created using a Python builder pattern:

```py
# FHIRPath builder for patients.
pat = fhir_path.builder('Patient', fhir_path_context)

# Build the expression and get it in string form.
fhir_path_string = pat.name.where(pat.name.use == 'official').family.fhir_path
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/google/fhir-py",
    "name": "google-fhir-r4",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.12,>=3.8",
    "maintainer_email": null,
    "keywords": "google, fhir, python, healthcare",
    "author": "Google LLC",
    "author_email": "google-fhir-pypi@google.com",
    "download_url": "https://github.com/google/fhir-py/releases",
    "platform": null,
    "description": "Protocol buffer conversion, validation and utilities for FHIR R4 resources.\n\nUsers in interested in analyzing FHIR data should reference the\n`google.fhir.views` package. This library contains underlying capabilities to\nwork with FHIR data represented in protocol buffers in PYthon code.\n\n## FHIR JSON to and from Protocol Buffers\nThe `json_format` package supports converting FHIR protocol buffers to and\nfrom the FHIR JSON format. Here are some simple examples:\n\n```py\nfrom google.fhir.r4 import json_format\nfrom google.fhir.r4.proto.core.resources import patient_pb2\n\npatient_json = \"\"\"\n{\n  \"resourceType\" : \"Patient\",\n  \"id\" : \"example\",\n  \"name\" : [{\n    \"use\" : \"official\",\n    \"family\" : \"Roosevelt\",\n    \"given\" : [\"Franklin\", \"Delano\"]\n  }]\n}\n\"\"\"\n\n# Read the JSON as a proto:\npatient = json_format.json_fhir_string_to_proto(patient_json, patient_pb2.Patient)\n\n# Get the FHIR JSON representation of the proto:\njson_format.print_fhir_to_json_string(patient)\n```\n\n## FHIRPath support\nFHIRPath is the basis of the `google-fhir-views` logic, but can also be used\ndirectly against FHIR protos themselves. Here is an example:\n\n```py\nfrom google.fhir.r4 import fhir_path\nfrom google.fhir.r4 import r4_package\nfrom google.fhir.core.fhir_path import context\n\n# Create the FHIRPath context for use.\nfhir_path_context = context.LocalFhirPathContext(r4_package.load_base_r4())\n\n# Compile the FHIRPath expressions for evaluation. This validates the FHIRPath and returns\n# an optimized structure that can be efficiently evaluated over protocol buffers.\n# The compiled expression is typically created once and reused for many following invocations.\nexpr = fhir_path.compile_expression('Patient', fhir_path_context, \"name.where(use = 'official').family\")\n\n# Now we evaluate the expression on the given resource.\nresult = expr.evaluate(patient)\n\n# Check to see if the result matched anything.\nif result.has_value():\n  # Gets the result as protocol buffer messages.\n  result_as_messages = result.messages\n  # Converts the result to a simple string, if applicable.\n  result_as_simple_string = result.as_string()\n```\n\nThe library also supports a fluent Python builder for creating FHIRPath expressions,\nwhich is used extensively in the `google.fhir.views` package. Here is\nthe above string being created using a Python builder pattern:\n\n```py\n# FHIRPath builder for patients.\npat = fhir_path.builder('Patient', fhir_path_context)\n\n# Build the expression and get it in string form.\nfhir_path_string = pat.name.where(pat.name.use == 'official').family.fhir_path\n```\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Components for working with FHIR R4.",
    "version": "0.11.0",
    "project_urls": {
        "Download": "https://github.com/google/fhir-py/releases",
        "Homepage": "https://github.com/google/fhir-py"
    },
    "split_keywords": [
        "google",
        " fhir",
        " python",
        " healthcare"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ffa0be06c228096ba19361e4b5c9ed2cc082369a05e474e4e0ab55893a1bec85",
                "md5": "ffaf9027d5b377aee10ec5f2cbe396d2",
                "sha256": "53a6d75b8db786fe6a4481e08d31274a2d9f72fd754b73e370abc5bbe9019315"
            },
            "downloads": -1,
            "filename": "google_fhir_r4-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ffaf9027d5b377aee10ec5f2cbe396d2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.8",
            "size": 5286349,
            "upload_time": "2024-07-15T21:51:28",
            "upload_time_iso_8601": "2024-07-15T21:51:28.545920Z",
            "url": "https://files.pythonhosted.org/packages/ff/a0/be06c228096ba19361e4b5c9ed2cc082369a05e474e4e0ab55893a1bec85/google_fhir_r4-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-15 21:51:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "google",
    "github_project": "fhir-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "google-fhir-r4"
}
        
Elapsed time: 0.33034s