- Timestamp:
- 05/11/08 23:52:52 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/complex_obs/src/api/org/openmrs/api/ObsService.java
r3847 r4166 14 14 package org.openmrs.api; 15 15 16 import java.util.Collection; 16 17 import java.util.Date; 17 18 import java.util.List; 19 import java.util.Map; 18 20 import java.util.Set; 19 21 … … 28 30 import org.openmrs.logic.Aggregation; 29 31 import org.openmrs.logic.Constraint; 32 import org.openmrs.obs.ComplexData; 33 import org.openmrs.obs.ComplexObsHandler; 30 34 import org.openmrs.reporting.PatientSet; 31 35 import org.openmrs.util.OpenmrsConstants; … … 33 37 34 38 /** 35 * The ObsService provides methods for acting on Obs, ObsGroup, and 36 * ComplexObsobjects.39 * The ObsService provides methods for acting on Obs, ObsGroup, and ComplexObs 40 * objects. 37 41 * 38 * Use: 39 * <code> 42 * Use: <code> 40 43 * Context.getObsService().getObs(123); 41 44 * </code> 42 45 * 43 * There are also a number of convenience methods for extracting obs 44 * pertainingto certain Concepts, people, or encounters46 * There are also a number of convenience methods for extracting obs pertaining 47 * to certain Concepts, people, or encounters 45 48 * 46 49 */ 47 50 @Transactional 48 51 public interface ObsService { 49 52 50 53 public static final Integer PERSON = 1; 51 54 public static final Integer PATIENT = 2; 52 55 public static final Integer USER = 4; 53 56 54 57 public void setObsDAO(ObsDAO dao); 55 58 … … 60 63 * @throws APIException 61 64 */ 62 @Authorized( {OpenmrsConstants.PRIV_ADD_OBS})65 @Authorized( { OpenmrsConstants.PRIV_ADD_OBS }) 63 66 public void createObs(Obs obs) throws APIException; 64 67 65 68 /** 66 69 * Create a grouping of observations (observations linked by … … 68 71 * 69 72 * The proper use is: 73 * 70 74 * <pre> 71 75 * Obs obsGroup = new Obs(); … … 78 82 * @param obs array of observations to be grouped 79 83 * @throws APIException 80 * @deprecated This method should no longer need to be called on the api. This81 * was meant as temporary until we created a true ObsGroup pojo.82 * Replaced by {@link #createObsGroup(Obs, List)}84 * @deprecated This method should no longer need to be called on the api. 85 * This was meant as temporary until we created a true ObsGroup 86 * pojo. Replaced by {@link #createObsGroup(Obs, List)} 83 87 * 84 88 * @see #createObsGroup(Obs, List) 85 89 */ 86 @Authorized( {OpenmrsConstants.PRIV_ADD_OBS})90 @Authorized( { OpenmrsConstants.PRIV_ADD_OBS }) 87 91 public void createObsGroup(Obs[] obs) throws APIException; 88 92 … … 90 94 * Get an observation 91 95 * 92 * @param integer 93 * obsId of observation desired 96 * @param integer obsId of observation desired 94 97 * @return matching Obs 95 98 * @throws APIException 96 99 */ 97 100 @Transactional(readOnly = true) 98 @Authorized( {OpenmrsConstants.PRIV_VIEW_OBS})101 @Authorized( { OpenmrsConstants.PRIV_VIEW_OBS }) 99 102 public Obs getObs(Integer obsId) throws APIException; 100 103 101 104 /** 105 * Get a complex observation. If obs.isComplex() is true, then returns an 106 * Obs with its ComplexData. Otherwise returns a simple Obs. 107 * 108 * @param obsId 109 * @return Obs with a ComplexData 110 */ 111 @Transactional(readOnly = true) 112 @Authorized( { OpenmrsConstants.PRIV_VIEW_OBS }) 113 public Obs getComplexObs(Integer obsId) throws APIException; 114 115 /** 116 * Get the ComplexData for an Obs. If obs.isComplex() is false, then returns 117 * null. 118 * 119 * @param obsId 120 * @return 121 */ 122 @Transactional(readOnly = true) 123 @Authorized( { OpenmrsConstants.PRIV_VIEW_OBS }) 124 public ComplexData getComplexData(Integer obsId) throws APIException; 125 126 /** 102 127 * Save changes to observation 103 128 * … … 105 130 * @throws APIException 106 131 */ 107 @Authorized( {OpenmrsConstants.PRIV_EDIT_OBS})132 @Authorized( { OpenmrsConstants.PRIV_EDIT_OBS }) 108 133 public void updateObs(Obs obs) throws APIException; 109 134 … … 111 136 * Equivalent to deleting an observation 112 137 * 138 * @param Obs obs to void 139 * @param String reason 140 * @throws APIException 141 */ 142 @Authorized( { OpenmrsConstants.PRIV_EDIT_OBS }) 143 public void voidObs(Obs obs, String reason) throws APIException; 144 145 /** 146 * Revive an observation (pull a Lazarus) 147 * 113 148 * @param Obs 114 * obs to void 115 * @param String 116 * reason 117 * @throws APIException 118 */ 119 @Authorized({OpenmrsConstants.PRIV_EDIT_OBS}) 120 public void voidObs(Obs obs, String reason) throws APIException; 121 122 /** 123 * Revive an observation (pull a Lazarus) 149 * @throws APIException 150 */ 151 @Authorized( { OpenmrsConstants.PRIV_EDIT_OBS }) 152 public void unvoidObs(Obs obs) throws APIException; 153 154 /** 155 * Delete an observation. SHOULD NOT BE CALLED unless caller is lower-level. 124 156 * 125 157 * @param Obs 126 158 * @throws APIException 127 */128 @Authorized({OpenmrsConstants.PRIV_EDIT_OBS})129 public void unvoidObs(Obs obs) throws APIException;130 131 /**132 * Delete an observation. SHOULD NOT BE CALLED unless caller is lower-level.133 *134 * @param Obs135 * @throws APIException136 159 * @see voidObs(Obs) 137 160 */ 138 @Authorized( {OpenmrsConstants.PRIV_DELETE_OBS})161 @Authorized( { OpenmrsConstants.PRIV_DELETE_OBS }) 139 162 public void deleteObs(Obs obs) throws APIException; 140 163 141 164 /** 142 165 * Get all mime types … … 151 174 * Get mimeType by internal identifier 152 175 * 153 * @param mimeType 154 * id 176 * @param mimeType id 155 177 * @return mimeType with given internal identifier 156 178 * @throws APIException … … 180 202 */ 181 203 @Transactional(readOnly = true) 182 public List<Obs> getObservations(Concept c, Location loc, String sort, Integer personType, boolean includeVoided); 204 public List<Obs> getObservations(Concept c, Location loc, String sort, 205 Integer personType, boolean includeVoided); 183 206 184 207 /** … … 191 214 */ 192 215 @Transactional(readOnly = true) 193 public Set<Obs> getObservations(Person who, Concept question, boolean includeVoided); 216 public Set<Obs> getObservations(Person who, Concept question, 217 boolean includeVoided); 194 218 195 219 /** 196 220 * e.g. get last 'n' number of observations for a person for given concept 197 221 * 198 * @param n 199 * number of concepts to retrieve 222 * @param n number of concepts to retrieve 200 223 * @param who 201 224 * @param question … … 204 227 @Transactional(readOnly = true) 205 228 public List<Obs> getLastNObservations(Integer n, Person who, 206 Concept question, boolean includeVoided);229 Concept question, boolean includeVoided); 207 230 208 231 /** 209 232 * e.g. get all observations referring to RETURN VISIT DATE 210 233 * 211 * @param question 212 * (Concept: RETURN VISIT DATE) 213 * @param sort 214 * (obsId, obsDatetime, etc) if null, defaults to obsId 215 * @param personType 216 * 217 * @return 218 */ 219 @Transactional(readOnly = true) 220 public List<Obs> getObservations(Concept question, String sort, Integer personType, boolean includeVoided); 221 222 /** 223 * Return all observations that have the given concept as an answer 224 * (<code>answer.getConceptId()</code> == value_coded) 234 * @param question (Concept: RETURN VISIT DATE) 235 * @param sort (obsId, obsDatetime, etc) if null, defaults to obsId 236 * @param personType 237 * 238 * @return 239 */ 240 @Transactional(readOnly = true) 241 public List<Obs> getObservations(Concept question, String sort, 242 Integer personType, boolean includeVoided); 243 244 /** 245 * Return all observations that have the given concept as an answer (<code>answer.getConceptId()</code> == 246 * value_coded) 225 247 * 226 248 * @param concept … … 229 251 */ 230 252 @Transactional(readOnly = true) 231 public List<Obs> getObservationsAnsweredByConcept(Concept answer, Integer personType, boolean includeVoided); 232 253 public List<Obs> getObservationsAnsweredByConcept(Concept answer, 254 Integer personType, boolean includeVoided); 255 233 256 /** 234 257 * Return all numeric answer values for the given concept ordered by value … … 238 261 * 239 262 * @param concept 240 * @param sortByValue true/false if sorting by valueNumeric. If false, will sort by obsDatetime 241 * @param personType 242 * 243 * @return List<Object[]> [0]=<code>obsId</code>, [1]=<code>obsDatetime</code>, [2]=<code>valueNumeric</code>s 244 */ 245 @Transactional(readOnly = true) 246 public List<Object[]> getNumericAnswersForConcept(Concept answer, Boolean sortByValue, Integer personType, boolean includeVoided); 247 263 * @param sortByValue true/false if sorting by valueNumeric. If false, will 264 * sort by obsDatetime 265 * @param personType 266 * 267 * @return List<Object[]> [0]=<code>obsId</code>, [1]=<code>obsDatetime</code>, 268 * [2]=<code>valueNumeric</code>s 269 */ 270 @Transactional(readOnly = true) 271 public List<Object[]> getNumericAnswersForConcept(Concept answer, 272 Boolean sortByValue, Integer personType, boolean includeVoided); 273 248 274 /** 249 275 * Get all observations from a specific encounter … … 274 300 */ 275 301 @Transactional(readOnly = true) 276 public List<Obs> findObservations(String search, boolean includeVoided, Integer personType); 302 public List<Obs> findObservations(String search, boolean includeVoided, 303 Integer personType); 277 304 278 305 /** … … 283 310 */ 284 311 @Transactional(readOnly = true) 285 public List<String> getDistinctObservationValues(Concept question, Integer personType); 312 public List<String> getDistinctObservationValues(Concept question, 313 Integer personType); 286 314 287 315 /** … … 295 323 @Authorized( { "View Person" }) 296 324 public List<Obs> getObservations(Person who, Aggregation aggregation, 297 Concept question, Constraint constraint); 298 299 /** 300 * Get all Observations for these concepts between these dates. Ideal for getting things like recent lab results regardless of what patient 301 * 302 * @param concepts get observations for these concepts (leave as null to get all) 325 Concept question, Constraint constraint); 326 327 /** 328 * Get all Observations for these concepts between these dates. Ideal for 329 * getting things like recent lab results regardless of what patient 330 * 331 * @param concepts get observations for these concepts (leave as null to get 332 * all) 303 333 * @param fromDate 304 334 * @param toDate … … 307 337 */ 308 338 @Transactional(readOnly = true) 309 public List<Obs> getObservations(List<Concept> concepts, Date fromDate, Date toDate, boolean includeVoided); 310 311 /** 312 * Get all Observations for these concepts between these dates. Ideal for getting things like recent lab results regardless of what patient 313 * 314 * @param concepts get observations for these concepts (leave as null to get all) 339 public List<Obs> getObservations(List<Concept> concepts, Date fromDate, 340 Date toDate, boolean includeVoided); 341 342 /** 343 * Get all Observations for these concepts between these dates. Ideal for 344 * getting things like recent lab results regardless of what patient 345 * 346 * @param concepts get observations for these concepts (leave as null to get 347 * all) 315 348 * @param fromDate 316 349 * @param toDate … … 318 351 */ 319 352 @Transactional(readOnly = true) 320 public List<Obs> getObservations(List<Concept> concepts, Date fromDate, Date toDate); 321 322 323 /** 324 * Get all Observations for this patient set, for these concepts, between these dates. Ideal for getting things like recent lab results for a set of patients 325 * 326 * @param ps the patientset for which to retrieve data for - null means all patients 327 * @param concepts list of the concepts for which to retrieve obs - null means all obs 353 public List<Obs> getObservations(List<Concept> concepts, Date fromDate, 354 Date toDate); 355 356 /** 357 * Get all Observations for this patient set, for these concepts, between 358 * these dates. Ideal for getting things like recent lab results for a set 359 * of patients 360 * 361 * @param ps the patientset for which to retrieve data for - null means all 362 * patients 363 * @param concepts list of the concepts for which to retrieve obs - null 364 * means all obs 328 365 * @param fromDate lower bound for date - null means no lower bound 329 366 * @param toDate upper bound for date - null means no upper bound 330 * @return observations, for this patient set, with concepts in list of concepts passed, between the two dates passed in 367 * @return observations, for this patient set, with concepts in list of 368 * concepts passed, between the two dates passed in 369 */ 370 @Transactional(readOnly = true) 371 public List<Obs> getObservations(PatientSet patients, 372 List<Concept> concepts, Date fromDate, Date toDate); 373 374 375 /** 376 * @return All registered ComplexObsHandler 331 377 */ 332 378 @Transactional(readOnly=true) 333 public List<Obs> getObservations(PatientSet patients, List<Concept> concepts, Date fromDate, Date toDate); 379 public List<ComplexObsHandler> getComplexObsHandlers(); 380 381 /** 382 * Auto generated method comment 383 * 384 * @param key 385 * @return 386 */ 387 @Transactional(readOnly=true) 388 public ComplexObsHandler getHandler(Class<? extends ComplexObsHandler> clazz); 389 390 /** 391 * Get the ComplexObsHandler 392 * 393 * @param key 394 * @return 395 */ 396 @Transactional(readOnly=true) 397 public ComplexObsHandler getHandler(String className); 398 399 /** 400 * Add the given map to this service's handlers 401 * 402 * This map is set via spring, see the applicationContext-service.xml file 403 * 404 * @param handlers Map of class to handler object 405 */ 406 public void setHandlers(Map<Class<? extends ComplexObsHandler>, ComplexObsHandler> handlers) throws APIException; 407 408 /** 409 * Gets the handlers map registered to this report service 410 * 411 * @return 412 * @throws APIException 413 */ 414 public Map<Class<? extends ComplexObsHandler>, ComplexObsHandler> getHandlers() throws APIException; 415 416 /** 417 * Registers the given handler with the service 418 * 419 * @param handlerClass 420 * @param handler 421 * @throws APIException 422 */ 423 public void registerHandler(Class<? extends ComplexObsHandler> handlerClass, ComplexObsHandler handler) throws APIException; 424 425 /** 426 * Convenience method for {@link #registerHandler(Class, ComplexObsHandler)} 427 * 428 * @param handlerClass 429 * @throws APIException 430 */ 431 public void registerHandler(String handlerClass) throws APIException; 432 433 /** 434 * Remove the handler associated with <code>handlerClass</code> from the 435 * list of available handlers 436 * 437 * @param handlerClass 438 */ 439 public void removeHandler(Class<? extends ComplexObsHandler> handlerClass) throws APIException; 440 441 334 442 }