Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.iemr.mmu</groupId>
<artifactId>mmu-api</artifactId>
<version>3.9.0</version>
<version>3.13.0</version>
<packaging>war</packaging>

<name>MMU-API</name>
Expand Down Expand Up @@ -294,7 +294,12 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<!-- CSV parsing for the Nikshay results-file import (quoted/embedded-comma fields) -->
<!-- AWS SDK v2 - S3 client, used for diagnostic document sync -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.25.60</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
Expand Down
17 changes: 17 additions & 0 deletions src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ spring.datasource.username=@env.DATABASE_USERNAME@
spring.datasource.password=@env.DATABASE_PASSWORD@
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

## S3 storage for diagnostic documents pushed from a van
aws.s3.access-key=@env.AWS_S3_ACCESS_KEY@
aws.s3.secret-key=@env.AWS_S3_SECRET_KEY@
aws.s3.region=@env.AWS_S3_REGION@
diagnostic.documents.s3.bucket=@env.DIAGNOSTIC_DOCUMENTS_S3_BUCKET@

## Carestream URLs, local
carestreamOrderCreateURL=@env.COMMON_API@carestream/createOrder

Expand All @@ -28,6 +34,11 @@ dataSyncUploadUrl=@env.MMU_CENTRAL_SERVER@dataSync/van-to-server
## Data download API, central
dataSyncDownloadUrl=@env.MMU_CENTRAL_SERVER@dataSync/server-to-van

## Diagnostic document push (this server -> further central server)
diagnosticDocumentUploadUrl=@env.MMU_CENTRAL_SERVER@dataSync/diagnostic-documents
diagnosticDocument.push.batchSize=@env.DIAGNOSTIC_DOCUMENT_PUSH_BATCH_SIZE@
diagnostic.documents.storage-root=@env.DIAGNOSTIC_DOCUMENTS_STORAGE_ROOT@

## TC specialist slot booking, # not required
tcSpecialistSlotBook=@env.TM_API@schedule/bookSlot

Expand Down Expand Up @@ -99,3 +110,9 @@ cors.allowed-origins=@env.CORS_ALLOWED_ORIGINS@

# Server that hosts the failedBeneficiaries API
nikshay.failedBeneficiariesUrl=@env.MMU_CENTRAL_SERVER@nikshay/syncStatus/failedBeneficiaries

## BenID auto top-up URLs (feature stays off: stoptb.* not set for these builds)
benCheckUrlLocal=@env.IDENTITY_API_BASE_URL@id/checkAvailablBenIDLocalServer
centralLoginUrl=@env.COMMON_API_OPEN_SYNC@user/userAuthenticate
centralRefreshTokenUrl=@env.COMMON_API_OPEN_SYNC@user/refreshToken
centralSessionUrl=@env.COMMON_API_OPEN_SYNC@user/getLoginResponse
25 changes: 25 additions & 0 deletions src/main/environment/common_docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ spring.datasource.username=${DATABASE_USERNAME}
spring.datasource.password=${DATABASE_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

## S3 storage for diagnostic documents pushed from a van
aws.s3.access-key=${AWS_S3_ACCESS_KEY:}
aws.s3.secret-key=${AWS_S3_SECRET_KEY:}
aws.s3.region=${AWS_S3_REGION:ap-south-1}
diagnostic.documents.s3.bucket=${DIAGNOSTIC_DOCUMENTS_S3_BUCKET:}

## Carestream URLs, local
carestreamOrderCreateURL=${COMMON_API}carestream/createOrder

Expand All @@ -28,6 +34,11 @@ dataSyncUploadUrl=${MMU_CENTRAL_SERVER}dataSync/van-to-server
## Data download API, central
dataSyncDownloadUrl=${MMU_CENTRAL_SERVER}dataSync/server-to-van

## Diagnostic document push (this server -> further central server)
diagnosticDocumentUploadUrl=${MMU_CENTRAL_SERVER}dataSync/diagnostic-documents
diagnosticDocument.push.batchSize=${DIAGNOSTIC_DOCUMENT_PUSH_BATCH_SIZE:3}
diagnostic.documents.storage-root=${DIAGNOSTIC_DOCUMENTS_STORAGE_ROOT}

## TC specialist slot booking, # not required
tcSpecialistSlotBook=${TM_API}schedule/bookSlot

Expand Down Expand Up @@ -97,3 +108,17 @@ springdoc.swagger-ui.enabled=${SWAGGER_DOC_ENABLED}

# Server that hosts the failedBeneficiaries API
nikshay.failedBeneficiariesUrl=${MMU_CENTRAL_SERVER}nikshay/syncStatus/failedBeneficiaries

## BenID auto top-up (StopTB laptops only; off unless STOPTB_ENFORCE_VANID=true and STOPTB_VAN_ID>0)
benCheckUrlLocal=${IDENTITY_API_BASE_URL}id/checkAvailablBenIDLocalServer
centralLoginUrl=${COMMON_API_OPEN_SYNC}user/userAuthenticate
centralRefreshTokenUrl=${COMMON_API_OPEN_SYNC}user/refreshToken
centralSessionUrl=${COMMON_API_OPEN_SYNC}user/getLoginResponse
stoptb.enforce.vanid=${STOPTB_ENFORCE_VANID:false}
stoptb.van.id=${STOPTB_VAN_ID:0}
benid.pool.lowerLimit=${BENID_POOL_LOWER_LIMIT:2000}
benid.pool.batchSize=${BENID_POOL_BATCH_SIZE:1000}
benid.pool.bootstrapSize=${BENID_POOL_BOOTSTRAP_SIZE:10000}
benid.token.dir=${BENID_TOKEN_DIR:/opt/amrit/data}
benid.autoTopUp.initialDelayMs=${BENID_AUTO_TOPUP_INITIAL_DELAY_MS:120000}
benid.autoTopUp.checkIntervalMs=${BENID_AUTO_TOPUP_CHECK_INTERVAL_MS:300000}
40 changes: 39 additions & 1 deletion src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ spring.datasource.username=<Enter your AMRIT DB username>
spring.datasource.password=<Enter your AMRIT DB password>
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

## S3 storage for diagnostic documents pushed from a van (POST /dataSync/diagnostic-documents)
aws.s3.access-key=<Enter your AWS access key here>
aws.s3.secret-key=<Enter your AWS secret key here>
aws.s3.region=ap-south-1
diagnostic.documents.s3.bucket=<Enter your private bucket name here>

## Carestream URLs, local
#carestreamOrderCreateURL =http://localhost:1040/carestream/createOrder
carestreamOrderCreateURL =http://localhost:8083/carestream/createOrder
Expand Down Expand Up @@ -44,6 +50,10 @@ dataSyncUploadUrl=http://10.208.122.38:8080/mmu-api/dataSync/van-to-server
#dataSyncDownloadUrl=http://localhost:82/dataSync/server-to-van
dataSyncDownloadUrl=http://10.208.122.38:8080/mmu-api/dataSync/server-to-van

diagnosticDocumentUploadUrl=http://localhost:8087/mmu-api/dataSync/diagnostic-documents
diagnosticDocument.push.batchSize=3
diagnostic.documents.storage-root=<Enter your diagnostic documents storage root path here>

## TC specialist slot booking, # not required
#tcSpecialistSlotBook=http://localhost:8080/schedule/bookSlot
tcSpecialistSlotBook=http://10.208.122.38:8080/tm-api/schedule/bookSlot
Expand Down Expand Up @@ -112,4 +122,32 @@ logging.path=logs/
logging.file.name=logs/mmu-api.log


cors.allowed-origins=http://localhost:*
cors.allowed-origins=http://localhost:*

## BenID auto top-up (StopTB laptops only)
benCheckUrlLocal=http://localhost:8094/id/checkAvailablBenIDLocalServer
centralLoginUrl=https://uatstoptb.piramalswasthya.org/common-api/user/userAuthenticate
centralRefreshTokenUrl=https://uatstoptb.piramalswasthya.org/common-api/user/refreshToken
centralSessionUrl=https://uatstoptb.piramalswasthya.org/common-api/user/getLoginResponse
stoptb.enforce.vanid=false
stoptb.van.id=0
benid.pool.lowerLimit=2000
benid.pool.batchSize=1000
benid.pool.bootstrapSize=10000
benid.token.dir=/opt/amrit/data
benid.autoTopUp.initialDelayMs=120000
benid.autoTopUp.checkIntervalMs=300000

## Automatic Data Sync (StopTB laptops only; needs the BenID central connection above). Off by default: manual sync only.
sync.autoUpload.enabled=false
sync.autoUpload.intervalMs=1800000
sync.autoMasterDownload.enabled=false
sync.autoMasterDownload.intervalMs=21600000
# automatic master download fetches only inventory masters (items, stores, item->store mapping); false = all masters
sync.autoMasterDownload.inventoryOnly=true
sync.autoInventoryDownload.enabled=false

## Central upload: replace van IDs in link columns (BenVisitID, PrescriptionID) by central IDs.
## Off by default (other MMU servers unchanged); on for the StopTB central.
## Env alternative: DATASYNC_TRANSLATEVANLINKS=true
dataSync.translateVanLinks=false
2 changes: 2 additions & 0 deletions src/main/java/com/iemr/mmu/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.iemr.mmu.data.login.Users;
import com.iemr.mmu.utils.IEMRApplBeans;

@SpringBootApplication
@EnableScheduling
public class Application {

public static void main(String[] args) {
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/iemr/mmu/config/S3ClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.iemr.mmu.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.presigner.S3Presigner;

/***
* @purpose S3 client beans used to store diagnostic documents pushed from a van. Built
* once and shared, rather than re-built per request.
*/
@Configuration
public class S3ClientConfig {

@Value("${aws.s3.access-key}")
private String accessKey;

@Value("${aws.s3.secret-key}")
private String secretKey;

@Value("${aws.s3.region}")
private String region;

/*
* Only the central server talks to S3; a van (camp laptop) runs the same war but never
* calls it, so it must be able to start without AWS keys. AwsBasicCredentials rejects blank
* keys at construction time, so fall back to the SDK default chain, which is resolved lazily
* on the first S3 call rather than at startup.
*/
private AwsCredentialsProvider credentialsProvider() {
if (accessKey == null || accessKey.isBlank() || secretKey == null || secretKey.isBlank()) {
return DefaultCredentialsProvider.create();
}
return StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey));
}

@Bean
public S3Client diagnosticDocumentS3Client() {
return S3Client.builder().region(Region.of(region)).credentialsProvider(credentialsProvider()).build();
}

@Bean
public S3Presigner diagnosticDocumentS3Presigner() {
return S3Presigner.builder().region(Region.of(region)).credentialsProvider(credentialsProvider()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.mmu.controller.benid;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iemr.mmu.service.benid.BenIdAutoTopUpService;
import com.iemr.mmu.service.benid.CentralAuthService;
import com.iemr.mmu.utils.response.OutputResponse;

import io.swagger.v3.oas.annotations.Operation;

@RestController
@RequestMapping(value = "/centralAuth", headers = "Authorization", produces = "application/json")
public class CentralAuthController {

private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

@Autowired
private CentralAuthService centralAuthService;

@Autowired
private BenIdAutoTopUpService benIdAutoTopUpService;

@Operation(summary = "Automatic BenID top-up and central connection status")
@GetMapping(value = "/status")
public String status() {
OutputResponse response = new OutputResponse();
try {
response.setResponse(benIdAutoTopUpService.status().toString());
} catch (Exception e) {
logger.error("Error reading BenID auto top-up status: " + e.getMessage());
response.setError(e);
}
return response.toString();
}

/**
* Called by MMU-UI right after a successful login. Returns immediately; the
* central login and any top-up happen in the background.
*/
@Operation(summary = "Connect this laptop to central with the user's login (one time)")
@PostMapping(value = "/capture", consumes = "application/json")
public String capture(@RequestBody String requestOBJ) {
OutputResponse response = new OutputResponse();
try {
if (!centralAuthService.isEnabled()) {
response.setResponse("disabled");
return response.toString();
}
JSONObject obj = new JSONObject(requestOBJ);
String userName = obj.optString("userName", null);
String password = obj.optString("password", null);
boolean force = obj.optBoolean("reconnect", false);
benIdAutoTopUpService.runInBackground(() -> {
if (centralAuthService.capture(userName, password, force)) {
benIdAutoTopUpService.triggerNow();
}
});
response.setResponse("accepted");
} catch (Exception e) {
logger.error("Error in central capture: " + e.getMessage());
response.setError(e);
}
return response.toString();
}
}
Loading
Loading