Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
08/14/08 21:19:41 (5 months ago)
Author:
kevjay
Message:

logicws: Fixed bug where Obs cannot be extracted for some token Results.

Files:

Legend:

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

    r5220 r5284  
    102102 
    103103        List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); 
    104         tokens.add(LogicCriteria.parse("{GENDER}")); 
    105         // tokens.add(LogicCriteria.parse("LAST {AGE}")); 
    106         tokens.add(LogicCriteria.parse("{WEIGHT (KG)}")); 
     104        //tokens.add(LogicCriteria.parse("{GENDER}")); 
     105        tokens.add(LogicCriteria.parse("LAST {AGE}")); 
     106        //tokens.add(LogicCriteria.parse("{WEIGHT (KG)}")); 
    107107 
    108108        Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; 
     
    116116        System.out.println(resultsForTokens); 
    117117    } 
     118     
     119     
    118120 
    119121    public void testGetStackedData() { 
     
    165167                                + resByPat.getValue().get(i).getResultDate() 
    166168                                + "</value>"); 
    167  
    168                         Obs obs = (Obs) resByPat.getValue().get(i) 
    169                                 .getResultObject(); 
     169                         
     170                        Obs obs = null; 
     171                         
     172                        try 
     173                        { 
     174                            obs = (Obs) resByPat.getValue().get(i).getResultObject(); 
     175                        } 
     176                        catch(ClassCastException e) 
     177                        { 
     178                        } 
     179 
    170180                        System.out.println("<value>" + obs.getLocation() 
    171181                                + "</value>"); 
     
    200210                            + resByPat.getValue().getResultDate() + "</value>"); 
    201211 
    202                     Obs obs = (Obs) resByPat.getValue().getResultObject(); 
    203  
     212                    Obs obs = null; 
     213 
     214                    try 
     215                    { 
     216                        obs = (Obs) resByPat.getValue().getResultObject(); 
     217                    } 
     218                    catch(ClassCastException e) 
     219                    { 
     220                    } 
     221                     
    204222                    if (obs != null) { 
    205223                        System.out.println("<value>" + obs.getLocation() 
     
    223241        } 
    224242    } 
     243     
     244    public void testCauseOfDeath() { 
     245        CohortDefinition cohortDefinition = Context.getCohortService() 
     246                .getCohortDefinition( 
     247                        "5:org.openmrs.cohort.StaticCohortDefinition"); 
     248        Cohort patients = Context.getCohortService().evaluate(cohortDefinition, 
     249                null); 
     250 
     251        LogicService ls = Context.getLogicService(); 
     252 
     253        List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); 
     254        tokens.add(LogicCriteria.parse("{CAUSE OF DEATH}")); 
     255        //tokens.add(LogicCriteria.parse("{AGE}")); 
     256        //tokens.add(LogicCriteria.parse("{HEIGHT (CM)}")); 
     257 
     258        Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; 
     259        try { 
     260            resultsForTokens = ls.eval(patients, tokens); 
     261        } catch (LogicException e) { 
     262            // TODO Auto-generated catch block 
     263            e.printStackTrace(); 
     264        } 
     265 
     266        String save = ""; 
     267 
     268        for (Map.Entry<LogicCriteria, Map<Integer, Result>> resByCrit : resultsForTokens 
     269                .entrySet()) { 
     270            for (Map.Entry<Integer, Result> resByPat : resByCrit.getValue() 
     271                    .entrySet()) { 
     272 
     273                if (resByPat.getValue().size() > 0) { 
     274                    for (int i = 0; i < resByPat.getValue().size(); i++) { 
     275                        System.out.println("<row>"); 
     276 
     277                        // always print the patient id first 
     278                        System.out.println("<value>" + resByPat.getKey() 
     279                                + "</value>"); 
     280 
     281                        System.out.println("<value>" 
     282                                + resByCrit.getKey().getRootToken() 
     283                                + "</value>"); 
     284 
     285                        System.out.println("<value>" 
     286                                + resByPat.getValue().get(i).toString() 
     287                                + "</value>"); 
     288 
     289                        System.out.println("<value>" 
     290                                + resByPat.getValue().get(i).getResultDate() 
     291                                + "</value>"); 
     292 
     293                        Obs obs = null; 
     294                         
     295                        try 
     296                        { 
     297                            obs = (Obs) resByPat.getValue().get(i).getResultObject(); 
     298                        } 
     299                        catch(ClassCastException e) 
     300                        { 
     301                        } 
     302                         
     303                        System.out.println("<value>" + obs.getLocation() 
     304                                + "</value>"); 
     305 
     306                        System.out.println("<value>" 
     307                                + obs.getEncounter().getEncounterDatetime() 
     308                                + "</value>"); 
     309 
     310                        System.out.println("<value>" 
     311                                + obs.getEncounter().getEncounterType() 
     312                                + "</value>"); 
     313 
     314                        // assertFalse(save.equals(resByPat.getValue().get(i).toString())); 
     315                        save = resByPat.getValue().get(i).toString(); 
     316 
     317                        System.out.println("</row>"); 
     318                    } 
     319                } else { 
     320                    System.out.println("<row>"); 
     321 
     322                    // always print the patient id first 
     323                    System.out.println("<value>" + resByPat.getKey() 
     324                            + "</value>"); 
     325 
     326                    System.out.println("<value>" 
     327                            + resByCrit.getKey().getRootToken() + "</value>"); 
     328 
     329                    System.out.println("<value>" 
     330                            + resByPat.getValue().toString() + "</value>"); 
     331 
     332                    System.out.println("<value>" 
     333                            + resByPat.getValue().getResultDate() + "</value>"); 
     334 
     335                    Obs obs = null; 
     336                     
     337                    try 
     338                    { 
     339                        obs = (Obs) resByPat.getValue().getResultObject(); 
     340                    } 
     341                    catch(ClassCastException e) 
     342                    { 
     343                         
     344                    } 
     345                    if (obs != null) { 
     346                        System.out.println("<value>" + obs.getLocation() 
     347                                + "</value>"); 
     348 
     349                        System.out.println("<value>" 
     350                                + obs.getEncounter().getEncounterDatetime() 
     351                                + "</value>"); 
     352 
     353                        System.out.println("<value>" 
     354                                + obs.getEncounter().getEncounterType() 
     355                                + "</value>"); 
     356 
     357                        System.out.println("</row>"); 
     358                    } 
     359 
     360                    System.out.println("</row>"); 
     361 
     362                } 
     363            } 
     364        } 
     365    } 
    225366}