Skip to content

Commit

Permalink
Few Modified changes for ABDM Facility (#58)
Browse files Browse the repository at this point in the history
* Modified tnxId keyword to txnId

* Abha-address search API changes

* added validation for multiple phraddress

* Abha-address search response changes

* Save facility id variable change chnages

* Added check to avoid multiple save of single care-context

* removed unused variables

---------

Co-authored-by: KA40094929 <KA40094929@APL-5CD1394ZJT>
Co-authored-by: Karyamsetty Helen Grace <[email protected]>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 617c316 commit 03e6ac4
Showing 1 changed file with 49 additions and 73 deletions.
122 changes: 49 additions & 73 deletions src/main/java/com/wipro/fhir/service/common/CommonServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -59,7 +58,6 @@
import com.wipro.fhir.data.mongo.care_context.NDHMResponse;
import com.wipro.fhir.data.mongo.care_context.Notification;
import com.wipro.fhir.data.mongo.care_context.PatientCareContexts;
import com.wipro.fhir.data.mongo.care_context.PatientCareContextsStringOBJ;
import com.wipro.fhir.data.mongo.care_context.SMSNotify;
import com.wipro.fhir.data.patient.PatientDemographic;
import com.wipro.fhir.data.patient_data_handler.PatientDemographicModel_NDHM_Patient_Profile;
Expand Down Expand Up @@ -96,17 +94,13 @@ public class CommonServiceImpl implements CommonService {

@Value("${patient-search-page-size}")
private String patient_search_page_size;

@Value("${abhaMode}")
private String abhaMode;

private static String authKey;
private UUID uuid;

//public static String NDHM_AUTH_TOKEN;
//public static Long NDHM_TOKEN_EXP;
//public static String NDHM_OTP_TOKEN;

@Value("${clientID}")
private String clientID;

Expand All @@ -127,7 +121,6 @@ public class CommonServiceImpl implements CommonService {
private APIChannel aPIChannel;
@Autowired
private AMRIT_ResourceMongoRepo aMRIT_ResourceMongoRepo;


@Autowired
private PatientCareContextsMongoRepo patientCareContextsMongoRepo;
Expand All @@ -148,7 +141,7 @@ public class CommonServiceImpl implements CommonService {

@Autowired
private PatientDataGatewayService patientDataGatewayService;

@Autowired
private MongoTemplate mongoTemplate;

Expand All @@ -159,7 +152,7 @@ public class CommonServiceImpl implements CommonService {
private PatientDemographic patientDemographic;
@Autowired
private Common_NDHMService common_NDHMService;

@Autowired
private BenHealthIDMappingRepo benHealthIDMappingRepo;

Expand Down Expand Up @@ -196,10 +189,11 @@ public String processResourceOperation() throws FHIRException {
if (patientDemographicOBJ.getPreferredPhoneNo() != null)
sendAbdmAdvSMS(patientDemographicOBJ.getPreferredPhoneNo());
else
throw new FHIRException("Advertisement sms could not be sent as beneficiary phone no not found");
}
else
throw new FHIRException("Beneficiary not found, benRegId = " +resourceRequestHandler.getBeneficiaryRegID());
throw new FHIRException(
"Advertisement sms could not be sent as beneficiary phone no not found");
} else
throw new FHIRException(
"Beneficiary not found, benRegId = " + resourceRequestHandler.getBeneficiaryRegID());

} catch (Exception e) {
logger.error(e.getMessage());
Expand All @@ -212,7 +206,8 @@ public String processResourceOperation() throws FHIRException {
int j = diagnosticReportRecordBundle.processDiagnosticReportRecordBundle(resourceRequestHandler, p);
// 3. prescription Bundle
int k = prescriptionBundle.processPrescriptionRecordBundle(resourceRequestHandler, p);
logger.info("The value of i: " +i + " The value of j: " + j + " The value of k: " + k );

logger.info("The value of i: " + i + " The value of j: " + j + " The value of k: " + k);

if (i > 0 && j > 0 && k > 0) {

Expand Down Expand Up @@ -290,76 +285,61 @@ public String getUUID() {

// 31-03-2021
// @Override
public int addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForResourceCreation pVisit)
public void addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForResourceCreation pVisit)
throws FHIRException {
int response = 0;

if (pDemo != null && pVisit != null) {

// JsonObject jsnOBJ = new JsonObject();
// JsonParser jsnParser = new JsonParser();
// JsonElement jsnElmnt = jsnParser.parse(requestObj);
// jsnOBJ = jsnElmnt.getAsJsonObject();

PatientCareContextsStringOBJ patientCareContextsStringOBJ = new PatientCareContextsStringOBJ();

// wrong variable name in request obj for benregid, need to correct in main
// request obj first
// Long benID = null;
// Long benRegID = null;
// Long visitCode = null;
//
// if (jsnOBJ.has("beneficiaryID") && jsnOBJ.get("beneficiaryID") != null)
// benRegID = jsnOBJ.get("beneficiaryID").getAsLong();
// if (jsnOBJ.has("visitCode") && jsnOBJ.get("visitCode") != null)
// visitCode = jsnOBJ.get("visitCode").getAsLong();
// String healthID = jsnOBJ.get("healthID").getAsString();
// String healthIDNumber = jsnOBJ.get("healthIdNumber").getAsString();
// String visitCategory = jsnOBJ.get("visitCategory").getAsString();
// String phoneNo;
// String gender;
// String yearOfBirth;
// String name;
// String email;

// get benid
// if (benRegID != null)
// benID = benHealthIDMappingRepo.getBenID(benRegID);

// fetch abdm facility id
logger.info("********t_benvisistData fetch request pvisit data :" , pVisit);
// fetch abdm facility id
logger.info("********t_benvisistData fetch request pvisit data :", pVisit);

List<Object[]> res = benHealthIDMappingRepo.getAbdmFacilityAndlinkedDate(pVisit.getVisitCode());

// check care context record in mongo against beneficiaryID
ArrayList<CareContexts> ccList = new ArrayList<>();

CareContexts cc = new CareContexts();
logger.info("********t_benvisistData fetch response : {}", res);

cc.setReferenceNumber(pVisit.getVisitCode() != null ? pVisit.getVisitCode().toString() : null);
cc.setDisplay(pVisit.getVisitCategory() != null ? pVisit.getVisitCategory().toString() : null);
cc.setDisplay(pVisit.getVisitCategory() != null ? pVisit.getVisitCategory().toString() : null);
Object[] resData = null;
if (res.get(0) != null) {
resData = res.get(0);
cc.setAbdmFacilityId(resData[0] != null ? resData[0].toString() : null );
cc.setCareContextLinkedDate(resData[1] != null ? resData[1].toString() : null);
cc.setAbdmFacilityId(resData[0] != null ? resData[0].toString() : null);
cc.setCareContextLinkedDate(resData[1] != null ? resData[1].toString() : null);
}

logger.info("********data to be saved in mongo :" , cc);
PatientCareContexts pcc;
PatientCareContexts resultSet = null;

logger.info("********data to be saved in mongo :", cc);
PatientCareContexts pcc;

if (pDemo.getBeneficiaryID() != null) {
pcc = patientCareContextsMongoRepo.findByIdentifier(pDemo.getBeneficiaryID().toString());

if (pcc != null && pcc.getIdentifier() != null) {
ccList = pcc.getCareContextsList();
ccList.add(cc);
pcc.setCareContextsList(ccList);
resultSet = patientCareContextsMongoRepo.save(pcc);

// Get the existing careContextsList
if (pcc.getCareContextsList() != null && pcc.getCareContextsList().size() > 0) {
ccList = pcc.getCareContextsList();

// Check if the visitCode is already in the careContextsList
for (CareContexts existingContext : ccList) {
if (existingContext.getReferenceNumber() != null
&& existingContext.getReferenceNumber().equals(pVisit.getVisitCode().toString())) {
logger.info("Visit code already Exisit in Mongo for benId:" + pDemo.getBeneficiaryID().toString() + "and visit code : " + pVisit.getVisitCode() );
return;
}
}
ccList.add(cc);
pcc.setCareContextsList(ccList);
patientCareContextsMongoRepo.save(pcc);
}
// }
// if (pcc != null && pcc.getIdentifier() != null) {
// ccList = pcc.getCareContextsList();
// ccList.add(cc);
// pcc.setCareContextsList(ccList);
// resultSet = patientCareContextsMongoRepo.save(pcc);
//
} else {
pcc = new PatientCareContexts();
pcc.setCaseReferenceNumber(pDemo.getBeneficiaryID().toString());
Expand Down Expand Up @@ -394,15 +374,11 @@ public int addCareContextToMongo(PatientDemographic pDemo, PatientEligibleForRes
ccList.add(cc);
pcc.setCareContextsList(ccList);
// save carecontext back to mongo
resultSet = patientCareContextsMongoRepo.save(pcc);
patientCareContextsMongoRepo.save(pcc);
}

if (resultSet != null && resultSet.get_id() != null)
response = 1;
}

}
return response;
}

@Deprecated
Expand All @@ -424,15 +400,15 @@ public String ndhmUserAuthenticate() throws FHIRException {
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(responseStrLogin);
jsnOBJ = jsnElmnt.getAsJsonObject();
//NDHM_AUTH_TOKEN = "Bearer" + " " + jsnOBJ.get("accessToken").getAsString();
// NDHM_AUTH_TOKEN = "Bearer" + " " + jsnOBJ.get("accessToken").getAsString();
Integer expiry = jsnOBJ.get("expiresIn").getAsInt();
double time = expiry / 60;
Date date = new Date();
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
Calendar ndhmCalendar = Calendar.getInstance();
ndhmCalendar.setTime(sqlDate);
ndhmCalendar.add(Calendar.MINUTE, (int) time);

res = "success";
} else
res = "Error while accessing authenticate API";
Expand Down Expand Up @@ -478,7 +454,7 @@ public List<TempCollection> fetchTempResourceFromMongo(ResourceRequestHandler re
* @author SH20094090
* @return
*
* get the UUID and isoTimestamp for NDMH API's
* get the UUID and isoTimestamp for NDMH API's
*/
@Deprecated
@Override
Expand Down Expand Up @@ -542,7 +518,7 @@ public String getMongoNDHMResponse(String requestID) throws FHIRException {
* @param reqID
* @return
*
* hitting MongoDB
* hitting MongoDB
*/
@Deprecated
NDHMResponse getResponseMongo(String reqID) {
Expand Down Expand Up @@ -629,8 +605,8 @@ public void sendAbdmAdvSMS(String phone) throws FHIRException {
SMSNotify smsNotify = new SMSNotify(obj.getRequestId(), obj.getTimestamp(), notification);
String requestOBJ = new Gson().toJson(smsNotify);
logger.info("NDHM_FHIR Generate Notify SMS request Obj: " + requestOBJ);
if(abhaMode !=null && !(abhaMode.equalsIgnoreCase("abdm") || abhaMode.equalsIgnoreCase("sbx")))
abhaMode="sbx";
if (abhaMode != null && !(abhaMode.equalsIgnoreCase("abdm") || abhaMode.equalsIgnoreCase("sbx")))
abhaMode = "sbx";
HttpHeaders headers = common_NDHMService.getHeaders(ndhmAuthToken, abhaMode);
ResponseEntity<String> responseEntity = httpUtils.postWithResponseEntity(generateABDM_NotifySMS, requestOBJ,
headers);
Expand Down

0 comments on commit 03e6ac4

Please sign in to comment.