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
28 changes: 13 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,31 +291,29 @@
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>4.9.10</version>
<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>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix>git</prefix>
<verbose>false</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>
${project.build.outputDirectory}/git.properties
</generateGitPropertiesFilename>
<format>json</format>
<gitDescribe>
<skip>false</skip>
<always>false</always>
<dirty>-dirty</dirty>
</gitDescribe>
<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>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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.identity.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 jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import com.iemr.common.identity.service.health.HealthService;
import com.iemr.common.identity.utils.JwtAuthenticationUtil;
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;
private final JwtAuthenticationUtil jwtAuthenticationUtil;

public HealthController(HealthService healthService, JwtAuthenticationUtil jwtAuthenticationUtil) {
this.healthService = healthService;
this.jwtAuthenticationUtil = jwtAuthenticationUtil;
}
@GetMapping
@Operation(summary = "Check infrastructure health",
description = "Returns the health status of MySQL, Redis, Elasticsearch, 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<Map<String, Object>> checkHealth() {
logger.info("Health check endpoint called");

try {
Map<String, Object> healthStatus = healthService.checkHealth();
String overallStatus = (String) healthStatus.get("status");

// Return 503 only if DOWN; 200 for both UP and DEGRADED (DEGRADED = operational with warnings)
HttpStatus httpStatus = "DOWN".equals(overallStatus) ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;

logger.debug("Health check completed with status: {}", overallStatus);
return new ResponseEntity<>(healthStatus, httpStatus);

} catch (Exception e) {
logger.error("Unexpected error during health check", e);

// Return sanitized error response
Map<String, Object> errorResponse = Map.of(
"status", "DOWN",
"timestamp", Instant.now().toString()
);

return new ResponseEntity<>(errorResponse, HttpStatus.SERVICE_UNAVAILABLE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,59 @@
*/
package com.iemr.common.identity.controller.version;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iemr.common.identity.utils.response.OutputResponse;

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

@RestController
public class VersionController {

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

private static final String UNKNOWN_VALUE = "unknown";

@Operation(summary = "Get version information")
@GetMapping(value = "/version",consumes = "application/json", produces = "application/json")
public String versionInformation() {
OutputResponse output = new OutputResponse();
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, String>> versionInformation() {
Map<String, String> response = new LinkedHashMap<>();
try {
logger.info("version Controller Start");
output.setResponse(readGitProperties());
} catch (Exception e) {
output.setError(e);
}

Properties gitProperties = loadGitProperties();
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
} catch (Exception e) {
logger.error("Failed to load version information", e);
response.put("buildTimestamp", UNKNOWN_VALUE);
response.put("version", UNKNOWN_VALUE);
response.put("branch", UNKNOWN_VALUE);
response.put("commitHash", UNKNOWN_VALUE);
}
logger.info("version Controller End");
return output.toString();
return ResponseEntity.ok(response);
}
private String readGitProperties() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("git.properties");

return readFromInputStream(inputStream);
}
private String readFromInputStream(InputStream inputStream)
throws IOException {
StringBuilder resultStringBuilder = new StringBuilder();
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = br.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
}
}
return resultStringBuilder.toString();

private Properties loadGitProperties() throws IOException {
Properties properties = new Properties();
try (InputStream input = getClass().getClassLoader()
.getResourceAsStream("git.properties")) {
if (input != null) {
properties.load(input);
}
}
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,55 @@ public class RMNCHBeneficiaryDetailsRmnch {
@Column(name = "noOfDaysForDelivery")
private Integer noOfDaysForDelivery;


@Expose
private Boolean isDeath;

@Expose
private String isDeathValue;

@Expose
private String dateOfDeath;

@Expose
private String timeOfDeath;

@Expose
private String reasonOfDeath;

@Expose
private Integer reasonOfDeathId;

@Expose
private String placeOfDeath;

@Expose
private Integer placeOfDeathId;

@Expose
private String otherPlaceOfDeath;

@Expose
private Boolean isSpouseAdded;


@Expose
private Boolean isChildrenAdded;

@Expose
private Boolean isMarried;

@Expose
private Boolean doYouHavechildren;


@Expose
private Integer noofAlivechildren;

@Expose
private Integer noOfchildren;

@Expose
private Boolean isDeactivate;

}
83 changes: 42 additions & 41 deletions src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,53 +165,54 @@ MBeneficiarymapping getWithVanSerialNoVanID(@Param("vanSerialNo") BigInteger van
*/
@Query(value = "SELECT " +
"m.BenRegId, " + // 0
"brm.BeneficiaryId, " +
"brm.BeneficiaryId, " + // 1
"d.FirstName, " + // 2
"d.LastName, " + // 3
"d.GenderID, " + // 4
"g.GenderName, " + // 5
"d.DOB, " + // 6
"TIMESTAMPDIFF(YEAR, d.DOB, CURDATE()), " + // 7 - age
"d.FatherName, " + // 8
"d.SpouseName, " + // 9
"d.IsHIVPositive, " + // 10
"m.CreatedBy, " + // 11
"m.CreatedDate, " + // 12
"UNIX_TIMESTAMP(m.LastModDate) * 1000, " + // 13
"m.BenAccountID, " + // 14
"contact.PreferredPhoneNum, " + // 15
// "h.HealthID, " + "h.HealthIDNumber, " +
"fam.BenFamilyMapId, " +
"addr.CurrStateId, " + // 19
"addr.CurrState, " + // 20
"addr.CurrDistrictId, " + // 21
"addr.CurrDistrict, " + // 22
"addr.CurrSubDistrictId, " + // 23
"addr.CurrSubDistrict, " + // 24
"addr.CurrVillageId, " + // 25
"addr.CurrVillage, " + // 26
"addr.CurrPinCode, " + // 27
"addr.CurrServicePointId, " + // 28
"addr.CurrServicePoint, " + // 29
"addr.ParkingPlaceID, " + // 30
"addr.PermStateId, " + // 31
"addr.PermState, " + // 32
"addr.PermDistrictId, " + // 33
"addr.PermDistrict, " + // 34
"addr.PermSubDistrictId, " + // 35
"addr.PermSubDistrict, " + // 36
"addr.PermVillageId, " + // 37
"addr.PermVillage " + // 38
// "id.GovtIdentityNo, " + // 39 - Aadhar/Govt ID
// "id.IdentityNo " + // 40 - Another identity
"d.MiddleName, " + // 3
"d.LastName, " + // 4
"d.GenderID, " + // 5
"g.GenderName, " + // 6
"d.DOB, " + // 7
"TIMESTAMPDIFF(YEAR, d.DOB, CURDATE()), " + // 8 - age
"d.FatherName, " + // 9
"d.SpouseName, " + // 10
"d.MaritalStatusID, " + // 11
"ms.Status as MaritalStatusName, " + // 12 - MaritalStatusName
"d.IsHIVPositive, " + // 13
"m.CreatedBy, " + // 14
"m.CreatedDate, " + // 15
"UNIX_TIMESTAMP(m.LastModDate) * 1000, " + // 16
"m.BenAccountID, " + // 17
"contact.PreferredPhoneNum, " + // 18
"fam.BenFamilyMapId, " + // 19
"addr.CurrStateId, " + // 20
"addr.CurrState, " + // 21
"addr.CurrDistrictId, " + // 22
"addr.CurrDistrict, " + // 23
"addr.CurrSubDistrictId, " + // 24
"addr.CurrSubDistrict, " + // 25
"addr.CurrVillageId, " + // 26
"addr.CurrVillage, " + // 27
"addr.CurrPinCode, " + // 28
"addr.CurrServicePointId, " + // 29
"addr.CurrServicePoint, " + // 30
"addr.ParkingPlaceID, " + // 31
"addr.PermStateId, " + // 32
"addr.PermState, " + // 33
"addr.PermDistrictId, " + // 34
"addr.PermDistrict, " + // 35
"addr.PermSubDistrictId, " + // 36
"addr.PermSubDistrict, " + // 37
"addr.PermVillageId, " + // 38
"addr.PermVillage " + // 39
"FROM i_beneficiarymapping m " +
"LEFT JOIN i_beneficiarydetails d ON m.BenDetailsId = d.BeneficiaryDetailsID " +
"LEFT JOIN db_iemr.m_gender g ON d.GenderID = g.GenderID " +
"LEFT JOIN db_iemr.m_maritalstatus ms ON d.MaritalStatusID = ms.MaritalStatusID " +
"LEFT JOIN i_beneficiaryaddress addr ON m.BenAddressId = addr.BenAddressID " +
"LEFT JOIN i_beneficiarycontacts contact ON m.BenContactsId = contact.BenContactsID " +
"LEFT JOIN m_beneficiaryregidmapping brm ON brm.BenRegId = m.BenRegId " +
"LEFT JOIN db_iemr.m_benhealthidmapping h ON m.BenRegId = h.BeneficiaryRegID " +
"LEFT JOIN i_beneficiaryfamilymapping fam " +
"LEFT JOIN m_beneficiaryregidmapping brm ON brm.BenRegId = m.BenRegId " +
"LEFT JOIN db_iemr.m_benhealthidmapping h ON m.BenRegId = h.BeneficiaryRegID " +
"LEFT JOIN i_beneficiaryfamilymapping fam " +
" ON m.BenRegId = fam.AssociatedBenRegID " +
" AND fam.Deleted = false " +
"WHERE m.BenRegId IN :benRegIds " +
Expand Down
Loading
Loading