Skip to content

Commit

Permalink
Adds FHIR STU3/R4 Python parsing/printing/validating.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 335512870
  • Loading branch information
Cameron Tew authored and nickgeorge committed Oct 5, 2020
1 parent d7b450f commit bba915b
Show file tree
Hide file tree
Showing 63 changed files with 13,736 additions and 0 deletions.
22 changes: 22 additions & 0 deletions py/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load(
"@rules_python//python:python.bzl",
"py_library",
)

package(
default_visibility = ["//visibility:public"],
)

licenses(["notice"])

# A Python3 library target for targets in //py/google/fhir/** to include
# as a dependency to allow for relative imports, e.g.:
# * Before: from py.google.fhir.jsonformat.core import resource_validation
# * After: from google.fhir.jsonformat.core import resource_validation
#
# See more at: https://github.com/bazelbuild/bazel/issues/6556.
py_library(
name = "py",
imports = ["."],
srcs_version = "PY3",
)
4 changes: 4 additions & 0 deletions py/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Files needed when creating sdist or bdist_wheel distributions.
include requirements.txt
include README.md
global-exclude *_test.py
27 changes: 27 additions & 0 deletions py/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Google FhirProto

## Introduction
This is the Python3 distribution for Google [FhirProto](http://github.com/google/fhir).

FhirProto is Google's implementation of the [FHIR Standard](http://hl7.org/fhir/) for Health Care data using [Protocol Buffers](https://developers.google.com/protocol-buffers). By leveraging Google’s core data storage format, FhirProto provides a type-safe, strongly validated FHIR format with cross-language support at a fraction of the size on disk, making it a great data model to develop your Health Care application on. Structured Codes and Extensions guarantee that your data will be in the correct format. Support for generating and validating against custom Implementation Guides allow you to customize FhirProto to your dataset and requirements. Parsing and Printing libraries make it easy to go back and forth between FhirProto format and JSON.

## Getting Started

### Installation

You can install the Python3 distribution of FhirProto with for use with Python interpreters >=3.6, <3.9 using the [pip](https://pypi.org/project/pip/) package manager. We strongly recommend installing into a Python3 virtual environment, such as [venv](https://docs.python.org/3/library/venv.html):
```sh
python3 -m venv fhir
source fhir/bin/activate

pip install --upgrade setuptools
pip install google-fhir
```

### Examples and Documentation
We think the best way to get an idea of how FhirProto works is to get in and start playing with it. To that end, we provide [https://github.com/google/fhir-examples](https://github.com/google/fhir-examples). This repo contains a script for using [Synthea](https://github.com/synthetichealth/synthea) to create a synthetic FHIR JSON dataset, and then shows some examples of parsing, printing, validating, profiling and querying. The repo also contains a [walkthrough](https://github.com/google/fhir-examples/blob/master/EXAMPLES.md) of many of the examples.

A Reference User Guide with in-depth descriptions of different concepts can be found [here](https://github.com/google/fhir-examples/blob/master/USERGUIDE.md).

## Trademark
FHIR® is the registered trademark of HL7 and is used with the permission of HL7. Use of the FHIR trademark does not constitute endorsement of this product by HL7.
169 changes: 169 additions & 0 deletions py/google/fhir/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
load(
"@rules_python//python:python.bzl",
"py_library",
)
load("@fhir_bazel_pip_dependencies//:requirements.bzl", "requirement")

package(
default_visibility = [
"//visibility:public",
],
)

licenses(["notice"])

py_library(
name = "primitive_time_utils",
srcs = [
"__init__.py",
"_primitive_time_utils.py",
],
srcs_version = "PY3",
visibility = ["//py/google/fhir:__subpackages__"],
deps = [
"@com_google_protobuf//:protobuf_python",
"//py",
"//py/google/fhir/utils:proto_utils",
requirement("python-dateutil"),
requirement("six"),
],
)

py_library(
name = "codes",
srcs = [
"__init__.py",
"codes.py",
],
srcs_version = "PY3",
deps = [
":fhir_errors",
"//proto/google/fhir/proto:annotations_py_pb2",
"//py",
"//py/google/fhir/utils:annotation_utils",
"//py/google/fhir/utils:fhir_types",
"//py/google/fhir/utils:proto_utils",
"@com_google_protobuf//:protobuf_python",
],
)

py_library(
name = "extensions",
srcs = [
"__init__.py",
"extensions.py",
],
srcs_version = "PY3",
deps = [
":codes",
":fhir_errors",
"//proto/google/fhir/proto:annotations_py_pb2",
"//py",
"//py/google/fhir/utils:annotation_utils",
"//py/google/fhir/utils:fhir_types",
"//py/google/fhir/utils:proto_utils",
"@com_google_protobuf//:protobuf_python",
],
)

py_library(
name = "fhir_errors",
srcs = [
"__init__.py",
"fhir_errors.py",
],
srcs_version = "PY3",
deps = ["//py"],
)

py_library(
name = "primitive_handler",
srcs = [
"__init__.py",
"primitive_handler.py",
],
srcs_version = "PY3",
deps = [
"//py",
"//py/google/fhir:primitive_time_utils",
"//py/google/fhir/json_format/wrappers:primitive_wrappers",
"@com_google_protobuf//:protobuf_python",
],
)

py_library(
name = "references",
srcs = [
"__init__.py",
"references.py",
],
srcs_version = "PY3",
deps = [
"//py",
"//py/google/fhir/utils:annotation_utils",
"//py/google/fhir/utils:path_utils",
"//py/google/fhir/utils:proto_utils",
"@com_google_protobuf//:protobuf_python",
],
)

py_library(
name = "resource_validation",
srcs = [
"__init__.py",
"resource_validation.py",
],
srcs_version = "PY3",
deps = [
":fhir_errors",
":primitive_handler",
"//proto/google/fhir/proto:annotations_py_pb2",
"//py",
"//py/google/fhir:primitive_time_utils",
"//py/google/fhir/utils:annotation_utils",
"//py/google/fhir/utils:fhir_types",
"//py/google/fhir/utils:proto_utils",
"@com_google_protobuf//:protobuf_python",
],
)

py_library(
name = "extensions_test",
testonly = 1,
srcs = [
"__init__.py",
"extensions_test.py",
],
srcs_version = "PY3",
deps = [
":extensions",
"@com_google_protobuf//:protobuf_python",
"//py",
"//py/google/fhir/testing:testdata_utils",
requirement("absl-py"),
requirement("six"),
],
)

py_library(
name = "primitive_handler_test",
testonly = 1,
srcs = [
"__init__.py",
"primitive_handler_test.py",
],
srcs_version = "PY3",
deps = [
":primitive_handler",
"@com_google_protobuf//:protobuf_python",
"//py",
"//py/google/fhir:extensions",
"//py/google/fhir:fhir_errors",
"//py/google/fhir:primitive_time_utils",
"//py/google/fhir/testing:testdata_utils",
"//py/google/fhir/utils:path_utils",
"//py/google/fhir/utils:proto_utils",
requirement("absl-py"),
requirement("six"),
],
)
14 changes: 14 additions & 0 deletions py/google/fhir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading

0 comments on commit bba915b

Please sign in to comment.