Skip to content

Commit 08e5d8c

Browse files
vanitha1822SauravBizbRollyDurgaPrasad-54
authored
Rebase 3.6.2 (#150)
* fix: enable multi-word fuzzy search requirement (#139) * fix: enable multi-word fuzzy search requirement * Downgrade version from 3.6.2 to 3.6.1 * fix: multi-word search (#140) * Fix the column mismatch issue in beneficiary search (#142) * fix: column mismatch issue * fix: update marital status * add new column in rmnch table for death and child record * add new column in rmnch table for death and child record * Cherry-pick health and version API enhancements to release-3.6.1 (#145) * feat(health,version): add health and version endpoints * feat(health,version): add health and version endpoints without auth * fix(health): remove unused private methods * fix(health): fix exception issue * fix(health): redact error details for unauthenticated health checks * fix code quality issues and reduce cognitive complexity * feat(health): add MySQL health endpoint * refactor(health): simplify MySQL health check and remove sensitive details * fix(health): remove unused imports and variables * refactor(health): address nitpicks (configurable ES scheme, log noise, graceful shutdown, record) * fix(health): scope PROCESSLIST lock-wait check to application DB user * refactor(health): remove unused params and reuse response/error constants * fix(health): remove unused imports and methods * chore(health): clean up unused imports, params, and dead helpers * fix(health): avoid sharing JDBC connections across threads in advanced MySQL checks * refactor(health): reuse REDIS_COMPONENT constant and extract nested try block * fix(health): avoid blocking DB I/O under write lock and restore interrupt flag * fix(health): cancel in-flight futures on generic failure * feat(health,version): add index existance, read-only detection, canary write for elasticsearch health check * refactor(health): reduce cognitive complexity, remove dead throws, and clean code smells --------- Co-authored-by: Saurav Mishra <saurav.mishra@bizbrolly.com> Co-authored-by: Saurav Mishra <80103738+SauravBizbRolly@users.noreply.github.com> Co-authored-by: KOPPIREDDY DURGA PRASAD <144464542+DurgaPrasad-54@users.noreply.github.com>
1 parent 39debc2 commit 08e5d8c

8 files changed

Lines changed: 1229 additions & 162 deletions

File tree

pom.xml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -291,31 +291,29 @@
291291
<version>3.3.0</version>
292292
</plugin>
293293
<plugin>
294-
<groupId>pl.project13.maven</groupId>
295-
<artifactId>git-commit-id-plugin</artifactId>
296-
<version>4.9.10</version>
294+
<groupId>io.github.git-commit-id</groupId>
295+
<artifactId>git-commit-id-maven-plugin</artifactId>
296+
<version>9.0.2</version>
297297
<executions>
298298
<execution>
299299
<id>get-the-git-infos</id>
300300
<goals>
301301
<goal>revision</goal>
302302
</goals>
303+
<phase>initialize</phase>
303304
</execution>
304305
</executions>
305306
<configuration>
306-
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
307-
<prefix>git</prefix>
308-
<verbose>false</verbose>
309307
<generateGitPropertiesFile>true</generateGitPropertiesFile>
310-
<generateGitPropertiesFilename>
311-
${project.build.outputDirectory}/git.properties
312-
</generateGitPropertiesFilename>
313-
<format>json</format>
314-
<gitDescribe>
315-
<skip>false</skip>
316-
<always>false</always>
317-
<dirty>-dirty</dirty>
318-
</gitDescribe>
308+
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
309+
<includeOnlyProperties>
310+
<property>^git.branch$</property>
311+
<property>^git.commit.id.abbrev$</property>
312+
<property>^git.build.version$</property>
313+
<property>^git.build.time$</property>
314+
</includeOnlyProperties>
315+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
316+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
319317
</configuration>
320318
</plugin>
321319

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* AMRIT – Accessible Medical Records via Integrated Technology
3+
* Integrated EHR (Electronic Health Records) Solution
4+
*
5+
* Copyright (C) "Piramal Swasthya Management and Research Institute"
6+
*
7+
* This file is part of AMRIT.
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program. If not, see https://www.gnu.org/licenses/.
21+
*/
22+
23+
package com.iemr.common.identity.controller.health;
24+
25+
import java.time.Instant;
26+
import java.util.Map;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
import org.springframework.http.HttpStatus;
30+
import org.springframework.http.ResponseEntity;
31+
import org.springframework.web.bind.annotation.GetMapping;
32+
import org.springframework.web.bind.annotation.RequestMapping;
33+
import org.springframework.web.bind.annotation.RestController;
34+
import jakarta.servlet.http.Cookie;
35+
import jakarta.servlet.http.HttpServletRequest;
36+
import com.iemr.common.identity.service.health.HealthService;
37+
import com.iemr.common.identity.utils.JwtAuthenticationUtil;
38+
import io.swagger.v3.oas.annotations.Operation;
39+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
40+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
41+
import io.swagger.v3.oas.annotations.tags.Tag;
42+
43+
44+
@RestController
45+
@RequestMapping("/health")
46+
@Tag(name = "Health Check", description = "APIs for checking infrastructure health status")
47+
public class HealthController {
48+
49+
private static final Logger logger = LoggerFactory.getLogger(HealthController.class);
50+
51+
private final HealthService healthService;
52+
private final JwtAuthenticationUtil jwtAuthenticationUtil;
53+
54+
public HealthController(HealthService healthService, JwtAuthenticationUtil jwtAuthenticationUtil) {
55+
this.healthService = healthService;
56+
this.jwtAuthenticationUtil = jwtAuthenticationUtil;
57+
}
58+
@GetMapping
59+
@Operation(summary = "Check infrastructure health",
60+
description = "Returns the health status of MySQL, Redis, Elasticsearch, and other configured services")
61+
@ApiResponses({
62+
@ApiResponse(responseCode = "200", description = "Services are UP or DEGRADED (operational with warnings)"),
63+
@ApiResponse(responseCode = "503", description = "One or more critical services are DOWN")
64+
})
65+
public ResponseEntity<Map<String, Object>> checkHealth() {
66+
logger.info("Health check endpoint called");
67+
68+
try {
69+
Map<String, Object> healthStatus = healthService.checkHealth();
70+
String overallStatus = (String) healthStatus.get("status");
71+
72+
// Return 503 only if DOWN; 200 for both UP and DEGRADED (DEGRADED = operational with warnings)
73+
HttpStatus httpStatus = "DOWN".equals(overallStatus) ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;
74+
75+
logger.debug("Health check completed with status: {}", overallStatus);
76+
return new ResponseEntity<>(healthStatus, httpStatus);
77+
78+
} catch (Exception e) {
79+
logger.error("Unexpected error during health check", e);
80+
81+
// Return sanitized error response
82+
Map<String, Object> errorResponse = Map.of(
83+
"status", "DOWN",
84+
"timestamp", Instant.now().toString()
85+
);
86+
87+
return new ResponseEntity<>(errorResponse, HttpStatus.SERVICE_UNAVAILABLE);
88+
}
89+
}
90+
}

src/main/java/com/iemr/common/identity/controller/version/VersionController.java

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,59 @@
2121
*/
2222
package com.iemr.common.identity.controller.version;
2323

24-
import java.io.BufferedReader;
2524
import java.io.IOException;
2625
import java.io.InputStream;
27-
import java.io.InputStreamReader;
26+
import java.util.LinkedHashMap;
27+
import java.util.Map;
28+
import java.util.Properties;
2829

2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
32+
33+
import org.springframework.http.MediaType;
34+
import org.springframework.http.ResponseEntity;
3135
import org.springframework.web.bind.annotation.GetMapping;
3236
import org.springframework.web.bind.annotation.RestController;
3337

34-
import com.iemr.common.identity.utils.response.OutputResponse;
35-
3638
import io.swagger.v3.oas.annotations.Operation;
3739

3840
@RestController
3941
public class VersionController {
4042

41-
private Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
43+
private final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
4244

45+
private static final String UNKNOWN_VALUE = "unknown";
46+
4347
@Operation(summary = "Get version information")
44-
@GetMapping(value = "/version",consumes = "application/json", produces = "application/json")
45-
public String versionInformation() {
46-
OutputResponse output = new OutputResponse();
48+
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
49+
public ResponseEntity<Map<String, String>> versionInformation() {
50+
Map<String, String> response = new LinkedHashMap<>();
4751
try {
4852
logger.info("version Controller Start");
49-
output.setResponse(readGitProperties());
50-
} catch (Exception e) {
51-
output.setError(e);
52-
}
53-
53+
Properties gitProperties = loadGitProperties();
54+
response.put("buildTimestamp", gitProperties.getProperty("git.build.time", UNKNOWN_VALUE));
55+
response.put("version", gitProperties.getProperty("git.build.version", UNKNOWN_VALUE));
56+
response.put("branch", gitProperties.getProperty("git.branch", UNKNOWN_VALUE));
57+
response.put("commitHash", gitProperties.getProperty("git.commit.id.abbrev", UNKNOWN_VALUE));
58+
} catch (Exception e) {
59+
logger.error("Failed to load version information", e);
60+
response.put("buildTimestamp", UNKNOWN_VALUE);
61+
response.put("version", UNKNOWN_VALUE);
62+
response.put("branch", UNKNOWN_VALUE);
63+
response.put("commitHash", UNKNOWN_VALUE);
64+
}
5465
logger.info("version Controller End");
55-
return output.toString();
66+
return ResponseEntity.ok(response);
5667
}
57-
private String readGitProperties() throws Exception {
58-
ClassLoader classLoader = getClass().getClassLoader();
59-
InputStream inputStream = classLoader.getResourceAsStream("git.properties");
60-
61-
return readFromInputStream(inputStream);
62-
}
63-
private String readFromInputStream(InputStream inputStream)
64-
throws IOException {
65-
StringBuilder resultStringBuilder = new StringBuilder();
66-
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
67-
String line;
68-
while ((line = br.readLine()) != null) {
69-
resultStringBuilder.append(line).append("\n");
70-
}
71-
}
72-
return resultStringBuilder.toString();
68+
69+
private Properties loadGitProperties() throws IOException {
70+
Properties properties = new Properties();
71+
try (InputStream input = getClass().getClassLoader()
72+
.getResourceAsStream("git.properties")) {
73+
if (input != null) {
74+
properties.load(input);
75+
}
76+
}
77+
return properties;
7378
}
7479
}

src/main/java/com/iemr/common/identity/data/rmnch/RMNCHBeneficiaryDetailsRmnch.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,55 @@ public class RMNCHBeneficiaryDetailsRmnch {
499499
@Column(name = "noOfDaysForDelivery")
500500
private Integer noOfDaysForDelivery;
501501

502+
503+
@Expose
504+
private Boolean isDeath;
505+
506+
@Expose
507+
private String isDeathValue;
508+
509+
@Expose
510+
private String dateOfDeath;
511+
512+
@Expose
513+
private String timeOfDeath;
514+
515+
@Expose
516+
private String reasonOfDeath;
517+
518+
@Expose
519+
private Integer reasonOfDeathId;
520+
521+
@Expose
522+
private String placeOfDeath;
523+
524+
@Expose
525+
private Integer placeOfDeathId;
526+
527+
@Expose
528+
private String otherPlaceOfDeath;
529+
530+
@Expose
531+
private Boolean isSpouseAdded;
532+
533+
534+
@Expose
535+
private Boolean isChildrenAdded;
536+
537+
@Expose
538+
private Boolean isMarried;
539+
540+
@Expose
541+
private Boolean doYouHavechildren;
542+
543+
544+
@Expose
545+
private Integer noofAlivechildren;
546+
547+
@Expose
548+
private Integer noOfchildren;
549+
550+
@Expose
551+
private Boolean isDeactivate;
552+
502553
}

src/main/java/com/iemr/common/identity/repo/BenMappingRepo.java

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -165,53 +165,54 @@ MBeneficiarymapping getWithVanSerialNoVanID(@Param("vanSerialNo") BigInteger van
165165
*/
166166
@Query(value = "SELECT " +
167167
"m.BenRegId, " + // 0
168-
"brm.BeneficiaryId, " +
168+
"brm.BeneficiaryId, " + // 1
169169
"d.FirstName, " + // 2
170-
"d.LastName, " + // 3
171-
"d.GenderID, " + // 4
172-
"g.GenderName, " + // 5
173-
"d.DOB, " + // 6
174-
"TIMESTAMPDIFF(YEAR, d.DOB, CURDATE()), " + // 7 - age
175-
"d.FatherName, " + // 8
176-
"d.SpouseName, " + // 9
177-
"d.IsHIVPositive, " + // 10
178-
"m.CreatedBy, " + // 11
179-
"m.CreatedDate, " + // 12
180-
"UNIX_TIMESTAMP(m.LastModDate) * 1000, " + // 13
181-
"m.BenAccountID, " + // 14
182-
"contact.PreferredPhoneNum, " + // 15
183-
// "h.HealthID, " + "h.HealthIDNumber, " +
184-
"fam.BenFamilyMapId, " +
185-
"addr.CurrStateId, " + // 19
186-
"addr.CurrState, " + // 20
187-
"addr.CurrDistrictId, " + // 21
188-
"addr.CurrDistrict, " + // 22
189-
"addr.CurrSubDistrictId, " + // 23
190-
"addr.CurrSubDistrict, " + // 24
191-
"addr.CurrVillageId, " + // 25
192-
"addr.CurrVillage, " + // 26
193-
"addr.CurrPinCode, " + // 27
194-
"addr.CurrServicePointId, " + // 28
195-
"addr.CurrServicePoint, " + // 29
196-
"addr.ParkingPlaceID, " + // 30
197-
"addr.PermStateId, " + // 31
198-
"addr.PermState, " + // 32
199-
"addr.PermDistrictId, " + // 33
200-
"addr.PermDistrict, " + // 34
201-
"addr.PermSubDistrictId, " + // 35
202-
"addr.PermSubDistrict, " + // 36
203-
"addr.PermVillageId, " + // 37
204-
"addr.PermVillage " + // 38
205-
// "id.GovtIdentityNo, " + // 39 - Aadhar/Govt ID
206-
// "id.IdentityNo " + // 40 - Another identity
170+
"d.MiddleName, " + // 3
171+
"d.LastName, " + // 4
172+
"d.GenderID, " + // 5
173+
"g.GenderName, " + // 6
174+
"d.DOB, " + // 7
175+
"TIMESTAMPDIFF(YEAR, d.DOB, CURDATE()), " + // 8 - age
176+
"d.FatherName, " + // 9
177+
"d.SpouseName, " + // 10
178+
"d.MaritalStatusID, " + // 11
179+
"ms.Status as MaritalStatusName, " + // 12 - MaritalStatusName
180+
"d.IsHIVPositive, " + // 13
181+
"m.CreatedBy, " + // 14
182+
"m.CreatedDate, " + // 15
183+
"UNIX_TIMESTAMP(m.LastModDate) * 1000, " + // 16
184+
"m.BenAccountID, " + // 17
185+
"contact.PreferredPhoneNum, " + // 18
186+
"fam.BenFamilyMapId, " + // 19
187+
"addr.CurrStateId, " + // 20
188+
"addr.CurrState, " + // 21
189+
"addr.CurrDistrictId, " + // 22
190+
"addr.CurrDistrict, " + // 23
191+
"addr.CurrSubDistrictId, " + // 24
192+
"addr.CurrSubDistrict, " + // 25
193+
"addr.CurrVillageId, " + // 26
194+
"addr.CurrVillage, " + // 27
195+
"addr.CurrPinCode, " + // 28
196+
"addr.CurrServicePointId, " + // 29
197+
"addr.CurrServicePoint, " + // 30
198+
"addr.ParkingPlaceID, " + // 31
199+
"addr.PermStateId, " + // 32
200+
"addr.PermState, " + // 33
201+
"addr.PermDistrictId, " + // 34
202+
"addr.PermDistrict, " + // 35
203+
"addr.PermSubDistrictId, " + // 36
204+
"addr.PermSubDistrict, " + // 37
205+
"addr.PermVillageId, " + // 38
206+
"addr.PermVillage " + // 39
207207
"FROM i_beneficiarymapping m " +
208208
"LEFT JOIN i_beneficiarydetails d ON m.BenDetailsId = d.BeneficiaryDetailsID " +
209209
"LEFT JOIN db_iemr.m_gender g ON d.GenderID = g.GenderID " +
210+
"LEFT JOIN db_iemr.m_maritalstatus ms ON d.MaritalStatusID = ms.MaritalStatusID " +
210211
"LEFT JOIN i_beneficiaryaddress addr ON m.BenAddressId = addr.BenAddressID " +
211212
"LEFT JOIN i_beneficiarycontacts contact ON m.BenContactsId = contact.BenContactsID " +
212-
"LEFT JOIN m_beneficiaryregidmapping brm ON brm.BenRegId = m.BenRegId " +
213-
"LEFT JOIN db_iemr.m_benhealthidmapping h ON m.BenRegId = h.BeneficiaryRegID " +
214-
"LEFT JOIN i_beneficiaryfamilymapping fam " +
213+
"LEFT JOIN m_beneficiaryregidmapping brm ON brm.BenRegId = m.BenRegId " +
214+
"LEFT JOIN db_iemr.m_benhealthidmapping h ON m.BenRegId = h.BeneficiaryRegID " +
215+
"LEFT JOIN i_beneficiaryfamilymapping fam " +
215216
" ON m.BenRegId = fam.AssociatedBenRegID " +
216217
" AND fam.Deleted = false " +
217218
"WHERE m.BenRegId IN :benRegIds " +

0 commit comments

Comments
 (0)