Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

root/openmrs/trunk/src/api/org/openmrs/api/PatientService.java

Revision 5368, 22.5 kB (checked in by mseaton, 3 days ago)

trunk: jUnit testing. Added @should and Test methods for testing PatientService.getAllIdentifierValidators

  • Property svn:eol-style set to CRLF
Line 
1 /**
2  * The contents of this file are subject to the OpenMRS Public License
3  * Version 1.0 (the "License"); you may not use this file except in
4  * compliance with the License. You may obtain a copy of the License at
5  * http://license.openmrs.org
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9  * License for the specific language governing rights and limitations
10  * under the License.
11  *
12  * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
13  */
14 package org.openmrs.api;
15
16 import java.util.Collection;
17 import java.util.Date;
18 import java.util.List;
19 import java.util.Set;
20
21 import org.openmrs.Concept;
22 import org.openmrs.Location;
23 import org.openmrs.Patient;
24 import org.openmrs.PatientIdentifier;
25 import org.openmrs.PatientIdentifierType;
26 import org.openmrs.Tribe;
27 import org.openmrs.annotation.Authorized;
28 import org.openmrs.api.db.PatientDAO;
29 import org.openmrs.patient.IdentifierValidator;
30 import org.openmrs.util.OpenmrsConstants;
31 import org.springframework.transaction.annotation.Transactional;
32
33 /**
34  * Contains methods pertaining to Patients in the system
35  *
36  * Use:<br/>
37  *
38  * <pre>
39  *   List<Patient> patients = Context.getPatientService().getAllPatients();
40  * </pre>
41  *
42  * @see org.openmrs.api.context.Context
43  * @see org.openmrs.Patient
44  */
45 @Transactional
46 public interface PatientService extends OpenmrsService {
47
48         /**
49          * Sets the DAO for this service.  This is done by DI and Spring.  See
50          * the applicationContext-service.xml definition file.
51          *
52          * @param dao DAO for this service
53          */
54         public void setPatientDAO(PatientDAO dao);
55
56         /**
57          * @see #savePatient(Patient)
58          * @deprecated replaced by #savePatient(Patient)
59          */
60         @Authorized( { OpenmrsConstants.PRIV_ADD_PATIENTS })
61         public Patient createPatient(Patient patient) throws APIException;
62
63         /**
64          * Saved the given <code>patient</code> to the database
65          *
66          * @param patient patient to be created or updated
67          * @return patient who was created or updated
68          * @throws APIException
69          */
70         @Authorized( { OpenmrsConstants.PRIV_ADD_PATIENTS,
71                 OpenmrsConstants.PRIV_EDIT_PATIENTS })
72         public Patient savePatient(Patient patient) throws APIException;
73
74         /**
75          * Get patient by internal identifier
76          *
77          * @param patientId internal patient identifier
78          * @return patient with given internal identifier
79          * @throws APIException
80          */
81         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
82         @Transactional(readOnly = true)
83         public Patient getPatient(Integer patientId) throws APIException;
84
85         /**
86          * @see #savePatient(Patient)
87          * @deprecated replaced by #savePatient(Patient)
88          */
89         public Patient updatePatient(Patient patient) throws APIException;
90        
91         /**
92          * Returns all non voided patients in the system
93          *
94          * @return non voided patients in the system
95          * @see #getAllPatients(boolean)
96          * @throws APIException
97          */
98         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
99         @Transactional(readOnly = true)
100         public List<Patient> getAllPatients() throws APIException;
101        
102         /**
103          * Returns patients in the system
104          *
105          * @param includeVoided if false, will limit the search to non-voided patients
106          * @return patients in the system
107          * @throws APIException
108          */
109         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
110         @Transactional(readOnly = true)
111         public List<Patient> getAllPatients(boolean includeVoided) throws APIException;
112        
113         /**
114          * @deprecated use #getPatientByIdentifier(String) instead
115          */
116         @Transactional(readOnly = true)
117         public Patient identifierInUse(String identifier,
118                 PatientIdentifierType type, Patient ignorePatient);
119        
120         /**
121          * @deprecated replaced by {@link #getPatients(String, String, List)
122          */
123         @Transactional(readOnly = true)
124         public List<Patient> getPatientsByIdentifier(String identifier,
125                 boolean includeVoided) throws APIException;
126
127         /**
128          * Get patients based on given criteria
129          *
130          * The identifier is matched with the regex
131          * <code>OpenmrsConstants.PATIENT_IDENTIFIER_REGEX</code>
132          *
133          * All parameters are optional and nullable.  If null, it is not included
134          * in the search.
135          *
136          * Will not return voided patients
137          *
138          * @param name (optional) this is a slight break from the norm, patients with a
139          *              partial match on this name will be returned
140          * @param identifier (optional) only patients with a matching identifier are returned
141          * @param identifierTypes (optional) the PatientIdentifierTypes to restrict to
142          * @param matchIdentifierExactly (required) if true, then the given <code>identifier</code>
143          *              must equal the id in the database.  if false, then the identifier is 'searched' for
144          *              by using a regular expression
145          * @return patients that matched the given criteria (and are not voided)
146          * @throws APIException
147          */
148         @Transactional(readOnly = true)
149         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
150         public List<Patient> getPatients(String name, String identifier, List<PatientIdentifierType> identifierTypes, boolean matchIdentifierExactly)
151                 throws APIException;
152        
153         /**
154          * @deprecated replaced by a call to
155          *              {@link #getPatients(String, String, List, boolean)} with "false" as the last parameter
156          */
157         @Transactional(readOnly = true)
158         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
159         public List<Patient> getPatients(String name, String identifier, List<PatientIdentifierType> identifierTypes)
160                 throws APIException;
161        
162         /**
163          * @deprecated replaced by getPatients( ... )
164          */
165         @Transactional(readOnly = true)
166         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
167         public List<Patient> getPatientsByIdentifierPattern(String identifier,
168                 boolean includeVoided) throws APIException;
169
170         /**
171          * @deprecated replaced by {@link #getPatients(String, String, List)}
172          */
173         @Transactional(readOnly = true)
174         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
175         public List<Patient> getPatientsByName(String name) throws APIException;
176
177         /**
178          * @deprecated replaced by getPatients( ... )
179          */
180         @Transactional(readOnly = true)
181         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
182         public List<Patient> getPatientsByName(String name, boolean includeVoided)
183                 throws APIException;
184
185         /**
186          * Void patient record (functionally delete patient from system)
187          *
188          * @param patient patient to be voided
189          * @param reason reason for voiding patient
190          * @return the voided patient
191          */
192         @Authorized( { OpenmrsConstants.PRIV_DELETE_PATIENTS })
193         public Patient voidPatient(Patient patient, String reason) throws APIException;
194
195         /**
196          * Unvoid patient record
197          *
198          * @param patient patient to be revived
199          * @return the revided Patient
200          */
201         @Authorized( { OpenmrsConstants.PRIV_DELETE_PATIENTS })
202         public Patient unvoidPatient(Patient patient) throws APIException;
203
204         /**
205          * @see #purgePatient(Patient)
206          * @deprecated replaced by {@link #purgePatient(Patient)}
207          */
208         @Authorized( { OpenmrsConstants.PRIV_PURGE_PATIENTS })
209         public void deletePatient(Patient patient) throws APIException;
210
211         /**
212          * Delete patient from database. This <b>should not be called</b> except
213          * for testing and administration purposes. Use the void method instead.
214          *
215          * @param patient patient to be deleted
216          * @throws APIException
217          *
218          * @see #voidPatient(org.openmrs.Patient,java.lang.String)
219          */
220         @Authorized( { OpenmrsConstants.PRIV_PURGE_PATIENTS })
221         public void purgePatient(Patient patient) throws APIException;
222
223         /**
224          * @deprecated replaced by {@link #getPatientIdentifiers(String, List, List, List, Boolean, Boolean, boolean)}
225          */
226         @Transactional(readOnly = true)
227         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENT_IDENTIFIERS })
228         public List<PatientIdentifier> getPatientIdentifiers(
229                 PatientIdentifierType patientIdentifierType) throws APIException;
230
231         /**
232          * Get all patientIdentifiers that match all of the given criteria
233          *
234          * Voided identifiers are not returned
235          *
236          * @param identifier the full identifier to match on
237          * @param patientIdentifierTypes the type of identifiers to get
238          * @param locations the locations of the identifiers to match
239          * @param patients the patients containing these identifiers
240          * @param isPreferred if true, limits to only preferred identifiers
241          *                      if false, only non preferred.  if null, ignores preferred status
242          * @return PatientIdentifiers matching these criteria
243          * @throws APIException
244          */
245         @Transactional(readOnly = true)
246         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENT_IDENTIFIERS })
247         public List<PatientIdentifier> getPatientIdentifiers(String identifier,
248                 List<PatientIdentifierType> patientIdentifierTypes, List<Location> locations,
249                 List<Patient> patients, Boolean isPreferred)
250                 throws APIException;
251
252         /**
253          * @deprecated replaced by {@link #getPatientIdentifiers(String, List, List, List, Boolean, Boolean, boolean)}
254          */
255         @Transactional(readOnly = true)
256         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENT_IDENTIFIERS })
257         public List<PatientIdentifier> getPatientIdentifiers(String identifier,
258                 PatientIdentifierType pit) throws APIException;
259
260         /**
261          * Update patient identifier
262          *
263          * @param patientIdentifier identifier to be updated
264          * @deprecated patient identifiers should not be updated directly; rather,
265          *             after changing patient identifiers, use
266          *             {@link #savePatient(Patient)} to save changes to the database
267          * @throws APIException
268          */
269         @Authorized( { OpenmrsConstants.PRIV_EDIT_PATIENT_IDENTIFIERS })
270         public void updatePatientIdentifier(PatientIdentifier patientIdentifier)
271                 throws APIException;
272
273         /**
274          * Create or update a PatientIdentifierType
275          *
276          * @param PatientIdentifierType identifier type to create or update
277          * @return the saved type
278          * @throws APIException
279          */
280         @Authorized( { OpenmrsConstants.PRIV_MANAGE_IDENTIFIER_TYPES })
281         public PatientIdentifierType savePatientIdentifierType(
282                 PatientIdentifierType patientIdentifierType) throws APIException;
283
284         /**
285          * @see #getAllPatientIdentifierTypes()
286          * @deprecated replaced by {@link #getAllPatientIdentifierTypes()}
287          */
288         @Transactional(readOnly = true)
289         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
290         public List<PatientIdentifierType> getPatientIdentifierTypes()
291                 throws APIException;
292
293         /**
294          * Get all patientIdentifier types
295          *
296          * @return patientIdentifier types list
297          * @throws APIException
298          */
299         @Transactional(readOnly = true)
300         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
301         public List<PatientIdentifierType> getAllPatientIdentifierTypes()
302                 throws APIException;
303        
304         /**
305          * Get all patientIdentifier types
306          *
307          * @param includeRetired true/false whether retired types should be included
308          * @return patientIdentifier types list
309          * @throws APIException
310          */
311         @Transactional(readOnly = true)
312         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
313         public List<PatientIdentifierType> getAllPatientIdentifierTypes(boolean includeRetired)
314                 throws APIException;
315        
316         /**
317          * Get all patientIdentifier types that match the given criteria
318          *
319          * @param name name of the type to match on
320          * @param format the string format to match on
321          * @param required if true, limits to only identifiers marked as required
322          *                      if false, only non required.  if null, ignores required bit
323          * @param hasCheckDigit if true, limits to only check digit'd identifiers
324          *                      if false, only non checkdigit'd.  if null, ignores checkDigit
325          * @return patientIdentifier types list
326          * @throws APIException
327          */
328         @Transactional(readOnly = true)
329         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
330         public List<PatientIdentifierType> getPatientIdentifierTypes(String name,
331                 String format, Boolean required, Boolean hasCheckDigit)
332                 throws APIException;
333        
334         /**
335          * Get patientIdentifierType by internal identifier
336          *
337          * @param patientIdentifierType id
338          * @return patientIdentifierType with given internal identifier
339          * @throws APIException
340          */
341         @Transactional(readOnly = true)
342         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
343         public PatientIdentifierType getPatientIdentifierType(
344                 Integer patientIdentifierTypeId) throws APIException;
345
346         /**
347          * @deprecated use {@link #getPatientIdentifierTypeByName(String)}
348          */
349         @Transactional(readOnly = true)
350         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
351         public PatientIdentifierType getPatientIdentifierType(String name)
352                 throws APIException;
353        
354         /**
355          * Get patientIdentifierType by exact name
356          *
357          * @param name
358          * @return patientIdentifierType with given name
359          * @throws APIException
360          */
361         @Transactional(readOnly = true)
362         @Authorized( { OpenmrsConstants.PRIV_VIEW_IDENTIFIER_TYPES })
363         public PatientIdentifierType getPatientIdentifierTypeByName(String name)
364                 throws APIException;
365
366         /**
367          * Retire a type of patient identifier
368          *
369          * @param patientIdentifierType type of patient identifier to be retired
370          * @param reason the reason to retire this identifier type
371          * @return the retired type
372          * @throws APIException
373          */
374         @Authorized( { OpenmrsConstants.PRIV_MANAGE_IDENTIFIER_TYPES })
375         public PatientIdentifierType retirePatientIdentifierType(
376                 PatientIdentifierType patientIdentifierType, String reason) throws APIException;
377
378         /**
379          * Unretire a type of patient identifier
380          *
381          * @param patientIdentifierType type of patient identifier to be unretired
382          * @return the unretired type
383          * @throws APIException
384          */
385         @Authorized( { OpenmrsConstants.PRIV_MANAGE_IDENTIFIER_TYPES })
386         public PatientIdentifierType unretirePatientIdentifierType(
387                 PatientIdentifierType patientIdentifierType) throws APIException;
388
389         /**
390          * Purge PatientIdentifierType (cannot be undone)
391          *
392          * @param PatientIdentifierType to purge from the database
393          * @throws APIException
394          */
395         @Authorized( { OpenmrsConstants.PRIV_PURGE_IDENTIFIER_TYPES })
396         public void purgePatientIdentifierType(
397                 PatientIdentifierType patientIdentifierType) throws APIException;
398
399         /**
400          * Convenience method to validate a patient identifier.  Checks for things like blank
401          * identifiers, invalid check digits, etc
402          *
403          * @param patientIdentifier identifier to be validated
404          * @see #checkPatientIdentifiers(Patient)
405          * @throws PatientIdentifierException if the identifier is invalid
406          */
407         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENT_IDENTIFIERS })
408         public void checkPatientIdentifier(PatientIdentifier patientIdentifier)
409                 throws PatientIdentifierException;
410
411         /**
412          * Convenience method to validate all identifiers for a given patient
413          *
414          * @param patient patient for which to validate identifiers
415          * @see #checkPatientIdentifiers(Patient)
416          * @throws PatientIdentifierException if one or more of the identifiers are invalid
417          */
418         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENT_IDENTIFIERS })
419         public void checkPatientIdentifiers(Patient patient)
420                 throws PatientIdentifierException;
421
422         /**
423          * Get tribe by internal tribe identifier
424          *
425          * @return Tribe
426          * @param tribeId
427          * @deprecated tribe will be moved to patient attribute
428          * @throws APIException
429          */
430         @Transactional(readOnly = true)
431         @Authorized( { OpenmrsConstants.PRIV_VIEW_TRIBES })
432         public Tribe getTribe(Integer tribeId) throws APIException;
433
434         /**
435          * Get list of tribes that are not retired
436          *
437          * @return non-retired Tribe list
438          * @deprecated tribe will be moved to patient attributes
439          * @throws APIException
440          */
441         @Transactional(readOnly = true)
442         @Authorized( { OpenmrsConstants.PRIV_VIEW_TRIBES })
443         public List<Tribe> getTribes() throws APIException;
444
445         /**
446          * Find tribes by partial name lookup
447          *
448          * @return non-retired Tribe list
449          * @deprecated tribe will be moved to patient attributes
450          * @throws APIException
451          */
452         @Transactional(readOnly = true)
453         @Authorized( { OpenmrsConstants.PRIV_VIEW_TRIBES })
454         public List<Tribe> findTribes(String search) throws APIException;
455
456         /**
457          * @see #getPatients(String)
458          * @deprecated use #getPatients(String)
459          */
460         @Transactional(readOnly = true)
461         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
462         public List<Patient> findPatients(String query, boolean includeVoided) throws APIException;
463
464         /**
465          * Generic search on patients based on the given string.  Implementations
466          * can use this string to search on name, identifier, etc
467          *
468          * Voided patients are not returned in search results
469          *
470          * @param query the string to search on
471          * @return a list of matching Patients
472          */
473         @Transactional(readOnly = true)
474         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
475         public List<Patient> getPatients(String query) throws APIException;
476        
477         /**
478          * @see #getPatientByExample(Patient)
479          * @deprecated use #getPatientByExample(Patient)
480          */
481         @Transactional(readOnly = true)
482         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
483         public Patient findPatient(Patient patientToMatch) throws APIException;
484        
485         /**
486          * This method tries to find a patient in the database given the attributes
487          * on the given <code>patientToMatch</code> object.
488          *
489          * Assumes there could be a PersonAttribute on this Patient with
490          * PersonAttributeType.name = "Other Matching Information". This
491          * PersonAttribute has a "value" that is just key value pairs in the form of
492          * key:value;nextkey:nextvalue;
493          *
494          * @param patientToMatch
495          * @return null if no match found, a fresh patient object from the db if is
496          *         found
497          */
498         @Transactional(readOnly = true)
499         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
500         public Patient getPatientByExample(Patient patientToMatch) throws APIException;
501        
502         /**
503          * @deprecated use {@link #getDuplicatePatientsByAttributes(List)}
504          * @see #getDuplicatePatientsByAttributes(List)
505          */
506         @Transactional(readOnly = true)
507         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
508         public List<Patient> findDuplicatePatients(Set<String> attributes) throws APIException;
509        
510         /**
511          * Search the database for patients that both share the given attributes.  Each
512          * attribute that is passed in must be identical to what is stored for at least one
513          * other patient for both patients to be returned. 
514          *
515          * @param attributes attributes on a Person or Patient object.  similar to: [gender, tribe,
516          *                      givenName, middleName, familyName]
517          * @return list of patients that match other patients
518          * @throws APIException
519          */
520         @Transactional(readOnly = true)
521         @Authorized( { OpenmrsConstants.PRIV_VIEW_PATIENTS })
522         public List<Patient> getDuplicatePatientsByAttributes(List<String> attributes) throws APIException;
523        
524         /**
525          * Convenience method to join two patients' information into one record.
526          *
527          * <ol>
528          *   <li> Moves object (encounters/obs) pointing to <code>nonPreferred</code>
529          *      to point at <code>preferred</code></li>
530          *   <li> Copies data (gender/birthdate/names/ids/etc) from
531          *      <code>nonPreferred</code> to <code>preferred</code> IFF the data
532          *      is missing or null in <code>preferred</code></li>
533          *    <li><code>notPreferred</code> is marked as voided </li>
534          * </ol>
535          *
536          * @param preferred The Patient to merge to
537          * @param notPreferred The Patient to merge from (and then void)
538          * @throws APIException
539          */
540         @Authorized( { OpenmrsConstants.PRIV_EDIT_PATIENTS })
541         public void mergePatients(Patient preferred, Patient notPreferred)
542                 throws APIException;
543
544         /**
545          * Convenience method to establish that a patient has left the care center.
546          * This API call is responsible for: 1) Closing workflow statuses 2)
547          * Terminating programs 3) Discontinuing orders 4) Flagging patient table
548          * (if applicable) 5) Creating any relevant observations about the patient
549          *
550          * @param patient - the patient who has exited care
551          * @param dateExited - the declared date/time of the patient's exit
552          * @param reasonForExit - the concept that corresponds with why the patient
553          *        has been declared as exited
554          * @throws APIException
555          */
556         // TODO keep this in the PatientService?
557         @Authorized( { OpenmrsConstants.PRIV_EDIT_PATIENTS })
558         public void exitFromCare(Patient patient, Date dateExited,
559                 Concept reasonForExit) throws APIException;
560
561         /**
562          * Convenience method to establish that a patient has died. In addition to
563          * exiting the patient from care (see above), this method will also set the
564          * appropriate patient characteristics to indicate that they have died, when
565          * they died, etc.
566          *
567          * @param patient - the patient who has died
568          * @param dateDied - the declared date/time of the patient's death
569          * @param causeOfDeath - the concept that corresponds with the reason the
570          *        patient died
571          * @param otherReason - if the concept representing the reason is OTHER
572          *        NON-CODED, and a string-based "other" reason is supplied
573          * @throws APIException
574          */
575         // TODO Keep this in the PatientService?
576         @Authorized( { OpenmrsConstants.PRIV_EDIT_PATIENTS })
577         public void processDeath(Patient patient, Date dateDied,
578                 Concept causeOfDeath, String otherReason) throws APIException;
579
580         /**
581          * Convenience method that saves the Obs that indicates when and why the
582          * patient died (including any "other" reason there might be)
583          *
584          * @param patient - the patient who has died
585          * @param dateDied - the declared date/time of the patient's death
586          * @param causeOfDeath - the concept that corresponds with the reason the
587          *        patient died
588          * @param otherReason - if the concept representing the reason is OTHER
589          *        NON-CODED, and a string-based "other" reason is supplied
590          * @throws APIException
591          */
592         // TODO keep this in the PatientService?
593         @Authorized(value = { OpenmrsConstants.PRIV_VIEW_PATIENTS,
594                 OpenmrsConstants.PRIV_EDIT_OBS }, requireAll = true)
595         public void saveCauseOfDeathObs(Patient patient, Date dateDied,
596                 Concept causeOfDeath, String otherReason) throws APIException;
597        
598         /**
599      *
600      * @param identifierValidator which validator to get.
601      */
602     public IdentifierValidator getIdentifierValidator(Class<IdentifierValidator> clazz);
603
604     /**
605      *
606      */
607     public IdentifierValidator getIdentifierValidator(String pivClassName);
608    
609     /**
610      *
611      * @return the default IdentifierValidator
612      */
613     public IdentifierValidator getDefaultIdentifierValidator();
614
615         /**
616      * @return All registered PatientIdentifierValidators
617      * @should return all registered identifier validators
618      */
619     public Collection<IdentifierValidator> getAllIdentifierValidators();
620    
621 }
Note: See TracBrowser for help on using the browser.