Structured Medical Document Data Extraction using Google Gemini - n8n Workflow

Extract structured medical data from documents like receipts, prescriptions, and reports using an automated n8n workflow. Leverage Google Gemini AI for high-accuracy OCR and compliance.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Healthcare providers automating billing and records management.

  • Insurance companies needing fast, structured claim processing and documentation analysis.

  • Developers building robust document analysis APIs powered by n8n.

  • Data analysts requiring standardized, high-quality clinical data extraction from unstructured sources.

Overview

This advanced n8n workflow solves the complex challenge of automating medical document processing. Traditional OCR often fails to accurately categorize documents or extract data into standardized schemas required for regulatory compliance. This solution uses the powerful multimodal capabilities of Google Gemini 2.0 Flash in a two-stage process. First, it classifies the document (e.g., financial, clinical, diagnostic) and extracts raw text with high accuracy OCR. Second, it applies a strict medical taxonomy schema to extract specific details like diagnoses, medication dosages, and billing amounts, ensuring the final output is standardized and machine-readable.

By implementing this n8n template, organizations can achieve a significant reduction in manual data entry, ensuring high accuracy (95%+) and generating comprehensive quality metrics. This complete n8n workflow acts as a scalable API endpoint, transforming raw document images into actionable structured insights ready for integration with EMR or billing systems.

How it Works

The entire process is initiated by an API call via an n8n trigger, making it easily integrable into existing IT infrastructure.


  1. Trigger and Ingestion: The Webhook Input n8n trigger starts the process when an external system sends a POST request containing the imageurl of the medical document along with optional hints like expectedtype or language_hint.

  2. Data Preparation: A Set n8n node parses the input, followed by an HTTP Request n8n node that downloads the image file. The Extract to Base64 n8n node then converts the binary image data into a Base64 string, preparing it for the multimodal AI input.

  3. Phase 1: Classification & OCR: The first Google Gemini API call (via an HTTP Request n8n node) performs comprehensive classification and raw text extraction. Crucially, this n8n node leverages a JSON schema to guarantee structured output detailing document type, primary language, and image quality scores.

  4. Phase 2: Deep Structuring: The second Gemini API call uses the raw extracted text and the image context to perform deep structuring. This n8n node applies a detailed medical taxonomy JSON schema, ensuring fields like patientName, diagnosis, and specific medications are accurately extracted and formatted according to medical data standards.

  5. Finalization: The Finalize Track n8n node aggregates the results, calculates AI token usage (essential for cost monitoring), and adds processing metadata.

  6. Response: The API Response n8n node delivers the complete, comprehensive structured JSON to the requesting system, completing the automated n8n workflow.

Installation Guide

To use this n8n workflow, follow these steps:


  1. Import: Copy the provided JSON code and paste it into your n8n canvas via the 'Import from JSON' option.

  2. Credentials Setup: Locate the two HTTP Request n8n nodes named 'Gemini Classify Extract' and 'Gemini Structure Data'. Both require Google Gemini (PaLM) API credentials.

Obtain your Gemini API Key from Google AI Studio.
In n8n, navigate to Credentials and add a new 'Google Gemini (PaLM) API' credential type.
* Input your API key and link this credential to both Gemini HTTP Request n8n nodes.

  1. Webhook Configuration: The Webhook Input n8n trigger is automatically configured with the path /analyze-medical-document and method POST. Ensure your n8n instance is accessible externally (via tunnel or self-hosted deployment).

  2. Testing: Send a POST request to your n8n webhook URL (e.g., YOURN8NURL/webhook/analyze-medical-document) with a JSON body containing an image_url pointing to a medical document.

Node Details

Webhook Input (n8n trigger): The entry point configured as a POST endpoint at /analyze-medical-document. It accepts a JSON payload, primarily requiring an imageurl.
Download Image (HTTP Request n8n node): Fetches the file specified by the image
url. Key Configuration: Response Format is set to file to handle the binary data correctly.
Extract to Base64 (n8n node): Converts the downloaded binary image file into a Base64 property named imagedata, which is the format Google Gemini requires for multimodal inputs.
Gemini Classify Extract (HTTP Request n8n node): Executes the first AI call. Function: Classifies the document and extracts raw text. Key Configuration: Uses gemini-2.0-flash, employs a specific JSON response
schema to structure the classification results, and includes the image data and prompt text to guide the classification process.
Gemini Structure Data (HTTP Request n8n node): Executes the second, more complex AI call. Function: Takes the raw extracted text from the previous step and structures it against a strict, multi-layered medical data taxonomy. Key Configuration: Uses a highly detailed response_schema that defines complex properties like medications (with dosage, frequency) and services (with cost), ensuring regulatory-compliant output from this powerful n8n node.
Finalize Track (Set n8n node): Aggregates the final structured data and calculates token usage for both AI calls, providing essential cost and audit metadata for the completed n8n workflow.


  • API Response (Respond to Webhook n8n node): Sends the final aggregated JSON result, including structured medical data and performance metrics, back to the calling application.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
Louis Chan
Louis Chan

Featured*