Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/11/08 23:52:52 (7 months ago)
Author:
bmckown
Message:

complex_obs branch: Changed to mapping the ComplexObsHandlers instead of using ConceptComplexHandler class.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/complex_obs/src/api/org/openmrs/api/ObsService.java

    r3847 r4166  
    1414package org.openmrs.api; 
    1515 
     16import java.util.Collection; 
    1617import java.util.Date; 
    1718import java.util.List; 
     19import java.util.Map; 
    1820import java.util.Set; 
    1921 
     
    2830import org.openmrs.logic.Aggregation; 
    2931import org.openmrs.logic.Constraint; 
     32import org.openmrs.obs.ComplexData; 
     33import org.openmrs.obs.ComplexObsHandler; 
    3034import org.openmrs.reporting.PatientSet; 
    3135import org.openmrs.util.OpenmrsConstants; 
     
    3337 
    3438/** 
    35  * The ObsService provides methods for acting on Obs, ObsGroup, and  
    36  * ComplexObs objects. 
     39 * The ObsService provides methods for acting on Obs, ObsGroup, and ComplexObs 
     40 * objects. 
    3741 *  
    38  * Use: 
    39  * <code> 
     42 * Use: <code> 
    4043 *      Context.getObsService().getObs(123); 
    4144 * </code> 
    4245 *  
    43  * There are also a number of convenience methods for extracting obs 
    44  * pertaining to certain Concepts, people, or encounters 
     46 * There are also a number of convenience methods for extracting obs pertaining 
     47 * to certain Concepts, people, or encounters 
    4548 *  
    4649 */ 
    4750@Transactional 
    4851public interface ObsService { 
    49          
     52 
    5053        public static final Integer PERSON = 1; 
    5154        public static final Integer PATIENT = 2; 
    5255        public static final Integer USER = 4; 
    53          
     56 
    5457        public void setObsDAO(ObsDAO dao); 
    5558 
     
    6063         * @throws APIException 
    6164         */ 
    62         @Authorized({OpenmrsConstants.PRIV_ADD_OBS}) 
     65        @Authorized( { OpenmrsConstants.PRIV_ADD_OBS }) 
    6366        public void createObs(Obs obs) throws APIException; 
    64          
     67 
    6568        /** 
    6669         * Create a grouping of observations (observations linked by 
     
    6871         *  
    6972         * The proper use is: 
     73         *  
    7074         * <pre> 
    7175         * Obs obsGroup = new Obs(); 
     
    7882         * @param obs array of observations to be grouped 
    7983         * @throws APIException 
    80          * @deprecated This method should no longer need to be called on the api. This 
    81          *                       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)} 
    8387         *  
    8488         * @see #createObsGroup(Obs, List) 
    8589         */ 
    86         @Authorized({OpenmrsConstants.PRIV_ADD_OBS}) 
     90        @Authorized( { OpenmrsConstants.PRIV_ADD_OBS }) 
    8791        public void createObsGroup(Obs[] obs) throws APIException; 
    8892 
     
    9094         * Get an observation 
    9195         *  
    92          * @param integer 
    93          *            obsId of observation desired 
     96         * @param integer obsId of observation desired 
    9497         * @return matching Obs 
    9598         * @throws APIException 
    9699         */ 
    97100        @Transactional(readOnly = true) 
    98         @Authorized({OpenmrsConstants.PRIV_VIEW_OBS}) 
     101        @Authorized( { OpenmrsConstants.PRIV_VIEW_OBS }) 
    99102        public Obs getObs(Integer obsId) throws APIException; 
    100103 
    101104        /** 
     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        /** 
    102127         * Save changes to observation 
    103128         *  
     
    105130         * @throws APIException 
    106131         */ 
    107         @Authorized({OpenmrsConstants.PRIV_EDIT_OBS}) 
     132        @Authorized( { OpenmrsConstants.PRIV_EDIT_OBS }) 
    108133        public void updateObs(Obs obs) throws APIException; 
    109134 
     
    111136         * Equivalent to deleting an observation 
    112137         *  
     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         *  
    113148         * @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. 
    124156         *  
    125157         * @param Obs 
    126158         * @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 Obs 
    135          * @throws APIException 
    136159         * @see voidObs(Obs) 
    137160         */ 
    138         @Authorized({OpenmrsConstants.PRIV_DELETE_OBS}) 
     161        @Authorized( { OpenmrsConstants.PRIV_DELETE_OBS }) 
    139162        public void deleteObs(Obs obs) throws APIException; 
    140          
     163 
    141164        /** 
    142165         * Get all mime types 
     
    151174         * Get mimeType by internal identifier 
    152175         *  
    153          * @param mimeType 
    154          *            id 
     176         * @param mimeType id 
    155177         * @return mimeType with given internal identifier 
    156178         * @throws APIException 
     
    180202         */ 
    181203        @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); 
    183206 
    184207        /** 
     
    191214         */ 
    192215        @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); 
    194218 
    195219        /** 
    196220         * e.g. get last 'n' number of observations for a person for given concept 
    197221         *  
    198          * @param n 
    199          *            number of concepts to retrieve 
     222         * @param n number of concepts to retrieve 
    200223         * @param who 
    201224         * @param question 
     
    204227        @Transactional(readOnly = true) 
    205228        public List<Obs> getLastNObservations(Integer n, Person who, 
    206                        Concept question, boolean includeVoided); 
     229                Concept question, boolean includeVoided); 
    207230 
    208231        /** 
    209232         * e.g. get all observations referring to RETURN VISIT DATE 
    210233         *  
    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) 
    225247         *  
    226248         * @param concept 
     
    229251         */ 
    230252        @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 
    233256        /** 
    234257         * Return all numeric answer values for the given concept ordered by value 
     
    238261         *  
    239262         * @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 
    248274        /** 
    249275         * Get all observations from a specific encounter 
     
    274300         */ 
    275301        @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); 
    277304 
    278305        /** 
     
    283310         */ 
    284311        @Transactional(readOnly = true) 
    285         public List<String> getDistinctObservationValues(Concept question, Integer personType); 
     312        public List<String> getDistinctObservationValues(Concept question, 
     313                Integer personType); 
    286314 
    287315        /** 
     
    295323        @Authorized( { "View Person" }) 
    296324        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) 
    303333         * @param fromDate 
    304334         * @param toDate 
     
    307337         */ 
    308338        @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) 
    315348         * @param fromDate 
    316349         * @param toDate 
     
    318351         */ 
    319352        @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 
    328365         * @param fromDate lower bound for date - null means no lower bound 
    329366         * @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  
    331377         */ 
    332378        @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         
    334442}