diff --git a/src/main/environment/common_ci.properties b/src/main/environment/common_ci.properties index 6bfc4aba..5f9eb8f9 100644 --- a/src/main/environment/common_ci.properties +++ b/src/main/environment/common_ci.properties @@ -73,7 +73,7 @@ generateHealthCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/health/facility/getPngCa generateHealthIDCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/account/getPngCard ## Generate Notify SMS once episode completed -generateABDM_NotifySMS=@env.ABDM_BASE_URL@/gateway/v1/patients/sms/notify2 +generateABDM_NotifySMS=@env.ABDM_HIECM_BASE_URL@/api/hiecm/hip/v3/link/patient/links/sms/notify2 ##verifyBio abdmVerifyBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/verifyBio diff --git a/src/main/environment/common_docker.properties b/src/main/environment/common_docker.properties index ee4b1267..b21d3ae9 100644 --- a/src/main/environment/common_docker.properties +++ b/src/main/environment/common_docker.properties @@ -73,7 +73,8 @@ generateHealthCard=${ABDM_HEALTH_ID_BASE_URL}/api/v1/health/facility/getPngCard generateHealthIDCard=${ABDM_HEALTH_ID_BASE_URL}/api/v1/account/getPngCard ## Generate Notify SMS once episode completed -generateABDM_NotifySMS=${ABDM_BASE_URL}/gateway/v1/patients/sms/notify2 +generateABDM_NotifySMS=${ABDM_HIECM_BASE_URL}/api/hiecm/hip/v3/link/patient/links/sms/notify2 + ##verifyBio abdmVerifyBio=${ABDM_HEALTH_ID_BASE_URL}/api/v1/registration/aadhaar/verifyBio diff --git a/src/main/environment/common_example.properties b/src/main/environment/common_example.properties index e4771265..81c2659a 100644 --- a/src/main/environment/common_example.properties +++ b/src/main/environment/common_example.properties @@ -76,7 +76,7 @@ generateHealthCard=https://healthidsbx.abdm.gov.in/api/v1/health/facility/getPng generateHealthIDCard=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/account/getPngCard ## Generate Notify SMS once episode completed -generateABDM_NotifySMS=https://dev.abdm.gov.in/gateway/v1/patients/sms/notify2 +generateABDM_NotifySMS=@env.ABDM_HIECM_BASE_URL@/api/hiecm/hip/v3/link/patient/links/sms/notify2 ##verifyBio abdmVerifyBio=@env.ABDM_HEALTH_ID_BASE_URL@/api/v1/registration/aadhaar/verifyBio diff --git a/src/main/java/com/wipro/fhir/data/healthID/BenHealthIDMapping.java b/src/main/java/com/wipro/fhir/data/healthID/BenHealthIDMapping.java index 8a0fdef5..5618cf26 100644 --- a/src/main/java/com/wipro/fhir/data/healthID/BenHealthIDMapping.java +++ b/src/main/java/com/wipro/fhir/data/healthID/BenHealthIDMapping.java @@ -78,4 +78,16 @@ public class BenHealthIDMapping { @Transient private boolean isNewAbha; + @Expose + @Transient + private String name; + + @Expose + @Transient + private String gender; + + @Expose + @Transient + private String yearOfBirth; + } diff --git a/src/main/java/com/wipro/fhir/data/v3/careContext/CareContextLinkTokenRequest.java b/src/main/java/com/wipro/fhir/data/v3/careContext/CareContextLinkTokenRequest.java index 83d7b363..b9859d79 100644 --- a/src/main/java/com/wipro/fhir/data/v3/careContext/CareContextLinkTokenRequest.java +++ b/src/main/java/com/wipro/fhir/data/v3/careContext/CareContextLinkTokenRequest.java @@ -9,7 +9,7 @@ public class CareContextLinkTokenRequest { private String abhaAddress; private String name; private String gender; - private int yearOfBirth; + private Integer yearOfBirth; private String abdmFacilityId; } diff --git a/src/main/java/com/wipro/fhir/data/v3/careContext/GenerateCareContextTokenRequest.java b/src/main/java/com/wipro/fhir/data/v3/careContext/GenerateCareContextTokenRequest.java index 6dcac587..4aeb2cf1 100644 --- a/src/main/java/com/wipro/fhir/data/v3/careContext/GenerateCareContextTokenRequest.java +++ b/src/main/java/com/wipro/fhir/data/v3/careContext/GenerateCareContextTokenRequest.java @@ -9,6 +9,6 @@ public class GenerateCareContextTokenRequest { private String abhaAddress; private String name; private String gender; - private int yearOfBirth; + private Integer yearOfBirth; } diff --git a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java index 2ddbc363..0af9866e 100644 --- a/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java @@ -82,6 +82,7 @@ import com.wipro.fhir.service.ndhm.Common_NDHMService; import com.wipro.fhir.service.ndhm.GenerateSession_NDHMService; import com.wipro.fhir.service.patient_data_handler.PatientDataGatewayService; +import com.wipro.fhir.service.v3.abha.GenerateAuthSessionService; import com.wipro.fhir.utils.exception.FHIRException; import com.wipro.fhir.utils.http.HttpUtils; @@ -151,6 +152,10 @@ public class CommonServiceImpl implements CommonService { @Autowired private GenerateSession_NDHMService generateSession_NDHM; + + @Autowired + private GenerateAuthSessionService generateAuthSessionService; + private static int ACCEPTED = 202; @Autowired private PatientDemographic patientDemographic; @@ -232,56 +237,86 @@ public String processResourceOperation() throws FHIRException { // 1. OP consult resource bundle if (p.getVisitCategory().equalsIgnoreCase("General OPD") || p.getVisitCategory().equalsIgnoreCase("General OPD (QC)")) { - int opConsult = oPConsultResourceBundle.processOpConsultRecordBundle(resourceRequestHandler, p); - if (opConsult <= 0) + try { + int opConsult = oPConsultResourceBundle.processOpConsultRecordBundle(resourceRequestHandler, p); + if (opConsult <= 0) + processed = false; + logger.info(" The value of opConsult proceesed: " + processed); + } catch (Exception e) { processed = false; - logger.info(" The value of opConsult proceesed: " + processed); + logger.error("Op Consult FHIR Resource Bundle failed with error - " + e.getMessage()); + } } // 2. diagnostic report record bundle int hasLabTests = careContextRepo.hasLabtestsDone(p.getVisitCode().toString()); if (hasLabTests > 0) { - int diagReport = diagnosticReportResourceBundle - .processDiagnosticReportRecordBundle(resourceRequestHandler, p); - if (diagReport <= 0) + try { + int diagReport = diagnosticReportResourceBundle + .processDiagnosticReportRecordBundle(resourceRequestHandler, p); + if (diagReport <= 0) + processed = false; + logger.info(" The value of diagReport proceesed: " + processed); + } catch (Exception e) { processed = false; - logger.info(" The value of diagReport proceesed: " + processed); + logger.error("Diagnostic Report FHIR Resource Bundle failed with error - " + e.getMessage()); + } } // 3. prescription Bundle int hasPrescription = careContextRepo.hasPrescribedDrugs(p.getVisitCode().toString()); if (hasPrescription > 0) { - int presp = prescriptionResourceBundle.processPrescriptionRecordBundle(resourceRequestHandler, p); - if (presp <= 0) + try { + int presp = prescriptionResourceBundle.processPrescriptionRecordBundle(resourceRequestHandler, p); + if (presp <= 0) + processed = false; + logger.info(" The value of presp proceesed: " + processed); + } catch (Exception e) { processed = false; - logger.info(" The value of presp proceesed: " + processed); + logger.error("Prescription FHIR Resource Bundle failed with error - " + e.getMessage()); + } } // 4. wellness Bundle int hasPhyVitals = careContextRepo.hasPhyVitals(p.getVisitCode().toString()); if (hasPhyVitals > 0) { - int wellness = wellnessRecordResourceBundle.processWellnessRecordBundle(resourceRequestHandler, p); - if (wellness <= 0) + try { + int wellness = wellnessRecordResourceBundle.processWellnessRecordBundle(resourceRequestHandler, p); + if (wellness <= 0) + processed = false; + logger.info(" The value of wellness proceesed: " + processed); + } catch (Exception e) { processed = false; - logger.info(" The value of wellness proceesed: " + processed); + logger.error("Wellness FHIR Resource Bundle failed with error - " + e.getMessage()); + } } // 5. Immunization record int hasVaccineDetails = careContextRepo.hasVaccineDetails(p.getVisitCode().toString()); if (hasVaccineDetails > 0) { - int immunization = immunizationRecordResourceBundle - .processImmunizationRecordBundle(resourceRequestHandler, p); - if (immunization <= 0) + try { + int immunization = immunizationRecordResourceBundle + .processImmunizationRecordBundle(resourceRequestHandler, p); + if (immunization <= 0) + processed = false; + logger.info(" The value of immunization proceesed: " + processed); + } catch (Exception e) { processed = false; - logger.info(" The value of immunization proceesed: " + processed); + logger.error("Immunization FHIR Resource Bundle failed with error - " + e.getMessage()); + } } // 6. Discharge Summary - int dischargeSummary = dischargeSummaryResourceBundle - .processDischargeSummaryRecordBundle(resourceRequestHandler, p); - if (dischargeSummary <= 0) + try { + int dischargeSummary = dischargeSummaryResourceBundle + .processDischargeSummaryRecordBundle(resourceRequestHandler, p); + if (dischargeSummary <= 0) + processed = false; + logger.info(" The value of dischargeSummary proceesed: " + processed); + } catch (Exception e) { processed = false; - logger.info(" The value of dischargeSummary proceesed: " + processed); + logger.error("Discharge Summary FHIR Resource Bundle failed with error - " + e.getMessage()); + } logger.info(" The value of final proceesed: " + processed); @@ -714,7 +749,7 @@ public Page searchPatientProfileFr */ public void sendAbdmAdvSMS(String phone) throws FHIRException { try { - String ndhmAuthToken = generateSession_NDHM.getNDHMAuthToken(); + String ndhmAuthToken = generateAuthSessionService.getAbhaAuthToken(); HIP hip = new HIP("Piramal Swasthya", clientID); NDHMRequest obj = common_NDHMService.getRequestIDAndTimeStamp(); Notification notification = new Notification(phone, hip); diff --git a/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java b/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java index b066fee1..57464c46 100644 --- a/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/facility/FacilityServiceImpl.java @@ -116,9 +116,12 @@ public String saveAbdmFacilityId(String reqObj) throws FHIRException { String res = null; try { SaveFacilityIdForVisit requestObj = InputMapper.gson().fromJson(reqObj, SaveFacilityIdForVisit.class); - if(requestObj.getAbdmFacilityId() == null || requestObj.getAbdmFacilityId() == "") { + if (requestObj.getAbdmFacilityId() == null || requestObj.getAbdmFacilityId().trim().isEmpty()) { requestObj.setAbdmFacilityId(abdmFacilityId); } + if (requestObj.getAbdmFacilityId() == null || requestObj.getAbdmFacilityId().trim().isEmpty()) { + return "ABDM Facility ID is not configured. Please map the facility before proceeding."; + } Integer response = benHealthIDMappingRepo.updateFacilityIdForVisit(requestObj.getVisitCode(), requestObj.getAbdmFacilityId()); if(response > 0 ) { res = "ABDM Facility ID updated successfully"; diff --git a/src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java b/src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java index 39c3ed90..a42de241 100644 --- a/src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/healthID/HealthIDServiceImpl.java @@ -185,6 +185,7 @@ public String getBenHealthID(Long benRegID) { .collect(Collectors.toList()); Map abhaMap = new HashMap<>(); + Map healthIdDetailsMap = new HashMap<>(); if (!healthIdNumbers.isEmpty()) { List abhaResults = benHealthIDMappingRepo.getIsNewAbhaBatch(healthIdNumbers); for (Object[] row : abhaResults) { @@ -192,11 +193,26 @@ public String getBenHealthID(Long benRegID) { Boolean isNewAbha = (Boolean) row[1]; abhaMap.put(healthIdNumber, isNewAbha); } + for (String hIdNumber : healthIdNumbers) { + ArrayList details = healthIDRepo.getHealthIDDetailsUsingHealthNumber(hIdNumber); + if (details != null && !details.isEmpty()) { + healthIdDetailsMap.put(hIdNumber, details.get(0)); + } + } } for (BenHealthIDMapping healthDetails : healthDetailsList) { Boolean isNew = abhaMap.get(healthDetails.getHealthIdNumber()); healthDetails.setNewAbha(Boolean.TRUE.equals(isNew)); + HealthIDResponse hdResponse = healthIdDetailsMap.get(healthDetails.getHealthIdNumber()); + if (hdResponse != null) { + healthDetails.setName(hdResponse.getName()); + healthDetails.setGender(hdResponse.getGender()); + healthDetails.setYearOfBirth(hdResponse.getYearOfBirth()); + if (hdResponse.getHealthId() != null && !hdResponse.getHealthId().isEmpty()) { + healthDetails.setHealthId(hdResponse.getHealthId()); + } + } } Map responseMap = new HashMap<>(); diff --git a/src/main/java/com/wipro/fhir/service/ndhm/LinkCareContext_NDHMServiceImpl.java b/src/main/java/com/wipro/fhir/service/ndhm/LinkCareContext_NDHMServiceImpl.java index f20f0837..022888ca 100644 --- a/src/main/java/com/wipro/fhir/service/ndhm/LinkCareContext_NDHMServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/ndhm/LinkCareContext_NDHMServiceImpl.java @@ -268,19 +268,22 @@ public String addCareContext(String request, String ndhmOTPToken) throws FHIRExc JsonParser jsnParser = new JsonParser(); JsonElement jsnElmnt = jsnParser.parse(addCareContextResponse); jsnOBJ = jsnElmnt.getAsJsonObject(); - try { - if (jsnOBJ.get("Acknowledgement") != null - && jsnOBJ.getAsJsonObject("Acknowledgement").get("Status") != null) - successResponse = jsnOBJ.getAsJsonObject("Acknowledgement").get("Status").getAsString(); - else - throw new FHIRException( - "NDHM_FHIR " + jsnOBJ.getAsJsonObject("Error").get("Message").getAsString()); - } catch (Exception e) { + // v0.5 callback: {"Acknowledgement":{"Status":"SUCCESS"}} + // v3 callback: {"status":"Successfully Linked care context","response":{...}} + if (jsnOBJ.get("Acknowledgement") != null + && jsnOBJ.getAsJsonObject("Acknowledgement").get("Status") != null) { + successResponse = jsnOBJ.getAsJsonObject("Acknowledgement").get("Status").getAsString(); + } else if (jsnOBJ.get("status") != null) { + successResponse = jsnOBJ.get("status").getAsString(); + } else if (jsnOBJ.get("Error") != null + && jsnOBJ.getAsJsonObject("Error").get("Message") != null) { throw new FHIRException( "NDHM_FHIR " + jsnOBJ.getAsJsonObject("Error").get("Message").getAsString()); + } else { + throw new FHIRException("NDHM_FHIR Unexpected care context response: " + addCareContextResponse); } - if (successResponse.equalsIgnoreCase("success")) { + if (successResponse != null && successResponse.toLowerCase().contains("success")) { response = "Care Context added successfully"; } diff --git a/src/main/java/com/wipro/fhir/service/resource_model/DiagnosticReportResource.java b/src/main/java/com/wipro/fhir/service/resource_model/DiagnosticReportResource.java index e3dbbed6..d39f9bc4 100644 --- a/src/main/java/com/wipro/fhir/service/resource_model/DiagnosticReportResource.java +++ b/src/main/java/com/wipro/fhir/service/resource_model/DiagnosticReportResource.java @@ -22,7 +22,6 @@ package com.wipro.fhir.service.resource_model; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -83,53 +82,43 @@ private List generateDiagnosticReportResource(Patient patient, List diagnosticReportList = new ArrayList<>(); - Map testMap = new HashMap(); - - CodeableConcept cc; - Reference observationRef; - List observationListRef; - - for (DiagnosticReportDataModel d : diagnosticList) { - if (d.getProcedureID() != null && testMap != null && !testMap.containsKey(d.getProcedureID())) { - - diagnosticReport = new DiagnosticReport(); - UUID = commonService.getUUID(); - diagnosticReport.setId("DiagnosticReport/" + UUID); - - DateTimeType dtt = new DateTimeType(d.getCreatedDate()); - diagnosticReport.setEffective(dtt); - - diagnosticReport.setStatus(DiagnosticReportStatus.FINAL); - - cc = new CodeableConcept(); - cc.setText(d.getProcedureName()); - - diagnosticReport.setCode(cc); - - // referance - patient - diagnosticReport.setSubject(new Reference(patient.getIdElement().getValue())); - - if (observationMap != null && observationMap.size() > 0) { - List observationList = observationMap.get(d.getProcedureID()); - - if (observationList != null && observationList.size() > 0) { - observationListRef = new ArrayList<>(); - for (Observation o : observationList) { - observationRef = new Reference(o.getIdElement().getValue()); - observationListRef.add(observationRef); - } - - diagnosticReport.setResult(observationListRef); + // Collect all observation references across all procedures into one report. + // Previously one DiagnosticReport was created per procedure, causing the ABHA + // app to render both the DiagnosticReport (name only, no value) and each + // Observation (name + value) — producing duplicate entries when the procedure + // name matched the component name. + List allObservationRefs = new ArrayList<>(); + if (observationMap != null) { + for (List obsList : observationMap.values()) { + if (obsList != null) { + for (Observation o : obsList) { + allObservationRefs.add(new Reference(o.getIdElement().getValue())); } } + } + } + + if (!allObservationRefs.isEmpty()) { + diagnosticReport = new DiagnosticReport(); + UUID = commonService.getUUID(); + diagnosticReport.setId("DiagnosticReport/" + UUID); + diagnosticReport.setStatus(DiagnosticReportStatus.FINAL); - diagnosticReport.setConclusion(""); + CodeableConcept cc = new CodeableConcept(); + cc.setText("Laboratory Report"); + diagnosticReport.setCode(cc); - diagnosticReportList.add(diagnosticReport); + diagnosticReport.setSubject(new Reference(patient.getIdElement().getValue())); - testMap.put(d.getProcedureID(), true); + if (!diagnosticList.isEmpty() && diagnosticList.get(0).getCreatedDate() != null) { + diagnosticReport.setEffective(new DateTimeType(diagnosticList.get(0).getCreatedDate())); } + + diagnosticReport.setResult(allObservationRefs); + diagnosticReport.setConclusion(""); + diagnosticReportList.add(diagnosticReport); } + return diagnosticReportList; } diff --git a/src/main/java/com/wipro/fhir/service/v3/careContext/CareContextLinkingServiceImpl.java b/src/main/java/com/wipro/fhir/service/v3/careContext/CareContextLinkingServiceImpl.java index 40fcb064..6bc21825 100644 --- a/src/main/java/com/wipro/fhir/service/v3/careContext/CareContextLinkingServiceImpl.java +++ b/src/main/java/com/wipro/fhir/service/v3/careContext/CareContextLinkingServiceImpl.java @@ -44,6 +44,8 @@ import com.wipro.fhir.data.v3.careContext.PatientCareContext; import com.wipro.fhir.repo.mongo.generateToken_response.GenerateTokenAbdmResponsesRepo; import com.wipro.fhir.repo.v3.careContext.CareContextRepo; +import com.wipro.fhir.repo.healthID.HealthIDRepo; +import com.wipro.fhir.data.healthID.HealthIDResponse; import com.wipro.fhir.data.v3.careContext.AddCareContextRequest; import com.wipro.fhir.service.ndhm.Common_NDHMService; import com.wipro.fhir.service.v3.abha.GenerateAuthSessionService; @@ -76,7 +78,10 @@ public class CareContextLinkingServiceImpl implements CareContextLinkingService @Autowired private CareContextRepo careContextRepo; - + + @Autowired + private HealthIDRepo healthIDRepo; + private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); @Override @@ -127,11 +132,30 @@ public String generateTokenForCareContext(String request) throws FHIRException { generateTokenRequest.setAbhaAddress(careContextLinkRequest.getAbhaAddress()); generateTokenRequest.setName(careContextLinkRequest.getName()); - generateTokenRequest.setYearOfBirth(careContextLinkRequest.getYearOfBirth()); - if (careContextLinkRequest.getGender().equalsIgnoreCase("female")) { + // Use yearOfBirth from request; fall back to DB lookup if missing/invalid + Integer yearOfBirth = careContextLinkRequest.getYearOfBirth(); + if (yearOfBirth == null || yearOfBirth < 1900 || yearOfBirth > 2200) { + try { + String abhaAddr = careContextLinkRequest.getAbhaAddress(); + if (abhaAddr != null && !abhaAddr.isEmpty()) { + ArrayList hdList = healthIDRepo.getHealthIDDetails(abhaAddr); + if (hdList != null && !hdList.isEmpty() && hdList.get(0).getYearOfBirth() != null) { + yearOfBirth = Integer.parseInt(hdList.get(0).getYearOfBirth()); + } + } + } catch (Exception ex) { + logger.warn("Could not fetch yearOfBirth from DB: " + ex.getMessage()); + } + } + if (yearOfBirth != null && yearOfBirth >= 1900 && yearOfBirth <= 2200) { + generateTokenRequest.setYearOfBirth(yearOfBirth); + } + + String gender = careContextLinkRequest.getGender(); + if ("female".equalsIgnoreCase(gender) || "F".equalsIgnoreCase(gender)) { generateTokenRequest.setGender("F"); - } else if (careContextLinkRequest.getGender().equalsIgnoreCase("male")) { + } else if ("male".equalsIgnoreCase(gender) || "M".equalsIgnoreCase(gender)) { generateTokenRequest.setGender("M"); } else { generateTokenRequest.setGender("O");