Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 5042

Show
Ignore:
Timestamp:
07/25/08 03:37:34 (4 months ago)
Author:
kevjay
Message:

logicws: rudimentary support for flat and stacked style data output. Select between flat and stacked by adding &datastyle=flat or &datastyle=stacked to URL request.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/logicws/.classpath

    r4990 r5042  
    3535        <classpathentry kind="lib" path="lib-common/commons-logging-1.1.1.jar"/> 
    3636        <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"/> 
     37        <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0.13.5027.jar"/> 
     38        <classpathentry kind="lib" path="lib-common/tests-openmrs-api-1.3.0.13.5027.jar"/> 
     39        <classpathentry kind="lib" path="lib-common/web-openmrs-api-1.3.0.13.5027.jar"/> 
    4040        <classpathentry kind="output" path="build"/> 
    4141</classpath> 
  • openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsHTTPtest.java

    r4990 r5042  
    186186        {                
    187187           // 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"); 
     188                WebRequest req = new PostMethodWebRequest("http://localhost:8080/openmrs/moduleServlet/logicws/api/getData?query=SELECT%20{WEIGHT%20(KG)}%20FROM%205:org.openmrs.cohort.StaticCohortDefinition&datastyle=stacked"); 
     189            try  
     190            { 
     191                        WebResponse resp = wc.getResponse(req);                  
     192                        assertTrue(resp.getText().indexOf("dataset") > 0);                       
     193                         
     194                        System.out.println("\n"); 
     195                        System.out.println("Data Response:\n"); 
     196                        prettyPrint(resp.getDOM(), System.out); 
     197                        System.out.println("\n"); 
     198                         
     199                } catch (IOException e) { 
     200                        // TODO Auto-generated catch block 
     201                        e.printStackTrace(); 
     202                } catch (SAXException e) { 
     203                        // TODO Auto-generated catch block 
     204                        e.printStackTrace(); 
     205                }  
     206                catch (Exception e) { 
     207                        // TODO Auto-generated catch block 
     208                        e.printStackTrace(); 
     209                }                
     210        } 
     211         
     212        public void testGetFlatData()  
     213        {                
     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"); 
    189216            try  
    190217            { 
  • openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/DataResource.java

    r5020 r5042  
    3232 
    3333                log.info("Data request: " + request.getParameter("query")); 
    34                  
     34                log.info("Data request: " + request.getParameter("datastyle")); 
    3535                 
    3636                switch (operation) { 
     
    119119                                                                         log.info("<value>" + resByPat.getKey() + "</value>"); 
    120120                                                                          
     121                                                                         //resByCrit.getValue().get(i).getResultObject().toString(); 
     122                                                                          
    121123                                                                         out.print("<value>" + resByCrit.getKey().getRootToken() + "</value>"); 
    122124                                                                         log.info("<value>" + resByCrit.getKey().getRootToken() + "</value>"); 
    123125                                                                          
     126                                                                         
    124127                                                                         out.print("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
    125128                                                                         log.info("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
     129                                                                          
     130                                                                         
     131                                                                         /* 
     132                                                                         out.print("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
     133                                                                         log.info("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
     134                                                                         */ 
    126135                                                                          
    127136                                                                         out.print("</row>"); 
     
    170179                                 
    171180                        } 
     181                        else if(dataQuery.getDataStyle().equals("flat")) 
     182                        { 
     183                                int max = 5; 
     184                                 
     185                                for (String t : tokenNamesFromQuery) 
     186                                { 
     187                                        for(int i = 1; i < max + 1; i++) 
     188                                        { 
     189                                                out.print("<column token=\"" + t + "_" + i + "\" />");           
     190                                                log.info("<column token=\"" + t + "_" + i + "\" />"); 
     191                                        } 
     192                                         
     193                                } 
     194                                out.print("</columns>"); 
     195                                log.info("</columns>"); 
     196         
     197                                // List rows 
     198                                out.print("<rows>"); 
     199                                log.info("<rows>"); 
     200                                 
     201                                Cohort patients; 
     202                                LogicService ls = Context.getLogicService(); 
     203         
     204                                try { 
     205         
     206                                        CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition(filter); 
     207                                        patients = Context.getCohortService().evaluate(cohortDefinition, null); 
     208                                         
     209                                        Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; 
     210                                        try 
     211                                        { 
     212                                                resultsForTokens = ls.eval(patients, tokens); 
     213                                        }  
     214                                        catch (LogicException e)  
     215                                        { 
     216                                                // TODO Auto-generated catch block 
     217                                                e.printStackTrace(); 
     218                                        }        
     219                                                                                 
     220                                        for (Integer patient: patients.getMemberIds())  
     221                                        { 
     222                                                out.print("<row>"); 
     223                                                log.info("<row>"); 
     224                                                 
     225                                                //always print the patient id first 
     226                                                out.print("<value>" + patient + "</value>"); 
     227                                                log.info("<value>" + patient + "</value>"); 
     228                                                 
     229                                                for (LogicCriteria token: tokens)  
     230                                                { 
     231                                                        Result res = resultsForTokens.get(token).get(patient); 
     232                                                                                                         
     233                                                        for(int i = 0; i < max; i++) 
     234                                                        { 
     235                                                                out.print("<value>" + res.get(i) + "</value>"); 
     236                                                                log.info("<value>" + res.get(i) + "</value>");                                                           
     237                                                        }                                                 
     238                                                 } 
     239                                                 
     240                                                out.print("</row>"); 
     241                                                log.info("</row>"); 
     242                                        } 
     243                                         
     244                                        out.print("</rows>"); 
     245                                        log.info("</rows>"); 
     246                                 
     247                                        out.print("</dataset>"); 
     248                                        log.info("<rows>");              
     249                                 
     250                                        break; 
     251                                }  
     252                                 
     253                                catch (org.openmrs.api.APIAuthenticationException e)  
     254                                { 
     255                                        out.print("<error>" + e.toString() 
     256                                                        + "</error></rows></dataset>"); 
     257                                        break; 
     258                                } 
     259                        } 
    172260                        else 
    173261                        {