Changeset 4358 for openmrs/trunk/src/api/org/openmrs/api/ObsService.java
- Timestamp:
- 05/24/08 14:37:02 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/trunk/src/api/org/openmrs/api/ObsService.java
r4190 r4358 28 28 import org.openmrs.api.db.ObsDAO; 29 29 import org.openmrs.util.OpenmrsConstants; 30 import org.openmrs.util.OpenmrsConstants.PERSON_TYPE; 30 31 import org.springframework.transaction.annotation.Transactional; 31 32 32 33 /** 33 * The ObsService provides methods for acting on Obs, ObsGroup, and34 * ComplexObs objects.34 * The ObsService deals with saving and getting Obs to/from the 35 * database 35 36 * 36 * Use: 37 * <code> 38 * Context.getObsService().getObs(123); 39 * </code> 37 * Usage: 38 * <pre> 39 * ObsService obsService = Context.getObsService(); 40 * // get the obs for patient with internal identifier of 1235 41 * List<Obs> someObsList = obsService.getObservationsByPerson(new Patient(1235)); 42 * </pre> 40 43 * 41 44 * There are also a number of convenience methods for extracting obs 42 45 * pertaining to certain Concepts, people, or encounters 43 * 46 * 47 * @see org.openmrs.Obs 48 * @see org.openmrs.ComplexObs 49 * @see org.openmrs.MimeType 50 * @see org.openmrs.api.context.Context 44 51 */ 45 52 @Transactional 46 public interface ObsService { 47 53 public interface ObsService extends OpenmrsService { 54 55 /** 56 * @see org.openmrs.util.OpenmrsConstants 57 * @deprecated Use org.openmrs.util.OpenmrsConstants#PERSON_TYPE.PATIENT 58 */ 48 59 public static final Integer PERSON = 1; 60 61 /** 62 * @see org.openmrs.util.OpenmrsConstants 63 * @deprecated Use OpenmrsConstants#PERSON_TYPE.PATIENT 64 */ 49 65 public static final Integer PATIENT = 2; 66 67 /** 68 * @see org.openmrs.util.OpenmrsConstants 69 * @deprecated Use OpenmrsConstants.PERSON_TYPE.USER 70 */ 50 71 public static final Integer USER = 4; 51 72 73 /** 74 * Set the given <code>dao</code> on this obs service. 75 * The dao will act as the conduit through with all obs 76 * calls get to the database 77 * 78 * @param dao specific ObsDAO to use for this service 79 */ 52 80 public void setObsDAO(ObsDAO dao); 53 81 … … 57 85 * @param Obs 58 86 * @throws APIException 59 */ 60 @Authorized({OpenmrsConstants.PRIV_ADD_OBS}) 87 * @deprecated use {@link #saveObs(Obs, String)} 88 */ 89 @Authorized(OpenmrsConstants.PRIV_ADD_OBS) 61 90 public void createObs(Obs obs) throws APIException; 62 91 … … 82 111 * @see #createObsGroup(Obs, List) 83 112 */ 84 @Authorized( {OpenmrsConstants.PRIV_ADD_OBS})113 @Authorized(OpenmrsConstants.PRIV_ADD_OBS) 85 114 public void createObsGroup(Obs[] obs) throws APIException; 86 115 … … 93 122 */ 94 123 @Transactional(readOnly = true) 95 @Authorized( {OpenmrsConstants.PRIV_VIEW_OBS})124 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 96 125 public Obs getObs(Integer obsId) throws APIException; 97 126 … … 101 130 * @param Obs 102 131 * @throws APIException 103 */ 104 @Authorized({OpenmrsConstants.PRIV_EDIT_OBS}) 132 * @deprecated use {@link #saveObs(Obs, String)} 133 */ 134 @Authorized(OpenmrsConstants.PRIV_EDIT_OBS) 105 135 public void updateObs(Obs obs) throws APIException; 136 137 /** 138 * Save the given obs to the database. This will move the 139 * contents of the given <code>obs</code> to the database. This 140 * acts as both the initial save and an update kind of save. 141 * The returned obs will be the same as the obs passed in. It is 142 * included for chaining. 143 * 144 * If this is an initial save, the obsId on the given 145 * <code>obs</code> object will be updated to reflect the auto 146 * numbering from the database. The obsId on the returned obs 147 * will also have this number. 148 * 149 * If there is already an obsId on the given <code>obs</code> object, 150 * the given obs will be voided and a new row in the database will be 151 * created that has a new obs id. 152 * 153 * @param obs the Obs to save to the database 154 * @param changeMessage String explaining why <code>obs</code> is being changed. If 155 * <code>obs</code> is a new obs, changeMessage is nullable, or if 156 * it is being updated, it would be required 157 * @return Obs that was saved to the database 158 * @throws APIException 159 */ 160 @Authorized({OpenmrsConstants.PRIV_ADD_OBS, OpenmrsConstants.PRIV_EDIT_OBS}) 161 public Obs saveObs(Obs obs, String changeMessage) throws APIException; 106 162 107 163 /** … … 112 168 * @throws APIException 113 169 */ 114 @Authorized( {OpenmrsConstants.PRIV_EDIT_OBS})115 public voidvoidObs(Obs obs, String reason) throws APIException;170 @Authorized(OpenmrsConstants.PRIV_EDIT_OBS) 171 public Obs voidObs(Obs obs, String reason) throws APIException; 116 172 117 173 /** … … 121 177 * @throws APIException 122 178 */ 123 @Authorized({OpenmrsConstants.PRIV_EDIT_OBS}) 124 public void unvoidObs(Obs obs) throws APIException; 125 126 /** 127 * Delete an observation. SHOULD NOT BE CALLED unless caller is lower-level. 179 @Authorized(OpenmrsConstants.PRIV_EDIT_OBS) 180 public Obs unvoidObs(Obs obs) throws APIException; 181 182 /** 183 * This method shouldn't be used. Use either {@link #purgeObs(Obs)} or 184 * {@link #voidObs(Obs)} 128 185 * 129 186 * @param Obs 130 187 * @throws APIException 131 * @ see voidObs(Obs)132 */ 133 @Authorized( {OpenmrsConstants.PRIV_DELETE_OBS})188 * @deprecated use #purgeObs(Obs) 189 */ 190 @Authorized(OpenmrsConstants.PRIV_DELETE_OBS) 134 191 public void deleteObs(Obs obs) throws APIException; 135 192 136 193 /** 137 * Get all mime types 138 * 139 * @return mime types list 140 * @throws APIException 141 */ 142 @Transactional(readOnly = true) 194 * Completely remove an observation from the database. This should typically 195 * not be called because we don't want to ever lose data. The data really 196 * <i>should</i> be voided and then it is not seen in interface any longer 197 * (see #voidObs(Obs) for that one) 198 * 199 * If other things link to this obs, an error will be thrown. 200 * 201 * @param Obs 202 * @throws APIException 203 */ 204 @Authorized(OpenmrsConstants.PRIV_DELETE_OBS) 205 public void purgeObs(Obs obs) throws APIException; 206 207 /** 208 * Completely remove an observation from the database. This should typically 209 * not be called because we don't want to ever lose data. The data really 210 * <i>should</i> be voided and then it is not seen in interface any longer 211 * (see #voidObs(Obs) for that one) 212 * 213 * @param Obs the observation to remove from the database 214 * @param cascade true/false whether or not to cascade down to other things 215 * that link to this observation (like Orders and ObsGroups) 216 * @throws APIException 217 * @see #purgeObs(Obs, boolean) 218 */ 219 @Authorized(OpenmrsConstants.PRIV_DELETE_OBS) 220 public void purgeObs(Obs obs, boolean cascade) throws APIException; 221 222 /** 223 * @deprecated use {@link #getAllMimeTypes()} 224 */ 225 @Transactional(readOnly = true) 226 @Authorized(OpenmrsConstants.PRIV_VIEW_MIME_TYPES) 143 227 public List<MimeType> getMimeTypes() throws APIException; 228 229 /** 230 * Gets all mime types (including retired ones) 231 * 232 * @return list of MimeTypes in the system 233 * @see #getAllMimeTypes(boolean) 234 * @throws APIException 235 */ 236 @Authorized(OpenmrsConstants.PRIV_VIEW_MIME_TYPES) 237 public List<MimeType> getAllMimeTypes() throws APIException; 238 239 /** 240 * Gets all mime types and disregards the retired ones 241 * if <code>includeRetired</code> is true 242 * 243 * @param includeRetired true/false of whether to also return the retired ones 244 * @return list of MimeTypes lll 245 * @throws APIException 246 */ 247 @Authorized(OpenmrsConstants.PRIV_VIEW_MIME_TYPES) 248 public List<MimeType> getAllMimeTypes(boolean includeRetired) throws APIException; 144 249 145 250 /** … … 151 256 */ 152 257 @Transactional(readOnly = true) 258 @Authorized(OpenmrsConstants.PRIV_VIEW_MIME_TYPES) 153 259 public MimeType getMimeType(Integer mimeTypeId) throws APIException; 154 260 155 261 /** 156 * Get all Observations for a person 157 * 158 * @param who 159 * @param includeVoided 262 * Save the given <code>mimeType</code> to the database. 263 * If mimeType is not null, the mimeType is updated in the database. 264 * If mimeType is null, a new mimeType is added to the database 265 * 266 * @param mimeType mimeType 267 * @return mimeType that was saved/updated in the database 268 * @throws APIException 269 */ 270 @Authorized(OpenmrsConstants.PRIV_MANAGE_MIME_TYPES) 271 public MimeType saveMimeType(MimeType mimeType) throws APIException; 272 273 /** 274 * This effectively removes the given mimeType from the system. Voided 275 * mimeTypes are still linked to from complexObs, they just aren't shown 276 * in the list of available mimeTypes 277 * 278 * @param mimeType the MimeType to remove 279 * @param reason the reason this mimeType is being voided 160 280 * @return 161 */ 162 @Transactional(readOnly = true) 281 * @throws APIException 282 * @see {@link #createObs(Obs)} 283 */ 284 @Authorized(OpenmrsConstants.PRIV_MANAGE_MIME_TYPES) 285 public MimeType voidMimeType(MimeType mimeType, String reason) throws APIException; 286 287 /** 288 * This completely removes the given <code>MimeType</code> from the database. 289 * If data has been stored already that points at this mimeType an 290 * exception is thrown 291 * 292 * @param mimeType the MimeType to remove 293 * @throws APIException 294 * @see {@link #purgeMimeType(MimeType) 295 */ 296 @Authorized(OpenmrsConstants.PRIV_PURGE_MIME_TYPES) 297 public void purgeMimeType(MimeType mimeType) throws APIException; 298 299 /** 300 * @see {@link org.openmrs.Person#getObservations()} 301 * @deprecated use the method on the org.openmrs.Person for getObservations 302 */ 303 @Transactional(readOnly = true) 304 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 163 305 public Set<Obs> getObservations(Person who, boolean includeVoided); 164 306 165 307 /** 166 * Get all Observations for this concept/location Sort is optional 167 * 168 * @param concept 169 * @param location 170 * @param sort 171 * @param personType 172 * @param includeVoided 173 * @return list of obs for a location 174 */ 175 @Transactional(readOnly = true) 176 public List<Obs> getObservations(Concept c, Location loc, String sort, 177 Integer personType, boolean includeVoided); 178 179 /** 180 * e.g. get all CD4 counts for a person 181 * 182 * @param who 183 * @param question 184 * @param includeVoided 308 * Get all Observations for the given personperson 309 * 310 * @param who the user to match on 185 311 * @return 186 */ 187 @Transactional(readOnly = true) 188 public Set<Obs> getObservations(Person who, Concept question, 189 boolean includeVoided); 190 191 /** 192 * e.g. get last 'n' number of observations for a person for given concept 193 * 194 * @param n number of concepts to retrieve 195 * @param who 196 * @param question 197 * @return 198 */ 199 @Transactional(readOnly = true) 312 * @see {@link #getObservations(List, List, List, List, List, List, String, Integer, Integer, Date, Date, boolean)} 313 */ 314 @Transactional(readOnly = true) 315 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 316 public List<Obs> getObservationsByPerson(Person who); 317 318 /** 319 * This method fetches observations according to the criteria in 320 * the given arguments. All arguments are optional and nullable. If 321 * more than one argument is non-null, the result is equivalent to an 322 * "and"ing of the arguments. (e.g. if both a <code>location</code> and 323 * a <code>fromDate</code> are given, only Obs that are <u>both</u> at 324 * that Location and after the fromDate are returned). 325 * 326 * Note: If <code>whom</code> has elements, <code>personType</code> is ignored 327 * 328 * @param whom List<Person> to restrict obs to (optional) 329 * @param encounters List<Encounter> to restrict obs to (optional) 330 * @param questions List<Concept> to restrict the obs to (optional) 331 * @param answers List<Concept> to restrict the valueCoded to (optional) 332 * @param personType PERSON_TYPE objects to restrict this to. Only used if <code>whom</code> not an 333 * empty list (optional) 334 * @param locations The org.openmrs.Location objects to restrict to (optional) 335 * @param sort list of column names to sort on (obsId, obsDatetime, etc) if null, defaults to obsDatetime (optional) 336 * @param mostRecentN restrict the number of obs returned to this size (optional) 337 * @param obsGroupId the Obs.getObsGroupId() to this integer (optional) 338 * @param fromDate the earliest Obs date to get (optional) 339 * @param toDate the latest Obs date to get (optional) 340 * @param includeVoidedObs true/false whether to also include the voided obs (required) 341 * @return list of Observations that match all of the criteria given in the arguments 342 * @throws APIException 343 */ 344 @Transactional(readOnly = true) 345 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 346 public List<Obs> getObservations(List<Person> whom, List<Encounter> encounters, 347 List<Concept> questions, List<Concept> answers, 348 List<PERSON_TYPE> personTypes, List<Location> locations, 349 List<String> sort, Integer mostRecentN, Integer obsGroupId, 350 Date fromDate, Date toDate, boolean includeVoidedObs) 351 throws APIException; 352 353 /** 354 * This method searches the obs table based on the given 355 * <code>searchString</code>. 356 * 357 * @param searchString The string to search on 358 * @return observations matching the given string 359 * @throws APIException 360 */ 361 @Transactional(readOnly = true) 362 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 363 public List<Obs> getObservations(String searchString) throws APIException; 364 365 /** 366 * @deprecated use {@link #getObservations(List, Encounter, List, List, List, List, String, Integer, Integer, Date, Date, boolean)} 367 */ 368 @Transactional(readOnly = true) 369 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 370 public List<Obs> getObservations(Concept c, Location loc, String sort, Integer personType, boolean includeVoided); 371 372 /** 373 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 374 */ 375 @Transactional(readOnly = true) 376 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 377 public Set<Obs> getObservations(Person who, Concept question, boolean includeVoided); 378 379 /** 380 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 381 */ 382 @Transactional(readOnly = true) 383 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 200 384 public List<Obs> getLastNObservations(Integer n, Person who, 201 385 Concept question, boolean includeVoided); 202 386 203 387 /** 204 * e.g. get all observations referring to RETURN VISIT DATE 205 * 206 * @param question (Concept: RETURN VISIT DATE) 207 * @param sort (obsId, obsDatetime, etc) if null, defaults to obsId 208 * @param personType 209 * 210 * @return 211 */ 212 @Transactional(readOnly = true) 213 public List<Obs> getObservations(Concept question, String sort, 214 Integer personType, boolean includeVoided); 215 216 /** 217 * Return all observations that have the given concept as an answer (<code>answer.getConceptId()</code> == 218 * value_coded) 219 * 220 * @param concept 221 * @param personType 222 * @return list of obs 223 */ 224 @Transactional(readOnly = true) 225 public List<Obs> getObservationsAnsweredByConcept(Concept answer, 226 Integer personType, boolean includeVoided); 388 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 389 */ 390 @Transactional(readOnly = true) 391 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 392 public List<Obs> getObservations(Concept question, String sort, Integer personType, boolean includeVoided); 393 394 /** 395 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 396 */ 397 @Transactional(readOnly = true) 398 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 399 public List<Obs> getObservationsAnsweredByConcept(Concept answer, Integer personType, boolean includeVoided); 227 400 228 401 /** … … 236 409 * sort by obsDatetime 237 410 * @param personType 238 * 239 * @return List<Object[]> [0]=<code>obsId</code>, [1]=<code>obsDatetime</code>, 240 * [2]=<code>valueNumeric</code>s 241 */ 242 @Transactional(readOnly = true) 243 public List<Object[]> getNumericAnswersForConcept(Concept answer, 244 Boolean sortByValue, Integer personType, boolean includeVoided); 245 246 /** 247 * Get all observations from a specific encounter 248 * 249 * @param whichEncounter 250 * @return Set of Obs 251 */ 252 @Transactional(readOnly = true) 411 * @deprecated use {@link #getObservations(List, Encounter, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 412 * 413 * @return List<Object[]> [0]=<code>obsId</code>, [1]=<code>obsDatetime</code>, [2]=<code>valueNumeric</code>s 414 **/ 415 @Transactional(readOnly = true) 416 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 417 public List<Object[]> getNumericAnswersForConcept(Concept answer, Boolean sortByValue, Integer personType, boolean includeVoided); 418 419 /** 420 * @deprecated use org.openmrs.Encounter.getObservations() 421 * @see {@link org.openmrs.Encounter.getObservations()} 422 */ 423 @Transactional(readOnly = true) 424 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 253 425 public Set<Obs> getObservations(Encounter whichEncounter); 254 426 255 427 /** 256 * Get all observations that have been voided Observations are ordered by 257 * descending voidedDate 258 * 259 * @return List of Obs 260 */ 261 @Transactional(readOnly = true) 428 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 429 */ 430 @Transactional(readOnly = true) 431 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 262 432 public List<Obs> getVoidedObservations(); 263 433 264 434 /** 265 * Find observations matching the search string "matching" is defined as 266 * either the obsId or the person identifier 267 * 268 * @param search 269 * @param includeVoided 270 * @param personType 271 * @return list of matched observations 272 */ 273 @Transactional(readOnly = true) 274 public List<Obs> findObservations(String search, boolean includeVoided, 275 Integer personType); 276 277 /** 278 * 279 * @param question 280 * @param personType 281 * @return 282 */ 283 @Transactional(readOnly = true) 284 public List<String> getDistinctObservationValues(Concept question, 285 Integer personType); 286 287 /** 288 * @param obsGroupId 289 * @return All obs that share obsGroupId 290 * @deprecated -- should use obs.getGroupMembers 291 */ 292 @Transactional(readOnly = true) 435 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 436 */ 437 @Transactional(readOnly = true) 438 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 439 public List<Obs> findObservations(String search, boolean includeVoided, Integer personType); 440 441 /** 442 * @deprecated should use Obs.getGroupMembers() or {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 443 */ 444 @Transactional(readOnly = true) 445 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 293 446 public List<Obs> findObsByGroupId(Integer obsGroupId); 294 447 295 448 /** 296 * Get all Observations for these concepts between these dates. Ideal for getting things like recent lab results regardless of what patient 297 * 298 * @param concepts get observations for these concepts (leave as null to get all) 299 * @param fromDate 300 * @param toDate 301 * @param includeVoided 302 * @return list of obs for a location 303 */ 304 @Transactional(readOnly = true) 449 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 450 */ 451 @Transactional(readOnly = true) 452 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 305 453 public List<Obs> getObservations(List<Concept> concepts, Date fromDate, Date toDate, boolean includeVoided); 306 454 307 455 /** 308 * Get all Observations for these concepts between these dates. Ideal for getting things like recent lab results regardless of what patient 309 * 310 * @param concepts get observations for these concepts (leave as null to get all) 311 * @param fromDate 312 * @param toDate 313 * @return list of obs for a location 314 */ 315 @Transactional(readOnly = true) 456 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 457 */ 458 @Transactional(readOnly = true) 459 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 316 460 public List<Obs> getObservations(List<Concept> concepts, Date fromDate, Date toDate); 317 461 318 462 319 463 /** 320 * 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 321 * 322 * @param patients the patientset for which to retrieve data for - null means all patients 323 * @param concepts list of the concepts for which to retrieve obs - null means all obs 324 * @param fromDate lower bound for date - null means no lower bound 325 * @param toDate upper bound for date - null means no upper bound 326 * @return observations, for this patient set, with concepts in list of concepts passed, between the two dates passed in 464 * @deprecated use {@link #getObservations(List, List, List, org.openmrs.api.ObsService.PERSON_TYPE, Location, String, Integer, Integer, Date, Date, boolean)} 327 465 */ 328 466 @Transactional(readOnly=true) 467 @Authorized(OpenmrsConstants.PRIV_VIEW_OBS) 329 468 public List<Obs> getObservations(Cohort patients, List<Concept> concepts, Date fromDate, Date toDate); 469 330 470 }