Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 5028

Show
Ignore:
Timestamp:
07/24/08 02:26:17 (6 months ago)
Author:
kevjay
Message:

logicws: added test for stacked data that reproduces issue where all patients have same height and weight.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/logicws/test/org/openmrs/module/logicws/test/LogicWsTest.java

    r4968 r5028  
    11package org.openmrs.module.logicws.test; 
    22 
    3 import java.io.File; 
    4 import java.text.DateFormat; 
    5 import java.text.DecimalFormat; 
    6 import java.text.Format; 
    7 import java.text.NumberFormat; 
    8 import java.text.SimpleDateFormat; 
    93import java.util.ArrayList; 
    10 import java.util.Collection; 
    11 import java.util.Collections; 
    12 import java.util.Date; 
    13 import java.util.HashMap; 
    14 import java.util.Iterator; 
     4 
    155import java.util.List; 
    166import java.util.Map; 
    177import java.util.Set; 
    18 import java.util.logging.Level; 
    19 import java.util.logging.Logger; 
    20  
    21 import javax.servlet.ServletException; 
    22  
    238import org.apache.commons.logging.Log; 
    249import org.apache.commons.logging.LogFactory; 
    2510import org.openmrs.Cohort; 
    26 import org.openmrs.Obs; 
    27 import org.openmrs.Patient; 
    2811import org.openmrs.api.context.Context; 
    2912import org.openmrs.cohort.CohortDefinition; 
    3013import org.openmrs.cohort.CohortDefinitionItemHolder; 
    31 import org.openmrs.logic.LogicContext; 
    3214import org.openmrs.logic.LogicCriteria; 
    3315import org.openmrs.logic.LogicException; 
    3416import org.openmrs.logic.LogicService; 
    3517import org.openmrs.logic.result.Result; 
    36 import org.openmrs.report.EvaluationContext; 
    3718import org.openmrs.test.BaseModuleContextSensitiveTest; 
    3819 
     
    4930        @Override 
    5031        protected void onSetUpBeforeTransaction() throws Exception { 
     32                 
    5133                super.onSetUpBeforeTransaction(); 
    5234                authenticate(); 
     
    6143         * Public constructor 
    6244         */ 
    63         public LogicWsTest() { } 
     45        public LogicWsTest()  
     46        { 
     47                 
     48        } 
    6449 
    6550        /** 
     
    10691         
    10792         
    108         public void testGetData() 
     93        public void testGetStackedData() 
    10994        { 
    110                 CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("3:org.openmrs.cohort.StaticCohortDefinition"); 
     95                CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("5:org.openmrs.cohort.StaticCohortDefinition"); 
    11196                Cohort patients = Context.getCohortService().evaluate(cohortDefinition, null); 
    112  
    113                 String[] tokens = {"GENDER", "AGE"}; 
    11497                 
    115                 LogicContext logicContext = new LogicContext(patients); 
    116                 LogicService ls = Context.getLogicService(); 
     98                LogicService ls = Context.getLogicService();                     
    11799                                 
    118                 //List<Map<Integer, Result>> resultsForTokens = new ArrayList<Map<Integer, Result>>(); 
     100                List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); 
     101                tokens.add(LogicCriteria.parse("{WEIGHT (KG)}"));        
     102                tokens.add(LogicCriteria.parse("{AGE}")); 
     103                tokens.add(LogicCriteria.parse("{HEIGHT (CM)}")); 
     104          
     105                Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; 
     106                try 
     107                { 
     108                        resultsForTokens = ls.eval(patients, tokens); 
     109                }  
     110                catch (LogicException e)  
     111                { 
     112                        // TODO Auto-generated catch block 
     113                        e.printStackTrace(); 
     114                }        
    119115                 
    120                 try  
    121                 { 
    122                         for (String t : tokens)  
    123                         { 
    124                                 Set<Integer> patientIDs = patients.getMemberIds(); 
    125                                 Iterator<Integer> iter = patientIDs.iterator(); 
    126                                  
    127                                 //Map<Integer,Result> patientResult = new HashMap<Integer, Result>(); 
    128                                                                                                  
    129                                 while(iter.hasNext()) 
    130                                 { 
    131                                         Patient patient = Context.getPatientService().getPatient(iter.next()); 
     116                String save = ""; 
     117                 
     118                for (Map.Entry<LogicCriteria, Map<Integer, Result>> resByCrit : resultsForTokens.entrySet())  
     119                {                                                
     120                         for(Map.Entry<Integer, Result> resByPat : resByCrit.getValue().entrySet()) 
     121                         { 
     122                                   
     123                                 if(resByPat.getValue().size() > 0) 
     124                                 { 
     125                                         for(int i = 0; i < resByPat.getValue().size(); i++) 
     126                                         { 
     127                                                 System.out.println("<row>"); 
     128                                                 
     129                                                 //always print the patient id first 
     130                                                 System.out.println("<value>" + resByPat.getKey() + "</value>"); 
     131                                                  
     132                                                 System.out.println("<value>" + resByCrit.getKey().getRootToken() + "</value>"); 
     133                                                  
     134                                                 System.out.println("<value>" + resByPat.getValue().get(i).toString() + "</value>"); 
     135                                                  
     136                                                 assertFalse(save.equals(resByPat.getValue().get(i).toString())); 
     137                                                 save = resByPat.getValue().get(i).toString(); 
     138                                                 
     139                                                 System.out.println("</row>"); 
     140                                         } 
     141                                 } 
     142                                 else 
     143                                 { 
     144                                         System.out.println("<row>"); 
    132145                                         
    133                                         System.out.println("LogicContext.read - " + logicContext.read(patient, (new LogicCriteria(t)))); 
    134                                          
    135                                         System.out.println("LogicService.eval - " + ls.eval(patient, (new LogicCriteria(t)))); 
    136                                          
    137                                         //patientResult.put(patient.getPatientId(), logicContext.read(patient, (new LogicCriteria(t)))); 
    138                                 } 
    139                                  
    140                                 //resultsForTokens.add(patientResult); 
    141                         } 
    142                 } catch (Exception e) { 
    143                         e.printStackTrace(); 
    144                 }               
     146                                        //always print the patient id first 
     147                                        System.out.println("<value>" + resByPat.getKey() + "</value>"); 
     148                                         
     149                                        System.out.println("<value>" + resByCrit.getKey().getRootToken() + "</value>"); 
     150                                                                        
     151                                        System.out.println("<value>" + resByPat.getValue().toString() + "</value>"); 
     152                                         
     153                                        System.out.println("</row>"); 
     154                                         
     155                                } 
     156                        } 
     157                }  
    145158        } 
    146159}