Skip to content

Commit b33f298

Browse files
vanitha1822SauravBizbRollyDurgaPrasad-54
authored
Merge Release 3.6.1 to main (#146)
* Elasticsearch implementation for Beneficiary Search (#123) * fix: ES Implementation-mapping, indexing and async records * fix: add service for ES Search * fix: search implementation * fix: add additional fields as per the requirement * fix: comment extra fields * fix: rename the files, remove commented code * fix: update pom.xml * fix: revert advancesearch * fix: add properties * fix: coderabbit comments * fix: remove comment code * fix: accept numeric values for search * fix: update the env variable * fix: advance search functionality * fix: update the advance search ES functionality * fix: sync and fetch benid * fix: size limit issue * fix: improve response time * fix: updated the end point to advancedSearchES * fix: age issue while moving to nurse worklist (#130) * Optimize the Elasticsearch for better Response Time (#131) * fix: optimize the index and reduce the size * fix: align indent * fix: abha / health id issue * fix: sync optimization * fix: get abha created date * fix: state issue * fix: village issue * fix: add abha details * fix: abha fix and refresh index * fix: refresh index * fix: remove duplicate dependency * fix: fuzzy search, resume, refresh api's * fix: add middlename, maritalstatus * fix: remove refresh while bulk indexing * fix: add license * fix: remove the bean function to create the index automatically (#133) * Fix ES Issue in the Query (#137) * fix: ES Exception * fix: ES exception * Nd/vs/fix es (#138) * fix: ES Exception * fix: ES exception * 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 2ed618d commit b33f298

33 files changed

Lines changed: 7274 additions & 1765 deletions

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.iemr.common.identity</groupId>
77
<artifactId>identity-api</artifactId>
8-
<version>3.6.0</version>
8+
<version>3.6.1</version>
99

1010
<packaging>war</packaging>
1111

@@ -73,6 +73,16 @@
7373
<version>1.3.2</version>
7474
</dependency>
7575
<dependency>
76+
<groupId>org.springframework.boot</groupId>
77+
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
78+
</dependency>
79+
<dependency>
80+
<groupId>co.elastic.clients</groupId>
81+
<artifactId>elasticsearch-java</artifactId>
82+
<version>8.11.0</version>
83+
</dependency>
84+
85+
<dependency>
7686
<groupId>org.springframework.boot</groupId>
7787
<artifactId>spring-boot-devtools</artifactId>
7888
<scope>runtime</scope>

src/main/environment/common_ci.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ fhir-url=@env.FHIR_API@
2323
spring.redis.host=@env.REDIS_HOST@
2424

2525
cors.allowed-origins=@env.CORS_ALLOWED_ORIGINS@
26+
27+
# Elasticsearch Configuration
28+
elasticsearch.host=@env.ELASTICSEARCH_HOST@
29+
elasticsearch.port=@env.ELASTICSEARCH_PORT@
30+
elasticsearch.username=@env.ELASTICSEARCH_USERNAME@
31+
elasticsearch.password=@env.ELASTICSEARCH_PASSWORD@
32+
elasticsearch.index.beneficiary=@env.ELASTICSEARCH_INDEX_BENEFICIARY@
33+
34+
# Enable/Disable ES (for gradual rollout)
35+
elasticsearch.enabled=@env.ELASTICSEARCH_ENABLED@

src/main/environment/common_docker.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ fhir-url=${FHIR_API}
2323
spring.redis.host=${REDIS_HOST}
2424

2525
cors.allowed-origins=${CORS_ALLOWED_ORIGINS}
26+
27+
# Elasticsearch Configuration
28+
elasticsearch.host=${ELASTICSEARCH_HOST}
29+
elasticsearch.port=${ELASTICSEARCH_PORT}
30+
elasticsearch.username=${ELASTICSEARCH_USERNAME}
31+
elasticsearch.password=${ELASTICSEARCH_PASSWORD}
32+
elasticsearch.index.beneficiary=${ELASTICSEARCH_INDEX_BENEFICIARY}
33+
34+
# Enable/Disable ES (for gradual rollout)
35+
elasticsearch.enabled=${ELASTICSEARCH_ENABLED}

src/main/environment/common_example.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ fhir-url=http://localhost:8093/
1818
# Redis Config
1919
spring.redis.host=localhost
2020
cors.allowed-origins=http://localhost:*
21+
22+
# Elasticsearch Configuration
23+
elasticsearch.host=localhost
24+
elasticsearch.port=9200
25+
elasticsearch.username=elastic
26+
elasticsearch.password=piramalES
27+
elasticsearch.index.beneficiary=beneficiary_index
28+
29+
# Enable/Disable ES (for gradual rollout)
30+
elasticsearch.enabled=true
31+

src/main/java/com/iemr/common/identity/IdentityApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import org.springframework.boot.builder.SpringApplicationBuilder;
2727
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
2828
import org.springframework.context.annotation.Bean;
29+
import org.springframework.context.annotation.ComponentScan;
2930

3031
import com.iemr.common.identity.utils.IEMRApplBeans;
3132

3233
@SpringBootApplication
34+
@ComponentScan(basePackages = {"com.iemr.common.identity"})
3335
public class IdentityApplication extends SpringBootServletInitializer {
3436

3537
public static void main(String[] args) {
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
package com.iemr.common.identity.config;
23+
24+
import java.io.IOException;
25+
26+
import co.elastic.clients.elasticsearch.ElasticsearchClient;
27+
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
28+
import co.elastic.clients.transport.ElasticsearchTransport;
29+
import co.elastic.clients.transport.rest_client.RestClientTransport;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
33+
import org.apache.http.HttpHost;
34+
import org.apache.http.auth.AuthScope;
35+
import org.apache.http.auth.UsernamePasswordCredentials;
36+
import org.apache.http.impl.client.BasicCredentialsProvider;
37+
import org.elasticsearch.client.RestClient;
38+
import org.springframework.beans.factory.annotation.Value;
39+
import org.springframework.context.annotation.Bean;
40+
import org.springframework.context.annotation.Configuration;
41+
42+
@Configuration
43+
public class ElasticsearchConfig {
44+
45+
private static final Logger logger = LoggerFactory.getLogger(ElasticsearchConfig.class);
46+
47+
@Value("${elasticsearch.host}")
48+
private String esHost;
49+
50+
@Value("${elasticsearch.port}")
51+
private int esPort;
52+
53+
@Value("${elasticsearch.username}")
54+
private String esUsername;
55+
56+
@Value("${elasticsearch.password}")
57+
private String esPassword;
58+
59+
@Value("${elasticsearch.index.beneficiary}")
60+
private String indexName;
61+
62+
@Bean
63+
public ElasticsearchClient elasticsearchClient() {
64+
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
65+
credentialsProvider.setCredentials(
66+
AuthScope.ANY,
67+
new UsernamePasswordCredentials(esUsername, esPassword)
68+
);
69+
70+
RestClient restClient = RestClient.builder(
71+
new HttpHost(esHost, esPort, "http")
72+
).setHttpClientConfigCallback(httpClientBuilder ->
73+
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
74+
).build();
75+
76+
ElasticsearchTransport transport = new RestClientTransport(
77+
restClient,
78+
new JacksonJsonpMapper()
79+
);
80+
81+
return new ElasticsearchClient(transport);
82+
}
83+
84+
85+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
package com.iemr.common.identity.config;
23+
24+
import java.util.concurrent.Executor;
25+
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.scheduling.annotation.EnableAsync;
29+
import org.springframework.scheduling.annotation.EnableScheduling;
30+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
31+
32+
/**
33+
* Configuration for async processing and scheduling
34+
*/
35+
@Configuration
36+
@EnableAsync
37+
@EnableScheduling
38+
public class ElasticsearchSyncConfig {
39+
40+
/**
41+
* Thread pool for Elasticsearch sync operations
42+
* Configured for long-running background jobs
43+
*/
44+
@Bean(name = "elasticsearchSyncExecutor")
45+
public Executor elasticsearchSyncExecutor() {
46+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
47+
48+
// Only 1-2 sync jobs should run at a time to avoid overwhelming DB/ES
49+
executor.setCorePoolSize(2);
50+
executor.setMaxPoolSize(4);
51+
executor.setQueueCapacity(100);
52+
executor.setThreadNamePrefix("es-sync-");
53+
executor.setKeepAliveSeconds(60);
54+
executor.setWaitForTasksToCompleteOnShutdown(true);
55+
executor.setAwaitTerminationSeconds(60);
56+
57+
// Handle rejected tasks
58+
executor.setRejectedExecutionHandler((r, executor1) -> {
59+
throw new RuntimeException("Elasticsearch sync queue is full. Please wait for current job to complete.");
60+
});
61+
62+
executor.initialize();
63+
return executor;
64+
}
65+
66+
/**
67+
* General purpose async executor
68+
*/
69+
@Bean(name = "taskExecutor")
70+
public Executor taskExecutor() {
71+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
72+
executor.setCorePoolSize(5);
73+
executor.setMaxPoolSize(10);
74+
executor.setQueueCapacity(100);
75+
executor.setThreadNamePrefix("async-");
76+
executor.initialize();
77+
return executor;
78+
}
79+
}

0 commit comments

Comments
 (0)