Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

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

Revision 5493, 1.5 kB (checked in by bwolfe, 4 months ago)

restmodule: updated to work with openmrs 1.3

Line 
1 package org.openmrs.module.restmodule.web;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.Collection;
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 a simple RESTful access to patients
18  * 
19  * @author Burke Mamlin
20  * @version 1.0
21  */
22 public class PatientResource implements RestResource {
23
24         /**
25          * Handle all requests to this 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                         Collection<Patient> patientList = Context.getPatientService()
37                                         .getPatientsByIdentifier(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.