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 287 287 this.separator = separator; 288 288 } 289 289 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; 292 292 } 293 293 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; 296 296 } 297 297 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; 300 300 } 301 301 302 protected Boolean getCohortHelper(String key , EvaluationContext context) {302 protected Boolean getCohortHelper(String key) { 303 303 if (cohortMap.containsKey(key)) 304 304 return cohortMap.get(key).contains(getPatientId()); 305 305 306 //TODO try to cache the evaluation context 307 EvaluationContext context = new EvaluationContext(); 308 306 309 log.debug("getting cohort/definition for key: " + key); 307 310 //PatientSet ps = null; 308 311 Cohort ps = null; -
test/api/org/openmrs/reporting/export/DataExportTest.java
old new 22 22 23 23 import org.junit.Test; 24 24 import org.openmrs.Cohort; 25 import org.openmrs.api.context.Context; 25 26 import org.openmrs.test.BaseContextSensitiveTest; 26 27 import org.openmrs.util.OpenmrsUtil; 27 28 … … 571 572 assertEquals("The output is not right.", expectedOutput, output); 572 573 573 574 } 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 } 574 611 }
Download in other formats:
Powered by Trac 0.10.5
By Edgewall Software.
Visit the Trac open source project at
http://trac.edgewall.com/