EHR Dashboard Backend API
Relevant source files
The following files were used as context for generating this wiki page:
The EHR Dashboard Backend API is a high-performance Python-based service developed using FastAPI. It serves as an orchestration layer between the OpenMRS core system and advanced clinical features such as voice transcription, AI-powered vitals extraction, and clinical summarization. Its primary purpose is to provide structured data to the EHR Dashboard and specialized frontend widgets.
The API integrates several third-party AI services, including Sarvam AI for speech-to-text (STT) and Google Gemini for natural language processing (NLP). It handles complex workflows like converting raw audio recordings into structured medical observations and generating comprehensive patient summaries by aggregating data from OpenMRS REST and FHIR APIs.
Sources: README.md:14-25, readmes/FINAL_SUMMARY.md:130-145
System Architecture and Integration
The backend is architected as a set of microservices running alongside the OpenMRS core. It consists of two main Python components: the primary AI Backend and the Gemini Proxy.
Component Relationship Diagram
This diagram illustrates how the Backend API interacts with OpenMRS and external AI providers.
Core Components
| Component | Port | Technology | Purpose |
|---|---|---|---|
| AI Backend | 3001 | Python/FastAPI | Voice transcription, OCR, vitals extraction, and previsit workflows. |
| Gemini Proxy | 8001 | Python/FastAPI | LLM-backed clinical summarization and proxying for Google Gemini. |
| OpenMRS Backend | 8080 | Java/Spring | Primary source for patient data, clinical encounters, and REST/FHIR services. |
| Sources: deployment/HOSPITAL-DEPLOYMENT-GUIDE.md:28-36, README.md:14-25 |
API Endpoints and Data Flow
The Backend API provides several specialized endpoints to handle AI-intensive clinical tasks.
Vitals Transcription and Extraction
One of the primary functions is the /process_vitals_transcription endpoint. This service receives a text transcript and uses a specialized NLP model to extract structured vital signs.
Endpoint Specification
| Endpoint | Method | Input | Output | Description |
|---|---|---|---|---|
/transcribe_batch | POST | Audio Blob (WebM/WAV) | Plain Text | Transcribes clinical voice recordings using Sarvam AI. |
/process_vitals_transcription | POST | JSON String (Transcript) | Structured JSON | Uses Gemini to extract 10 vital sign fields and perform unit conversions. |
/generate_summary | POST | Patient Data / Prompt | HTML/Markdown | Generates comprehensive patient summaries via Gemini Proxy. |
| Sources: readmes/FINAL_SUMMARY.md:40-50, readmes/VOICE_VITALS_IMPLEMENTATION.md:150-165 |
Data Processing Logic
The API implements significant business logic to ensure medical data quality during the extraction process.
AI Extraction and Transformation
When processing vitals, the backend performs the following automated transformations:
- Unit Conversion: Automatically converts Fahrenheit to Celsius, pounds to kilograms, and inches to centimeters.
- Blood Pressure Parsing: Splits single spoken BP values (e.g., "120 over 80") into distinct systolic and diastolic fields.
- BMI Calculation: Automatically calculates Body Mass Index if both height and weight are extracted.
- Intelligent Null Handling: Fields not found in the transcript are returned as
nullrather than zeros to prevent clinical data corruption.
Sources: readmes/FINAL_SUMMARY.md:65-80, readmes/VOICE_VITALS_IMPLEMENTATION.md:200-215
Data Mapping Structure
The backend ensures compatibility with the OpenMRS form schema via a mapping utility.
Configuration and Deployment
The API relies on environment variables for secure access to AI cloud providers and OpenMRS services.
Environment Configuration
| Variable | Description | Source |
|---|---|---|
SARVAM_API_KEY | Key for speech-to-text features. | Sarvam AI Console |
GEMINI_API_KEY | Key for NLP extraction and summarization. | Google AI Studio |
OPENMRS_API_URL | Base URL for the OpenMRS REST API. | Internal Network |
OPENMRS_USERNAME | Admin/Service user for OpenMRS authentication. | Core System |
| Sources: deployment/HOSPITAL-DEPLOYMENT-GUIDE.md:135-145, README.md:48-60 |
Technical Requirements
The backend environment requires Python 3.10+ and specific system libraries for audio processing:
- FFmpeg: Required for converting WebM audio blobs from the browser into WAV format for the STT API.
- FastAPI / Uvicorn: The web framework and ASGI server hosting the API.
- Google Generative AI SDK: Integrated for communicating with the Gemini 1.5/2.0 models.
Sources: deployment/HOSPITAL-DEPLOYMENT-GUIDE.md:60-70, readmes/VOICE_VITALS_IMPLEMENTATION.md:300-310
Conclusion
The EHR Dashboard Backend API acts as the intelligence layer of the clinical system. By offloading complex transcription, unit conversion, and NLP extraction to this Python-based service, the OpenMRS environment gains advanced AI capabilities while maintaining high performance and data integrity. It is designed to be production-ready with comprehensive error handling and responsive data mapping for mobile and desktop clinical workflows.