Skip to content

Commit

Permalink
Add sql rest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwanganto committed Mar 13, 2024
1 parent bc9c7b9 commit cab6260
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ private Map<String, String[]> conditionallyAddVisitLocation(Map<String, String[]
Map<String, String[]> updatedParams = new HashMap<String, String[]>(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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "\\$\\{[^{]*\\}";
Expand All @@ -35,7 +38,7 @@ public SqlQueryHelper() {
}

List<String> getParamNamesFromPlaceHolders(String query){
List<String> params = new ArrayList<>();
List<String> params = new ArrayList<String>();
Matcher matcher = paramPlaceHolderPattern.matcher(query);
while(matcher.find()){
params.add(stripDelimiters(matcher.group()));
Expand All @@ -60,7 +63,7 @@ public PreparedStatement constructPreparedStatement(String queryString, Map<Stri
List<String> 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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<org.openmrs.module.webservices.rest.SimpleObject> search(@RequestParam("q") String query, HttpServletRequest request) throws Exception {
return Context.getService(KenyaEmrService.class).search(query, request.getParameterMap());
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.6</target>
<source>1.6</source>
<target>1.8</target>
<source>1.8</source>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit cab6260

Please sign in to comment.