Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Ticket #1166: 1166.patch

File 1166.patch, 3.9 kB (added by djazayeri, 1 year ago)
  • src/api/org/openmrs/reporting/export/DataExportFunctions.java

    old new  
    287287                this.separator = separator; 
    288288        } 
    289289         
    290         public String getCohortMembership(Integer cohortId, String valueIfTrue, String valueIfFalse, EvaluationContext context) { 
    291                 return getCohortHelper("C." + cohortId, context) ? valueIfTrue : valueIfFalse; 
     290        public String getCohortMembership(Integer cohortId, String valueIfTrue, String valueIfFalse) { 
     291                return getCohortHelper("C." + cohortId) ? valueIfTrue : valueIfFalse; 
    292292        } 
    293293         
    294         public String getCohortDefinitionMembership(Integer filterId, String valueIfTrue, String valueIfFalse, EvaluationContext context) { 
    295                 return getCohortHelper("F." + filterId, context) ? valueIfTrue : valueIfFalse; 
     294        public String getCohortDefinitionMembership(Integer filterId, String valueIfTrue, String valueIfFalse) { 
     295                return getCohortHelper("F." + filterId) ? valueIfTrue : valueIfFalse; 
    296296        } 
    297297         
    298         public String getPatientSearchMembership(Integer searchId, String valueIfTrue, String valueIfFalse, EvaluationContext context) { 
    299                 return getCohortHelper("S." + searchId, context) ? valueIfTrue : valueIfFalse; 
     298        public String getPatientSearchMembership(Integer searchId, String valueIfTrue, String valueIfFalse) { 
     299                return getCohortHelper("S." + searchId) ? valueIfTrue : valueIfFalse; 
    300300        } 
    301301         
    302         protected Boolean getCohortHelper(String key, EvaluationContext context) { 
     302        protected Boolean getCohortHelper(String key) { 
    303303                if (cohortMap.containsKey(key)) 
    304304                        return cohortMap.get(key).contains(getPatientId()); 
    305305                 
     306                //TODO try to cache the evaluation context 
     307                EvaluationContext context = new EvaluationContext(); 
     308                 
    306309                log.debug("getting cohort/definition for key: " + key); 
    307310                //PatientSet ps = null; 
    308311                Cohort ps = null; 
  • test/api/org/openmrs/reporting/export/DataExportTest.java

    old new  
    2222 
    2323import org.junit.Test; 
    2424import org.openmrs.Cohort; 
     25import org.openmrs.api.context.Context; 
    2526import org.openmrs.test.BaseContextSensitiveTest; 
    2627import org.openmrs.util.OpenmrsUtil; 
    2728 
     
    571572                assertEquals("The output is not right.", expectedOutput, output); 
    572573                 
    573574        } 
     575         
     576        @Test 
     577        public void cohortColumnsShouldWork() throws Exception { 
     578                // First create a cohort. TODO maybe move this to xml 
     579                Cohort cohort = new Cohort(); 
     580                cohort.setName("A Cohort"); 
     581                cohort.setDescription("Just for testing"); 
     582                cohort.addMember(2); 
     583                cohort = Context.getCohortService().saveCohort(cohort); 
     584                 
     585                DataExportReportObject export = new DataExportReportObject(); 
     586                export.setName("Cohort column"); 
     587                 
     588                SimpleColumn patientId = new SimpleColumn("PATIENT_ID", "$!{fn.patientId}"); 
     589                export.getColumns().add(patientId); 
     590                 
     591                CohortColumn cohortCol = new CohortColumn("InCohort", cohort.getCohortId(), null, null, "Yes", "No"); 
     592                export.getColumns().add(cohortCol); 
     593                         
     594                // set the cohort to two patients, one of which is in the specified cohort 
     595                Cohort patients = new Cohort(); 
     596                patients.addMember(2); 
     597                patients.addMember(6); 
     598                 
     599                System.out.println("Template String: \n" + export.generateTemplate()); 
     600                 
     601                DataExportUtil.generateExport(export, patients, "\t", null); 
     602                File exportFile = DataExportUtil.getGeneratedFile(export); 
     603                 
     604                String expectedOutput = "PATIENT_ID\tInCohort\n2\tYes\n6\tNo\n"; 
     605                String output = OpenmrsUtil.getFileAsString(exportFile); 
     606                exportFile.delete(); 
     607                 
     608                //System.out.println("exportFile: \n" + output); 
     609                assertEquals("The output is not right.", expectedOutput, output); 
     610        } 
    574611}