Skip to content

pellse/assembler-spring-example

Repository files navigation

Real-Time Patient Monitoring with Spring and AI

This repository showcases the standalone usage of Assembler + an example of integration with different Spring related technologies like Spring AI, Spring Cloud, Spring WebFlux and Spring GraphQL for real-time data composition.

Tech Stack

Scenario

This example showcases a basic healthcare application designed to simulate monitoring patient data. Four services are implemented:

  • The Patient Service retrieves patient demographics from PostgreSQL.
  • The Blood Pressure Service fetches a patient's systolic and diastolic blood pressure readings from MongoDB.
    • Coming soon: Support for Change Data Capture (CDC) for real-time synchronization of the Blood Pressure Service's data cache.
  • The Heart Rate Streaming Service provides real-time heart rate monitoring from an ECG device via Kafka.
  • The Diagnosis AI Service analyzes heart rate and blood pressure data to produce diagnostic insights.

A GraphQL Controller implemented in PatientObservationController aggregates data from these services. A GraphQL Subscription and REST SSE (Server-Sent Events) endpoint are also implemented in VitalsMonitoringStreamController for real-time data aggregation from a stream of heart rate records.

Check out this brief presentation for a walkthrough of the Assembler API for the real-time streaming example (please note that the newly added AI/LLM integration is not covered in this presentation):

assembler.mp4

You can also view the presentation here and go through each slide at your own speed.

Assembler with Spring WebFlux/GraphQL for API Composition and solving the N+1 Query Problem

Batch Mapping (Data Querying)

The new BatchRule API from Assembler seamlessly integrates with the Spring GraphQL @BatchMapping mechanism, as shown in the usage example found in PatientObservationController. Additionally, this example showcases additional features of Assembler, including:

  • caching of service invocations using the cached() function
  • caching of real-time data streams with the streamTable() function.

image

Subscription Mapping (Data Streaming)

Assembler excels in complex data aggregation within a data streaming scenario. This example, via VitalsMonitoringStreamController, demonstrates its usage in standalone mode in conjunction with Spring WebFlux for REST Server-Sent Events, and Spring GraphQL using @SubscriptionMapping. By combining streaming and batching, Assembler enables seamless data stream augmentation for clients connected via persistent HTTP connections or WebSockets.

image

How to Run the Application

  • Configure application.yml with your OpenAI compatible API Key (Google Gemini is used in this example):
    spring:
      ai:
        openai:
          api-key: ${GEMINI_API_KEY}
          chat:
            base-url: https://generativelanguage.googleapis.com
            completions-path: /v1beta/openai/chat/completions
            options:
              model: gemini-2.0-flash
  • Make sure Docker is installed
  • Run the main method in src\test\java\io\github\pellse\example\PatientMonitoringApplicationTest.java
    • Or execute the bootTestRun Gradle Task

This repository takes advantage of the new Spring Boot 3.1.0 Testcontainers support for local development.

How to Use the Application (GraphQL)

Open a browser at http://localhost:8080/graphiql?path=/graphql

For Batch Mapping (Data Querying)

  • Run the following GraphQL Query:
query PatientQuery {
  patients {
    id
    name
    healthCardNumber
    bloodPressures {
      systolic
      diastolic
      time
    }
    heartRate {
      heartRateValue
      time
    }
  }
}

Periodically rerun the query, the number of HR (heart rate) values for each patient should increase:

PatientObservationController

For Subscription Mapping (Data Streaming)

  • Run the following GraphQL Query:
subscription VitalsMonitoringStream {
  vitals {
    patient {
      id
      name
      healthCardNumber
    }
    bloodPressures {
      systolic
      diastolic
      time
    }
    heartRate {
      heartRateValue
      time
    }
    diagnosis
  }
}

You should see the following:

2025-04-09.16-36-14.mp4

How to Use the Application (REST Server-Sent Events)

Open a browser or a an HTTP Client (e.g. Postman) at http://localhost:8080/vitals/stream

You should see the following:

2025-04-02.23-32-17.mp4

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages