GPT meets FHIR: Leveraging the power of Open API specs
Tags: ai, chatgpt, docker, python
Published: 2023-09-29 20:05:15


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lgy9d5qe3xaskx2w1en2.png)

 

FHIR has revolutionized the healthcare industry by providing a standardized data model for building healthcare applications and promoting data exchange between different healthcare systems. As the FHIR standard is based on modern API-driven approaches, making it more accessible to mobile and web developers. However, interacting with FHIR APIs can still be challenging especially when it comes to querying data using natural language.

Introducing the [FHIR - AI and OpenAPI Chain](https://openexchange.intersystems.com/package/FHIR---AI-and-OpenAPI-Chain) application, a solution that allows users to interact with FHIR APIs using natural language queries. Built with [OpenAI](https://openai.com/), [LangChain](https://langchain.com/), and [Streamlit](https://streamlit.io/), this application simplifies the process of querying FHIR APIs and makes it more user-friendly.

##  

## What are FHIR OpenAPI Specifications?

OpenAPI Specifications (formerly known as Swagger and currently part of [OpenAPI Initiative](https://www.openapis.org/)) have become an essential tool in the world of software development, enabling developers to design, document, and interact with APIs more efficiently. OpenAPI Specifications define a standard, machine-readable format for describing RESTful APIs, providing a clear and consistent way to understand their capabilities and use them effectively.

In the healthcare domain, FHIR emerged as a leading standard for data exchange and interoperability. To enhance the interoperability capabilities of FHIR, [HL7 has officially documented the FHIR OpenAPI Specifications](https://hapi.fhir.org/baseR4/api-docs), which enable developers to seamlessly integrate FHIR resources and operations into their software solutions.

##  

## Benefits of FHIR OpenAPI Specifications:

  1. **Standardized API Description**: OpenAPI Specifications provide a comprehensive and standardized description of FHIR resources, operations, and interactions. Developers can easily understand the structure and capabilities of FHIR-based APIs, making it easier to build integrations and interact with healthcare systems.
  2. **Promotion of Interoperability**: Foster collaboration among developers, driving the adoption of FHIR standards and best practices. The specifications provide a common language and framework for discussing FHIR-based integrations and implementations, fostering collaboration among developers.
  3. **Enhanced Documentation and Testing**: Interactive documentation and test suites for better understanding and validation. Developers can create detailed API documentation, making it easier for other developers to understand and utilize the FHIR-based APIs. Test suites based on the specifications enable comprehensive testing and validation of API integrations, ensuring the reliability and accuracy of healthcare data exchange.
  4. **Improved Developer Experience**: Automatic generation of client libraries and SDKs for seamless integration. This simplifies the integration process and reduces the time and effort required to incorporate FHIR functionality into their applications

##  

## How do FHIR, OpenAI, and OpenAPI Chain work together?

The [FHIR - AI and OpenAPI Chain](http://openexchange.intersystems.com/package/FHIR---AI-and-OpenAPI-Chain) application leverages LangChain to load and parse the OpenAPI specifications ([OpenAPI Chain](https://python.langchain.com/docs/modules/chains/popular/api)). After which, based on these specifications, the chain of prompts given through OpenAI aims to understand natural language queries and convert them into appropriate FHIR API requests. Users can ask questions in plain language, and the application will interact with the chosen FHIR API to retrieve the relevant information.

For example, a user might ask, "What is the latest blood pressure reading for patient, John Doe (ID 111)?" The application will then translate this query into an FHIR API request, fetch the required data, and present it to the user in an easily understandable format.

 
{% embed https://www.youtube.com/watch?v=U4qJaMfVo9Q %}


##  

## Benefits of FHIR - AI and OpenAPI Chain

  1. **User-friendly interactions**: By allowing users to interact with FHIR APIs using natural language queries, the application makes it easier for non-technical users to access and analyze healthcare data.
  2. **Improved efficiency**: The application streamlines the process of querying FHIR APIs, reducing the time and effort required to obtain relevant information. Also, it has the potential in reducing the number of clicks (time spent) to find any particular information from the application.
  3. **Customizable**: The FHIR Standards simplify the retrieval of consistent data from any FHIR server, allowing for easy customization. It can be effortlessly configured to seamlessly integrate with any FHIR API, providing a flexible and adaptable solution for diverse healthcare data requirements.

##  

## Getting Started with FHIR - AI and OpenAPI Chain

To start using the FHIR - AI and OpenAPI Chain application, follow these steps:

  1. Obtain an OpenAI API key from the [OpenAI Platform](https://beta.openai.com/signup/).
  2. Get an FHIR Server API endpoint. You can either use your own sample FHIR server (unauthenticated access needed) or create a temporary sample server by following the instructions given in the [InterSystems IRIS FHIR Learning platform](https://learning.intersystems.com/course/view.php?id=244).
  3. [Try the application online](https://fhir-ai-and-openapi-chain.streamlit.app/) or [set it up locally](https://github.com/ikram-shah/fhir-ai-and-openapi-chain) using the provided instructions.

 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2br34vv7nco93j5pidwr.png)

By integrating AI and natural language processing capabilities, the FHIR - AI and OpenAPI Chain application offers a more intuitive way to interact with FHIR APIs, making healthcare data more accessible and easier to analyze for users of all technical backgrounds.

**[Vote for our app in the Grand Prix contest](https://openexchange.intersystems.com/contest/32#349) if you find it promising!**

If you can think of any potential applications using this implementation, please feel free to share them in the discussion thread.