From ffbe0c03c566a1e791dbd29f6305967332211537 Mon Sep 17 00:00:00 2001 From: Karyamsetty Helen Grace Date: Wed, 21 Jun 2023 13:16:18 +0530 Subject: [PATCH] 1097 refferal sms changes --- src/main/environment/common_dev.properties | 13 ++ src/main/environment/common_local.properties | 14 ++ src/main/environment/common_test.properties | 13 +- .../com/iemr/common/data/sms/SMSTemplate.java | 2 + .../common/model/sms/SmsAPIRequestModel.java | 26 +++ .../repository/sms/SMSTemplateRepository.java | 4 + .../common/service/sms/SMSServiceImpl.java | 207 ++++++++++++------ src/main/resources/application.properties | 16 +- 8 files changed, 228 insertions(+), 67 deletions(-) create mode 100644 src/main/java/com/iemr/common/model/sms/SmsAPIRequestModel.java diff --git a/src/main/environment/common_dev.properties b/src/main/environment/common_dev.properties index dd232803..d2ac0620 100644 --- a/src/main/environment/common_dev.properties +++ b/src/main/environment/common_dev.properties @@ -81,3 +81,16 @@ callRetryConfiguration=3 #avni registration Duration avniRegistrationLimit=7 + +### SMS Gateway URL details +#sms-gateway-url=http://sms.smsjosh.com +sms-username=PIRAMAL_SW_AHxoyCXejeJba13oKHcv +sms-password=]Kt9GAp8}$S*@ +#send-message-url=api/mt/SendSMS?user=USERNAME&password=PASSWORD&senderid=iAMRIT&channel=Trans&DCS=0&flashsms=0&number=91RECEIVER_NUMBER&text=SMS_TEXT&route=9 +send-message-url=https://openapi.airtel.in/gateway/airtel-iq-sms-utility/sendSingleSms +#sms-sender-number=DOCTOR +source-address=AIDSHL +sms-message-type=SERVICE_EXPLICIT +sms-entityid=1201161708885589464 + + diff --git a/src/main/environment/common_local.properties b/src/main/environment/common_local.properties index 8f19692b..4429e05c 100644 --- a/src/main/environment/common_local.properties +++ b/src/main/environment/common_local.properties @@ -39,3 +39,17 @@ spring.redis.host=localhost #snomedcti snomedCTPageSize=10 ##missing commits + + +### SMS Gateway URL details +#sms-gateway-url=http://sms.smsjosh.com +sms-username=PIRAMAL_SW_AHxoyCXejeJba13oKHcv +sms-password=]Kt9GAp8}$S*@ +#send-message-url=api/mt/SendSMS?user=USERNAME&password=PASSWORD&senderid=iAMRIT&channel=Trans&DCS=0&flashsms=0&number=91RECEIVER_NUMBER&text=SMS_TEXT&route=9 +send-message-url=https://openapi.airtel.in/gateway/airtel-iq-sms-utility/sendSingleSms +#sms-sender-number=DOCTOR +source-address=AIDSHL +sms-message-type=SERVICE_EXPLICIT +sms-entityid=1201161708885589464 + + diff --git a/src/main/environment/common_test.properties b/src/main/environment/common_test.properties index f089c3fb..60c05ebe 100644 --- a/src/main/environment/common_test.properties +++ b/src/main/environment/common_test.properties @@ -75,7 +75,7 @@ get-agent-summary-report-job=2 hour get-details-call-report-job=2 hour ##-------------------------------------------------### Redis IP-------------------------------------------------------------- -spring.redis.host=localhost +spring.redis.host=localhosts ##--------------------------------------------------------------------------------------------------------------- ###CTI data sync schedular @@ -99,6 +99,17 @@ callRetryConfiguration=3 #avni registration Duration avniRegistrationLimit=7 +### SMS Gateway URL details +#sms-gateway-url=http://sms.smsjosh.com +sms-username=PIRAMAL_SW_AHxoyCXejeJba13oKHcv +sms-password=]Kt9GAp8}$S*@ +#send-message-url=api/mt/SendSMS?user=USERNAME&password=PASSWORD&senderid=iAMRIT&channel=Trans&DCS=0&flashsms=0&number=91RECEIVER_NUMBER&text=SMS_TEXT&route=9 +send-message-url=https://openapi.airtel.in/gateway/airtel-iq-sms-utility/sendSingleSms +#sms-sender-number=DOCTOR +source-address=AIDSHL +sms-message-type=SERVICE_EXPLICIT +sms-entityid=1201161708885589464 + diff --git a/src/main/java/com/iemr/common/data/sms/SMSTemplate.java b/src/main/java/com/iemr/common/data/sms/SMSTemplate.java index 4e1671cf..9413cfe5 100644 --- a/src/main/java/com/iemr/common/data/sms/SMSTemplate.java +++ b/src/main/java/com/iemr/common/data/sms/SMSTemplate.java @@ -34,6 +34,8 @@ public class SMSTemplate String smsTemplateName; @Column(name = "SMSTemplate") String smsTemplate; + @Column(name = "dltTemplateId") + String dltTemplateId; @Column(name = "SMSSenderName") String smsSenderID; @Column(name = "SMSTypeID") diff --git a/src/main/java/com/iemr/common/model/sms/SmsAPIRequestModel.java b/src/main/java/com/iemr/common/model/sms/SmsAPIRequestModel.java new file mode 100644 index 00000000..3737ca4a --- /dev/null +++ b/src/main/java/com/iemr/common/model/sms/SmsAPIRequestModel.java @@ -0,0 +1,26 @@ +package com.iemr.common.model.sms; + +public class SmsAPIRequestModel { + + private String customerId; + private StringBuffer destinationAddress; + private String message; + private String sourceAddress; + private String messageType; + private String dltTemplateId; + private String entityId; + + + public SmsAPIRequestModel(String customerId, StringBuffer destinationAddress, String message, + String sourceAddress, String messageType, String dltTemplateId, String entityId) { + this.customerId = customerId; + this.destinationAddress = destinationAddress; + this.message = message; + this.sourceAddress = sourceAddress; + this.messageType = messageType; + this.dltTemplateId = dltTemplateId; + this.entityId = entityId; + } + + +} diff --git a/src/main/java/com/iemr/common/repository/sms/SMSTemplateRepository.java b/src/main/java/com/iemr/common/repository/sms/SMSTemplateRepository.java index dc563d48..af1889e1 100644 --- a/src/main/java/com/iemr/common/repository/sms/SMSTemplateRepository.java +++ b/src/main/java/com/iemr/common/repository/sms/SMSTemplateRepository.java @@ -34,4 +34,8 @@ public List getSMSTemplateByProviderServiceMapIDAndSMSTypeID( @Modifying @Query("update SMSTemplate set deleted = :deleted where smsTemplateID = :smsTemplateID") public int updateSMSTemplate(@Param("smsTemplateID") Integer smsTemplateID, @Param("deleted") Boolean deleted); + + @Query("select smsTemplate.dltTemplateId from SMSTemplate smsTemplate where smsTemplate.smsTemplateID = :smsTemplateID and smsTemplate.deleted <> true") + public String findDLTTemplateID(@Param("smsTemplateID") Integer smsTemplateID ); + } diff --git a/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java b/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java index 3b7400d5..730196fb 100644 --- a/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java +++ b/src/main/java/com/iemr/common/service/sms/SMSServiceImpl.java @@ -19,9 +19,14 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; import com.iemr.common.data.feedback.FeedbackDetails; import com.iemr.common.data.feedback.FeedbackRequest; @@ -57,6 +62,7 @@ import com.iemr.common.model.sms.SMSRequest; import com.iemr.common.model.sms.SMSTemplateResponse; import com.iemr.common.model.sms.SMSTypeModel; +import com.iemr.common.model.sms.SmsAPIRequestModel; import com.iemr.common.model.sms.UpdateSMSRequest; import com.iemr.common.repository.callhandling.TCRequestModelRepo; import com.iemr.common.repository.feedback.FeedbackRepository; @@ -610,7 +616,7 @@ private SMSNotification prepareSMS( variableValue = getFeedbackData(className, methodName, request, authToken); break; case "Prescription": - variableValue = getPrescriptionData(className, methodName, request); + variableValue = getPrescriptionData(className, methodName, request, beneficiary); break; case "Blood on Call": variableValue = getBloodOnCallData(className, methodName, request, beneficiary); @@ -871,21 +877,25 @@ private String getInstituteData(String className, String methodName, SMSRequest return variableValue.trim(); } + @Async @Override public void publishSMS() { + RestTemplate restTemplateLogin = new RestTemplate(); if (!SMSServiceImpl.publishingSMS) { try { - SMSServiceImpl.publishingSMS = true; Boolean doSendSMS = ConfigProperties.getBoolean("send-sms"); String sendSMSURL = ConfigProperties.getPropertyByName("send-message-url"); - String sendSMSAPI = SMSServiceImpl.SMS_GATEWAY_URL + "/" + sendSMSURL; - String senderName = cryptoUtil.decrypt(ConfigProperties.getPropertyByName("sms-username")); - String senderPassword = cryptoUtil.decrypt(ConfigProperties.getPropertyByName("sms-password")); - String senderNumber = ConfigProperties.getPropertyByName("sms-sender-number"); - sendSMSAPI = sendSMSAPI.replace("USERNAME", senderName).replace("PASSWORD", senderPassword) - .replace("SENDER_NUMBER", senderNumber); +// String sendSMSAPI = SMSServiceImpl.SMS_GATEWAY_URL + "/" + sendSMSURL; + String senderName = ConfigProperties.getPropertyByName("sms-username"); + String senderPassword = ConfigProperties.getPropertyByName("sms-password"); +// String senderNumber = ConfigProperties.getPropertyByName("sms-sender-number"); + String sourceAddress = ConfigProperties.getPropertyByName("source-address"); + String smsMessageType = ConfigProperties.getPropertyByName("sms-message-type"); + String smsEntityID = ConfigProperties.getPropertyByName("sms-entityid"); +// sendSMSAPI = sendSMSAPI.replace("USERNAME", senderName).replace("PASSWORD", senderPassword) +// .replace("SENDER_NUMBER", senderNumber); java.util.Date date = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(date.getTime()); String text = sqlDate.toString(); @@ -900,69 +910,116 @@ public void publishSMS() { StringBuffer phoneNo = new StringBuffer(); for (SMSNotification sms : smsNotificationsToSend) { - String smsPublishURL = sendSMSAPI; +// String smsPublishURL = sendSMSAPI; try { - // smsPublishURL = smsPublishURL.replace("SMS_TEXT", - // URLEncoder.encode(sms.getSms(), "UTF-8")) - if (sms.getPhoneNo() != null && sms.getPhoneNo().length() > 10) phoneNo = new StringBuffer(sms.getPhoneNo().substring(sms.getPhoneNo().length() - 10)); else phoneNo = new StringBuffer(sms.getPhoneNo()); + + //for fetching dltTemplateId + String dltTemplateId = smsTemplateRepository.findDLTTemplateID(sms.getSmsTemplateID()); + + SmsAPIRequestModel smsAPICredentials104 = new SmsAPIRequestModel(senderName, phoneNo, + sms.getSms(), sourceAddress, dltTemplateId, smsMessageType, smsEntityID ); + + MultiValueMap headersLogin = new LinkedMultiValueMap(); + headersLogin.add("Content-Type", "application/json"); + headersLogin.add("AUTHORIZATION", senderName + ":" + senderPassword ); + // smsPublishURL = smsPublishURL.replace("SMS_TEXT", + // URLEncoder.encode(sms.getSms(), "UTF-8")) + + logger.info("SMS API login request OBj " + smsAPICredentials104.toString()); - smsPublishURL = smsPublishURL.replace("SMS_TEXT", sms.getSms()).replace("RECEIVER_NUMBER", - phoneNo); sms.setSmsStatus(SMSNotification.IN_PROGRESS); sms = smsNotification.save(sms); -// logger.info("Calling API to send SMS " + smsPublishURL); - ResponseEntity response = httpUtils.getV1(smsPublishURL); - if (response.getStatusCodeValue() == 200) { - String smsResponse = response.getBody(); + + HttpEntity requestLogin = new HttpEntity(smsAPICredentials104, headersLogin); + ResponseEntity responseLogin = restTemplateLogin.exchange(sendSMSURL, + HttpMethod.POST, requestLogin, String.class); + if (responseLogin.getStatusCodeValue() == 200 & responseLogin.hasBody()) { + String smsResponse = responseLogin.getBody(); JSONObject obj = new JSONObject(smsResponse); - String jobID = obj.getString("JobId"); - switch (smsResponse) { - case "0x200 - Invalid Username or Password": - case "0x201 - Account suspended due to one of several defined reasons": - case "0x202 - Invalid Source Address/Sender ID. As per GSM standard, the sender ID should " - + "be within 11 characters": - case "0x203 - Message length exceeded (more than 160 characters) if concat is set to 0": - case "0x204 - Message length exceeded (more than 459 characters) in concat is set to 1": - case "0x205 - DRL URL is not set": - case "0x206 - Only the subscribed service type can be accessed – " - + "make sure of the service type you are trying to connect with": - case "0x207 - Invalid Source IP – kindly check if the IP is responding": - case "0x208 - Account deactivated/expired": - case "0x209 - Invalid message length (less than 160 characters) if concat is set to 1": - case "0x210 - Invalid Parameter values": - case "0x211 - Invalid Message Length (more than 280 characters)": - case "0x212 - Invalid Message Length": - case "0x213 - Invalid Destination Number": - throw new Exception(smsResponse); - default: -// logger.info("SMS Sent successfully by calling API " + smsPublishURL); - sms.setTransactionError(null); - sms.setTransactionID(jobID); - sms.setIsTransactionError(false); - sms.setSmsSentDate(new Timestamp(Calendar.getInstance().getTime().getTime())); - sms.setSmsStatus(SMSNotification.SENT); - sms = smsNotification.save(sms); - break; - } + String messageRequestId = obj.getString("MessageRequestId"); +// logger.info("SMS Sent successfully by calling API " + smsPublishURL); + sms.setTransactionError(null); + sms.setTransactionID(messageRequestId); + sms.setIsTransactionError(false); + sms.setSmsSentDate(new Timestamp(Calendar.getInstance().getTime().getTime())); + sms.setSmsStatus(SMSNotification.SENT); + sms = smsNotification.save(sms); } else { - throw new Exception(response.getStatusCodeValue() + " and error " - + response.getStatusCode().toString()); - } - } catch (Exception e) { - logger.error("Failed to send sms on phone no/benRegID: " + sms.getPhoneNo() + "/" - + sms.getBeneficiaryRegID() + " with error " + e.getMessage(), e); - sms.setTransactionError(e.getMessage()); - sms.setIsTransactionError(true); - sms.setTransactionID(null); - sms.setSmsStatus(SMSNotification.NOT_SENT); - sms = smsNotification.save(sms); + throw new Exception(responseLogin.getStatusCodeValue() + " and error " + + responseLogin.getStatusCode().toString()); } + } catch (Exception e) { + logger.error("Failed to send sms on phone no/benRegID: " + sms.getPhoneNo() + "/" + + sms.getBeneficiaryRegID() + " with error " + e.getMessage(), e); + sms.setTransactionError(e.getMessage()); + sms.setIsTransactionError(true); + sms.setTransactionID(null); + sms.setSmsStatus(SMSNotification.NOT_SENT); + sms = smsNotification.save(sms); + } + +// if (sms.getPhoneNo() != null && sms.getPhoneNo().length() > 10) +// phoneNo = new StringBuffer(sms.getPhoneNo().substring(sms.getPhoneNo().length() - 10)); +// else +// phoneNo = new StringBuffer(sms.getPhoneNo()); + +// smsPublishURL = smsPublishURL.replace("SMS_TEXT", sms.getSms()).replace("RECEIVER_NUMBER", +// phoneNo); +// sms.setSmsStatus(SMSNotification.IN_PROGRESS); +// sms = smsNotification.save(sms); +// logger.info("Calling API to send SMS " + smsPublishURL); +// ResponseEntity response = httpUtils.getV1(smsPublishURL); +// if (response.getStatusCodeValue() == 200) { +// String smsResponse = response.getBody(); +// JSONObject obj = new JSONObject(smsResponse); +// String jobID = obj.getString("JobId"); +// switch (smsResponse) { +// case "0x200 - Invalid Username or Password": +// case "0x201 - Account suspended due to one of several defined reasons": +// case "0x202 - Invalid Source Address/Sender ID. As per GSM standard, the sender ID should " +// + "be within 11 characters": +// case "0x203 - Message length exceeded (more than 160 characters) if concat is set to 0": +// case "0x204 - Message length exceeded (more than 459 characters) in concat is set to 1": +// case "0x205 - DRL URL is not set": +// case "0x206 - Only the subscribed service type can be accessed – " +// + "make sure of the service type you are trying to connect with": +// case "0x207 - Invalid Source IP – kindly check if the IP is responding": +// case "0x208 - Account deactivated/expired": +// case "0x209 - Invalid message length (less than 160 characters) if concat is set to 1": +// case "0x210 - Invalid Parameter values": +// case "0x211 - Invalid Message Length (more than 280 characters)": +// case "0x212 - Invalid Message Length": +// case "0x213 - Invalid Destination Number": +// throw new Exception(smsResponse); +// default: +//// logger.info("SMS Sent successfully by calling API " + smsPublishURL); +// sms.setTransactionError(null); +// sms.setTransactionID(jobID); +// sms.setIsTransactionError(false); +// sms.setSmsSentDate(new Timestamp(Calendar.getInstance().getTime().getTime())); +// sms.setSmsStatus(SMSNotification.SENT); +// sms = smsNotification.save(sms); +// break; +// } +// } else { +// throw new Exception(response.getStatusCodeValue() + " and error " +// + response.getStatusCode().toString()); +// } +// } catch (Exception e) { +// logger.error("Failed to send sms on phone no/benRegID: " + sms.getPhoneNo() + "/" +// + sms.getBeneficiaryRegID() + " with error " + e.getMessage(), e); +// sms.setTransactionError(e.getMessage()); +// sms.setIsTransactionError(true); +// sms.setTransactionID(null); +// sms.setSmsStatus(SMSNotification.NOT_SENT); +// sms = smsNotification.save(sms); +// } } } catch (Exception e) { @@ -981,12 +1038,25 @@ public String getFullSMSTemplate(SMSRequest smsRequest) throws Exception { return OutputMapper.gsonWithoutExposeRestriction().toJson(smsTemplateResponse); } - private String getPrescriptionData(String className, String methodName, SMSRequest request) + + private String getPrescriptionData(String className, String methodName, SMSRequest request, + BeneficiaryModel beneficiary) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { PrescribedDrug prescribedDrug = prescribedDrugRepository.findOne(request.getPrescribedDrugID()); String variableValue = ""; switch (methodName.toLowerCase()) { + case "name": + String fname = beneficiary.getFirstName() != null ? beneficiary.getFirstName() + " " : ""; + String mname = beneficiary.getMiddleName() != null ? beneficiary.getMiddleName() + " " : ""; + String lname = beneficiary.getLastName() != null ? beneficiary.getLastName() + " " : ""; + variableValue = fname + mname + lname; + break; + case "callerid": + String beneficiaryID = beneficiary.getBeneficiaryID() != null + ? beneficiary.getBeneficiaryID() + " " : ""; + variableValue = beneficiaryID; + break; case "prescriptionid": String prescriptionid = prescribedDrug.getPrescriptionID() != null ? prescribedDrug.getPrescriptionID() + " " @@ -1009,13 +1079,23 @@ private String getPrescriptionData(String className, String methodName, SMSReque String dosage = prescribedDrug.getDosage() != null ? prescribedDrug.getDosage() + " " : ""; variableValue = dosage; break; - case "dosageinstruction": +// case "dosageinstruction": +// String drugForm = prescribedDrug.getM_104drugmapping().getRemarks() != null +// ? prescribedDrug.getM_104drugmapping().getRemarks() + " " +// : ""; +// variableValue = drugForm; +// break; + case "usage": String drugForm = prescribedDrug.getM_104drugmapping().getRemarks() != null ? prescribedDrug.getM_104drugmapping().getRemarks() + " " : ""; variableValue = drugForm; break; - case "frequency": +// case "frequency": +// String frequency = prescribedDrug.getFrequency() != null ? prescribedDrug.getFrequency() + " " : ""; +// variableValue = frequency; +// break; + case "timeToConsume": String frequency = prescribedDrug.getFrequency() != null ? prescribedDrug.getFrequency() + " " : ""; variableValue = frequency; break; @@ -1023,12 +1103,17 @@ private String getPrescriptionData(String className, String methodName, SMSReque String quantity = prescribedDrug.getNoOfDays() != null ? prescribedDrug.getNoOfDays() + " " : ""; variableValue = quantity; break; + case "by": + String createdBy = prescribedDrug.getCreatedBy() != null ? prescribedDrug.getCreatedBy() + " " : ""; + variableValue = createdBy; + break; default: break; } return variableValue; } + private String getBloodOnCallData(String className, String methodName, SMSRequest request, BeneficiaryModel beneficiary) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8e026dfc..475987ed 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -160,11 +160,16 @@ logging.logback.rollingpolicy.max-file-size=20KB logging.logback.rollingpolicy.max-history=1 ### SMS Gateway URL details -sms-gateway-url=http://sms.smsjosh.com -sms-username=cQXj/cvwruBg24NQd8Bv0/Ba0w8VGs/1usuW7EsGF3k= -sms-password=5o4ctqHfM1DNYxG3+WNYVvBa0w8VGs/1usuW7EsGF3k= -send-message-url=api/mt/SendSMS?user=USERNAME&password=PASSWORD&senderid=iAMRIT&channel=Trans&DCS=0&flashsms=0&number=91RECEIVER_NUMBER&text=SMS_TEXT&route=9 -sms-sender-number=DOCTOR +#sms-gateway-url=http://sms.smsjosh.com +sms-username=PIRAMAL_SW_AHxoyCXejeJba13oKHcv +sms-password=]Kt9GAp8}$S*@ +#send-message-url=api/mt/SendSMS?user=USERNAME&password=PASSWORD&senderid=iAMRIT&channel=Trans&DCS=0&flashsms=0&number=91RECEIVER_NUMBER&text=SMS_TEXT&route=9 +send-message-url=https://openapi.airtel.in/gateway/airtel-iq-sms-utility/sendSingleSms +#sms-sender-number=DOCTOR +source-address=AIDSHL +sms-message-type=SERVICE_EXPLICIT +sms-entityid=1201161708885589464 + ### Email Gateway URL details email-gateway-url=https://api.unicel.in @@ -332,3 +337,4 @@ avniRegistrationLimit=7 +