Changeset 4990
- Timestamp:
- 07/20/08 23:59:55 (4 months ago)
- Files:
-
- openmrs-modules/logicws/.classpath (modified) (2 diffs)
- openmrs-modules/logicws/lib-common/commons-logging-1.0.4.jar (deleted)
- openmrs-modules/logicws/lib-common/commons-logging-1.1.1.jar (added)
- openmrs-modules/logicws/lib-common/log4j-1.2.15.jar (added)
- openmrs-modules/logicws/lib-common/log4j.jar (deleted)
- openmrs-modules/logicws/lib-common/openmrs-api-1.3.0.00.4356.jar (deleted)
- openmrs-modules/logicws/lib-common/openmrs-api-1.3.0.13.4989.jar (added)
- openmrs-modules/logicws/lib-common/tests-openmrs-api-1.3.0.00.4356.jar (deleted)
- openmrs-modules/logicws/lib-common/tests-openmrs-api-1.3.0.13.4989.jar (added)
- openmrs-modules/logicws/lib-common/web-openmrs-api-1.3.0.00.4356.jar (deleted)
- openmrs-modules/logicws/lib-common/web-openmrs-api-1.3.0.13.4989.jar (added)
- openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsHTTPtest.java (modified) (1 diff)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/DataResource.java (modified) (5 diffs)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/FilterResource.java (modified) (3 diffs)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/TokenResource.java (modified) (1 diff)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/TokenTagResource.java (modified) (1 diff)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/URLdataQuery.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs-modules/logicws/.classpath
r4916 r4990 7 7 <classpathentry kind="lib" path="lib-common/commons-collections-3.1.jar"/> 8 8 <classpathentry kind="lib" path="lib-common/commons-io-1.1.jar"/> 9 <classpathentry kind="lib" path="lib-common/commons-logging-1.0.4.jar"/>10 9 <classpathentry kind="lib" path="lib-common/hibernate325.jar"/> 11 10 <classpathentry kind="lib" path="lib-common/junit-3.8.1.jar"/> … … 29 28 <classpathentry kind="lib" path="lib-common/cglib-2.1_3.jar"/> 30 29 <classpathentry kind="lib" path="lib-common/ehcache-1.2.4.jar"/> 31 <classpathentry kind="lib" path="lib-common/log4j.jar"/>32 30 <classpathentry kind="lib" path="lib-common/hapi-0.5.jar"/> 33 31 <classpathentry kind="lib" path="lib-common/simple-xml-1.6.1-mod.jar"/> 34 <classpathentry kind="lib" path="lib-common/tests-openmrs-api-1.3.0.00.4356.jar"/>35 <classpathentry kind="lib" path="lib-common/web-openmrs-api-1.3.0.00.4356.jar"/>36 32 <classpathentry kind="lib" path="lib-common/httpunit.jar"/> 37 33 <classpathentry kind="lib" path="lib-common/js-1.6R5.jar"/> 38 34 <classpathentry kind="lib" path="lib-common/nekohtml-0.9.5.jar"/> 39 <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0.00.4641.jar" sourcepath="/openmrs-logic-api-refactoring"/> 35 <classpathentry kind="lib" path="lib-common/commons-logging-1.1.1.jar"/> 36 <classpathentry kind="lib" path="lib-common/log4j-1.2.15.jar"/> 37 <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0.13.4989.jar" sourcepath="/logic-api-refactoring"/> 38 <classpathentry kind="lib" path="lib-common/tests-openmrs-api-1.3.0.13.4989.jar"/> 39 <classpathentry kind="lib" path="lib-common/web-openmrs-api-1.3.0.13.4989.jar"/> 40 40 <classpathentry kind="output" path="build"/> 41 41 </classpath> openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsHTTPtest.java
r4918 r4990 129 129 } 130 130 131 public void testGetDataWhereCohortIsEmpty() 132 { 133 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?filter=3:org.openmrs.reporting.PatientSearch&token=AGE&token=GENDER"); 134 135 try 136 { 137 WebResponse resp = wc.getResponse(req); 138 assertTrue(resp.getText().indexOf("dataset") > 0); 139 140 System.out.println("\n"); 141 System.out.println("Data Response:\n"); 142 prettyPrint(resp.getDOM(), System.out); 143 System.out.println("\n"); 144 145 } catch (IOException e) { 146 // TODO Auto-generated catch block 147 e.printStackTrace(); 148 } catch (SAXException e) { 149 // TODO Auto-generated catch block 150 e.printStackTrace(); 151 } 152 catch (Exception e) { 153 // TODO Auto-generated catch block 154 e.printStackTrace(); 155 } 156 } 157 158 public void testGetDataWhenNoArguments() 159 { 160 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData"); 161 162 try 163 { 164 WebResponse resp = wc.getResponse(req); 165 assertTrue(resp.getText().indexOf("dataset") > 0); 166 167 System.out.println("\n"); 168 System.out.println("Data Response:\n"); 169 prettyPrint(resp.getDOM(), System.out); 170 System.out.println("\n"); 171 172 } catch (IOException e) { 173 // TODO Auto-generated catch block 174 e.printStackTrace(); 175 } catch (SAXException e) { 176 // TODO Auto-generated catch block 177 e.printStackTrace(); 178 } 179 catch (Exception e) { 180 // TODO Auto-generated catch block 181 e.printStackTrace(); 182 } 183 } 184 131 185 public void testGetData() 132 186 { 133 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?filter=3&filterType=static&token=AGE&token=GENDER");134 187 // WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{GENDER}%20FROM%203:org.openmrs.cohort.StaticCohortDefinition"); 188 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{WEIGHT%20(KG)}%20FROM%203:org.openmrs.cohort.StaticCohortDefinition"); 135 189 try 136 190 { openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/DataResource.java
r4918 r4990 14 14 import javax.servlet.http.HttpServletResponse; 15 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 16 18 import org.openmrs.Cohort; 17 19 import org.openmrs.Obs; 20 import org.openmrs.Patient; 21 import org.openmrs.logic.LogicContext; 22 import org.openmrs.logic.LogicCriteria; 18 23 import org.openmrs.logic.LogicService; 19 24 import org.openmrs.logic.result.Result; 20 25 import org.openmrs.logic.LogicException; 21 26 import org.openmrs.api.context.Context; 27 import org.openmrs.api.impl.CohortServiceImpl; 28 import org.openmrs.cohort.CohortDefinition; 29 30 22 31 23 32 public class DataResource implements RestResource { 24 33 34 private Log log = LogFactory.getLog(this.getClass()); 35 25 36 public void handleRequest(Operation operation, HttpServletRequest request, 26 37 HttpServletResponse response) throws ServletException, IOException { 27 38 PrintWriter out = response.getWriter(); 28 39 40 log.info("Data request: " + request.getParameter("query")); 41 42 29 43 switch (operation) { 30 44 case POST: 31 45 URLdataQuery dataQuery = new URLdataQuery(request); 32 Integer filter = dataQuery.getFilter(); 33 String filterType = dataQuery.getFilterType(); 34 String[] tokens = dataQuery.getTokens(); 35 46 47 String filter = dataQuery.getFilter(); 48 49 String[] tokensFromQuery = dataQuery.getTokensWithModifiers(); 50 36 51 // Check for lack of parameters 37 if (filter == null 38 || filterType == null 39 || tokens == null 40 || (!filterType.equals("static") && !filterType 41 .equals("dynamic"))) { 52 if (filter == null || tokensFromQuery == null) 53 { 42 54 out.print("<dataset />"); 43 55 break; 44 56 } 45 57 58 List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); 59 for(int i = 0 ; i < tokensFromQuery.length; i++) 60 { 61 tokens.add(LogicCriteria.parse(tokensFromQuery[i])); 62 //tokens.add(new LogicCriteria(tokensFromQuery[i])); 63 } 64 46 65 out.print("<dataset>"); 47 66 67 String[] tokenNamesFromQuery = dataQuery.getTokenNames(); 68 48 69 // List columns 49 70 out.print("<columns>"); 50 for (String t : token s)71 for (String t : tokenNamesFromQuery) 51 72 { 52 out.print("<column token=\"" + t + "\" />"); 53 73 out.print("<column token=\"" + t + "\" />"); 74 75 /* 54 76 out.print("<column token=\"" + t + "_OBSERVATIONDATE\" />"); 55 77 out.print("<column token=\"" + t + "_OBSERVATIONLOCATION\" />"); 56 78 out.print("<column token=\"" + t + "_ENCOUNTERTYPE\" />"); 57 out.print("<column token=\"" + t + "_ENCOUNTERDATE\" />"); 79 out.print("<column token=\"" + t + "_ENCOUNTERDATE\" />"); 80 */ 58 81 } 59 82 out.print("</columns>"); … … 61 84 // List rows 62 85 out.print("<rows>"); 86 63 87 Cohort patients; 64 88 LogicService ls = Context.getLogicService(); … … 66 90 try { 67 91 68 69 if (filterType.equals("static")) {70 patients = Context.getCohortService().getCohort(filter);71 } else {72 patients = Context.getReportObjectService().getPatientFilterById(filter).filter(Context.getPatientSetService().getAllPatients(), null);73 }74 75 List<Map<Integer, Result>> resultsForTokens = new ArrayList<Map<Integer, Result>>();76 try {77 for (String t : tokens){78 resultsForTokens.add(ls.eval(patients, t));79 }80 } catch (LogicException e) {81 throw new ServletException(e);82 }83 for (Integer patient : patients.getPatientIds()){92 CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition(filter); 93 patients = Context.getCohortService().evaluate(cohortDefinition, null); 94 95 Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; 96 try 97 { 98 resultsForTokens = ls.eval(patients, tokens); 99 } 100 catch (LogicException e) 101 { 102 // TODO Auto-generated catch block 103 e.printStackTrace(); 104 } 105 106 for (Integer patient: patients.getMemberIds()) 107 { 84 108 out.print("<row>"); 85 for (Map<Integer, Result> map : resultsForTokens) { 86 Result res = map.get(patient); 109 for (LogicCriteria token: tokens) 110 { 111 Result res = resultsForTokens.get(token).get(patient); 87 112 88 113 out.print("<value>" + res + "</value>"); 89 114 115 /* 90 116 Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 91 117 118 92 119 //get the Obs from the result 93 120 Obs obs = (Obs)res.toObject(); … … 129 156 130 157 } 158 */ 131 159 } 132 160 out.print("</row>"); … … 135 163 out.print("</rows>"); 136 164 out.print("</dataset>"); 165 166 137 167 break; 138 168 } catch (org.openmrs.api.APIAuthenticationException e) { openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/FilterResource.java
r4918 r4990 11 11 import org.openmrs.reporting.PatientFilter; 12 12 import org.openmrs.api.context.Context; 13 import org.openmrs.cohort.CohortDefinitionItemHolder; 13 14 14 15 public class FilterResource implements RestResource { … … 22 23 out.print("<filterList>"); 23 24 25 26 for (CohortDefinitionItemHolder c : Context.getCohortService().getAllCohortDefinitions()) 27 { 28 out.print("<filter name=\"" + c.getName() + "\" id=\"" + c.getKey() + "\" />"); 29 } 30 31 32 /* 24 33 // List Filters <filter name="VALUE" id="VALUE" /> 25 34 for (Cohort c : Context.getCohortService().getCohorts()) { … … 28 37 } 29 38 30 /*39 31 40 for (PatientFilter pf : Context.getReportObjectService() 32 41 .getAllPatientFilters()) { openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/TokenResource.java
r4918 r4990 25 25 HttpServletResponse response) throws ServletException, IOException { 26 26 LogicService ls = Context.getLogicService(); 27 27 28 PrintWriter out = response.getWriter(); 28 29 openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/TokenTagResource.java
r4918 r4990 9 9 10 10 import java.util.Collection; 11 import java.util.Set; 11 12 12 13 import org.openmrs.api.context.Context; openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/URLdataQuery.java
r4919 r4990 2 2 3 3 import java.io.IOException; 4 import java.util.ArrayList; 5 import java.util.List; 4 6 5 7 import javax.servlet.ServletException; … … 8 10 public class URLdataQuery 9 11 { 10 Integerfilter;12 String filter; 11 13 12 String filterType;14 String[] tokensWithModifiers; 13 15 14 String [] tokens;16 String query; 15 17 16 18 public URLdataQuery(HttpServletRequest request) throws IOException, ServletException 17 19 { 18 filter = request.getParameter("filter") == null ? null 19 : Integer.parseInt(request.getParameter("filter")); 20 query = request.getParameter("query"); 20 21 21 filterType = request.getParameter("filterType"); 22 23 tokens = request.getParameterValues("token"); 22 if(query != null) 23 { 24 filter = query.indexOf("FROM") == -1 ? null 25 : query.substring(query.indexOf("FROM") + 5); 26 27 //extract the SELECT piece if it exists 28 if(query.contains("SELECT") && query.contains("FROM")) 29 { 30 String select = query.substring(query.indexOf("SELECT") + 7, query.indexOf("FROM") - 1); 31 tokensWithModifiers = select.split("\\|"); 32 } 33 else 34 tokensWithModifiers = null; 35 } 24 36 } 25 37 26 public IntegergetFilter()38 public String getFilter() 27 39 { 28 40 return filter; 29 41 } 30 31 public String getFilterType() { 32 return filterType; 42 43 public String[] getTokenNames() 44 { 45 String[] tokenName = query.split("\\|"); 46 47 String[] tokenNames = new String[tokenName.length]; 48 49 //go through each of the tokens 50 for(int i = 0; i < tokenName.length; i++) 51 { 52 //extract the actual token name 53 String token = tokenName[i].substring(tokenName[i].indexOf("{") + 1, tokenName[i].indexOf("}")); 54 55 tokenNames[i] = token; 56 } 57 58 return tokenNames; 33 59 } 34 35 public String[] getTokens () {36 return tokens ;60 61 public String[] getTokensWithModifiers() { 62 return tokensWithModifiers; 37 63 } 38 64