Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 5059

Show
Ignore:
Timestamp:
07/28/08 00:29:36 (4 months ago)
Author:
kevjay
Message:

logicws: Added support for 3 different data styles: most recent, stacked, and flat. Added support for splitting tokens into observation date, observation location, encounter date, and encounter type.

Files:

Legend:

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

    r5042 r5059  
    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.5027.jar"/> 
     37        <classpathentry kind="lib" path="lib-common/openmrs-api-1.3.0.13.5027.jar" sourcepath="/logic-api-refactoring"/> 
    3838        <classpathentry kind="lib" path="lib-common/tests-openmrs-api-1.3.0.13.5027.jar"/> 
    3939        <classpathentry kind="lib" path="lib-common/web-openmrs-api-1.3.0.13.5027.jar"/> 
     40        <classpathentry kind="lib" path="lib-common/hsqldb.jar"/> 
    4041        <classpathentry kind="output" path="build"/> 
    4142</classpath> 
  • openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsHTTPtest.java

    r5042 r5059  
    213213        {                
    214214           // 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"); 
    216243            try  
    217244            { 
  • openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsTest.java

    r5028 r5059  
    99import org.apache.commons.logging.LogFactory; 
    1010import org.openmrs.Cohort; 
     11import org.openmrs.Obs; 
    1112import org.openmrs.api.context.Context; 
    1213import org.openmrs.cohort.CohortDefinition; 
     
    2829        private static Log log = LogFactory.getLog(LogicWsTest.class); 
    2930 
     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         
    3042        @Override 
    3143        protected void onSetUpBeforeTransaction() throws Exception { 
     
    93105        public void testGetStackedData() 
    94106        { 
    95                 CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("5:org.openmrs.cohort.StaticCohortDefinition"); 
     107                CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("3:org.openmrs.cohort.StaticCohortDefinition"); 
    96108                Cohort patients = Context.getCohortService().evaluate(cohortDefinition, null); 
    97109                 
     
    134146                                                 System.out.println("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
    135147                                                  
    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())); 
    137161                                                 save = resByPat.getValue().get(i).toString(); 
    138162                                                 
     
    151175                                         System.out.println("<value>" + resByPat.getValue().toString() + "</value>"); 
    152176                                          
     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                                 
    153194                                         System.out.println("</row>"); 
    154195                                          
  • openmrs-modules/logicws/web/src/org/openmrs/module/logicws/web/DataResource.java

    r5042 r5059  
    33import java.io.IOException; 
    44import java.io.PrintWriter; 
     5import java.util.HashSet; 
    56import java.util.Map; 
    67import java.util.List; 
    78import java.util.ArrayList; 
     9import java.util.Set; 
    810 
    911import javax.servlet.ServletException; 
     
    1416import org.apache.commons.logging.LogFactory; 
    1517import org.openmrs.Cohort; 
     18import org.openmrs.Obs; 
    1619import org.openmrs.logic.LogicCriteria; 
    1720import org.openmrs.logic.LogicService; 
    1821import org.openmrs.logic.result.Result; 
     22import org.openmrs.logic.result.Result.Datatype; 
    1923import org.openmrs.logic.LogicException; 
    2024import org.openmrs.api.context.Context; 
     
    2529public class DataResource implements RestResource { 
    2630 
     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"; 
    2735        private Log log = LogFactory.getLog(this.getClass()); 
    2836         
     
    3846                        URLdataQuery dataQuery = new URLdataQuery(request); 
    3947                         
     48                        log.info("Built query"); 
     49                         
    4050                        String filter = dataQuery.getFilter(); 
    4151                         
     
    5363                        { 
    5464                                tokens.add(LogicCriteria.parse(tokensFromQuery[i]));             
    55                                 //tokens.add(new LogicCriteria(tokensFromQuery[i])); 
    5665                        } 
    5766                                 
     
    7786                                out.print("<column token=\"VALUE\" />"); 
    7887                                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                                } 
    79113                                 
    80114                                out.print("</columns>"); 
     
    128162                                                                         log.info("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
    129163                                                                          
    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                                                                         } 
    135228                                                                          
    136229                                                                         out.print("</row>"); 
     
    153246                                                                 log.info("<value>" + resByPat.getValue().toString() + "</value>"); 
    154247                                                                  
     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                                                                 } 
    155311                                                                 out.print("</row>"); 
    156                                                                  log.info("</row>"); 
    157                                                                   
    158                                                          } 
    159                                                           
    160                                                  } 
    161                                                  
     312                                                                 log.info("</row>");                                                              
     313                                                         }                                                        
     314                                                 }                                               
    162315                                        } 
    163316                                         
     
    189342                                                out.print("<column token=\"" + t + "_" + i + "\" />");           
    190343                                                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                                                 
    191357                                        } 
    192358                                         
     
    230396                                                { 
    231397                                                        Result res = resultsForTokens.get(token).get(patient); 
    232                                                                                                          
     398                                                                                                                
    233399                                                        for(int i = 0; i < max; i++) 
    234400                                                        { 
    235401                                                                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