diff --git a/.github/workflows/swagger-json.yml b/.github/workflows/swagger-json.yml
new file mode 100644
index 00000000..c658d340
--- /dev/null
+++ b/.github/workflows/swagger-json.yml
@@ -0,0 +1,107 @@
+name: Sync Swagger to AMRIT-Docs
+
+on:
+ push:
+ branches: [ main ]
+ workflow_dispatch:
+
+jobs:
+ swagger-sync:
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+
+ steps:
+ - name: Checkout API repo
+ uses: actions/checkout@v4
+
+ - name: Set up Java 17
+ uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: 17
+ cache: maven
+
+ - name: Build API (skip tests)
+ run: mvn -B clean package -DskipTests
+
+ - name: Install jq
+ run: sudo apt-get update && sudo apt-get install -y jq
+
+ - name: Run API in swagger profile
+ run: |
+ nohup java -jar target/tm-api-*.war \
+ --spring.profiles.active=swagger \
+ --server.port=9090 \
+ > app.log 2>&1 &
+ echo $! > api_pid.txt
+
+ - name: Wait for API & fetch Swagger
+ run: |
+ for i in {1..40}; do
+ CODE=$(curl --connect-timeout 2 --max-time 5 -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
+
+ if [ "$CODE" = "200" ]; then
+ jq . swagger_raw.json > tm-api.json || {
+ echo "Swagger JSON invalid"
+ cat swagger_raw.json
+ exit 1
+ }
+
+ if [ "$(jq '.paths | length' tm-api.json)" -eq 0 ]; then
+ echo "Swagger paths empty – failing"
+ exit 1
+ fi
+
+ echo "Swagger generated successfully"
+ exit 0
+ fi
+
+ echo "Waiting for API... ($i)"
+ sleep 4
+ done
+
+ echo "Swagger not generated"
+ cat app.log || true
+ exit 1
+
+ - name: Stop API
+ if: always()
+ run: |
+ # Graceful shutdown of the process group
+ sleep 5
+ # Force kill the process group if still running
+ if [ -f api_pid.txt ]; then
+ PID=$(cat api_pid.txt)
+ kill -TERM -- -"$PID" 2>/dev/null || true
+ sleep 2
+ kill -9 -- -"$PID" 2>/dev/null || true
+ fi
+ # Fallback: kill any remaining java process on port 9090
+ fuser -k 9090/tcp 2>/dev/null || true
+
+ - name: Checkout AMRIT-Docs
+ uses: actions/checkout@v4
+ with:
+ repository: PSMRI/AMRIT-Docs
+ token: ${{ secrets.DOCS_REPO_TOKEN }}
+ path: amrit-docs
+ fetch-depth: 0
+
+ - name: Copy Swagger JSON
+ run: |
+ mkdir -p amrit-docs/docs/swagger
+ cp tm-api.json amrit-docs/docs/swagger/tm-api.json
+
+ - name: Create Pull Request
+ uses: peter-evans/create-pull-request@v8
+ with:
+ token: ${{ secrets.DOCS_REPO_TOKEN }}
+ path: amrit-docs
+ branch: auto/swagger-update-tm-api
+ base: main
+ commit-message: "chore(docs): auto-update TM-API swagger"
+ title: "chore(docs): auto-update TM-API swagger"
+ delete-branch: true
+ body: |
+ This PR automatically updates TM-API Swagger JSON
+ from the latest main branch build.
diff --git a/README.md b/README.md
index 4d24c6ce..37d6505e 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,8 @@
# AMRIT - Telemedicine (TM) Service
[](https://www.gnu.org/licenses/gpl-3.0)
-
+[](https://deepwiki.com/PSMRI/TM-API)
+
The AMRIT Telemedicine (TM) Service enhances the capabilities of Health and Wellness Centers (HWCs) by providing remote healthcare services, improving accessibility, enabling collaborative care, and integrating with other facilities such as drug dispensing and laboratory services. This service aims to extend the reach and convenience of HWCs, ensuring that patients receive necessary medical advice and services without the need for in-person visits.
diff --git a/pom.xml b/pom.xml
index 6efb67ff..61212dd4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -299,12 +299,17 @@
0.12.6
runtime
+
+ com.h2database
+ h2
+ runtime
+
- ${artifactId}-${version}
+ ${project.artifactId}-${project.version}
@@ -348,6 +353,32 @@
maven-jar-plugin
3.0.2
+
+ io.github.git-commit-id
+ git-commit-id-maven-plugin
+ 9.0.2
+
+
+ get-the-git-infos
+
+ revision
+
+ initialize
+
+
+
+ true
+ ${project.build.outputDirectory}/git.properties
+
+ ^git.branch$
+ ^git.commit.id.abbrev$
+ ^git.build.version$
+ ^git.build.time$
+
+ false
+ false
+
+
org.springframework.boot
spring-boot-maven-plugin
diff --git a/src/main/java/com/iemr/tm/config/SwaggerConfig.java b/src/main/java/com/iemr/tm/config/SwaggerConfig.java
index 6ebc2666..82883a43 100644
--- a/src/main/java/com/iemr/tm/config/SwaggerConfig.java
+++ b/src/main/java/com/iemr/tm/config/SwaggerConfig.java
@@ -2,6 +2,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
@@ -11,14 +12,26 @@
@Configuration
public class SwaggerConfig {
-
- @Bean
- public OpenAPI customOpenAPI() {
- return new OpenAPI().info(new
- Info().title("TeleMedicine(TM) API").version("version").description("A microservice for the creation and management of beneficiaries."))
- .addSecurityItem(new SecurityRequirement().addList("my security"))
- .components(new Components().addSecuritySchemes("my security",
- new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")));
+ private static final String DEFAULT_SERVER_URL = "http://localhost:9090";
+
+ @Bean
+ public OpenAPI customOpenAPI(Environment env) {
+ String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL);
+ String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL);
+ String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL);
+ return new OpenAPI()
+ .info(new Info()
+ .title("TeleMedicine(TM) API")
+ .version("1.0.0")
+ .description("A microservice for TeleMedicine, providing APIs for remote healthcare consultations, patient management, and related telehealth operations."))
+ .addSecurityItem(new SecurityRequirement().addList("my security"))
+ .components(new Components().addSecuritySchemes("my security",
+ new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")))
+ .servers(java.util.Arrays.asList(
+ new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"),
+ new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"),
+ new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo")
+ ));
}
}
diff --git a/src/main/java/com/iemr/tm/controller/health/HealthController.java b/src/main/java/com/iemr/tm/controller/health/HealthController.java
new file mode 100644
index 00000000..650bf402
--- /dev/null
+++ b/src/main/java/com/iemr/tm/controller/health/HealthController.java
@@ -0,0 +1,84 @@
+/*
+* AMRIT – Accessible Medical Records via Integrated Technology
+* Integrated EHR (Electronic Health Records) Solution
+*
+* Copyright (C) "Piramal Swasthya Management and Research Institute"
+*
+* This file is part of AMRIT.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see https://www.gnu.org/licenses/.
+*/
+
+package com.iemr.tm.controller.health;
+
+import java.time.Instant;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.iemr.tm.service.health.HealthService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
+import io.swagger.v3.oas.annotations.tags.Tag;
+
+@RestController
+@RequestMapping("/health")
+@Tag(name = "Health Check", description = "APIs for checking infrastructure health status")
+public class HealthController {
+
+ private static final Logger logger = LoggerFactory.getLogger(HealthController.class);
+
+ private final HealthService healthService;
+
+ public HealthController(HealthService healthService) {
+ this.healthService = healthService;
+ }
+
+ @GetMapping
+ @Operation(summary = "Check infrastructure health",
+ description = "Returns the health status of MySQL, Redis, and other configured services")
+ @ApiResponses({
+ @ApiResponse(responseCode = "200", description = "Services are UP or DEGRADED (operational with warnings)"),
+ @ApiResponse(responseCode = "503", description = "One or more critical services are DOWN")
+ })
+ public ResponseEntity