Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/28/08 05:16:52 (8 months ago)
Author:
bmckown
Message:

complex_obs branch: Merging trunk to complex-obs [3891] [4378] TODO: sqldiff.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex-obs/src/api/org/openmrs/api/impl/ObsServiceImpl.java

    • Property svn:eol-style set to CRLF
    r4265 r4417  
    1919import java.util.LinkedHashMap; 
    2020import java.util.List; 
    21 import java.util.Locale; 
    2221import java.util.Map; 
    2322import java.util.Set; 
    24 import java.util.SortedSet; 
    25 import java.util.TreeSet; 
    2623import java.util.Vector; 
    2724 
    28 import org.apache.commons.logging.Log; 
    29 import org.apache.commons.logging.LogFactory; 
     25import org.openmrs.Cohort; 
    3026import org.openmrs.Concept; 
    31 import org.openmrs.ConceptComplex; 
    3227import org.openmrs.Encounter; 
    3328import org.openmrs.Location; 
     
    3530import org.openmrs.Obs; 
    3631import org.openmrs.Person; 
    37 import org.openmrs.api.APIAuthenticationException
     32import org.openmrs.User
    3833import org.openmrs.api.APIException; 
     34import org.openmrs.api.EncounterService; 
    3935import org.openmrs.api.ObsService; 
    4036import org.openmrs.api.context.Context; 
    4137import org.openmrs.api.db.ObsDAO; 
    42 import org.openmrs.logic.Aggregation; 
    43 import org.openmrs.logic.Constraint; 
    4438import org.openmrs.obs.ComplexData; 
    4539import org.openmrs.obs.ComplexObsHandler; 
    46 import org.openmrs.reporting.PatientSet; 
    4740import org.openmrs.util.OpenmrsClassLoader; 
    4841import org.openmrs.util.OpenmrsConstants; 
     42import org.openmrs.util.OpenmrsConstants.PERSON_TYPE; 
    4943 
    5044/** 
    51  * Observation-related services 
     45 * Default implementation of the Observation Service 
    5246 *  
    53  * @version 1.0 
     47 * @see org.openmrs.api.ObsService 
    5448 */ 
    55 public class ObsServiceImpl implements ObsService { 
    56  
    57         private Log log = LogFactory.getLog(this.getClass()); 
    58  
    59         private ObsDAO dao; 
     49public class ObsServiceImpl extends BaseOpenmrsService implements ObsService { 
     50 
     51        /** 
     52         * The data access object for the obs service 
     53         */ 
     54        protected ObsDAO dao; 
    6055 
    6156        /** 
     
    6762        private static Map<String, ComplexObsHandler> handlers = null; 
    6863 
     64        /** 
     65         * Default empty constructor for this obs service 
     66         */ 
    6967        public ObsServiceImpl() { 
    70         } 
    71  
    72         /** 
    73          * Returns the injected dao object for this class 
    74          *  
    75          * @return 
    76          */ 
    77         private ObsDAO getObsDAO() { 
    78                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_VIEW_OBS)) 
    79                         throw new APIAuthenticationException("Privilege required: " 
    80                                 + OpenmrsConstants.PRIV_VIEW_OBS); 
    81  
    82                 return dao; 
    8368        } 
    8469 
     
    9176 
    9277        /** 
    93          * @see org.openmrs.api.ObsService#createObs(org.openmrs.Obs) 
    94          */ 
    95         public void createObs(Obs obs) throws APIException { 
     78         * @see org.openmrs.api.ObsService#saveObs(org.openmrs.Obs, String) 
     79         */ 
     80        public Obs saveObs(Obs obs, String changeMessage) throws APIException { 
     81                // save or update complex obs 
     82                if (obs.isComplex() && null != obs.getComplexData().getData()) { 
     83                        ComplexObsHandler handler = getHandler(obs); 
     84                        if (null != handler) { 
     85                                handler.saveObs(obs); 
     86                        } 
     87                } 
     88                if (obs.getObsId() == null) { 
     89                        Context.requirePrivilege(OpenmrsConstants.PRIV_ADD_OBS); 
     90                        obs.setRequiredProperties(Context.getAuthenticatedUser(), 
     91                                                  new Date()); 
     92                        return dao.saveObs(obs); 
     93                } else { 
     94                        Context.requirePrivilege(OpenmrsConstants.PRIV_EDIT_OBS); 
     95 
     96                        if (changeMessage == null) 
     97                                throw new APIException("ChangeMessage is required when updating an obs in the database"); 
     98 
     99                        obs.setRequiredProperties(Context.getAuthenticatedUser(), 
     100                                                  new Date()); 
     101 
     102                        // get a copy of the passed in obs and save it to the 
     103                        // database. This allows us to create a new row and new obs_id 
     104                        // this method doesn't copy the obs_id 
     105                        Obs newObs = Obs.newInstance(obs); 
     106 
     107                        // unset any voided properties on the new obs 
     108                        newObs.setVoided(false); 
     109                        newObs.setVoidReason(null); 
     110                        newObs.setDateVoided(null); 
     111                        newObs.setVoidedBy(null); 
     112                        // unset the creation stats 
     113                        newObs.setCreator(null); 
     114                        newObs.setDateCreated(null); 
     115                        newObs.setRequiredProperties(Context.getAuthenticatedUser(), 
     116                                                     new Date()); 
     117 
     118                        // save the new row to the database with the changes that 
     119                        // have been made to it 
     120                        dao.saveObs(newObs); 
     121 
     122                        // void out the original observation to keep it around for 
     123                        // historical purposes 
     124                        Context.addProxyPrivilege(OpenmrsConstants.PRIV_DELETE_OBS); 
     125                        try { 
     126                                String reason = changeMessage + " (new obsId: " 
     127                                        + newObs.getObsId() + ")"; 
     128 
     129                                // fetch a clean copy of this obs from the database so that 
     130                                // we don't write the changes to the database when we save 
     131                                // the fact that the obs is now voided 
     132                                Context.evictFromSession(obs); 
     133                                obs = getObs(obs.getObsId()); 
     134                                // TODO: add a column to obs to link back to the new obs 
     135                                voidObs(obs, reason); 
     136 
     137                                // TODO should we evict the obs again here to avoid hb 
     138                                // nonuniqueobject errors? 
     139                                // Context.evictFromSession(obs); 
     140                        } finally { 
     141                                Context.removeProxyPrivilege(OpenmrsConstants.PRIV_DELETE_OBS); 
     142                        } 
     143 
     144                        return newObs; 
     145                } 
     146        } 
     147 
     148        /** 
     149         * @see org.openmrs.api.ObsService#getObs(java.lang.Integer) 
     150         */ 
     151        public Obs getObs(Integer obsId) throws APIException { 
     152                return dao.getObs(obsId); 
     153        } 
     154 
     155        /** 
     156         * @see org.openmrs.api.ObsService#updateObs(org.openmrs.Obs) 
     157         * @deprecated 
     158         */ 
     159        public void updateObs(Obs obs) throws APIException { 
     160                saveObs(obs, obs.getVoidReason()); 
     161        } 
     162 
     163        /** 
     164         * Voids an Obs 
     165         *  
     166         * If the Obs argument is an obsGroup, all group members will be voided. 
     167         *  
     168         * @see org.openmrs.api.ObsService#voidObs(org.openmrs.Obs, 
     169         *      java.lang.String) 
     170         * @param Obs obs the Obs to void 
     171         * @param String reason the void reason 
     172         * @throws APIException 
     173         */ 
     174        public Obs voidObs(Obs obs, String reason) throws APIException { 
     175                if (obs.isVoided()) { 
     176                        return obs; 
     177                } 
     178                // Handle complex obs. 
     179                // TODO: Is this necessary here? 
    96180                ComplexObsHandler handler = getHandler(obs); 
    97181                if (null != handler) { 
    98182                        handler.saveObs(obs); 
    99183                } 
    100                 setRequiredObsProperties(obs); 
    101  
    102                 getObsDAO().createObs(obs); 
    103         } 
    104  
    105         /** 
    106          * Sets the creator and dateCreated properties on the Obs object 
    107          *  
    108          * @param obs 
    109          */ 
    110         private void setRequiredObsProperties(Obs obs) { 
    111                 if (obs.getCreator() == null) 
    112                         obs.setCreator(Context.getAuthenticatedUser()); 
    113  
    114                 if (obs.getDateCreated() == null) 
    115                         obs.setDateCreated(new Date()); 
    116  
    117                 if (obs.getGroupMembers() != null) { 
    118                         for (Obs member : obs.getGroupMembers()) { 
    119                                 // if statement does a quick sanity check to 
    120                                 // avoid the simplest of infinite loops 
    121                                 if (member.getCreator() == null 
    122                                         || member.getDateCreated() == null) 
    123                                         setRequiredObsProperties(member); 
     184 
     185                User user = Context.getAuthenticatedUser(); 
     186                Date date = new Date(); 
     187 
     188                Set<Obs> obsToVoid = new HashSet<Obs>(); 
     189                obsToVoid.add(obs); 
     190 
     191                fetchObsMembers(obs, obsToVoid); 
     192 
     193                for (Obs o : obsToVoid) { 
     194                        // don't overwrite the void attrs of something that is already 
     195                        // voided 
     196                        if (o.isVoided() == false) { 
     197                                o.setVoided(true); 
     198                                o.setVoidReason(reason); 
     199                                o.setVoidedBy(user); 
     200                                o.setDateVoided(date); 
    124201                        } 
    125202                } 
    126         } 
    127  
    128         /** 
    129          *  
     203 
     204                return dao.saveObs(obs); 
     205        } 
     206 
     207        /** 
     208         * Convenience method that recursively finds all 
     209         * child/grandchild/greatgrandchild group members of the given parentObs 
     210         *  
     211         * @param parentObs 
     212         * @param childMembers 
     213         */ 
     214        private void fetchObsMembers(Obs parentObs, Set<Obs> childMembers) { 
     215                if (parentObs.isObsGrouping()) { 
     216                        for (Obs obsInner : parentObs.getGroupMembers()) { 
     217                                // add the current child iteration to the list of members 
     218                                // and if it was not already in the list, adds its children 
     219                                if (childMembers.add(obsInner) == true) 
     220                                        fetchObsMembers(obsInner, childMembers); 
     221                        } 
     222                } 
     223        } 
     224 
     225        /** 
     226         * Unvoids an Obs 
     227         *  
     228         * If the Obs argument is an obsGroup, all group members with the same 
     229         * dateVoided will also be unvoided. 
     230         *  
     231         * @see org.openmrs.api.ObsService#unvoidObs(org.openmrs.Obs) 
     232         * @param Obs obs the Obs to unvoid 
     233         * @throw APIException 
     234         */ 
     235        public Obs unvoidObs(Obs obs) throws APIException { 
     236                if (obs.isVoided() == false) { 
     237                        return obs; 
     238                } 
     239 
     240                Set<Obs> obsToUnvoid = new HashSet<Obs>(); 
     241                obsToUnvoid.add(obs); 
     242 
     243                fetchObsMembers(obs, obsToUnvoid); 
     244 
     245                Date originalDateVoided = obs.getDateVoided(); 
     246                for (Obs o : obsToUnvoid) { 
     247                        // unvoid all obs that have the same voided time as the 
     248                        if (originalDateVoided.equals(o.getDateVoided())) { 
     249                                o.setVoided(false); 
     250                                o.setVoidReason(null); 
     251                                o.setVoidedBy(null); 
     252                                o.setDateVoided(null); 
     253                        } 
     254                } 
     255                return dao.saveObs(obs); 
     256        } 
     257 
     258        /** 
     259         * @see org.openmrs.api.ObsService#purgeObs(org.openmrs.Obs, boolean) 
     260         */ 
     261        public void purgeObs(Obs obs, boolean cascade) throws APIException { 
     262                if (cascade) { 
     263                        throw new APIException("Cascading purge of obs not yet implemented"); 
     264                        // TODO delete any related objects here before deleting the obs 
     265                        // obsGroups objects? 
     266                        // orders? 
     267                } 
     268 
     269                dao.deleteObs(obs); 
     270        } 
     271 
     272        /** 
     273         * @see org.openmrs.api.ObsService#purgeObs(org.openmrs.Obs) 
     274         */ 
     275        public void purgeObs(Obs obs) throws APIException { 
     276                this.purgeComplexData(obs); 
     277                purgeObs(obs, false); 
     278        } 
     279 
     280        /** 
     281         * @see org.openmrs.api.ObsService#getMimeTypes() 
     282         * @deprecated use {@link #getAllMimeTypes()} 
     283         */ 
     284        public List<MimeType> getMimeTypes() throws APIException { 
     285                return getAllMimeTypes(); 
     286        } 
     287 
     288        /** 
     289         * @see org.openmrs.api.ObsService#getAllMimeTypes() 
     290         */ 
     291        public List<MimeType> getAllMimeTypes() throws APIException { 
     292                return dao.getAllMimeTypes(true); 
     293        } 
     294 
     295        /** 
     296         * @see org.openmrs.api.ObsService#getAllMimeTypes(boolean) 
     297         */ 
     298        public List<MimeType> getAllMimeTypes(boolean includeRetired) { 
     299                return dao.getAllMimeTypes(includeRetired); 
     300        } 
     301 
     302        /** 
     303         * @see org.openmrs.api.ObsService#saveMimeType(org.openmrs.MimeType) 
     304         */ 
     305        public MimeType saveMimeType(MimeType mimeType) throws APIException { 
     306                return dao.saveMimeType(mimeType); 
     307        } 
     308 
     309        /** 
     310         * @see org.openmrs.api.ObsService#voidMimeType(org.openmrs.MimeType, 
     311         *      java.lang.String) 
     312         */ 
     313        public MimeType voidMimeType(MimeType mimeType, String reason) 
     314                throws APIException { 
     315                // TODO implement voidMimeType 
     316                throw new APIException("Not yet implemented"); 
     317        } 
     318 
     319        /** 
     320         * @see org.openmrs.api.ObsService#getMimeType(java.lang.Integer) 
     321         */ 
     322        public MimeType getMimeType(Integer mimeTypeId) throws APIException { 
     323                return dao.getMimeType(mimeTypeId); 
     324        } 
     325 
     326        /** 
     327         * @see org.openmrs.api.ObsService#purgeMimeType(org.openmrs.MimeType) 
     328         */ 
     329        public void purgeMimeType(MimeType mimeType) { 
     330                dao.deleteMimeType(mimeType); 
     331        } 
     332 
     333        /** 
     334         * @see org.openmrs.api.ObsService#getObservations(java.util.List, 
     335         *      java.util.List, java.util.List, java.util.List, List, List, 
     336         *      java.util.List, java.lang.Integer, java.lang.Integer, 
     337         *      java.util.Date, java.util.Date, boolean) 
     338         */ 
     339        public List<Obs> getObservations(List<Person> whom, 
     340                List<Encounter> encounters, List<Concept> questions, 
     341                List<Concept> answers, List<PERSON_TYPE> personTypes, 
     342                List<Location> locations, List<String> sort, Integer mostRecentN, 
     343                Integer obsGroupId, Date fromDate, Date toDate, 
     344                boolean includeVoidedObs) throws APIException { 
     345                if (whom == null) 
     346                        whom = new Vector<Person>(); 
     347 
     348                if (encounters == null) 
     349                        encounters = new Vector<Encounter>(); 
     350 
     351                if (questions == null) 
     352                        questions = new Vector<Concept>(); 
     353 
     354                if (answers == null) 
     355                        answers = new Vector<Concept>(); 
     356 
     357                if (personTypes == null) 
     358                        personTypes = new Vector<PERSON_TYPE>(); 
     359 
     360                if (locations == null) 
     361                        locations = new Vector<Location>(); 
     362 
     363                if (sort == null) 
     364                        sort = new Vector<String>(); 
     365                if (sort.isEmpty()) 
     366                        sort.add("obsDatetime"); 
     367 
     368                // default to returning all observations 
     369                if (mostRecentN == null) 
     370                        mostRecentN = -1; 
     371 
     372                return dao.getObservations(whom, 
     373                                           encounters, 
     374                                           questions, 
     375                                           answers, 
     376                                           personTypes, 
     377                                           locations, 
     378                                           sort, 
     379                                           mostRecentN, 
     380                                           obsGroupId, 
     381                                           fromDate, 
     382                                           toDate, 
     383                                           includeVoidedObs); 
     384        } 
     385 
     386        /** 
     387         * This implementation queries the obs table comparing the given 
     388         * <code>searchString</code> with the patient's identifier, encounterId, 
     389         * and obsId 
     390         *  
     391         * @see org.openmrs.api.ObsService#getObservations(java.lang.String) 
     392         */ 
     393        public List<Obs> getObservations(String searchString) { 
     394                EncounterService es = Context.getEncounterService(); 
     395 
     396                // search on patient identifier 
     397                List<Encounter> encounters = es.getEncountersByPatientIdentifier(searchString); 
     398 
     399                // try to search on encounterId 
     400                try { 
     401                        Encounter e = es.getEncounter(Integer.valueOf(searchString)); 
     402                        if (e != null) 
     403                                encounters.add(e); 
     404                } catch (NumberFormatException e) { 
     405                        // pass 
     406                } 
     407 
     408                List<Obs> returnList = getObservations(null, 
     409                                                       encounters, 
     410                                                       null, 
     411                                                       null, 
     412                                                       null, 
     413                                                       null, 
     414                                                       null, 
     415                                                       null, 
     416                                                       null, 
     417                                                       null, 
     418                                                       null, 
     419                                                       false); 
     420 
     421                // try to search on obsId 
     422                try { 
     423                        Obs o = getObs(Integer.valueOf(searchString)); 
     424                        if (o != null) 
     425                                returnList.add(o); 
     426                } catch (NumberFormatException e) { 
     427                        // pass 
     428                } 
     429 
     430                return returnList; 
     431        } 
     432 
     433        /** 
     434         * @see org.openmrs.api.ObsService#createObs(org.openmrs.Obs) 
     435         * @deprecated 
     436         */ 
     437        public void createObs(Obs obs) throws APIException { 
     438                saveObs(obs, null); 
     439        } 
     440 
     441        /** 
    130442         * Correct use case: 
    131443         *  
     
    178490 
    179491        /** 
    180          * @see org.openmrs.api.ObsService#getObs(java.lang.Integer) 
    181          */ 
    182         public Obs getObs(Integer obsId) throws APIException { 
    183                 return getObsDAO().getObs(obsId); 
    184         } 
     492         * @see org.openmrs.api.ObsService#deleteObs(org.openmrs.Obs) 
     493         * @deprecated use #purgeObs(Obs) 
     494         */ 
     495        public void deleteObs(Obs obs) throws APIException { 
     496                purgeObs(obs); 
     497        } 
     498 
     499        /** 
     500         * @see org.openmrs.api.ObsService#getObservationsByPerson(org.openmrs.Person) 
     501         */ 
     502        public List<Obs> getObservationsByPerson(Person who) { 
     503                List<Person> whom = new Vector<Person>(); 
     504                whom.add(who); 
     505                return getObservations(whom, 
     506                                       null, 
     507                                       null, 
     508                                       null, 
     509                                       null, 
     510                                       null, 
     511                                       null, 
     512                                       null, 
     513                                       null, 
     514                                       null, 
     515                                       null, 
     516                                       false); 
     517        } 
     518 
     519        /** 
     520         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, 
     521         *      boolean includeVoided) 
     522         * @deprecated use {@link #getObservationsByPerson(Person)} 
     523         */ 
     524        public Set<Obs> getObservations(Person who, boolean includeVoided) { 
     525                if (includeVoided == true) 
     526                        throw new APIException("Voided observations are no longer allowed to be queried"); 
     527 
     528                Set<Obs> obsSet = new HashSet<Obs>(); 
     529                obsSet.addAll(getObservationsByPerson(who)); 
     530 
     531                return obsSet; 
     532        } 
     533 
     534        /** 
     535         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Concept, 
     536         *      org.openmrs.Location, java.lang.String, java.lang.Integer, boolean 
     537         *      includeVoided) 
     538         * @deprecated 
     539         */ 
     540        public List<Obs> getObservations(Concept c, Location loc, String sort, 
     541                Integer personType, boolean includeVoided) { 
     542                List<Concept> questions = new Vector<Concept>(); 
     543                questions.add(c); 
     544                List<Location> locations = new Vector<Location>(); 
     545                locations.add(loc); 
     546 
     547                // make the sort list from the given sort string 
     548                List<String> sortList = makeSortList(sort); 
     549 
     550                return getObservations(null, 
     551                                       null, 
     552                                       questions, 
     553                                       null, 
     554                                       getPersonTypeEnumerations(personType), 
     555                                       locations, 
     556                                       sortList, 
     557                                       null, 
     558                                       null, 
     559                                       null, 
     560                                       null, 
     561                                       includeVoided); 
     562        } 
     563 
     564        /** 
     565         * Convenience method for turning a string like "location.locationId asc, 
     566         * obs.valueDatetime desc" into a list of strings to sort on 
     567         *  
     568         * @param sort string 
     569         * @return simple list of strings to sort on without asc/desc 
     570         */ 
     571        private List<String> makeSortList(String sort) { 
     572                List<String> sortList = new Vector<String>(); 
     573                if (sort != null && !"".equals(sort)) { 
     574                        for (String sortPart : sort.split(",")) { 
     575 
     576                                sortPart = sortPart.trim(); 
     577 
     578                                // split out the asc/desc part if applicable 
     579                                if (sortPart.contains(" ")) 
     580                                        sortPart = sortPart.substring(0, sortPart.indexOf(" ")); 
     581 
     582                                // add the current sort to the list of things to sort on 
     583                                if (!"".equals(sort)) 
     584                                        sortList.add(sortPart); 
     585                        } 
     586                } 
     587 
     588                return sortList; 
     589        } 
     590 
     591        /** 
     592         * This method should be removed when all methods using an Integer 
     593         * personType are removed. 
     594         *  
     595         * This method does a bitwise compare on <code>personType</code> and 
     596         * returns a list of PERSON_TYPEs that are comparable 
     597         *  
     598         * @param personType Integer corresponding to {@link ObsService#PERSON}, 
     599         *        {@link ObsService#USER}, or {@link ObsService#PATIENT}, 
     600         * @return the enumeration that corresponds to the given integer (old way of 
     601         *         doing it) 
     602         */ 
     603        @SuppressWarnings("deprecation") 
     604        private List<PERSON_TYPE> getPersonTypeEnumerations(Integer personType) { 
     605                List<PERSON_TYPE> personTypes = new Vector<PERSON_TYPE>(); 
     606                if (personType == null) { 
     607                        personTypes.add(PERSON_TYPE.PERSON); 
     608                        return personTypes; 
     609                } else if ((personType & ObsService.PATIENT) == ObsService.PATIENT) { 
     610                        personTypes.add(PERSON_TYPE.PATIENT); 
     611                        return personTypes; 
     612                } else if ((personType & ObsService.USER) == ObsService.USER) { 
     613                        personTypes.add(PERSON_TYPE.USER); 
     614                        return personTypes; 
     615                } else { 
     616                        // default to an all-encompassing search 
     617                        return personTypes; 
     618                } 
     619        } 
     620 
     621        /** 
     622         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, 
     623         *      org.openmrs.Concept, boolean includeVoided) 
     624         * @deprecated 
     625         */ 
     626        public Set<Obs> getObservations(Person who, Concept question, 
     627                boolean includeVoided) { 
     628                List<Person> whom = new Vector<Person>(); 
     629                whom.add(who); 
     630                List<Concept> questions = new Vector<Concept>(); 
     631                questions.add(question); 
     632 
     633                List<Obs> obs = getObservations(whom, 
     634                                                null, 
     635                                                questions, 
     636                                                null, 
     637                                                null, 
     638                                                null, 
     639                                                null, 
     640                                                null, 
     641                                                null, 
     642                                                null, 
     643                                                null, 
     644                                                includeVoided); 
     645                Set<Obs> obsSet = new HashSet<Obs>(); 
     646                obsSet.addAll(obs); 
     647                return obsSet; 
     648        } 
     649 
     650        /** 
     651         * @see org.openmrs.api.ObsService#getLastNObservations(java.lang.Integer, 
     652         *      org.openmrs.Person, org.openmrs.Concept, boolean includeVoided) 
     653         * @deprecated 
     654         */ 
     655        public List<Obs> getLastNObservations(Integer n, Person who, 
     656                Concept question, boolean includeVoided) { 
     657                List<Person> whom = new Vector<Person>(); 
     658                whom.add(who); 
     659                List<Concept> questions = new Vector<Concept>(); 
     660                questions.add(question); 
     661 
     662                return getObservations(whom, 
     663                                       null, 
     664                                       questions, 
     665                                       null, 
     666                                       null, 
     667                                       null, 
     668                                       null, 
     669                                       n, 
     670                                       null, 
     671                                       null, 
     672                                       null, 
     673                                       includeVoided); 
     674        } 
     675 
     676        /** 
     677         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Concept, 
     678         *      java.lang.String, java.lang.Integer, boolean includeVoided) 
     679         * @deprecated 
     680         */ 
     681        public List<Obs> getObservations(Concept question, String sort, 
     682                Integer personType, boolean includeVoided) { 
     683                List<Concept> questions = new Vector<Concept>(); 
     684                questions.add(question); 
     685 
     686                // make the sort list from the given sort string 
     687                List<String> sortList = makeSortList(sort); 
     688 
     689                return getObservations(null, 
     690                                       null, 
     691                                       questions, 
     692                                       null, 
     693                                       getPersonTypeEnumerations(personType), 
     694                                       null, 
     695                                       sortList, 
     696                                       null, 
     697                                       null, 
     698                                       null, 
     699                                       null, 
     700                                       includeVoided); 
     701        } 
     702 
     703        /** 
     704         * @see org.openmrs.api.ObsService#getObservationsAnsweredByConcept(org.openmrs.Concept, 
     705         *      java.lang.Integer, boolean includeVoided) 
     706         * @deprecated 
     707         */ 
     708        public List<Obs> getObservationsAnsweredByConcept(Concept answer, 
     709                Integer personType, boolean includeVoided) { 
     710                List<Concept> answers = new Vector<Concept>(); 
     711                answers.add(answer); 
     712 
     713                return getObservations(null, 
     714                                       null, 
     715                                       null, 
     716                                       answers, 
     717                                       getPersonTypeEnumerations(personType), 
     718                                       null, 
     719                                       null, 
     720                                       null, 
     721                                       null, 
     722                                       null, 
     723                                       null, 
     724                                       includeVoided); 
     725        } 
     726 
     727        /** 
     728         * @see org.openmrs.api.ObsService#getNumericAnswersForConcept(org.openmrs.Concept, 
     729         *      java.lang.Boolean, java.lang.Integer, boolean includeVoided) 
     730         * @deprecated 
     731         */ 
     732        public List<Object[]> getNumericAnswersForConcept(Concept answer, 
     733                Boolean sortByValue, Integer personType, boolean includeVoided) { 
     734                List<String> sortList = new Vector<String>(); 
     735                if (sortByValue) { 
     736                        sortList.add("valueNumeric"); 
     737                } 
     738 
     739                List<Concept> answers = new Vector<Concept>(); 
     740                answers.add(answer); 
     741 
     742                List<Obs> obs = getObservations(null, 
     743                                                null, 
     744                                                null, 
     745                                                answers, 
     746                                                getPersonTypeEnumerations(personType), 
     747                                                null, 
     748                                                sortList, 
     749                                                null, 
     750                                                null, 
     751                                                null, 
     752                                                null, 
     753                                                includeVoided); 
     754 
     755                List<Object[]> returnList = new Vector<Object[]>(); 
     756 
     757                for (Obs o : obs) { 
     758                        returnList.add(new Object[] { o.getObsId(), o.getObsDatetime(), 
     759                                o.getValueNumeric() }); 
     760                } 
     761 
     762                return returnList; 
     763        } 
     764 
     765        /** 
     766         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Encounter) 
     767         * @deprecated use org.openmrs.Encounter#getObs() 
     768         */ 
     769        public Set<Obs> getObservations(Encounter whichEncounter) { 
     770                return whichEncounter.getObs(); 
     771        } 
     772 
     773        /** 
     774         * @see org.openmrs.api.ObsService#getVoidedObservations() 
     775         * @deprecated 
     776         */ 
     777        public List<Obs> getVoidedObservations() { 
     778                return getObservations(null, 
     779                                       null, 
     780                                       null, 
     781                                       null, 
     782                                       null, 
     783                                       null, 
     784                                       null, 
     785                                       null, 
     786                                       null, 
     787                                       null, 
     788                                       null, 
     789                                       true); 
     790        } 
     791 
     792        /** 
     793         * @see org.openmrs.api.ObsService#findObservations(java.lang.String, 
     794         *      boolean, java.lang.Integer) 
     795         * @deprecated 
     796         */ 
     797        public List<Obs> findObservations(String search, boolean includeVoided, 
     798                Integer personType) { 
     799                // ignoring voided and personTypes now 
     800                return getObservations(search); 
     801        } 
     802 
     803        /** 
     804         * @see org.openmrs.api.ObsService#findObsByGroupId(java.lang.Integer) 
     805         * @deprecated -- should use obs.getGroupMembers 
     806         */ 
     807        public List<Obs> findObsByGroupId(Integer obsGroupId) { 
     808                return getObservations(null, 
     809                                       null, 
     810                                       null, 
     811                                       null, 
     812                                       null, 
     813                                       null, 
     814                                       null, 
     815                                       null, 
     816                                       obsGroupId, 
     81