Medical reports analysis dashboard using Amazon Bedrock, LangChain, and Streamlit

In healthcare, the ability to quickly analyze and interpret medical reports is crucial for both healthcare providers and patients. While medical reports contain valuable information, they often remain underutilized due to their complex nature and the time-intensive process of analysis. This complexity manifests in several ways: the interpretation of multiple parameters and their relationships (such as various blood cell counts), the comparison of test results against standard reference ranges, and the need to analyze trends in health parameters over time. To address this challenge, we’ve conceptualized a medical reports analysis dashboard that illustrates how healthcare providers could enhance their interaction with medical data through a sample implementation

In this post, the created dashboard represents a convergent solution that brings together the power of Amazon Bedrock advanced AI capabilities, LangChain‘s document processing, and Streamlit‘s intuitive user interface. By using these technologies, we’ve created a system that not only stores and displays medical reports, but actively helps interpret them through natural language interactions and dynamic visualizations.

Solution overview

At the solution’s foundation are various large language models available through Amazon Bedrock, including Anthropic’s Claude series and Amazon Nova Foundation Models. You can select from options such as Claude Opus 4.1, Claude 3.7 Sonnet, Amazon Nova Pro, and others, each optimized for different performance and capability requirements. The chosen model processes natural language queries with medical context awareness, enabling detailed interpretation of healthcare data. With this flexibility, you can balance factors like accuracy, speed, and cost based on your specific needs. This is enhanced by LangChain’s document processing capabilities, which manage the retrieval system and maintain conversation context, facilitating accurate and relevant responses.

The solution’s data flow begins with medical reports securely stored in Amazon Simple Storage Service (Amazon S3), which are then processed through LangChain’s document handling system. When you interact with the Streamlit frontend, your queries are analyzed by Amazon Bedrock, while LangChain maintains the conversation context and manages document retrieval. The system processes this information and presents results through an intuitive interface featuring interactive visualizations.

These visualizations, powered by Plotly, include range comparison charts that clearly display normal versus actual values, bar charts for parameter comparisons, and trend lines for tracking changes over time. The Streamlit interface ties everything together, providing real-time interaction with the AI system while managing user session state and conversation history. This comprehensive approach helps ensure that medical professionals can quickly access, analyze, and interpret their medical reports through natural language queries while viewing supporting visual data.

The following is the architecture diagram of the solution that has four layers:

  • User Interface Layer: Streamlit Web App, Chat interface, Plotly data visualizations
  • Processing Layer: LangChain document processing, Conversation retrieval chain, Data parsing
  • AI/ML Layer: Amazon Bedrock, Amazon Bedrock embeddings, In-memory vector store
  • Storage Layer: Amazon S3 for medical reports, Conversation buffer memory

Architectural diagram showing four main layers: User Interface (with Streamlit, chat, and visualization components), Processing (LangChain and data transformation), AI/ML (AWS Bedrock and vector store), and Storage (S3 and conversation buffer).

Prerequisites

Before deploying the Medical Reports Analysis Dashboard, you need:

We’ll be using a Python virtual environment (venv) for this project to provide a clean, isolated environment. Virtual environments help avoid package conflicts between projects and make dependency management more straightforward. While we’re using Python’s built-in venv, you could alternatively use miniconda or other environment managers.

Deployment

To get started with deployment, install the necessary packages on a local machine.

  1. Clone the repository:
git clone https://github.com/aws-samples/sample-medical-analysis-dashboard.git
  1. Navigate to the project directory.
  2. Create and activate a virtual environment (recommended):

For Mac/Linux:

python3 -m venv venv
source venv/bin/activate

For Windows:

python3 -m venv venv
venv\Scripts\activate
  1. Update pip to the latest version:
python3 -m pip install --upgrade pip
  1. Install required packages:
pip install -r requirements.txt

Project’s dependencies are listed in requirements.txt:

  • boto3
  • streamlit
  • unstructured
  • langchain-aws
  • langchain-community
  • pandas
  • plotly
  • numpy
  • docarray

These packages will handle AWS integration, web interface, data processing, and visualizations. They’ll be installed in our virtual environment during the deployment process. This setup helps ensure that the components are properly installed and isolated in a virtual environment for optimal performance.

  1. Follow Configuring environment variables for the AWS CLI to configure AWS credentials.
export AWS_ACCESS_KEY_ID='your-access-key'
export AWS_SECRET_ACCESS_KEY='your-secret-key'
  1. Upload sample CSV files to the S3 bucket created in prerequisites section:

Our repository contains two sample files:

  • basic_test.csv: Complete blood work with 15 parameters
  • blood_test.csv with basic parameters

The following is the content of basic_test.csv:

Parameter,Value,Reference_Range,Unit
Hemoglobin,13.8,13.5-17.5,g/dL
RBC,4.8,4.5-5.9,million/µL
WBC,8500,4000-11000,cells/µL
Glucose,92,70-100,mg/dL
Creatinine,1.0,0.7-1.3,mg/dL

Run the following commands to upload sample files to the S3 bucket:

aws s3 cp basic_test.csv s3://BUCKET_NAME/

aws s3 cp blood_test.csv s3://BUCKET_NAME/

Go to app.py line 68 and update the S3 bucket name in app.py to match your actual S3 bucket name.

BUCKET_NAME = "your-bucket-name"
  1. Run the application:
streamlit run app.py

The dashboard will be available at http://localhost:8501. You can now interact with your medical reports through the web interface.

Using the dashboard

This section walks through the key features and demonstrates how to effectively use the dashboard for medical data analysis.

Dashboard interface overview

The following figures show the complete dashboard where the selected medical report is blood_test.csv from the repo showing the navigation pane and main content. The first figure also shows the first two graphs.

Medical dashboard showing blood test results with raw data table and parameter visualizations

The following figure shows the second graph of the three that are included in this dashboard.

Medical analysis interface with blood test parameters displayed as bar chart and time series graph using AWS Bedrock

The dashboard interface is organized into three main sections for medical report analysis:

  1. Document selection and model choice (navigation pane)
    • Selection of Amazon Bedrock model (for example: Claude Opus 4.1, Claude 3.7 Sonnet, or Amazon Nova Pro)
    • List of available medical reports in a dropdown menu
    • Currently analyzing blood_test.csv
    • Token usage display (input, output, and total tokens)
  2. Chat analysis section
    • Clean chat interface for natural language queries
    • History of conversation maintained
    • Clear response formatting
  3. Visualization area
    • Range comparison chart showing normal compared to actual values
    • Bar chart displaying the parameters
    • Trend lines for multiple parameters

Context-aware query system

The dashboard’s AI-powered query system demonstrates sophisticated understanding of medical reports through natural conversations. Here’s a sequence of interactions showing the system’s capabilities.

Question 1: Initial query about hemoglobin:

What is the hemoglobin level in report?

Chat interface showing hemoglobin level query and AI response

Question 2: Follow-up question demonstrating context awareness:

How does this compare to other parameters in the report? Are there any that stand out?

Medical report analysis detailing blood cell parameters, notable findings, and metabolic markers

Question 3: Complex analysis request:

Can you analyze the distribution patterns of percentage-based measurements versus absolute values in this report, and identify any notable patterns in their reference ranges?

Medical analytics dashboard displaying percentage-based and absolute value measurements with Claude AI model integration

The system maintains conversation context while providing detailed insights from the medical reports, supporting responses with relevant data visualizations.

The solution can be further enhanced by fine-tuning the foundational model on organization-specific medical data, clinical questions, and domain expertise. This specialized training helps the model better understand medical terminology, standard protocols, and institution-specific practices. Additionally, organizations can use pre-trained medical LLMs available in AWS Marketplace, which are specifically optimized for healthcare use cases. When combined with the system’s existing capabilities, these specialized models can provide contextually relevant responses to medical queries while maintaining compliance with healthcare data governance requirements.

Amazon Bedrock guardrails should be configured to restrict the model from providing medical advice, prescriptions, or diagnoses, making sure responses are limited to data analysis and interpretation only.

Security considerations

While our current deployment uses dummy medical data for demonstration purposes, it’s crucial to consider security and compliance measures for real-world healthcare applications. Here are recommendations for enhancing security in a production environment:

Data privacy:

Recommended AWS security implementation:

These are general recommendations. For a production healthcare application, consult with security experts and conduct a risk assessment to make sure all relevant compliance standards are met.

Clean up

To avoid ongoing AWS charges, follow these steps to clean up the resources created:

  1. Delete the created Amazon S3 bucket
  2. Delete the created local resources:
# Deactivate virtual environment
deactivate
# Remove project directory and virtual environment
rm -rf medical-analysis-dashboard/

Conclusion

In this post, we demonstrated the development of a conceptual Medical Reports Analysis Dashboard that combines Amazon Bedrock AI capabilities, LangChain’s document processing, and Streamlit’s interactive visualization features. The solution transforms complex medical data into accessible insights through a context-aware chat system powered by large language models available through Amazon Bedrock and dynamic visualizations of health parameters.

This project showcases how cloud and AI technologies can be applied to healthcare analytics, making medical report interpretation more intuitive and efficient. While our implementation uses dummy data for demonstration purposes, the architecture provides a foundation for building secure, compliance-aligned healthcare applications that can be enhanced to meet healthcare organizational requirements and security protocols.


About the authors

Aditya Ranjan is a Delivery Consultant with AWS, specializing in distributed systems architecture and cloud-native solutions. He collaborates with customers to design and implement well-architected technical solutions using AWS’s latest technologies, including generative AI services, enabling them to achieve their business goals and objectives.

Shubham Tiwari is a Solutions Architect at AWS specializing in Modernisation, containers and Security. He has been helping customers in deploying highly scalable, resilient and cost optimised architecture on AWS.



from Artificial Intelligence https://ift.tt/iAUtXSg

Post a Comment

Previous Post Next Post