Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 4968

Show
Ignore:
Timestamp:
07/17/08 13:56:41 (4 months ago)
Author:
kevjay
Message:

logicwebservice - updated test with latest APIs from logic api refactoring branch

Files:

Legend:

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

    r4342 r4968  
    44import java.text.DateFormat; 
    55import java.text.DecimalFormat; 
     6import java.text.Format; 
    67import java.text.NumberFormat; 
    78import java.text.SimpleDateFormat; 
     
    1819import java.util.logging.Logger; 
    1920 
     21import javax.servlet.ServletException; 
     22 
    2023import org.apache.commons.logging.Log; 
    2124import org.apache.commons.logging.LogFactory; 
     25import org.openmrs.Cohort; 
     26import org.openmrs.Obs; 
     27import org.openmrs.Patient; 
    2228import org.openmrs.api.context.Context; 
     29import org.openmrs.cohort.CohortDefinition; 
     30import org.openmrs.cohort.CohortDefinitionItemHolder; 
     31import org.openmrs.logic.LogicContext; 
     32import org.openmrs.logic.LogicCriteria; 
     33import org.openmrs.logic.LogicException; 
     34import org.openmrs.logic.LogicService; 
     35import org.openmrs.logic.result.Result; 
     36import org.openmrs.report.EvaluationContext; 
    2337import org.openmrs.test.BaseModuleContextSensitiveTest; 
    2438 
     
    5367         * @throws Exception 
    5468         */ 
    55         public void testGetTokens() throws Exception {  
     69        public void testGetTokens() throws Exception  
     70        {  
    5671                Set<String> tokens = Context.getLogicService().getTokens(); 
    57                 log.info("Tokens: " + tokens); 
     72                System.out.println("Tokens: " + tokens); 
    5873                 
    5974        } 
     75         
     76         
     77        /* 
     78        public void testAddTokenTags() throws Exception  
     79        {  
     80                Context.getLogicService().addTokenTag("AGE", "COMMON"); 
     81                Context.getLogicService().addTokenTag("GENDER", "COMMON"); 
     82                Context.getLogicService().addTokenTag("DEATH DATE", "COMMON"); 
     83                 
     84                System.out.println(Context.getLogicService().getTokensByTag("COMMON")); 
     85                 
     86                System.out.println(Context.getLogicService().getTagsByToken("GENDER")); 
     87                //Context.getLogicService(). 
     88                 
     89        } 
     90        */ 
     91         
     92        public void testGetCohorts() 
     93        { 
     94                         
     95                for (CohortDefinitionItemHolder c : Context.getCohortService().getAllCohortDefinitions())  
     96                { 
     97            System.out.println("<filter name=\"" + c.getName() + "\" id=\"" + c.getKey() + "\" />"); 
     98        } 
     99        }                
     100 
     101        public void testGetTags() throws Exception {  
     102                Set<String> tags = Context.getLogicService().findTags(""); 
     103                System.out.println("Tags: " + tags); 
     104                 
     105        } 
     106         
     107         
     108        public void testGetData() 
     109        { 
     110                CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("3:org.openmrs.cohort.StaticCohortDefinition"); 
     111                Cohort patients = Context.getCohortService().evaluate(cohortDefinition, null); 
     112 
     113                String[] tokens = {"GENDER", "AGE"}; 
     114                 
     115                LogicContext logicContext = new LogicContext(patients); 
     116                LogicService ls = Context.getLogicService(); 
    60117                                 
    61  
     118                //List<Map<Integer, Result>> resultsForTokens = new ArrayList<Map<Integer, Result>>(); 
     119                 
     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()); 
     132                                         
     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                }                
     145        } 
    62146} 
    63          
    64