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
Original file line number Diff line number Diff line change
Expand Up @@ -116,29 +116,27 @@ public String verifyOTPAndGenerateHealthID(
*/
@CrossOrigin()
@Operation(summary = "Get Beneficiary ABHA details")
@PostMapping(value = { "/getBenhealthID" })
public String getBenhealthID(
@Param(value = "{\"beneficiaryRegID\":\"Long\"}") @RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();
@PostMapping("/getBenhealthID")
public String getBenhealthID(@RequestBody String comingRequest) {
OutputResponse response = new OutputResponse();

logger.info("NDHM_FHIR Request obj to fetch beneficiary ABHA details :" + comingRequest);
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.length() > 0) {
Long benRegID = obj.getLong("beneficiaryRegID");
String res = healthIDService.getBenHealthID(benRegID);
response.setResponse(res);
} else {
logger.info("NDHM_FHIR Invalid Request Data.");
response.setError(5000, "NDHM_FHIR Invalid request");
}
} catch (Exception e) {
response.setError(5000, e.getMessage());
logger.error("NDHM_FHIR Error while getting beneficiary ABHA:" + e);
}
logger.info("NDHM_FHIR get beneficiary ABHA response:" + response.toString());
return response.toString();
}
try {
JSONObject obj = new JSONObject(comingRequest);
if (obj.has("beneficiaryRegID")) {
Long benRegID = obj.getLong("beneficiaryRegID");
String res = healthIDService.getBenHealthID(benRegID);
response.setResponse(res);
} else {
response.setError(4001, "Missing 'beneficiaryRegID' in request");
}
} catch (Exception e) {
logger.error("NDHM_FHIR Error while getting beneficiary ABHA: ", e);
response.setError(5000, "Error: " + e.getMessage());
}

logger.info("NDHM_FHIR Response:", response);
return response.toString();
}

@CrossOrigin()
@Operation(summary = "Get Beneficiary Id for ABHA Id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public class BenHealthIDMapping {
private Timestamp lastModDate;

@Transient
private Boolean isNewAbha;
private boolean isNewAbha;

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public interface BenHealthIDMappingRepo extends CrudRepository<BenHealthIDMappin
Integer updateFacilityIdForVisit(@Param("visitCode") BigInteger visitCode, @Param("abdmFacilityId") String abdmFacilityId);

@Query(value = "select isNewAbha from t_healthid where HealthIdNumber=:healthIdNumber order by 1 desc limit 1", nativeQuery = true)
Boolean getIsNewAbha(@Param("healthIdNumber") String healthIdNumber);
boolean getIsNewAbha(@Param("healthIdNumber") String healthIdNumber);

}
@Query(value = "SELECT HealthIdNumber, isNewAbha FROM t_healthid WHERE HealthIdNumber IN :healthIdNumbers ORDER BY HealthIdNumber, isNewAbha DESC", nativeQuery = true)
List<Object[]> getIsNewAbhaBatch(@Param("healthIdNumbers") List<String> healthIdNumbers);


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -115,24 +117,33 @@ public String mapHealthIDToBeneficiary(String request) throws FHIRException {
}

public String getBenHealthID(Long benRegID) {
Map<String, Object> resMap = new HashMap<>();
List<BenHealthIDMapping> healthDetailsList = benHealthIDMappingRepo.getHealthDetails(benRegID);

ArrayList<BenHealthIDMapping> healthDetailsList = benHealthIDMappingRepo.getHealthDetails(benRegID);
ArrayList<BenHealthIDMapping> healthDetailsWithAbhaList = new ArrayList<>();

if(healthDetailsList.size() > 0) {
for(BenHealthIDMapping healthDetails: healthDetailsList) {
String healthIdNumber = healthDetails.getHealthIdNumber();
Boolean isNewAbha = benHealthIDMappingRepo.getIsNewAbha(healthIdNumber);
healthDetails.setIsNewAbha(isNewAbha);

healthDetailsWithAbhaList.add(healthDetails);
}
List<String> healthIdNumbers = healthDetailsList.stream()
.map(BenHealthIDMapping::getHealthIdNumber)
.filter(Objects::nonNull)
.collect(Collectors.toList());

Map<String, Boolean> abhaMap = new HashMap<>();
if (!healthIdNumbers.isEmpty()) {
List<Object[]> abhaResults = benHealthIDMappingRepo.getIsNewAbhaBatch(healthIdNumbers);
for (Object[] row : abhaResults) {
String healthIdNumber = (String) row[0];
Boolean isNewAbha = (Boolean) row[1];
abhaMap.put(healthIdNumber, isNewAbha);
}
}

for (BenHealthIDMapping healthDetails : healthDetailsList) {
Boolean isNew = abhaMap.get(healthDetails.getHealthIdNumber());
healthDetails.setNewAbha(Boolean.TRUE.equals(isNew));
}
resMap.put("BenHealthDetails", new Gson().toJson(healthDetailsWithAbhaList));

return resMap.toString();
}
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("BenHealthDetails", healthDetailsList);

return new Gson().toJson(responseMap);
}

@Override
public String addRecordToHealthIdTable(String request) throws FHIRException {
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

spring.datasource.tomcat.initial-size=5
spring.datasource.tomcat.max-active=30
spring.datasource.tomcat.max-idle=5
Expand All @@ -15,13 +14,15 @@ spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.Ph
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jackson.serialization.fail-on-empty-beans=false

# Add these under your existing jackson property
spring.jackson.default-property-inclusion=NON_NULL
spring.jackson.deserialization.fail-on-unknown-properties=false
spring.jackson.serialization.write-dates-as-timestamps=true
spring.jackson.parser.allow-unquoted-field-names=true
spring.jackson.parser.allow-single-quotes=true
spring.jpa.hibernate.ddl-auto=none

spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.format_sql=true

Expand Down Expand Up @@ -68,3 +69,9 @@ logging.level.com.iemr.ecd=INFO
logging.level.web=INFO
logging.level.org.springframework.web=INFO
logging.level.org.hibernate=INFO

#If both properties are set, only logging.file.name takes effect.
logging.path=logs/
logging.file.name=logs/fhir-api.log


Loading