google-fhir

repository·master·Indexed 21 days ago

https://github.com/google/fhir

FhirProto is Google's Protocol Buffer-based implementation of the HL7 FHIR standard, designed for high-performance, type-safe healthcare data modeling and storage. It provides tools for parsing, printing, validating, and profiling FHIR data, including support for custom implementation guides and JSON interoperability. The repository includes examples for uploading FHIR resources to BigQuery, provisioning Cloud Dataproc clusters for TensorFlow model training, and generating STU3 FHIR Proto definitions.

Tokens
8.7K
Snippets
27
Records
36
Agent score
76%

What's inside google-fhir

  1. Overview of FhirProto

    master

    FhirProto is Google's implementation of the FHIR (Fast Healthcare Interoperability Resources) standard using Protocol Buffers. It is designed to provide a type-safe, strongly validated FHIR format that is optimized for storage efficiency and cross-language support.

    Key features include:

    • Type Safety & Validation: Uses Protocol Buffers to ensure data adheres to the FHIR standard.
    • Structured Codes and Extensions: Guarantees data follows correct formats.
    • Custom Implementation Guides: Supports generating and validating against custom profiles to meet specific dataset requirements.
    • JSON Interoperability: Includes parsing and printing libraries to convert between FhirProto format and standard FHIR JSON.
  2. Overview of the US Core Implementation Guide

    master

    The US Core Implementation Guide defines the minimum mandatory conformance requirements for accessing patient data in the US realm. It is based on the 2015 Meaningful Use Common Clinical Data Set (CCDS) and incorporates requirements from the Argonaut pilot implementations.

    US Core serves as the foundation for future US Realm FHIR implementation guides. It is distinct from the DAF-Research Implementation Guide, which is specifically designed for researchers accessing data across multiple organizations in the context of a Learning Health System (LHS).

  3. Locate FHIR specification and implementation guide packages

    master

    The spec/ directory contains various versions of the FHIR specification and downloaded implementation guides. Packages are organized into directories named using the pattern {package_name}/{version_number}. This structure follows the FHIR NPM package spec.

    For example, to find the STU3 core specification, navigate to the hl7.fhir.core/3.0.1/ directory.

  4. Use generated Go Protos with Go modules

    master

    The Go code in the go/ directory is generated from the protocol buffers in proto/. This generated code is specifically provided to enable compatibility with the native Go build toolchain (go mod and go get).

    Note: This generated code is used when building FHIR libraries with the native go tool, but it is not used when building with Bazel.

  5. Getting started with FhirProto examples

    master

    To learn how to use FhirProto, you can explore the google/fhir-examples repository. This repository provides a practical environment to see the library in action, including:

    1. Synthetic Data Generation: Uses a script with Synthea to create synthetic FHIR JSON datasets.
    2. Core Operations: Demonstrates how to perform parsing, printing, validating, profiling, and querying.
    3. Guided Learning: Includes a walkthrough of the provided examples and a Reference User Guide for in-depth conceptual descriptions.
  6. Generate test data from FHIR JSON

    master

    Use the generate-testdata.sh script to generate .prototxt files from FHIR JSON example data. This script utilizes com.google.fhir.examples.JsonToProtoMain.

    By default, it uses examples located in fhir/testdata/stu3/examples/ and outputs to the current directory (./).

    ./generate-testdata.sh [-i input-dir] [-o output-dir]
  7. Provision a Cloud Dataproc cluster and Cloud Datalab on GCP

    master

    To train a TensorFlow model from FHIR Bundles, you must first provision a Google Cloud Dataproc cluster with Cloud Datalab on the master node.

    Prerequisites

    1. A GCP Project.
    2. Google Cloud SDK installed and initialized with your project.
    3. A unique Google Cloud Storage (GCS) bucket name.

    Setup Steps

    1. Configure Environment: Create a custom environment file (e.g., myenv.sh) by copying and updating ./scripts/provisioning/env.sh. Ensure the bucket name is unique to avoid conflicts.
    2. Source Environment: Load your configuration into your shell:
      source ./myenv.sh
    3. Prepare Initialization Scripts: Move cluster initialization scripts to your GCS bucket. Optionally, pass hivemeta to use a persistent Hive metastore (CloudSQL instance).
      ./01-prep.sh {hivemeta}
    4. Build FHIR Dependencies: Build the FHIR code repositories (run this only as needed).
      ./02-gen-fhirdependencies.sh
    5. Create Cluster: Provision a 3-node Dataproc cluster. Optionally, pass hivemeta to include a Hive metastore.
      ./03-cluster.sh {hivemeta}
    #!/bin/bash
    # Example sequence for provisioning
    source ./myenv.sh
    ./01-prep.sh
    ./02-gen-fhirdependencies.sh
    ./03-cluster.sh
  8. Access Cloud Datalab via secure SSH tunnel

    master

    To access the Cloud Datalab instance running on the Dataproc master node via a Chrome web browser, follow these steps to establish a secure connection.

    Connection Steps

    1. Add Firewall Rules: Add the necessary ingress firewall rules to allow SSH tunneling.
      ./firewall_ssh.sh {your env file}
    2. Open SSH Tunnel: Establish the tunnel to the master node.
      ./sshtunnel.sh {your env file}
    3. Open Jupyter Notebook: Use the platform-specific script to launch the notebook in Chrome.

    For macOS:

    ./jupyterconnect-mac.sh {your env file}

    For Linux:

    ./jupyterconnect-linux.sh {your env file}

    Once opened, upload the notebooks from the ./notebooks/*.ipynb directory into Cloud Datalab to begin execution.

    ./firewall_ssh.sh ./myenv.sh
    ./sshtunnel.sh ./myenv.sh
    ./jupyterconnect-linux.sh ./myenv.sh
  9. Generate DescriptorProtos as .prototxt files

    master

    Use the generate-descriptors.sh script to generate DescriptorProtos in .prototxt format. By default, the script reads from fhir/testdata/stu3/ and outputs to the current directory (./).

    ./generate-descriptors.sh [-i input-dir] [-o output-dir]
  10. Regenerate Go Protos

    master

    If you modify the protocol buffers located in the proto/ directory at the root of the repository, you must regenerate the Go code in the go/ directory.

    Prerequisites:

    • protoc (the protocol buffer compiler) must be in your PATH.
    • protoc-gen-go (the Go protocol buffer plugin) must be in your PATH.

    On Linux, you can install protoc using:

    sudo apt install -y protobuf-compiler

    Regeneration Command: Run the following script from the repository root to regenerate the Go protos:

    ./go/generate_go_protos_default.sh
    #!/bin/sh
    ./go/generate_go_protos_default.sh
  11. Generate custom FHIR profiles and convert data

    master

    This workflow demonstrates how to create a custom FHIR profile, convert existing data (e.g., a standard Patient resource) into that custom profile (e.g., DemoPatient), generate a BigQuery schema, and upload the data to BigQuery.

    This process is intended to be performed between steps 2 and 3 of the BigQuery examples.

    # 1. Generate .proto files
    ./generate_definitions_and_protos.sh //examples/profiles:demo
    
    # 2. Convert Patient to DemoPatient
    # Note: Replace 'DemoPatient' if you use a different profile name
    bazel run //examples/profiles:LocalProfiler $MY_DIR
    
    # 3. Generate Schema
    bazel run //java:BigQuerySchemaGenerator $MY_DIR
    
    # 4. Upload the converted data to BigQuery
    bq load --source_format=NEWLINE_DELIMITED_JSON --schema=$MY_DIR/DemoPatient.schema.json synthea.DemoPatient $MY_DIR/DemoPatient.ndjson
    
    # 5. Run a query to verify
    bq query --nouse_legacy_sql "\n  SELECT \n    birthPlace.city, \n    APPROX_TOP_COUNT(SUBSTR(mothersMaidenName, 0, 3), 2), \n    count(*) \n  FROM \n    synthea.DemoPatient p \n  GROUP BY 1 \n  ORDER BY 3 DESC \n"