8000 GitHub - jmandel/fhir-diff
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

jmandel/fhir-diff

Repository files navigation

FHIR R4 vs R6 Comparison Scripts

This project contains scripts for fetching FHIR resource definitions from official sources and leveraging AI (Google Gemini) to analyze and compare R4 and R6 versions.

Prerequisites

  1. Bun Runtime: These scripts are written in TypeScript and designed to be run with Bun. Installation instructions: https://bun.sh/docs/installation
  2. Google Gemini API Key: You need an API key for Google Gemini for the generate_resource_summaries.ts and analyze_difference.ts scripts.
    • The scripts require the GEMINI_API_KEY environment variable to be set.
    • Methods to set the API key: Bun automatically loads .env files from the current working directory. The recommended way is to place a .env file in this project root.
      1. Using a .env file (Recommended): Create a file named .env in the project root directory with the content:
        GEMINI_API_KEY="YOUR_API_KEY_HERE"
        Ensure this file is in your .gitignore.
      2. Directly in the shell (before running commands):
        export GEMINI_API_KEY="YOUR_API_KEY_HERE"
      3. Prefixing the command:
        GEMINI_API_KEY="YOUR_API_KEY_HERE" bun run ./script_name.ts <ResourceName>

Directory Structure for Outputs

When run from this project root, these scripts will generate output in the following directories:

  • sources/r4/: Stores fetched HTML excerpts for R4 resources.
  • sources/r6/: Stores fetched HTML excerpts for R6/build resources.
  • summaries/: Contains the per-version resource summaries generated by Gemini.
    • summaries/r4/<ResourceName>.md
    • summaries/r6/<ResourceName>.md
  • analysis/: Contains the final difference analysis generated by Gemini.
    • analysis/diff/<ResourceName>.md

Example/template files used by these scripts are located within ./examples/.

Scripts Overview & Usage

All scripts below are designed to be invoked from this project root directory.

  1. generate_fhir_doc.ts:

    • Purpose: Fetches HTML content for a specified FHIR resource.
    • Output: Saves HTML segments to sources/r4/ and sources/r6/.
    • Usage:
      bun run ./generate_fhir_doc.ts <ResourceName>
  2. generate_resource_summaries.ts:

    • Purpose: Generates structured markdown summaries for R4 and R6 using Gemini.
    • Requires: GEMINI_API_KEY to be set. Input HTML files from generate_fhir_doc.ts (in sources/).
    • Output: Saves markdown files to summaries/r4/ and summaries/r6/.
    • Usage:
      bun run ./generate_resource_summaries.ts <ResourceName>
  3. analyze_difference.ts:

    • Purpose: Generates a markdown report comparing the R4 and R6 summaries using Gemini.
    • Requires: GEMINI_API_KEY to be set. Input markdown summaries from generate_resource_summaries.ts (in summaries/).
    • Output: Saves a markdown difference report to analysis/diff/.
    • Usage:
      bun run ./analyze_difference.ts <ResourceName>
  4. fetch_us_core.ts:

    • Purpose: Contains a hardcoded list of US Core FHIR resource names. Can be run independently to execute only the generate_fhir_doc.ts step for all listed US Core resources.
    • Usage (for generating only HTML docs for US Core):
      bun run ./fetch_us_core.ts
  5. analyze_us_core_migration.ts:

    • Purpose: Analyzes the migration impact for each US Core profile found in ../us-core-profiles/json/. For each profile, it considers its definition, its inheritance hierarchy (other US Core profiles), and the R4->R6 changes of its ultimate base FHIR resource type (e.g., Observation, Patient) fetched from ../analysis/diff/.
    • Requires: GEMINI_API_KEY to be set. Input JSON profile definitions in ../us-core-profiles/json/. Base resource diffs in ../analysis/diff/. Profile HTML in ../us-core-profiles/html/ (optional, for context).
    • Output: Saves detailed markdown analysis reports to ../analysis/us-core-migration/<profile-id>.md.
    • Usage:
      bun run ./analyze_us_core_migration.ts
  6. run_fhir_comparison.ts:

    • Purpose: Main orchestrator script. Runs the full fetch -> summarize -> diff pipeline for all resources listed in fetch_us_core.ts.
    • Requires: GEMINI_API_KEY to be set.
    • Usage:
      bun run ./run_fhir_comparison.ts

Running an Automated Workflow

The recommended way to process the full list of base FHIR resources (e.g., US Core base types) through the fetch/summarize/diff pipeline is by using the run_fhir_comparison.ts script:

bun run ./run_fhir_comparison.ts

This script handles dependency checks and skips already completed steps for the base resource analysis.

To generate the specific US Core profile migration analyses (after running the above), use:

bun run ./analyze_us_core_migration.ts

Note on Script Design

Each primary script (generate_fhir_doc.ts, generate_resource_summaries.ts, analyze_difference.ts, analyze_us_core_migration.ts) exports an async function (e.g., ensureFhirDocHtml) that contains its core logic, or performs its analysis directly in its main/helper functions. Where applicable, functions are designed to be idempotent (skip if output exists) and handle their own dependencies. When run directly via CLI, the main function within each script calls its respective ensure... function or performs its primary task.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0