跳转到主要内容

FHIR R4组件。

项目描述

协议缓冲区转换、验证和FHIR R4资源实用工具。

对分析FHIR数据感兴趣的用户应参考google.fhir.views包。此库包含在Python代码中表示FHIR数据时与协议缓冲区一起工作的底层功能。

FHIR JSON与协议缓冲区的相互转换

json_format包支持将FHIR协议缓冲区转换为FHIR JSON格式,反之亦然。以下是一些简单的示例

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支持

FHIRPath是google-fhir-views逻辑的基础,但也可以直接针对FHIR原型本身使用。以下是一个示例

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()

该库还支持用于创建FHIRPath表达式的流畅Python构建器,这在google.fhir.views包中得到了广泛使用。以下是使用Python构建器模式创建的上述字符串

# 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

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

本发行版没有源分布文件。请参阅关于生成发行存档的教程。

构建的发行版

google_fhir_r4-0.11.0-py3-none-any.whl (5.3 MB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面