Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

root/openmrs-modules/restmodule/web/src/org/openmrs/module/restmodule/web/FindPatientResource.java

Revision 2091, 1.5 kB (checked in by agjendem, 1 year ago)

- Changed all the GET/SET/UPDATE/DELETE fields to an enum and applied that in that change in the necessary files.
- Removed some warnings about use of static fields that should be referenced in a static way ( e.g. HttpServletResponse.SC_FORBIDDEN)

Line 
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 }
Note: See TracBrowser for help on using the browser.