Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
28 changes: 27 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.iemr.common-API</groupId>
<artifactId>common-api</artifactId>
<version>3.6.0</version>
<version>3.6.1</version>
<packaging>war</packaging>

<name>Common-API</name>
Expand Down Expand Up @@ -520,6 +520,32 @@
<build>
<finalName>${artifactId}-${version}</finalName>
<plugins>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>9.0.2</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<property>^git.branch$</property>
<property>^git.commit.id.abbrev$</property>
<property>^git.build.version$</property>
<property>^git.build.time$</property>
</includeOnlyProperties>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand Down
1 change: 1 addition & 0 deletions src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ km-base-path=@env.KM_API_BASE_PATH@
km-root-path=/okm:personal/users/
km-guest-user=@env.KM_GUEST_USER@
km-guest-password=@env.KM_GUEST_PASSWORD@
tempFilePath=@env.TEMP_FILE_PATH@

# CTI Config
cti-server-ip=@env.CTI_SERVER_IP@
Expand Down
2 changes: 1 addition & 1 deletion src/main/environment/common_docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ everwellRegisterBenficiary = ${COMMON_API_BASE_URL}/beneficiary/create
## LungAssessment credentials
lungAssessmentEmail = ${SWAASA_EMAIL}
lungAssessmentPassword =${SWAASA_PASSWORD}

tempFilePath=${TEMP_FILE_PATH}

## SWASSA APIs
lungAssessmentAdminLogin = ${SWAASA_BASE_URL}/api/adminLogin
Expand Down
2 changes: 2 additions & 0 deletions src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ km-root-path=/okm:personal/users/
km-guest-user=guest
km-guest-password=guest

tempFilePath=/opt/openkm

# CTI Config
cti-server-ip=10.208.122.99
cti-logger_base_url=http://10.208.122.99/logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -70,6 +71,8 @@
import com.iemr.common.service.userbeneficiarydata.MaritalStatusService;
import com.iemr.common.service.userbeneficiarydata.StatusService;
import com.iemr.common.service.userbeneficiarydata.TitleService;
import com.iemr.common.utils.CookieUtil;
import com.iemr.common.utils.JwtUtil;
import com.iemr.common.utils.mapper.InputMapper;
import com.iemr.common.utils.mapper.OutputMapper;
import com.iemr.common.utils.response.OutputResponse;
Expand Down Expand Up @@ -103,6 +106,8 @@
private BeneficiaryOccupationService beneficiaryOccupationService;
private GovtIdentityTypeService govtIdentityTypeService;

@Autowired

Check warning on line 109 in src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.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_Common-API&issues=AZ0FdwEy3JYEkI94NNnb&open=AZ0FdwEy3JYEkI94NNnb&pullRequest=377
private JwtUtil jwtUtil;

@Autowired
public void setBenRelationshipTypeService(BenRelationshipTypeService benRelationshipTypeService) {
Expand Down Expand Up @@ -324,7 +329,7 @@
BenPhoneMap benPhoneMap = OutputMapper.gson().fromJson(request, BenPhoneMap.class);
int pageNumber = requestObj.has("pageNo") ? (requestObj.getInt("pageNo") - 1) : 0;
int rows = requestObj.has("rowsPerPage") ? requestObj.getInt("rowsPerPage") : 1000;
if (requestObj.has("is1097") && requestObj.getBoolean("is1097") == true) {

Check failure on line 332 in src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "is1097" 5 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwEy3JYEkI94NNnZ&open=AZ0FdwEy3JYEkI94NNnZ&pullRequest=377
benPhoneMap.setIs1097(true);
}

Expand All @@ -342,6 +347,54 @@
return response.toString();
}

@Operation(summary = "Provide the list of beneficiaries using Elasticsearch")
@RequestMapping(value = "/searchUser", method = RequestMethod.POST, headers = "Authorization")

Check warning on line 351 in src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "@RequestMapping(method = RequestMethod.POST)" with "@PostMapping"

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwEy3JYEkI94NNnc&open=AZ0FdwEy3JYEkI94NNnc&pullRequest=377
public String searchUser(@RequestBody String request, HttpServletRequest httpRequest) {
OutputResponse response = new OutputResponse();
try {
logger.info("Universal search request received");

JsonParser parser = new JsonParser();
JsonObject requestObj = parser.parse(request).getAsJsonObject();

String searchQuery = null;
if (requestObj.has("search") && !requestObj.get("search").isJsonNull()) {

Check failure on line 361 in src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "search" 3 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwEy3JYEkI94NNna&open=AZ0FdwEy3JYEkI94NNna&pullRequest=377
searchQuery = requestObj.get("search").getAsString();
}

if (searchQuery == null || searchQuery.trim().isEmpty()) {
response.setError(400, "Search query is required");
return response.toString();
}

String auth = httpRequest.getHeader("Authorization");

Integer userID = jwtUtil.getUserIdFromRequest(httpRequest);

logger.info("ES search for userId: {}", userID);

Boolean is1097 = false;
if (requestObj.has("is1097") && !requestObj.get("is1097").isJsonNull()) {
is1097 = requestObj.get("is1097").getAsBoolean();
}

logger.info("Searching with query: {}, userId: {}, is1097: {}", searchQuery, userID, is1097);
String result = iemrSearchUserService.searchUser(searchQuery, userID, auth, is1097);

if (result == null || result.trim().isEmpty()) {
response.setError(200, "No beneficiaries found");
return response.toString();
}

return result;

} catch (Exception e) {
logger.error("Error in universal search: {}", e.getMessage(), e);
response.setError(400, "Error searching beneficiaries: " + e.getMessage());
return response.toString();
}
}

@Operation(summary = "Provide the list of beneficiaries based on search criteria")
@RequestMapping(value = "/searchBeneficiary", method = RequestMethod.POST, headers = "Authorization")
public String searchBeneficiary(
Expand All @@ -364,6 +417,41 @@
return output.toString();
}

/**
* Elasticsearch-based advanced search endpoint
*/
@Operation(summary = "Advanced search beneficiaries using Elasticsearch")
@RequestMapping(value = "/searchBeneficiaryES", method = RequestMethod.POST, headers = "Authorization")

Check warning on line 424 in src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "@RequestMapping(method = RequestMethod.POST)" with "@PostMapping"

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwEy3JYEkI94NNnd&open=AZ0FdwEy3JYEkI94NNnd&pullRequest=377
public String searchBeneficiaryES(
@RequestBody BeneficiaryModel request,
HttpServletRequest httpRequest) {

logger.info("searchBeneficiaryES request: {}", request);
OutputResponse output = new OutputResponse();

try {

String auth = httpRequest.getHeader("Authorization");

Integer userID = jwtUtil.getUserIdFromRequest(httpRequest);

logger.info("ES Advanced search for userId: {}", userID);

String result = iemrSearchUserService.findBeneficiaryES(request, userID, auth);

Check warning on line 440 in src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Immediately return this expression instead of assigning it to the temporary variable "result".

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwEy3JYEkI94NNnY&open=AZ0FdwEy3JYEkI94NNnY&pullRequest=377

return result;

} catch (NumberFormatException ne) {
logger.error("searchBeneficiaryES failed with number format error: {}", ne.getMessage(), ne);
output.setError(400, "Invalid number format in search criteria");
return output.toString();
} catch (Exception e) {
logger.error("searchBeneficiaryES failed with error: {}", e.getMessage(), e);
output.setError(500, "Error searching beneficiaries: " + e.getMessage());
return output.toString();
}
}

@Operation(summary = "Provide all common data list needed for beneficiary registration")
@RequestMapping(value = "/getRegistrationData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
public String getRegistrationData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public ResponseEntity<ApiResponse<?>> deleteField(@PathVariable Long fieldId) {
}

@GetMapping(value = "form/{formId}/fields")
public ResponseEntity<ApiResponse<?>> getStructuredForm(@PathVariable String formId, @RequestParam(name = "lang", defaultValue = "en") String lang) {
public ResponseEntity<ApiResponse<?>> getStructuredForm(@PathVariable String formId, @RequestParam(name = "lang", defaultValue = "en") String lang,@RequestHeader(value = "jwttoken") String token) {
try {
Object result = formMasterService.getStructuredFormByFormId(formId,lang);
Object result = formMasterService.getStructuredFormByFormId(formId,lang,token);
return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.success("Form structure fetched successfully", HttpStatus.OK.value(), result));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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.common.controller.health;

import com.iemr.common.service.health.HealthService;
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.RestController;

/**
* Health check controller for Common-API.
* Verifies application liveness and dependency health (DB, Redis).
*
* @author vaishnavbhosale
*/
@RestController
public class HealthController {

private static final Logger logger = LoggerFactory.getLogger(HealthController.class);

private final HealthService healthService;

public HealthController(HealthService healthService) {
this.healthService = healthService;
}

@GetMapping("/health")
public ResponseEntity<Map<String, Object>> health() {
logger.info("Health check endpoint called");


Map<String, Object> healthStatus = healthService.checkHealth();

// Standard HTTP Status logic
String status = (String) healthStatus.get("status");
HttpStatus httpStatus = "UP".equals(status) ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE;

logger.info("Health check completed with status: {}", status);

return ResponseEntity.status(httpStatus).body(healthStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,19 @@

// Get user details
// Get user details
String userId = claims.get("userId", String.class);

Check failure on line 279 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "userId" 3 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwD83JYEkI94NNnV&open=AZ0FdwD83JYEkI94NNnV&pullRequest=377
User user = iemrAdminUserServiceImpl.getUserById(Long.parseLong(userId));

// validate if user account is locked or de-activated
if(user.getDeleted()){

Check warning on line 283 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a primitive boolean expression here.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwD83JYEkI94NNnU&open=AZ0FdwD83JYEkI94NNnU&pullRequest=377
logger.warn("Your account is locked or de-activated. Please contact administrator");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Your account is locked or de-activated. Please contact administrator.");
}
if(user.getStatusID()>2){
logger.warn("Your account is not active. Please contact administrator");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Your account is not active. Please contact administrator.");
}

// Validate that the user still exists and is active
if (user == null) {
logger.warn("Token validation failed: user not found for userId in token.");
Expand Down Expand Up @@ -1221,10 +1231,28 @@
try {
List<User> users = iemrAdminUserServiceImpl.getUserIdbyUserName(userName);
if (users.isEmpty()) {
return new ResponseEntity<>(Map.of("error", "UserName Not Found"), HttpStatus.NOT_FOUND);

Check failure on line 1234 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "error" 4 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwD83JYEkI94NNnW&open=AZ0FdwD83JYEkI94NNnW&pullRequest=377
}
User user = users.get(0);
return new ResponseEntity<>(Map.of("userName", user.getUserName(), "userId", user.getUserID()), HttpStatus.OK);
return new ResponseEntity<>(Map.of("userName", user.getUserName(), "userId", user.getUserID()),
HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(Map.of("error", "Internal server error"), HttpStatus.INTERNAL_SERVER_ERROR);
}

}

@Operation(summary = "Get UserId based on userName")
@GetMapping(value = "/checkUserName/{userName}", produces = MediaType.APPLICATION_JSON, headers = "Authorization")
public ResponseEntity<?> checkUserDetails(@PathVariable("userName") String userName) {

Check failure on line 1247 in src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove usage of generic wildcard type.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ0FdwD83JYEkI94NNnX&open=AZ0FdwD83JYEkI94NNnX&pullRequest=377
try {
List<User> users = iemrAdminUserServiceImpl.findUserIdByUserName(userName);
if (users.isEmpty()) {
return new ResponseEntity<>(Map.of("error", "UserName Not Found"), HttpStatus.NOT_FOUND);
}
User user = users.get(0);
return new ResponseEntity<>(Map.of("userName", user.getUserName(), "userId", user.getUserID()),
HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(Map.of("error", "Internal server error"), HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand Down
Loading
Loading