| 27 | | |
|---|
| 28 | | |
|---|
| 29 | | // Logger |
|---|
| 30 | | private static Log log = LogFactory.getLog(LogicWsTest.class); |
|---|
| 31 | | /* |
|---|
| 32 | | |
|---|
| 33 | | @Override |
|---|
| 34 | | protected void onSetUpInTransaction() throws Exception { |
|---|
| 35 | | initializeInMemoryDatabase(); |
|---|
| 36 | | |
|---|
| 37 | | executeDataSet("org/openmrs/module/logicws/test/include/LogicServiceIssue.xml"); |
|---|
| 38 | | |
|---|
| 39 | | authenticate(); |
|---|
| 40 | | } |
|---|
| 41 | | |
|---|
| 42 | | */ |
|---|
| 43 | | |
|---|
| 44 | | @Override |
|---|
| 45 | | protected void onSetUpBeforeTransaction() throws Exception { |
|---|
| 46 | | |
|---|
| 47 | | super.onSetUpBeforeTransaction(); |
|---|
| 48 | | authenticate(); |
|---|
| 49 | | } |
|---|
| 50 | | |
|---|
| 51 | | @Override |
|---|
| 52 | | public Boolean useInMemoryDatabase() { |
|---|
| 53 | | return false; |
|---|
| 54 | | } |
|---|
| 55 | | |
|---|
| 56 | | /** |
|---|
| 57 | | * Public constructor |
|---|
| 58 | | */ |
|---|
| 59 | | public LogicWsTest() |
|---|
| 60 | | { |
|---|
| 61 | | |
|---|
| 62 | | } |
|---|
| 63 | | |
|---|
| 64 | | /** |
|---|
| 65 | | * Tests whether the logic service returns tokens |
|---|
| 66 | | * @throws Exception |
|---|
| 67 | | */ |
|---|
| 68 | | public void testGetTokens() throws Exception |
|---|
| 69 | | { |
|---|
| 70 | | Set<String> tokens = Context.getLogicService().getTokens(); |
|---|
| 71 | | System.out.println("Tokens: " + tokens); |
|---|
| 72 | | |
|---|
| 73 | | } |
|---|
| 74 | | |
|---|
| 75 | | |
|---|
| 76 | | /* |
|---|
| 77 | | public void testAddTokenTags() throws Exception |
|---|
| 78 | | { |
|---|
| 79 | | Context.getLogicService().addTokenTag("AGE", "COMMON"); |
|---|
| 80 | | Context.getLogicService().addTokenTag("GENDER", "COMMON"); |
|---|
| 81 | | Context.getLogicService().addTokenTag("DEATH DATE", "COMMON"); |
|---|
| 82 | | |
|---|
| 83 | | System.out.println(Context.getLogicService().getTokensByTag("COMMON")); |
|---|
| 84 | | |
|---|
| 85 | | System.out.println(Context.getLogicService().getTagsByToken("GENDER")); |
|---|
| 86 | | //Context.getLogicService(). |
|---|
| 87 | | |
|---|
| 88 | | } |
|---|
| 89 | | */ |
|---|
| 90 | | |
|---|
| 91 | | public void testGetCohorts() |
|---|
| 92 | | { |
|---|
| 93 | | |
|---|
| 94 | | for (CohortDefinitionItemHolder c : Context.getCohortService().getAllCohortDefinitions()) |
|---|
| 95 | | { |
|---|
| 96 | | System.out.println("<filter name=\"" + c.getName() + "\" id=\"" + c.getKey() + "\" />"); |
|---|
| 97 | | } |
|---|
| 98 | | } |
|---|
| 99 | | |
|---|
| 100 | | public void testGetTags() throws Exception { |
|---|
| 101 | | Set<String> tags = Context.getLogicService().findTags(""); |
|---|
| 102 | | System.out.println("Tags: " + tags); |
|---|
| 103 | | |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| 106 | | public void testAggregate() |
|---|
| 107 | | { |
|---|
| 108 | | CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("5:org.openmrs.cohort.StaticCohortDefinition"); |
|---|
| 109 | | Cohort patients = Context.getCohortService().evaluate(cohortDefinition, null); |
|---|
| 110 | | |
|---|
| 111 | | LogicService ls = Context.getLogicService(); |
|---|
| 112 | | |
|---|
| 113 | | List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); |
|---|
| 114 | | tokens.add(LogicCriteria.parse("{GENDER}")); |
|---|
| 115 | | //tokens.add(LogicCriteria.parse("LAST {AGE}")); |
|---|
| 116 | | tokens.add(LogicCriteria.parse("{WEIGHT (KG)}")); |
|---|
| 117 | | |
|---|
| 118 | | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| 119 | | try |
|---|
| 120 | | { |
|---|
| 121 | | resultsForTokens = ls.eval(patients, tokens); |
|---|
| 122 | | } |
|---|
| 123 | | catch (LogicException e) |
|---|
| 124 | | { |
|---|
| 125 | | // TODO Auto-generated catch block |
|---|
| 126 | | e.printStackTrace(); |
|---|
| 127 | | } |
|---|
| 128 | | |
|---|
| 129 | | System.out.println(resultsForTokens); |
|---|
| 130 | | } |
|---|
| 131 | | |
|---|
| 132 | | public void testGetStackedData() |
|---|
| 133 | | { |
|---|
| 134 | | CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition("5:org.openmrs.cohort.StaticCohortDefinition"); |
|---|
| 135 | | Cohort patients = Context.getCohortService().evaluate(cohortDefinition, null); |
|---|
| 136 | | |
|---|
| 137 | | LogicService ls = Context.getLogicService(); |
|---|
| 138 | | |
|---|
| 139 | | List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); |
|---|
| 140 | | tokens.add(LogicCriteria.parse("{WEIGHT (KG)}")); |
|---|
| 141 | | tokens.add(LogicCriteria.parse("{AGE}")); |
|---|
| 142 | | tokens.add(LogicCriteria.parse("{HEIGHT (CM)}")); |
|---|
| 143 | | |
|---|
| 144 | | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| 145 | | try |
|---|
| 146 | | { |
|---|
| 147 | | resultsForTokens = ls.eval(patients, tokens); |
|---|
| 148 | | } |
|---|
| 149 | | catch (LogicException e) |
|---|
| 150 | | { |
|---|
| 151 | | // TODO Auto-generated catch block |
|---|
| 152 | | e.printStackTrace(); |
|---|
| 153 | | } |
|---|
| 154 | | |
|---|
| 155 | | String save = ""; |
|---|
| 156 | | |
|---|
| 157 | | for (Map.Entry<LogicCriteria, Map<Integer, Result>> resByCrit : resultsForTokens.entrySet()) |
|---|
| 158 | | { |
|---|
| 159 | | for(Map.Entry<Integer, Result> resByPat : resByCrit.getValue().entrySet()) |
|---|
| 160 | | { |
|---|
| 161 | | |
|---|
| 162 | | if(resByPat.getValue().size() > 0) |
|---|
| 163 | | { |
|---|
| 164 | | for(int i = 0; i < resByPat.getValue().size(); i++) |
|---|
| 165 | | { |
|---|
| 166 | | System.out.println("<row>"); |
|---|
| 167 | | |
|---|
| 168 | | //always print the patient id first |
|---|
| 169 | | System.out.println("<value>" + resByPat.getKey() + "</value>"); |
|---|
| 170 | | |
|---|
| 171 | | System.out.println("<value>" + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| 172 | | |
|---|
| 173 | | System.out.println("<value>" + resByPat.getValue().get(i).toString() + "</value>"); |
|---|
| 174 | | |
|---|
| 175 | | System.out.println("<value>" + resByPat.getValue().get(i).getResultDate() + "</value>"); |
|---|
| 176 | | |
|---|
| 177 | | Obs obs = (Obs) resByPat.getValue().get(i).getResultObject(); |
|---|
| 178 | | System.out.println("<value>" + obs.getLocation() + "</value>"); |
|---|
| 179 | | |
|---|
| 180 | | System.out.println("<value>" + obs.getEncounter().getEncounterDatetime() + "</value>"); |
|---|
| 181 | | |
|---|
| 182 | | System.out.println("<value>" + obs.getEncounter().getEncounterType() + "</value>"); |
|---|
| 183 | | |
|---|
| 184 | | |
|---|
| 185 | | |
|---|
| 186 | | |
|---|
| 187 | | //assertFalse(save.equals(resByPat.getValue().get(i).toString())); |
|---|
| 188 | | save = resByPat.getValue().get(i).toString(); |
|---|
| 189 | | |
|---|
| 190 | | System.out.println("</row>"); |
|---|
| 191 | | } |
|---|
| 192 | | } |
|---|
| 193 | | else |
|---|
| 194 | | { |
|---|
| 195 | | System.out.println("<row>"); |
|---|
| 196 | | |
|---|
| 197 | | //always print the patient id first |
|---|
| 198 | | System.out.println("<value>" + resByPat.getKey() + "</value>"); |
|---|
| 199 | | |
|---|
| 200 | | System.out.println("<value>" + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| 201 | | |
|---|
| 202 | | System.out.println("<value>" + resByPat.getValue().toString() + "</value>"); |
|---|
| 203 | | |
|---|
| 204 | | System.out.println("<value>" + resByPat.getValue().getResultDate() + "</value>"); |
|---|
| 205 | | |
|---|
| 206 | | Obs obs = (Obs) resByPat.getValue().getResultObject(); |
|---|
| 207 | | |
|---|
| 208 | | if(obs != null) |
|---|
| 209 | | { |
|---|
| 210 | | System.out.println("<value>" + obs.getLocation() + "</value>"); |
|---|
| 211 | | |
|---|
| 212 | | |
|---|
| 213 | | |
|---|
| 214 | | System.out.println("<value>" + obs.getEncounter().getEncounterDatetime() + "</value>"); |
|---|
| 215 | | |
|---|
| 216 | | System.out.println("<value>" + obs.getEncounter().getEncounterType() + "</value>"); |
|---|
| 217 | | |
|---|
| 218 | | System.out.println("</row>"); |
|---|
| 219 | | } |
|---|
| 220 | | |
|---|
| 221 | | System.out.println("</row>"); |
|---|
| 222 | | |
|---|
| 223 | | } |
|---|
| 224 | | } |
|---|
| 225 | | } |
|---|
| 226 | | } |
|---|
| | 27 | |
|---|
| | 28 | // Logger |
|---|
| | 29 | private static Log log = LogFactory.getLog(LogicWsTest.class); |
|---|
| | 30 | |
|---|
| | 31 | /* |
|---|
| | 32 | * |
|---|
| | 33 | * @Override protected void onSetUpInTransaction() throws Exception { |
|---|
| | 34 | * initializeInMemoryDatabase(); |
|---|
| | 35 | * |
|---|
| | 36 | * executeDataSet("org/openmrs/module/logicws/test/include/LogicServiceIssue.xml"); |
|---|
| | 37 | * |
|---|
| | 38 | * authenticate(); } |
|---|
| | 39 | * |
|---|
| | 40 | */ |
|---|
| | 41 | |
|---|
| | 42 | @Override |
|---|
| | 43 | protected void onSetUpBeforeTransaction() throws Exception { |
|---|
| | 44 | |
|---|
| | 45 | super.onSetUpBeforeTransaction(); |
|---|
| | 46 | authenticate(); |
|---|
| | 47 | } |
|---|
| | 48 | |
|---|
| | 49 | @Override |
|---|
| | 50 | public Boolean useInMemoryDatabase() { |
|---|
| | 51 | return false; |
|---|
| | 52 | } |
|---|
| | 53 | |
|---|
| | 54 | /** |
|---|
| | 55 | * Public constructor |
|---|
| | 56 | */ |
|---|
| | 57 | public LogicWsTest() { |
|---|
| | 58 | |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | /** |
|---|
| | 62 | * Tests whether the logic service returns tokens |
|---|
| | 63 | * |
|---|
| | 64 | * @throws Exception |
|---|
| | 65 | */ |
|---|
| | 66 | public void testGetTokens() throws Exception { |
|---|
| | 67 | Set<String> tokens = Context.getLogicService().getTokens(); |
|---|
| | 68 | System.out.println("Tokens: " + tokens); |
|---|
| | 69 | |
|---|
| | 70 | } |
|---|
| | 71 | |
|---|
| | 72 | /* |
|---|
| | 73 | * public void testAddTokenTags() throws Exception { |
|---|
| | 74 | * Context.getLogicService().addTokenTag("AGE", "COMMON"); |
|---|
| | 75 | * Context.getLogicService().addTokenTag("GENDER", "COMMON"); |
|---|
| | 76 | * Context.getLogicService().addTokenTag("DEATH DATE", "COMMON"); |
|---|
| | 77 | * |
|---|
| | 78 | * System.out.println(Context.getLogicService().getTokensByTag("COMMON")); |
|---|
| | 79 | * |
|---|
| | 80 | * System.out.println(Context.getLogicService().getTagsByToken("GENDER")); |
|---|
| | 81 | * //Context.getLogicService(). |
|---|
| | 82 | * } |
|---|
| | 83 | */ |
|---|
| | 84 | |
|---|
| | 85 | public void testGetCohorts() { |
|---|
| | 86 | |
|---|
| | 87 | for (CohortDefinitionItemHolder c : Context.getCohortService() |
|---|
| | 88 | .getAllCohortDefinitions()) { |
|---|
| | 89 | System.out.println("<filter name=\"" + c.getName() + "\" id=\"" |
|---|
| | 90 | + c.getKey() + "\" />"); |
|---|
| | 91 | } |
|---|
| | 92 | } |
|---|
| | 93 | |
|---|
| | 94 | public void testGetTags() throws Exception { |
|---|
| | 95 | Set<String> tags = Context.getLogicService().findTags(""); |
|---|
| | 96 | System.out.println("Tags: " + tags); |
|---|
| | 97 | |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | public void testAggregate() { |
|---|
| | 101 | CohortDefinition cohortDefinition = Context.getCohortService() |
|---|
| | 102 | .getCohortDefinition( |
|---|
| | 103 | "5:org.openmrs.cohort.StaticCohortDefinition"); |
|---|
| | 104 | Cohort patients = Context.getCohortService().evaluate(cohortDefinition, |
|---|
| | 105 | null); |
|---|
| | 106 | |
|---|
| | 107 | LogicService ls = Context.getLogicService(); |
|---|
| | 108 | |
|---|
| | 109 | List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); |
|---|
| | 110 | tokens.add(LogicCriteria.parse("{GENDER}")); |
|---|
| | 111 | // tokens.add(LogicCriteria.parse("LAST {AGE}")); |
|---|
| | 112 | tokens.add(LogicCriteria.parse("{WEIGHT (KG)}")); |
|---|
| | 113 | |
|---|
| | 114 | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| | 115 | try { |
|---|
| | 116 | resultsForTokens = ls.eval(patients, tokens); |
|---|
| | 117 | } catch (LogicException e) { |
|---|
| | 118 | // TODO Auto-generated catch block |
|---|
| | 119 | e.printStackTrace(); |
|---|
| | 120 | } |
|---|
| | 121 | |
|---|
| | 122 | System.out.println(resultsForTokens); |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | public void testGetStackedData() { |
|---|
| | 126 | CohortDefinition cohortDefinition = Context.getCohortService() |
|---|
| | 127 | .getCohortDefinition( |
|---|
| | 128 | "5:org.openmrs.cohort.StaticCohortDefinition"); |
|---|
| | 129 | Cohort patients = Context.getCohortService().evaluate(cohortDefinition, |
|---|
| | 130 | null); |
|---|
| | 131 | |
|---|
| | 132 | LogicService ls = Context.getLogicService(); |
|---|
| | 133 | |
|---|
| | 134 | List<LogicCriteria> tokens = new ArrayList<LogicCriteria>(); |
|---|
| | 135 | tokens.add(LogicCriteria.parse("{WEIGHT (KG)}")); |
|---|
| | 136 | tokens.add(LogicCriteria.parse("{AGE}")); |
|---|
| | 137 | tokens.add(LogicCriteria.parse("{HEIGHT (CM)}")); |
|---|
| | 138 | |
|---|
| | 139 | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| | 140 | try { |
|---|
| | 141 | resultsForTokens = ls.eval(patients, tokens); |
|---|
| | 142 | } catch (LogicException e) { |
|---|
| | 143 | // TODO Auto-generated catch block |
|---|
| | 144 | e.printStackTrace(); |
|---|
| | 145 | } |
|---|
| | 146 | |
|---|
| | 147 | String save = ""; |
|---|
| | 148 | |
|---|
| | 149 | for (Map.Entry<LogicCriteria, Map<Integer, Result>> resByCrit : resultsForTokens |
|---|
| | 150 | .entrySet()) { |
|---|
| | 151 | for (Map.Entry<Integer, Result> resByPat : resByCrit.getValue() |
|---|
| | 152 | .entrySet()) { |
|---|
| | 153 | |
|---|
| | 154 | if (resByPat.getValue().size() > 0) { |
|---|
| | 155 | for (int i = 0; i < resByPat.getValue().size(); i++) { |
|---|
| | 156 | System.out.println("<row>"); |
|---|
| | 157 | |
|---|
| | 158 | // always print the patient id first |
|---|
| | 159 | System.out.println("<value>" + resByPat.getKey() |
|---|
| | 160 | + "</value>"); |
|---|
| | 161 | |
|---|
| | 162 | System.out.println("<value>" |
|---|
| | 163 | + resByCrit.getKey().getRootToken() |
|---|
| | 164 | + "</value>"); |
|---|
| | 165 | |
|---|
| | 166 | System.out.println("<value>" |
|---|
| | 167 | + resByPat.getValue().get(i).toString() |
|---|
| | 168 | + "</value>"); |
|---|
| | 169 | |
|---|
| | 170 | System.out.println("<value>" |
|---|
| | 171 | + resByPat.getValue().get(i).getResultDate() |
|---|
| | 172 | + "</value>"); |
|---|
| | 173 | |
|---|
| | 174 | Obs obs = (Obs) resByPat.getValue().get(i) |
|---|
| | 175 | .getResultObject(); |
|---|
| | 176 | System.out.println("<value>" + obs.getLocation() |
|---|
| | 177 | + "</value>"); |
|---|
| | 178 | |
|---|
| | 179 | System.out.println("<value>" |
|---|
| | 180 | + obs.getEncounter().getEncounterDatetime() |
|---|
| | 181 | + "</value>"); |
|---|
| | 182 | |
|---|
| | 183 | System.out.println("<value>" |
|---|
| | 184 | + obs.getEncounter().getEncounterType() |
|---|
| | 185 | + "</value>"); |
|---|
| | 186 | |
|---|
| | 187 | // assertFalse(save.equals(resByPat.getValue().get(i).toString())); |
|---|
| | 188 | save = resByPat.getValue().get(i).toString(); |
|---|
| | 189 | |
|---|
| | 190 | System.out.println("</row>"); |
|---|
| | 191 | } |
|---|
| | 192 | } else { |
|---|
| | 193 | System.out.println("<row>"); |
|---|
| | 194 | |
|---|
| | 195 | // always print the patient id first |
|---|
| | 196 | System.out.println("<value>" + resByPat.getKey() |
|---|
| | 197 | + "</value>"); |
|---|
| | 198 | |
|---|
| | 199 | System.out.println("<value>" |
|---|
| | 200 | + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| | 201 | |
|---|
| | 202 | System.out.println("<value>" |
|---|
| | 203 | + resByPat.getValue().toString() + "</value>"); |
|---|
| | 204 | |
|---|
| | 205 | System.out.println("<value>" |
|---|
| | 206 | + resByPat.getValue().getResultDate() + "</value>"); |
|---|
| | 207 | |
|---|
| | 208 | Obs obs = (Obs) resByPat.getValue().getResultObject(); |
|---|
| | 209 | |
|---|
| | 210 | if (obs != null) { |
|---|
| | 211 | System.out.println("<value>" + obs.getLocation() |
|---|
| | 212 | + "</value>"); |
|---|
| | 213 | |
|---|
| | 214 | System.out.println("<value>" |
|---|
| | 215 | + obs.getEncounter().getEncounterDatetime() |
|---|
| | 216 | + "</value>"); |
|---|
| | 217 | |
|---|
| | 218 | System.out.println("<value>" |
|---|
| | 219 | + obs.getEncounter().getEncounterType() |
|---|
| | 220 | + "</value>"); |
|---|
| | 221 | |
|---|
| | 222 | System.out.println("</row>"); |
|---|
| | 223 | } |
|---|
| | 224 | |
|---|
| | 225 | System.out.println("</row>"); |
|---|
| | 226 | |
|---|
| | 227 | } |
|---|
| | 228 | } |
|---|
| | 229 | } |
|---|
| | 230 | } |
|---|