Changeset 5059
- Timestamp:
- 07/28/08 00:29:36 (4 months ago)
- Files:
-
- openmrs-modules/logicws/.classpath (modified) (1 diff)
- openmrs-modules/logicws/lib-common/hsqldb.jar (added)
- openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsHTTPtest.java (modified) (1 diff)
- openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsTest.java (modified) (5 diffs)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/DataResource.java (modified) (14 diffs)
- openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/URLdataQuery.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs-modules/logicws/.classpath
r5042 r5059 35 35 <classpathentry kind="lib" path="lib-common/commons-logging-1.1.1.jar"/> 36 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.5027.jar" />37 <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0.13.5027.jar" sourcepath="/logic-api-refactoring"/> 38 38 <classpathentry kind="lib" path="lib-common/tests-openmrs-api-1.3.0.13.5027.jar"/> 39 39 <classpathentry kind="lib" path="lib-common/web-openmrs-api-1.3.0.13.5027.jar"/> 40 <classpathentry kind="lib" path="lib-common/hsqldb.jar"/> 40 41 <classpathentry kind="output" path="build"/> 41 42 </classpath> openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsHTTPtest.java
r5042 r5059 213 213 { 214 214 // WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{GENDER}%20FROM%203:org.openmrs.cohort.StaticCohortDefinition"); 215 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{WEIGHT%20(KG)}|{AGE}%20FROM%205:org.openmrs.cohort.StaticCohortDefinition&datastyle=flat"); 215 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{AGE}:OBSERVATIONDATE|%20{GENDER}:OBSERVATIONDATE|%20{WEIGHT%20(KG)}%20LT%2022:OBSERVATIONDATE%20FROM%205:org.openmrs.cohort.StaticCohortDefinition&datastyle=flat"); 216 try 217 { 218 WebResponse resp = wc.getResponse(req); 219 assertTrue(resp.getText().indexOf("dataset") > 0); 220 221 System.out.println("\n"); 222 System.out.println("Data Response:\n"); 223 prettyPrint(resp.getDOM(), System.out); 224 System.out.println("\n"); 225 226 } catch (IOException e) { 227 // TODO Auto-generated catch block 228 e.printStackTrace(); 229 } catch (SAXException e) { 230 // TODO Auto-generated catch block 231 e.printStackTrace(); 232 } 233 catch (Exception e) { 234 // TODO Auto-generated catch block 235 e.printStackTrace(); 236 } 237 } 238 239 public void testGetStackedData() 240 { 241 // WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{GENDER}%20FROM%203:org.openmrs.cohort.StaticCohortDefinition"); 242 WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{AGE}:OBSERVATIONDATE|%20{GENDER}:OBSERVATIONDATE|%20{WEIGHT%20(KG)}%20LT%2022:OBSERVATIONDATE%20FROM%203:org.openmrs.cohort.StaticCohortDefinition&datastyle=stacked"); 216 243 try 217 244 { openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsTest.java
r5028 r5059 9 9 import org.apache.commons.logging.LogFactory; 10 10 import org.openmrs.Cohort; 11 import org.openmrs.Obs; 11 12 import org.openmrs.api.context.Context; 12 13 import org.openmrs.cohort.CohortDefinition; … … 28 29 private static Log log = LogFactory.getLog(LogicWsTest.class); 29 30 31 /* 32 @Override 33 protected void onSetUpInTransaction() throws Exception { 34 initializeInMemoryDatabase(); 35 36 executeDataSet("org/openmrs/module/logicws/test/include/LogicServiceIssue.xml"); 37 38 authenticate(); 39 } 40 */ 41 30 42 @Override 31 43 protected void onSetUpBeforeTransaction() throws Exception { … … 93 105 public void testGetStackedData() 94 106 { 95 CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition(" 5:org.openmrs.cohort.StaticCohortDefinition");107 CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("3:org.openmrs.cohort.StaticCohortDefinition"); 96 108 Cohort patients = Context.getCohortService().evaluate(cohortDefinition, null); 97 109 … … 134 146 System.out.println("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 135 147 136 assertFalse(save.equals(resByPat.getValue().get(i).toString())); 148 System.out.println("<value>" + resByPat.getValue().get(i).getResultDate() + "</value>"); 149 150 Obs obs = (Obs) resByPat.getValue().get(i).getResultObject(); 151 System.out.println("<value>" + obs.getLocation() + "</value>"); 152 153 System.out.println("<value>" + obs.getEncounter().getEncounterDatetime() + "</value>"); 154 155 System.out.println("<value>" + obs.getEncounter().getEncounterType() + "</value>"); 156 157 158 159 160 //assertFalse(save.equals(resByPat.getValue().get(i).toString())); 137 161 save = resByPat.getValue().get(i).toString(); 138 162 … … 151 175 System.out.println("<value>" + resByPat.getValue().toString() + "</value>"); 152 176 177 System.out.println("<value>" + resByPat.getValue().getResultDate() + "</value>"); 178 179 Obs obs = (Obs) resByPat.getValue().getResultObject(); 180 181 if(obs != null) 182 { 183 System.out.println("<value>" + obs.getLocation() + "</value>"); 184 185 186 187 System.out.println("<value>" + obs.getEncounter().getEncounterDatetime() + "</value>"); 188 189 System.out.println("<value>" + obs.getEncounter().getEncounterType() + "</value>"); 190 191 System.out.println("</row>"); 192 } 193 153 194 System.out.println("</row>"); 154 195 openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/DataResource.java
r5042 r5059 3 3 import java.io.IOException; 4 4 import java.io.PrintWriter; 5 import java.util.HashSet; 5 6 import java.util.Map; 6 7 import java.util.List; 7 8 import java.util.ArrayList; 9 import java.util.Set; 8 10 9 11 import javax.servlet.ServletException; … … 14 16 import org.apache.commons.logging.LogFactory; 15 17 import org.openmrs.Cohort; 18 import org.openmrs.Obs; 16 19 import org.openmrs.logic.LogicCriteria; 17 20 import org.openmrs.logic.LogicService; 18 21 import org.openmrs.logic.result.Result; 22 import org.openmrs.logic.result.Result.Datatype; 19 23 import org.openmrs.logic.LogicException; 20 24 import org.openmrs.api.context.Context; … … 25 29 public class DataResource implements RestResource { 26 30 31 private static final String ENCOUNTERDATE = "ENCOUNTERDATE"; 32 private static final String ENCOUNTERTYPE = "ENCOUNTERTYPE"; 33 private static final String OBSERVATIONLOCATION = "OBSERVATIONLOCATION"; 34 private static final String OBSERVATIONDATE = "OBSERVATIONDATE"; 27 35 private Log log = LogFactory.getLog(this.getClass()); 28 36 … … 38 46 URLdataQuery dataQuery = new URLdataQuery(request); 39 47 48 log.info("Built query"); 49 40 50 String filter = dataQuery.getFilter(); 41 51 … … 53 63 { 54 64 tokens.add(LogicCriteria.parse(tokensFromQuery[i])); 55 //tokens.add(new LogicCriteria(tokensFromQuery[i]));56 65 } 57 66 … … 77 86 out.print("<column token=\"VALUE\" />"); 78 87 log.info("<column token=\"VALUE\" />"); 88 89 //add the neccessary splitter columns 90 //if any of the tokens split, we need to include this column 91 Set<String> uniqueSplits = new HashSet<String>(); 92 93 for(int i = 0; i < tokenNamesFromQuery.length; i++) 94 { 95 String[] splits = dataQuery.getTokenSplits(tokenNamesFromQuery[i]); 96 97 if(splits != null) 98 { 99 for(int j = 0; j < splits.length; j++) 100 { 101 uniqueSplits.add(splits[j]); 102 } 103 } 104 105 106 } 107 108 for(String split: uniqueSplits) 109 { 110 out.print("<column token=\"" + split + "\" />"); 111 log.info("<column token=\"" + split + "\" />"); 112 } 79 113 80 114 out.print("</columns>"); … … 128 162 log.info("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 129 163 130 131 /* 132 out.print("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 133 log.info("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 134 */ 164 //add splitter values 165 for(String split: uniqueSplits) 166 { 167 if(split.equals(OBSERVATIONDATE)) 168 { 169 if(resByPat.getValue().get(i).getResultDate() != null) 170 { 171 out.print("<value>" + resByPat.getValue().get(i).getResultDate().getTime() + "</value>"); 172 log.info("<value>" + resByPat.getValue().get(i).getResultDate().getTime() + "</value>"); 173 } 174 else 175 { 176 out.print("<value></value>"); 177 log.info("<value></value>"); 178 } 179 180 181 } 182 else if(split.equals(OBSERVATIONLOCATION)) 183 { 184 Obs obs = (Obs) resByPat.getValue().get(i).getResultObject(); 185 186 if(obs != null) 187 { 188 out.print("<value>" + obs.getLocation() + "</value>"); 189 log.info("<value>" + obs.getLocation() + "</value>"); 190 } 191 else 192 { 193 out.print("<value></value>"); 194 log.info("<value></value>"); 195 } 196 } 197 else if(split.equals(ENCOUNTERDATE)) 198 { 199 Obs obs = (Obs) resByPat.getValue().get(i).getResultObject(); 200 201 if(obs != null) 202 { 203 out.print("<value>" + obs.getEncounter().getEncounterDatetime().getTime() + "</value>"); 204 log.info("<value>" + obs.getEncounter().getEncounterDatetime().getTime() + "</value>"); 205 } 206 else 207 { 208 out.print("<value></value>"); 209 log.info("<value></value>"); 210 } 211 } 212 else if(split.equals(ENCOUNTERTYPE)) 213 { 214 Obs obs = (Obs) resByPat.getValue().get(i).getResultObject(); 215 216 if(obs != null) 217 { 218 out.print("<value>" + obs.getEncounter().getEncounterType() + "</value>"); 219 log.info("<value>" + obs.getEncounter().getEncounterType() + "</value>"); 220 } 221 else 222 { 223 out.print("<value></value>"); 224 log.info("<value></value>"); 225 } 226 } 227 } 135 228 136 229 out.print("</row>"); … … 153 246 log.info("<value>" + resByPat.getValue().toString() + "</value>"); 154 247 248 249 //add splitter values 250 for(String split: uniqueSplits) 251 { 252 if(split.equals(OBSERVATIONDATE)) 253 { 254 if(resByPat.getValue().getResultDate() != null) 255 { 256 out.print("<value>" + resByPat.getValue().getResultDate().getTime() + "</value>"); 257 log.info("<value>" + resByPat.getValue().getResultDate().getTime() + "</value>"); 258 } 259 else 260 { 261 out.print("<value></value>"); 262 log.info("<value></value>"); 263 } 264 } 265 else if(split.equals(OBSERVATIONLOCATION)) 266 { 267 Obs obs = (Obs) resByPat.getValue().getResultObject(); 268 269 if(obs != null) 270 { 271 out.print("<value>" + obs.getLocation() + "</value>"); 272 log.info("<value>" + obs.getLocation() + "</value>"); 273 } 274 else 275 { 276 out.print("<value></value>"); 277 log.info("<value></value>"); 278 } 279 } 280 else if(split.equals(ENCOUNTERDATE)) 281 { 282 Obs obs = (Obs) resByPat.getValue().getResultObject(); 283 284 if(obs != null) 285 { 286 out.print("<value>" + obs.getEncounter().getEncounterDatetime().getTime() + "</value>"); 287 log.info("<value>" + obs.getEncounter().getEncounterDatetime().getTime() + "</value>"); 288 } 289 else 290 { 291 out.print("<value></value>"); 292 log.info("<value></value>"); 293 } 294 } 295 else if(split.equals(ENCOUNTERTYPE)) 296 { 297 Obs obs = (Obs) resByPat.getValue().getResultObject(); 298 299 if(obs != null) 300 { 301 out.print("<value>" + obs.getEncounter().getEncounterType() + "</value>"); 302 log.info("<value>" + obs.getEncounter().getEncounterType() + "</value>"); 303 } 304 else 305 { 306 out.print("<value></value>"); 307 log.info("<value></value>"); 308 } 309 } 310 } 155 311 out.print("</row>"); 156 log.info("</row>"); 157 158 } 159 160 } 161 312 log.info("</row>"); 313 } 314 } 162 315 } 163 316 … … 189 342 out.print("<column token=\"" + t + "_" + i + "\" />"); 190 343 log.info("<column token=\"" + t + "_" + i + "\" />"); 344 345 //add the split columns 346 String[] splits = dataQuery.getTokenSplits(t); 347 348 if(splits != null) 349 { 350 for(String split: splits) 351 { 352 out.print("<column token=\"" + t + "_" + i + "_" + split + "\" />"); 353 log.info("<column token=\"" + t + "_" + i + "_" + split + "\" />"); 354 } 355 } 356 191 357 } 192 358 … … 230 396 { 231 397 Result res = resultsForTokens.get(token).get(patient); 232 398 233 399 for(int i = 0; i < max; i++) 234 400 { 235 401 out.print("<value>" + res.get(i) + "</value>"); 236 log.info("<value>" + res.get(i) + "</value>"); 402 log.info("<value>" + res.get(i) + "</value>"); 403 404 //add splitter values 405 String[] splits = dataQuery.getTokenSplits(token.getRootToken()); 406 407 if(splits != null) 408 { 409 for(String split: splits) 410 { 411 if(split.equals(OBSERVATIONDATE)) 412 { 413 if(res.get(i).getResultDate() != null) 414 { 415 out.print("<value>" + res.get(i).getResultDate().getTime() + "</value>"); 416 log.info("<value>" + res.get(i).getResultDate().getTime() + "</value>"); 417 } 418 else 419 { 420 out.print("<value></value>"); 421 log.info("<value></value>"); 422 } 423 424 } 425 else if(split.equals(OBSERVATIONLOCATION)) 426 { 427 Obs obs = (Obs) res.get(i).getResultObject(); 428 if(obs != null) 429 { 430 out.print("<value>" + obs.getLocation() + "</value>"); 431 log.info("<value>" + obs.getLocation() + "</value>"); 432 } 433