| | 125 | /** |
|---|
| | 126 | * Auto generated method comment |
|---|
| | 127 | * |
|---|
| | 128 | * @param definitionClass |
|---|
| | 129 | * @return |
|---|
| | 130 | * @throws APIException |
|---|
| | 131 | */ |
|---|
| | 132 | private CohortDefinitionProvider getCohortDefinitionProvider(Class<? extends CohortDefinition> definitionClass) throws APIException { |
|---|
| | 133 | CohortDefinitionProvider ret = cohortDefinitionProviders.get(definitionClass); |
|---|
| | 134 | if (ret == null) |
|---|
| | 135 | throw new APIException("No CohortDefinitionProvider registered for " + definitionClass); |
|---|
| | 136 | else |
|---|
| | 137 | return ret; |
|---|
| | 138 | } |
|---|
| | 139 | |
|---|
| | 140 | /** |
|---|
| | 141 | * @see org.openmrs.api.CohortService#evaluate(org.openmrs.cohort.CohortDefinition, org.openmrs.report.EvaluationContext) |
|---|
| | 142 | */ |
|---|
| | 143 | public Cohort evaluate(CohortDefinition definition, EvaluationContext evalContext) throws APIException { |
|---|
| | 144 | CohortDefinitionProvider provider = getCohortDefinitionProvider(definition.getClass()); |
|---|
| | 145 | return provider.evaluate(definition, evalContext); |
|---|
| | 146 | } |
|---|
| | 147 | |
|---|
| | 148 | |
|---|
| | 149 | |
|---|
| | 150 | /** |
|---|
| | 151 | * @see org.openmrs.api.CohortService#getAllPatientsCohortDefinition() |
|---|
| | 152 | */ |
|---|
| | 153 | public CohortDefinition getAllPatientsCohortDefinition() { |
|---|
| | 154 | PatientSearch ps = new PatientSearch(); |
|---|
| | 155 | ps.setFilterClass(PatientCharacteristicFilter.class); |
|---|
| | 156 | return ps; |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| | 159 | /** |
|---|
| | 160 | * @see org.openmrs.api.CohortService#getCohortDefinition(java.lang.Class, java.lang.Integer) |
|---|
| | 161 | */ |
|---|
| | 162 | public CohortDefinition getCohortDefinition(Class<CohortDefinition> clazz, Integer id) { |
|---|
| | 163 | CohortDefinitionProvider provider = getCohortDefinitionProvider(clazz); |
|---|
| | 164 | return provider.getCohortDefinition(id); |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | /** |
|---|
| | 168 | * @see org.openmrs.api.CohortService#getCohortDefinitions() |
|---|
| | 169 | */ |
|---|
| | 170 | public List<CohortDefinition> getAllCohortDefinitions() { |
|---|
| | 171 | List<CohortDefinition> ret = new ArrayList<CohortDefinition>(); |
|---|
| | 172 | for (CohortDefinitionProvider p : cohortDefinitionProviders.values()) { |
|---|
| | 173 | ret.addAll(p.getAllCohortDefinitions()); |
|---|
| | 174 | } |
|---|
| | 175 | return ret; |
|---|
| | 176 | } |
|---|
| | 177 | |
|---|
| | 178 | /** |
|---|
| | 179 | * @see org.openmrs.api.CohortService#purgeCohortDefinition(org.openmrs.cohort.CohortDefinition) |
|---|
| | 180 | */ |
|---|
| | 181 | public void purgeCohortDefinition(CohortDefinition definition) { |
|---|
| | 182 | CohortDefinitionProvider provider = getCohortDefinitionProvider(definition.getClass()); |
|---|
| | 183 | provider.purgeCohortDefinition(definition); |
|---|
| | 184 | } |
|---|
| | 185 | |
|---|
| | 186 | /** |
|---|
| | 187 | * @see org.openmrs.api.CohortService#setCohortDefinitionProviders(Map) |
|---|
| | 188 | */ |
|---|
| | 189 | public void setCohortDefinitionProviders(Map<Class<? extends CohortDefinition>, CohortDefinitionProvider> providerClassMap) { |
|---|
| | 190 | for (Map.Entry<Class<? extends CohortDefinition>, CohortDefinitionProvider> entry : providerClassMap.entrySet()) { |
|---|
| | 191 | registerCohortDefinitionProvider(entry.getKey(), entry.getValue()); |
|---|
| | 192 | } |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|
| | 195 | /** |
|---|
| | 196 | * @see org.openmrs.api.CohortService#getCohortDefinitionProviders() |
|---|
| | 197 | */ |
|---|
| | 198 | public Map<Class<? extends CohortDefinition>, CohortDefinitionProvider> getCohortDefinitionProviders() { |
|---|
| | 199 | if (cohortDefinitionProviders == null) |
|---|
| | 200 | cohortDefinitionProviders = new LinkedHashMap<Class<? extends CohortDefinition>, CohortDefinitionProvider>(); |
|---|
| | 201 | |
|---|
| | 202 | return cohortDefinitionProviders; |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | /** |
|---|
| | 206 | * @see org.openmrs.api.CohortService#registerCohortDefinitionProvider(java.lang.Class, org.openmrs.api.CohortDefinitionService) |
|---|
| | 207 | */ |
|---|
| | 208 | public void registerCohortDefinitionProvider(Class<? extends CohortDefinition> defClass, CohortDefinitionProvider cohortDefProvider) throws APIException { |
|---|
| | 209 | getCohortDefinitionProviders().put(defClass, cohortDefProvider); |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | /** |
|---|
| | 213 | * @see org.openmrs.api.CohortService#removeCohortDefinitionProvider(java.lang.Class) |
|---|
| | 214 | */ |
|---|
| | 215 | public void removeCohortDefinitionProvider(Class<? extends CohortDefinitionProvider> providerClass) { |
|---|
| | 216 | |
|---|
| | 217 | // TODO: should this be looking through the values or the keys? |
|---|
| | 218 | for (Iterator<CohortDefinitionProvider> i = cohortDefinitionProviders.values().iterator(); i.hasNext(); ) { |
|---|
| | 219 | if (i.next().getClass().equals(providerClass)) |
|---|
| | 220 | i.remove(); |
|---|
| | 221 | } |
|---|
| | 222 | } |
|---|
| | 223 | |
|---|
| | 224 | /** |
|---|
| | 225 | * @see org.openmrs.api.CohortService#saveCohortDefinition(org.openmrs.cohort.CohortDefinition) |
|---|
| | 226 | */ |
|---|
| | 227 | public CohortDefinition saveCohortDefinition(CohortDefinition definition) throws APIException { |
|---|
| | 228 | CohortDefinitionProvider provider = getCohortDefinitionProvider(definition.getClass()); |
|---|
| | 229 | return provider.saveCohortDefinition(definition); |
|---|
| | 230 | } |
|---|
| | 231 | |
|---|
| | 232 | /** |
|---|
| | 233 | * @see org.openmrs.api.CohortService#getCohortDefinitions(java.lang.Class) |
|---|
| | 234 | */ |
|---|
| | 235 | public List<CohortDefinition> getCohortDefinitions(Class providerClass) { |
|---|
| | 236 | CohortDefinitionProvider provider = getCohortDefinitionProvider(providerClass); |
|---|
| | 237 | return provider.getAllCohortDefinitions(); |
|---|
| | 238 | } |
|---|