-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EA-211: Expose getLocationThatSupportsVisit RESTfully
- Loading branch information
1 parent
8b657bf
commit 53c72da
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...n/java/org/openmrs/module/emrapi/web/controller/LocationThatSupportsVisitsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.openmrs.module.emrapi.web.controller; | ||
|
||
import org.openmrs.Location; | ||
import org.openmrs.module.emrapi.adt.AdtService; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.web.ConversionUtil; | ||
import org.openmrs.module.webservices.rest.web.RequestContext; | ||
import org.openmrs.module.webservices.rest.web.RestUtil; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Controller | ||
public class LocationThatSupportsVisitsController { | ||
|
||
@Autowired | ||
private AdtService adtService; | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/rest/**/emrapi/locationThatSupportsVisits") | ||
@ResponseBody | ||
public SimpleObject getLocationThatSupportsVisits(HttpServletRequest request, | ||
HttpServletResponse response, | ||
@RequestParam(required = true, value = "location") Location location) { | ||
|
||
SimpleObject res = new SimpleObject(); | ||
|
||
RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT); | ||
Location visitLocation = adtService.getLocationThatSupportsVisits(location); | ||
|
||
if (visitLocation != null) { | ||
res = (SimpleObject) ConversionUtil.convertToRepresentation(visitLocation, context.getRepresentation()); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
} |