Skip to content
Merged
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
2 changes: 1 addition & 1 deletion 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.2</version>
<version>3.12.0</version>
<packaging>war</packaging>

<name>MMU-API</name>
Expand Down
8 changes: 7 additions & 1 deletion src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ logging.file.name=@env.MMU_API_LOGGING_FILE_NAME@
springdoc.api-docs.enabled=@env.SWAGGER_DOC_ENABLED@
springdoc.swagger-ui.enabled=@env.SWAGGER_DOC_ENABLED@

cors.allowed-origins=@env.CORS_ALLOWED_ORIGINS@
cors.allowed-origins=@env.CORS_ALLOWED_ORIGINS@

## 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
16 changes: 15 additions & 1 deletion src/main/environment/common_docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,18 @@ logging.path=logs
logging.file.name=${MMU_API_LOGGING_FILE_NAME}

springdoc.api-docs.enabled=${SWAGGER_DOC_ENABLED}
springdoc.swagger-ui.enabled=${SWAGGER_DOC_ENABLED}
springdoc.swagger-ui.enabled=${SWAGGER_DOC_ENABLED}

## 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}
16 changes: 15 additions & 1 deletion src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ 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
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
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

Check warning on line 46 in src/main/java/com/iemr/mmu/controller/benid/CentralAuthController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this field injection and use constructor injection instead.

See more on https://sonarcloud.io/project/issues?id=PSMRI_MMU-API&issues=AaE6FldgghVCWurGbnDe&open=AaE6FldgghVCWurGbnDe&pullRequest=200
private CentralAuthService centralAuthService;

@Autowired

Check warning on line 49 in src/main/java/com/iemr/mmu/controller/benid/CentralAuthController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this field injection and use constructor injection instead.

See more on https://sonarcloud.io/project/issues?id=PSMRI_MMU-API&issues=AaE6FldgghVCWurGbnDf&open=AaE6FldgghVCWurGbnDf&pullRequest=200
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());

Check warning on line 59 in src/main/java/com/iemr/mmu/controller/benid/CentralAuthController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=PSMRI_MMU-API&issues=AaE6FldgghVCWurGbnDg&open=AaE6FldgghVCWurGbnDg&pullRequest=200
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());

Check warning on line 89 in src/main/java/com/iemr/mmu/controller/benid/CentralAuthController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=PSMRI_MMU-API&issues=AaE6FldgghVCWurGbnDh&open=AaE6FldgghVCWurGbnDh&pullRequest=200
response.setError(e);
}
return response.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.iemr.mmu.service.benid.BenIdAutoTopUpService;
import com.iemr.mmu.service.dataSyncActivity.DownSyncDataFromServerImpl;
import com.iemr.mmu.service.dataSyncActivity.DownloadDataFromServerImpl;
import com.iemr.mmu.service.dataSyncActivity.DownloadDataFromServerTransactionalImpl;
Expand Down Expand Up @@ -71,6 +72,9 @@ public class StartSyncActivity {
@Autowired
private DownSyncDataFromServerImpl downSyncDataFromServerImpl;

@Autowired
private BenIdAutoTopUpService benIdAutoTopUpService;

private static final String GROUP_ID = "groupID";
private static final String PROVIDER_SERVICE_MAP_ID = "providerServiceMapID";

Expand All @@ -89,6 +93,8 @@ public String dataSyncToServer(@RequestBody String requestOBJ,
serverAuthorization, jwtToken);
// if (s != null)
response.setResponse(s);
// internet is up right now: top up the BenID pool if it is low
benIdAutoTopUpService.triggerNow();
// else
// response.setError(5000, "Error in data sync");
} else {
Expand Down Expand Up @@ -180,8 +186,11 @@ public String startMasterDownload(@RequestBody String requestOBJ,
if (s.equalsIgnoreCase("inProgress"))
response.setError(5000,
"Download is already in progress from different device, kindly wait to finish this");
else
else {
response.setResponse(s);
// internet is up right now: top up the BenID pool if it is low
benIdAutoTopUpService.triggerNow();
}
} else
response.setError(5000, s);
} else {
Expand Down
Loading
Loading