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:
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:
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:
# 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
Metadata
Release files for google-fhir-r4 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| google_fhir_r4-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / google_fhir_r4-0.11.0-py3-none-any.whl
| Download URL | google_fhir_r4-0.11.0-py3-none-any.whl |
|---|---|
| Size | 5.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53a6d75b8db786fe6a4481e08d31274a2d9f72fd754b73e370abc5bbe9019315
|
|
BLAKE2b-256 checksum How to use checksums |
ffa0be06c228096ba19361e4b5c9ed2cc082369a05e474e4e0ab55893a1bec85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.8
|
Security for google-fhir-r4 0.11.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.