From cab6260867def885595a6096c82b7a6fa6b2c650 Mon Sep 17 00:00:00 2001 From: ojwanganto Date: Wed, 13 Mar 2024 13:08:05 +0300 Subject: [PATCH] Add sql rest endpoint --- .../module/kenyaemr/api/impl/KenyaEmrServiceImpl.java | 5 ++--- .../org/openmrs/module/kenyaemr/util/SqlQueryHelper.java | 7 +++++-- .../web/controller/KenyaemrCoreRestController.java | 2 +- pom.xml | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) 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 3be5083323..c24db10d81 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 @@ -297,9 +297,8 @@ private Map conditionallyAddVisitLocation(Map updatedParams = new HashMap(params); if (params.containsKey("location_uuid")) { String locationUuid = params.get("location_uuid")[0]; - String visitLocation = ""; - String[] visitLcoationValue = {visitLocation}; - updatedParams.put("visit_location_uuid", visitLcoationValue); + String[] visitLocationValue = {locationUuid}; + updatedParams.put("visit_location_uuid", visitLocationValue); } return updatedParams; } diff --git a/api/src/main/java/org/openmrs/module/kenyaemr/util/SqlQueryHelper.java b/api/src/main/java/org/openmrs/module/kenyaemr/util/SqlQueryHelper.java index bec4a635ba..b45c1b6346 100644 --- a/api/src/main/java/org/openmrs/module/kenyaemr/util/SqlQueryHelper.java +++ b/api/src/main/java/org/openmrs/module/kenyaemr/util/SqlQueryHelper.java @@ -25,6 +25,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Handler for raw SQL + */ public class SqlQueryHelper { private final Pattern paramPlaceHolderPattern; private static final String PARAM_PLACE_HOLDER_REGEX = "\\$\\{[^{]*\\}"; @@ -35,7 +38,7 @@ public SqlQueryHelper() { } List getParamNamesFromPlaceHolders(String query){ - List params = new ArrayList<>(); + List params = new ArrayList(); Matcher matcher = paramPlaceHolderPattern.matcher(query); while(matcher.find()){ params.add(stripDelimiters(matcher.group())); @@ -60,7 +63,7 @@ public PreparedStatement constructPreparedStatement(String queryString, Map paramNamesFromPlaceHolders = getParamNamesFromPlaceHolders(finalQueryString); String statement = transformIntoPreparedStatementFormat(finalQueryString); PreparedStatement preparedStatement = conn.prepareStatement(statement); - if(params != null ){ + if(params != null && params.size() > 0 ){ int i=1; for (String paramName : paramNamesFromPlaceHolders) { String paramValue = params.get(paramName)[0]; diff --git a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java index 816841e9ff..6a9a1119c1 100644 --- a/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java +++ b/omod/src/main/java/org/openmrs/module/kenyaemr/web/controller/KenyaemrCoreRestController.java @@ -2674,7 +2674,7 @@ private String mapConceptNamesToShortNames(String conceptUuid) { * @return * @throws Exception */ - @RequestMapping(method = RequestMethod.GET, value = "/sql") // gets all flags for a patient + @RequestMapping(method = RequestMethod.GET, value = "/sql") @ResponseBody public List search(@RequestParam("q") String query, HttpServletRequest request) throws Exception { return Context.getService(KenyaEmrService.class).search(query, request.getParameterMap()); diff --git a/pom.xml b/pom.xml index 3a40ed45ae..f4fdd70b9e 100755 --- a/pom.xml +++ b/pom.xml @@ -381,8 +381,8 @@ org.apache.maven.plugins maven-compiler-plugin - 1.6 - 1.6 + 1.8 + 1.8