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
18 changes: 16 additions & 2 deletions src/main/environment/bengen_docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
start-bengen-scheduler=true

# To Run scheduler Every MON,WED,FRI
cron-scheduler-bengen=0 1 0 ? * MON,WED,FRI,SUN *
# cron-scheduler-bengen=0 1 0 ? * MON,WED,FRI,SUN *


# To Run scheduler Every Day
cron-scheduler-bengen=0 1 0 * * ? *

# To Run scheduler Every Minute
#cron-scheduler-bengen=0 0/1 * * * ? *
Expand All @@ -19,7 +23,16 @@ cron-scheduler-bengen=0 1 0 ? * MON,WED,FRI,SUN *
no-of-benID-to-be-generate=25000

### Total available Ben should not be less than this
lower-limit-of-beneficiary=20000
lower-limit-of-beneficiary=10000

### Rows inserted per batch (each batch commits on its own)
benID-batch-size=500

### Low-water-mark watcher: tops the pool up as soon as it drops below
### lower-limit-of-beneficiary, instead of only at the cron fire times.
bengen.pool-watcher-enabled=true
bengen.pool-watcher-interval-ms=300000
bengen.pool-watcher-initial-delay-ms=60000

### Health API warns (status DEGRADED) when available Ben IDs fall below this
health.min-available-beneficiary-ids=5000
Expand All @@ -31,3 +44,4 @@ spring.redis.host=${REDIS_HOST}
logging.path=logs/
logging.file.name=${BENEFICIARYID_GENERATION_API_LOGGING_FILE_NAME}
jwt.secret=${JWT_SECRET_KEY}

16 changes: 13 additions & 3 deletions src/main/environment/bengen_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
start-bengen-scheduler=true

# To Run scheduler Every MON,WED,FRI
cron-scheduler-bengen=0 1 0 ? * MON,WED,FRI,SUN *
# cron-scheduler-bengen=0 1 0 ? * MON,WED,FRI,SUN *

# To Run scheduler Every Day
# cron-scheduler-bengen=0 1 0 * * ? *
cron-scheduler-bengen=0 1 0 * * ? *

# To Run scheduler Every Minute
#cron-scheduler-bengen=0 0/1 * * * ? *
Expand All @@ -23,7 +23,16 @@ cron-scheduler-bengen=0 1 0 ? * MON,WED,FRI,SUN *
no-of-benID-to-be-generate=25000

### Total available Ben should not be less than this
lower-limit-of-beneficiary=20000
lower-limit-of-beneficiary=10000

### Rows inserted per batch (each batch commits on its own)
benID-batch-size=500

### Low-water-mark watcher: tops the pool up as soon as it drops below
### lower-limit-of-beneficiary, instead of only at the cron fire times.
bengen.pool-watcher-enabled=true
bengen.pool-watcher-interval-ms=300000
bengen.pool-watcher-initial-delay-ms=60000

### Health API warns (status DEGRADED) when available Ben IDs fall below this
health.min-available-beneficiary-ids=5000
Expand All @@ -38,3 +47,4 @@ logging.path=logs/
logging.file.name=logs/beneficiaryid-generation-api.log

cors.allowed-origins=http://localhost:*

Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,34 @@
*/
package com.iemr.common.bengen.config.quartz;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.iemr.common.bengen.repo.BeneficiaryIdRepo;
import com.iemr.common.bengen.service.GenerateBeneficiaryService;
import com.iemr.common.bengen.utils.config.ConfigProperties;

@Service
@Transactional
public class ScheduleJobServiceForBenGen implements Job
{
@DisallowConcurrentExecution
public class ScheduleJobServiceForBenGen implements Job {
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Autowired
BeneficiaryIdRepo beneficiaryIdRepo;

@Autowired
GenerateBeneficiaryService generateBeneficiaryService;


@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException
{
logger.info("Started job " + arg0.getClass().getName());
try
{
Long totalBenID= beneficiaryIdRepo.countBenID();
logger.info("Total Beneficiary ID available -> " + totalBenID);
Integer lowerLimitOfBen = ConfigProperties.getInteger("lower-limit-of-beneficiary");
if(totalBenID<lowerLimitOfBen)
{
generateBeneficiaryService.generateBeneficiaryIDs();
}
public void execute(JobExecutionContext context) throws JobExecutionException {
logger.info("Started scheduled beneficiary ID top-up");
try {
int inserted = generateBeneficiaryService.topUpPoolIfBelowLimit();
logger.info("Completed scheduled beneficiary ID top-up, inserted {} IDs", inserted);
} catch (Exception e) {
e.printStackTrace();
logger.error("Scheduled beneficiary ID top-up failed", e);
throw new JobExecutionException(e, false);
}
logger.info("Completed job " + arg0.getClass().getName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public String getBeneficiaryIDs(@Param("{\"benIDRequired\":\"Integer\",\"vanID\"

String response = getSuccessResponseString(list, 200, "success", "generateBeneficiaryIDs");

logger.info("generateBeneficiaryIDs response "+response.toString());
logger.info("generateBeneficiaryIDs returned {} IDs for vanID {}", list.size(), benMapping.getVanID());
/**
* sending the response...
*/
Expand All @@ -82,8 +82,6 @@ private String getSuccessResponseString(List<M_BeneficiaryRegidMapping> list,
private static final long serialVersionUID = 1L;
}.getType();
String data = OutputMapper.getInstance().gson().toJson(list, typeOfSrc);
logger.info("data: " + data);
logger.info("data.toStr: " + data.toString());
OutputResponse response = new OutputResponse.Builder().setDataJsonType("JsonObject.class")
.setStatusCode(statusCode).setStatusMessage(statusMsg)
.setDataObjectType(this.getClass().getSimpleName())
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/iemr/common/bengen/repo/BeneficiaryIdRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ Long countByReservedForPSMapIdAndProvisionedAndReserved(
+ " WHERE benregMap.provisioned =false and benregMap.reserved =false")
Long countBenID();

@Query(nativeQuery = true, value = "Select benregMap.benRegId, benregMap.beneficiaryId, " +
"benregMap.CreatedDate "
+ "from m_beneficiaryregidmapping benregMap "
+ "where benregMap.provisioned =false and benregMap.reserved =true " +
"and benregMap.vanID=:vanID order by benregMap.benRegId desc limit :num ")
List<Object[]> getBenIDGenerated(@Param("vanID") Integer vanID, @Param("num") Long num);
@Query(nativeQuery = true, value = "Select benregMap.benRegId, benregMap.beneficiaryId, "
+ "benregMap.CreatedDate "
+ "from m_beneficiaryregidmapping benregMap "
+ "where benregMap.provisioned =false and benregMap.reserved =true "
+ "and benregMap.vanID=:vanID and benregMap.CreatedDate >= :createdFrom "
+ "and benregMap.beneficiaryId in (:beneficiaryIds) "
+ "order by benregMap.benRegId")
List<Object[]> getBenIDGeneratedForRequest(@Param("vanID") Integer vanID,
@Param("createdFrom") Timestamp createdFrom,
@Param("beneficiaryIds") List<Long> beneficiaryIds);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* AMRIT - Accessible Medical Records via Integrated Technologies
* 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.bengen.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
@ConditionalOnProperty(name = "bengen.pool-watcher-enabled", havingValue = "true", matchIfMissing = true)
public class BeneficiaryPoolWatcher {
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Autowired

Check warning on line 37 in src/main/java/com/iemr/common/bengen/service/BeneficiaryPoolWatcher.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_BeneficiaryID-Generation-API&issues=AaCPlFxVr0kW89h1-FcZ&open=AaCPlFxVr0kW89h1-FcZ&pullRequest=71
GenerateBeneficiaryService generateBeneficiaryService;

@Scheduled(initialDelayString = "${bengen.pool-watcher-initial-delay-ms:60000}",
fixedDelayString = "${bengen.pool-watcher-interval-ms:300000}")
public void watchPool() {
try {
int inserted = generateBeneficiaryService.topUpPoolIfBelowLimit();
if (inserted > 0) {
logger.info("Pool watcher topped up {} beneficiary IDs", inserted);
}
} catch (Exception e) {
logger.error("Pool watcher top-up failed", e);
}
}
}
Loading
Loading