| 73 | | out.print("<column token=\"" + t + "\" />"); |
|---|
| 74 | | |
|---|
| 75 | | /* |
|---|
| 76 | | out.print("<column token=\"" + t + "_OBSERVATIONDATE\" />"); |
|---|
| 77 | | out.print("<column token=\"" + t + "_OBSERVATIONLOCATION\" />"); |
|---|
| 78 | | out.print("<column token=\"" + t + "_ENCOUNTERTYPE\" />"); |
|---|
| 79 | | out.print("<column token=\"" + t + "_ENCOUNTERDATE\" />"); |
|---|
| 80 | | */ |
|---|
| 81 | | } |
|---|
| 82 | | out.print("</columns>"); |
|---|
| 83 | | |
|---|
| 84 | | // List rows |
|---|
| 85 | | out.print("<rows>"); |
|---|
| 86 | | |
|---|
| 87 | | Cohort patients; |
|---|
| 88 | | LogicService ls = Context.getLogicService(); |
|---|
| 89 | | |
|---|
| 90 | | try { |
|---|
| 91 | | |
|---|
| 92 | | CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition(filter); |
|---|
| 93 | | patients = Context.getCohortService().evaluate(cohortDefinition, null); |
|---|
| 94 | | |
|---|
| 95 | | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| 96 | | try |
|---|
| | 74 | out.print("<column token=\"KEY\" />"); |
|---|
| | 75 | log.info("<column token=\"KEY\" />"); |
|---|
| | 76 | |
|---|
| | 77 | out.print("<column token=\"VALUE\" />"); |
|---|
| | 78 | log.info("<column token=\"VALUE\" />"); |
|---|
| | 79 | |
|---|
| | 80 | out.print("</columns>"); |
|---|
| | 81 | log.info("</columns>"); |
|---|
| | 82 | |
|---|
| | 83 | // List rows |
|---|
| | 84 | out.print("<rows>"); |
|---|
| | 85 | log.info("<rows>"); |
|---|
| | 86 | |
|---|
| | 87 | Cohort patients; |
|---|
| | 88 | LogicService ls = Context.getLogicService(); |
|---|
| | 89 | |
|---|
| | 90 | try { |
|---|
| | 91 | |
|---|
| | 92 | CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition(filter); |
|---|
| | 93 | patients = Context.getCohortService().evaluate(cohortDefinition, null); |
|---|
| | 94 | |
|---|
| | 95 | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| | 96 | try |
|---|
| | 97 | { |
|---|
| | 98 | resultsForTokens = ls.eval(patients, tokens); |
|---|
| | 99 | } |
|---|
| | 100 | catch (LogicException e) |
|---|
| | 101 | { |
|---|
| | 102 | // TODO Auto-generated catch block |
|---|
| | 103 | e.printStackTrace(); |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | for (Map.Entry<LogicCriteria, Map<Integer, Result>> resByCrit : resultsForTokens.entrySet()) |
|---|
| | 107 | { |
|---|
| | 108 | for(Map.Entry<Integer, Result> resByPat : resByCrit.getValue().entrySet()) |
|---|
| | 109 | { |
|---|
| | 110 | if(resByPat.getValue().size() > 0) |
|---|
| | 111 | { |
|---|
| | 112 | for(int i = 0; i < resByPat.getValue().size(); i++) |
|---|
| | 113 | { |
|---|
| | 114 | out.print("<row>"); |
|---|
| | 115 | log.info("<row>"); |
|---|
| | 116 | |
|---|
| | 117 | //always print the patient id first |
|---|
| | 118 | out.print("<value>" + resByPat.getKey() + "</value>"); |
|---|
| | 119 | log.info("<value>" + resByPat.getKey() + "</value>"); |
|---|
| | 120 | |
|---|
| | 121 | out.print("<value>" + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| | 122 | log.info("<value>" + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| | 123 | |
|---|
| | 124 | out.print("<value>" + resByPat.getValue().get(i).toString() + "</value>"); |
|---|
| | 125 | log.info("<value>" + resByPat.getValue().get(i).toString() + "</value>"); |
|---|
| | 126 | |
|---|
| | 127 | out.print("</row>"); |
|---|
| | 128 | log.info("</row>"); |
|---|
| | 129 | } |
|---|
| | 130 | } |
|---|
| | 131 | else |
|---|
| | 132 | { |
|---|
| | 133 | out.print("<row>"); |
|---|
| | 134 | log.info("<row>"); |
|---|
| | 135 | |
|---|
| | 136 | //always print the patient id first |
|---|
| | 137 | out.print("<value>" + resByPat.getKey() + "</value>"); |
|---|
| | 138 | log.info("<value>" + resByPat.getKey() + "</value>"); |
|---|
| | 139 | |
|---|
| | 140 | out.print("<value>" + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| | 141 | log.info("<value>" + resByCrit.getKey().getRootToken() + "</value>"); |
|---|
| | 142 | |
|---|
| | 143 | out.print("<value>" + resByPat.getValue().toString() + "</value>"); |
|---|
| | 144 | log.info("<value>" + resByPat.getValue().toString() + "</value>"); |
|---|
| | 145 | |
|---|
| | 146 | out.print("</row>"); |
|---|
| | 147 | log.info("</row>"); |
|---|
| | 148 | |
|---|
| | 149 | } |
|---|
| | 150 | |
|---|
| | 151 | } |
|---|
| | 152 | |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | out.print("</rows>"); |
|---|
| | 156 | log.info("</rows>"); |
|---|
| | 157 | |
|---|
| | 158 | out.print("</dataset>"); |
|---|
| | 159 | log.info("<rows>"); |
|---|
| | 160 | |
|---|
| | 161 | break; |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | catch (org.openmrs.api.APIAuthenticationException e) |
|---|
| 102 | | // TODO Auto-generated catch block |
|---|
| 103 | | e.printStackTrace(); |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| 106 | | for (Integer patient: patients.getMemberIds()) |
|---|
| 107 | | { |
|---|
| 108 | | out.print("<row>"); |
|---|
| 109 | | for (LogicCriteria token: tokens) |
|---|
| 110 | | { |
|---|
| 111 | | Result res = resultsForTokens.get(token).get(patient); |
|---|
| 112 | | |
|---|
| 113 | | out.print("<value>" + res + "</value>"); |
|---|
| 114 | | |
|---|
| 115 | | /* |
|---|
| 116 | | Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|---|
| 117 | | |
|---|
| 118 | | |
|---|
| 119 | | //get the Obs from the result |
|---|
| 120 | | Obs obs = (Obs)res.toObject(); |
|---|
| 121 | | |
|---|
| 122 | | if(obs == null) |
|---|
| | 176 | out.print("<column token=\"" + t + "\" />"); |
|---|
| | 177 | log.info("<column token=\"" + t + "\" />"); |
|---|
| | 178 | |
|---|
| | 179 | /* |
|---|
| | 180 | out.print("<column token=\"" + t + "_OBSERVATIONDATE\" />"); |
|---|
| | 181 | out.print("<column token=\"" + t + "_OBSERVATIONLOCATION\" />"); |
|---|
| | 182 | out.print("<column token=\"" + t + "_ENCOUNTERTYPE\" />"); |
|---|
| | 183 | out.print("<column token=\"" + t + "_ENCOUNTERDATE\" />"); |
|---|
| | 184 | */ |
|---|
| | 185 | } |
|---|
| | 186 | out.print("</columns>"); |
|---|
| | 187 | log.info("</columns>"); |
|---|
| | 188 | |
|---|
| | 189 | // List rows |
|---|
| | 190 | out.print("<rows>"); |
|---|
| | 191 | log.info("<rows>"); |
|---|
| | 192 | |
|---|
| | 193 | Cohort patients; |
|---|
| | 194 | LogicService ls = Context.getLogicService(); |
|---|
| | 195 | |
|---|
| | 196 | try { |
|---|
| | 197 | |
|---|
| | 198 | CohortDefinition cohortDefinition = Context.getCohortService().getCohortDefinition(filter); |
|---|
| | 199 | patients = Context.getCohortService().evaluate(cohortDefinition, null); |
|---|
| | 200 | |
|---|
| | 201 | Map<LogicCriteria, Map<Integer, Result>> resultsForTokens = null; |
|---|
| | 202 | try |
|---|
| | 203 | { |
|---|
| | 204 | resultsForTokens = ls.eval(patients, tokens); |
|---|
| | 205 | } |
|---|
| | 206 | catch (LogicException e) |
|---|
| | 207 | { |
|---|
| | 208 | // TODO Auto-generated catch block |
|---|
| | 209 | e.printStackTrace(); |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | for (Integer patient: patients.getMemberIds()) |
|---|
| | 213 | { |
|---|
| | 214 | out.print("<row>"); |
|---|
| | 215 | log.info("<row>"); |
|---|
| | 216 | |
|---|
| | 217 | //always print the patient id first |
|---|
| | 218 | out.print("<value>" + patient + "</value>"); |
|---|
| | 219 | log.info("<value>" + patient + "</value>"); |
|---|
| | 220 | |
|---|
| | 221 | for (LogicCriteria token: tokens) |
|---|