| 1 |
package org.openmrs.module.restmodule.web; |
|---|
| 2 |
|
|---|
| 3 |
import java.io.IOException; |
|---|
| 4 |
import java.io.PrintWriter; |
|---|
| 5 |
import java.util.List; |
|---|
| 6 |
|
|---|
| 7 |
import javax.servlet.ServletException; |
|---|
| 8 |
import javax.servlet.http.HttpServletRequest; |
|---|
| 9 |
import javax.servlet.http.HttpServletResponse; |
|---|
| 10 |
|
|---|
| 11 |
import org.openmrs.Patient; |
|---|
| 12 |
import org.openmrs.api.context.Context; |
|---|
| 13 |
import org.openmrs.module.restmodule.RestUtil; |
|---|
| 14 |
import org.openmrs.module.restmodule.XmlPatient; |
|---|
| 15 |
|
|---|
| 16 |
/** |
|---|
| 17 |
* Provides RESTful access to the patient search facilities of OpenMRS |
|---|
| 18 |
* |
|---|
| 19 |
* @author Burke Mamlin |
|---|
| 20 |
* @version 1.0 |
|---|
| 21 |
*/ |
|---|
| 22 |
public class FindPatientResource implements RestResource { |
|---|
| 23 |
|
|---|
| 24 |
/** |
|---|
| 25 |
* Handle all requests to this patient search resource |
|---|
| 26 |
*/ |
|---|
| 27 |
public void handleRequest(Operation operation, String restRequest, |
|---|
| 28 |
HttpServletRequest request, HttpServletResponse response) |
|---|
| 29 |
throws ServletException, IOException { |
|---|
| 30 |
|
|---|
| 31 |
PrintWriter out = response.getWriter(); |
|---|
| 32 |
|
|---|
| 33 |
switch (operation) { |
|---|
| 34 |
|
|---|
| 35 |
case GET: |
|---|
| 36 |
List<Patient> patientList = Context.getPatientService() |
|---|
| 37 |
.findPatients(restRequest, false); |
|---|
| 38 |
|
|---|
| 39 |
out.print("<patientList>"); |
|---|
| 40 |
int i = 0; |
|---|
| 41 |
int max = RestUtil.getMaxResults(); |
|---|
| 42 |
for (Patient patient : patientList) { |
|---|
| 43 |
out.print(XmlPatient.encode(patient)); |
|---|
| 44 |
i++; |
|---|
| 45 |
if (max > 0 && i >= max) |
|---|
| 46 |
break; // if max set, abort before exceeding |
|---|
| 47 |
} |
|---|
| 48 |
out.print("</patientList>"); |
|---|
| 49 |
break; |
|---|
| 50 |
|
|---|
| 51 |
case POST: |
|---|
| 52 |
case PUT: |
|---|
| 53 |
case DELETE: |
|---|
| 54 |
response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); |
|---|
| 55 |
return; |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
} |
|---|