diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/api/KenyaEmrService.java b/api/src/main/java/org/openmrs/module/kenyaemr/api/KenyaEmrService.java index ee5d63f53b..ec356e2d3d 100755 --- a/api/src/main/java/org/openmrs/module/kenyaemr/api/KenyaEmrService.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/api/KenyaEmrService.java @@ -26,7 +26,7 @@ */ @Transactional public interface KenyaEmrService extends OpenmrsService { - + /** * Get if this server has been properly configured * @return whether or not all required settings in the application are configured. @@ -35,7 +35,7 @@ public interface KenyaEmrService extends OpenmrsService { */ @Transactional(readOnly = true) boolean isSetupRequired(); - + /** * Sets the default location for this server, i.e. the value that should be auto-set for new * encounters, visits, etc. @@ -107,4 +107,6 @@ public interface KenyaEmrService extends OpenmrsService { */ @Authorized public List search(String sqlQuery, Map params); -} \ No newline at end of file + + public SimpleObject sendKenyaEmrSms(String recipient, String message); +} diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/api/impl/KenyaEmrServiceImpl.java b/api/src/main/java/org/openmrs/module/kenyaemr/api/impl/KenyaEmrServiceImpl.java index c24db10d81..0ec7dbc357 100755 --- a/api/src/main/java/org/openmrs/module/kenyaemr/api/impl/KenyaEmrServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/api/impl/KenyaEmrServiceImpl.java @@ -11,6 +11,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.json.simple.JSONObject; import org.openmrs.GlobalProperty; import org.openmrs.Location; import org.openmrs.LocationAttributeType; @@ -18,6 +25,7 @@ import org.openmrs.PatientIdentifierType; import org.openmrs.Visit; import org.openmrs.api.APIException; +import org.openmrs.api.AdministrationService; import org.openmrs.api.LocationService; import org.openmrs.api.context.Context; import org.openmrs.api.impl.BaseOpenmrsService; @@ -75,7 +83,7 @@ public class KenyaEmrServiceImpl extends BaseOpenmrsService implements KenyaEmrS public void setKenyaEmrDAO(KenyaEmrDAO dao) { this.dao = dao; } - + /** * @see org.openmrs.module.kenyaemr.api.KenyaEmrService#isSetupRequired() */ @@ -104,7 +112,7 @@ public void setDefaultLocation(Location location) { gp.setValue(location); Context.getAdministrationService().saveGlobalProperty(gp); } - + /** * @see org.openmrs.module.kenyaemr.api.KenyaEmrService#getDefaultLocation() */ @@ -122,7 +130,7 @@ public Location getDefaultLocation() { Context.removeProxyPrivilege(PrivilegeConstants.GET_GLOBAL_PROPERTIES); } } - + /** * @see org.openmrs.module.kenyaemr.api.KenyaEmrService#getDefaultLocationMflCode() */ @@ -302,4 +310,51 @@ private Map conditionallyAddVisitLocation(Map obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, concept); if (obsList.size() > 0) { @@ -3226,8 +3226,8 @@ public Object getLatestObs(@RequestParam("patientUuid") String patientUuid, @Req * @return */ @CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.OPTIONS}) - @RequestMapping(method = RequestMethod.GET, value = "/getSHAPatient/{payload}/{identifier}/{identifierType}") - public ResponseEntity getSHAPatient(@PathVariable String payload, @PathVariable String identifier, @PathVariable String identifierType) { + @RequestMapping(method = RequestMethod.GET, value = "/getSHAPatient/{identifier}/{identifierType}") + public ResponseEntity getSHAPatient( @PathVariable String identifier, @PathVariable String identifierType) { String strUserName = ""; String strPassword = ""; @@ -3248,12 +3248,13 @@ public ResponseEntity getSHAPatient(@PathVariable String payload, @PathV GlobalProperty globalGetPassword = Context.getAdministrationService().getGlobalPropertyObject(CommonMetadata.GP_SHA_CLIENT_VERIFICATION_GET_API_SECRET); strPassword = globalGetPassword.getPropertyValue(); // Prepare URL - String completeURL = baseURL + "/" + payload + "/" + identifier + "/" + identifierType; + String completeURL = baseURL + "?" + identifierType + "=" + identifier; System.out.println("SHA Client registry verification: Using SHA GET URL: " + completeURL); URL url = new URL(completeURL); // Set up connection String auth = strUserName + ":" + strPassword; + System.out.printf("Auth credentials"+auth); String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); @@ -3337,4 +3338,9 @@ public ResponseEntity getSHAPractitioner(@PathVariable String registrati return ResponseEntity.badRequest().contentType(MediaType.APPLICATION_JSON).body(errorResponse); } + @RequestMapping(method = RequestMethod.POST, value = "/send-kenyaemr-sms") + public Object sendKenyaEmrSms(@RequestParam("message") String message, @RequestParam("phone") String phone) { + return Context.getService(KenyaEmrService.class).sendKenyaEmrSms(phone, message); + } + } diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index f53675effd..9f83ed6c3d 100755 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -204,6 +204,34 @@ Location based patient filter. To enable, set value to false + + kenyaemr.sms.url + https://api.africastalking.com/version1/messaging + + The URL of the SMS gateway + + + + kenyaemr.sms.apiToken + test-api-token + + The API token of the SMS gateway + + + + kenyaemr.sms.senderId + HMIS-SMS + + The sender ID of the SMS gateway + + + + kenyaemr.sms.gateway + test-gateway + + The gateway of the SMS gateway + + kenyaemr.billing.exemptions