# fhir-examples **Repository Path**: mirrors_google/fhir-examples ## Basic Information - **Project Name**: fhir-examples - **Description**: Usage Examples for github.com/google/fhir - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-19 - **Last Updated**: 2026-03-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Usage Examples for FhirProto This repository contains examples of how to use the __FhirProto__ platform at [github.com/google/fhir](github.com/google/fhir). This repo contains a `generate-synthea.sh` 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. Some of these examples are left intentionally incomplete, to leave exercises to go along with this guide. The rest of this README contains instructions for setting up an environment for working with __FhirProto__. For instructions on running the examples, check out [EXAMPLES.md](github.com/google/fhir-examples/blob/master/EXAMPLES.md). For a more comprehensive explanation of the platform, see the [**User Guide**](https://github.com/google/fhir/blob/master/USERGUIDE.md) at the main repo ## Setting Up Bazel FhirProto uses [Bazel](https://bazel.build/) as its dependency management/build tool. This is a declarative build system used by Google, Tensorflow, and many others. We require a minimum Bazel version of [2.2.0](https://github.com/bazelbuild/bazel/releases/tag/2.2.0). Follow steps [here](https://bazel.build/install) to download and run the install script. Pro-tip: make sure not to drop the `--user` flag when running the script. Verify that bazel is installed correctly by running `bazel --version`. You can always check what version of Bazel you have by running `bazel --version` ## Gradle integration This repository also provides an example of Gradle integration with the published Java library on Google's Maven repository. See `build.gradle` for how to set it up and `ParsePatients.java` for how to run it. ## Setting Up the Example Repository Next, we’ll clone the example repository into a git directory. If you don’t have a directory you already use for git code, `~/git` is perfectly reasonable: ``` mkdir ~/git cd ~/git ``` Then, clone this repo using ``` git clone https://github.com/google/fhir-examples.git cd fhir-examples ``` Next, we’ll generate a synthetic FHIR JSON dataset, using [Synthea](https://github.com/synthetichealth/synthea), via the `generate-synthea.sh` script. We’ll need a workspace directory for this dataset - here we’ll use `~/fhirdata/` ``` WORKSPACE=~/fhirdata ./generate-synthea.sh $WORKSPACE ``` This will create three data directories: - __`$WORKSPACE/bundles/`__ contains 1000 patient bundles, each in its own JSON file - __`$WORKSPACE/ndjson/`__ contains one NDJSON file per resource type, where each line represents a record of that type - __`$WORKSPACE/analytic/`__ contains two files per resource type for use with [Analytic SQL-on-FHIR](https://github.com/FHIR/sql-on-fhir/blob/master/sql-on-fhir.md): a `.schema.json` file containing the analytic schema for each resource, and a `.analytic.ndjson` file containing the resources printing according to the analytic schema. For more on this, see the __Analytic Printing and BigQuery__ section in the User Guide. At this point, we can validate that our bazel environment is set up correctly and our dataset is generated by running a simple test example: ``` bazel build //cc/google/fhir_examples:ParsePatients bazel-bin/cc/google/fhir_examples/ParsePatients $WORKSPACE ``` This should parse all 1000 patients we generated into __FhirProto__, and print one out as an example. ## Add Proto Generation scripts to your bin Generating custom profiles and protos makes use of a couple of scripts defined by the FhirProto library. To add these to your `bin`, run ``` curl https://raw.githubusercontent.com/google/fhir/v0.5.0/bazel/generate_protos_utils.sh > ~/bin/generate_protos_utils.sh && \ curl https://raw.githubusercontent.com/google/fhir/v0.5.0/bazel/generate_protos.sh > ~/bin/generate_protos.sh && \ curl https://raw.githubusercontent.com/google/fhir/v0.5.0/bazel/generate_definitions_and_protos.sh > ~/bin/generate_definitions_and_protos.sh && \ chmod +x ~/bin/generate_protos.sh && chmod +x ~/bin/generate_definitions_and_protos.sh ``` ## BigQuery Finally, some examples show how to use [Analytic SQL-on-FHIR](https://github.com/FHIR/sql-on-fhir/blob/master/sql-on-fhir.md) with [BigQuery](https://cloud.google.com/bigquery/), which is free to set up and provides a [sandbox](https://cloud.google.com/bigquery/docs/sandbox) environment with pretty good quotas. There are some examples in [shell directory](https://github.com/google/fhir-examples/tree/master/shell) that show how to upload data to BigQuery using th [bq command line tool](https://cloud.google.com/bigquery/docs/bq-command-line-tool). Once it's there, you can either query it from the [Cloud Console](https://console.cloud.google.com/bigquery), or use the `bq` tool as is done in [run_queries.sh](https://github.com/google/fhir-examples/blob/master/shell/). ## 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.