Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/19/08 23:47:49 (6 months ago)
Author:
bmckown
Message:

complex_obs branch: Added ability to override handlers via Spring. Added methods to update and purge ComplexData from the file system. Added support for multiple mime types in ImageHandler based on file name. Added temporary files complexObsList.jsp and complexObsForm.jsp

Files:

Legend:

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

    r4239 r4265  
    6262         * Report handlers that have been registered. 
    6363         *  
    64          * This is filled via {@link #setHandlers(Map)} and spring's applicationContext-service.xml object 
     64         * This is filled via {@link #setHandlers(Map)} and spring's 
     65         * applicationContext-service.xml object 
    6566         */ 
    6667        private static Map<String, ComplexObsHandler> handlers = null; 
    67          
    68          
     68 
    6969        public ObsServiceImpl() { 
    7070        } 
     
    7878                if (!Context.hasPrivilege(OpenmrsConstants.PRIV_VIEW_OBS)) 
    7979                        throw new APIAuthenticationException("Privilege required: " 
    80                                        + OpenmrsConstants.PRIV_VIEW_OBS); 
     80                                + OpenmrsConstants.PRIV_VIEW_OBS); 
    8181 
    8282                return dao; 
     
    9999                } 
    100100                setRequiredObsProperties(obs); 
    101                  
     101 
    102102                getObsDAO().createObs(obs); 
    103103        } 
    104          
     104 
    105105        /** 
    106106         * Sets the creator and dateCreated properties on the Obs object 
     
    114114                if (obs.getDateCreated() == null) 
    115115                        obs.setDateCreated(new Date()); 
    116                  
     116 
    117117                if (obs.getGroupMembers() != null) { 
    118118                        for (Obs member : obs.getGroupMembers()) { 
    119119                                // if statement does a quick sanity check to 
    120120                                // avoid the simplest of infinite loops 
    121                                 if (member.getCreator() == null ||  
    122                                        member.getDateCreated() == null) 
    123                                                setRequiredObsProperties(member); 
     121                                if (member.getCreator() == null 
     122                                        || member.getDateCreated() == null) 
     123                                        setRequiredObsProperties(member); 
    124124                        } 
    125125                } 
     
    129129         *  
    130130         * Correct use case: 
     131         *  
    131132         * <pre> 
    132133         * Obs parent = new Obs(); 
     
    138139         * </pre> 
    139140         *  
    140          * @deprecated This method should no longer need to be called on the api. This 
    141          *                        was meant as temporary until we created a true ObsGroup pojo. 
     141         * @deprecated This method should no longer need to be called on the api. 
     142         *             This was meant as temporary until we created a true ObsGroup 
     143         *             pojo. 
    142144         *  
    143145         * @see org.openmrs.api.ObsService#createObsGroup(org.openmrs.Obs[]) 
     
    146148                if (obs == null || obs.length < 1) 
    147149                        return; // silently tolerate calls with missing/empty parameter 
    148                  
    149                 String conceptIdStr = Context.getAdministrationService(). 
    150                 getGlobalProperty( 
    151                           OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS,  
    152           "1238"); 
     150 
     151                String conceptIdStr = Context.getAdministrationService() 
     152                                             .getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS, 
     153                                                                "1238"); 
    153154                // fail silently if a default obs group is not defined 
    154155                if (conceptIdStr == null || conceptIdStr.length() == 0) 
    155156                        return; 
    156                  
     157 
    157158                Integer conceptId = Integer.valueOf(conceptIdStr); 
    158                 Concept defaultObsGroupConcept = Context.getConceptService().getConcept(conceptId); 
    159                  
     159                Concept defaultObsGroupConcept = Context.getConceptService() 
     160                                                        .getConcept(conceptId); 
     161 
    160162                // if they defined a bad concept, bail 
    161163                if (defaultObsGroupConcept == null) 
    162                 throw new APIException("There is no concept defined with concept id: " + conceptIdStr + 
    163                                "You should correctly define the default obs group concept id with the global propery" +  
    164                                OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS); 
    165                  
     164                        throw new APIException("There is no concept defined with concept id: " 
     165                                + conceptIdStr 
     166                                + "You should correctly define the default obs group concept id with the global propery" 
     167                                + OpenmrsConstants.GLOBAL_PROPERTY_MEDICAL_RECORD_OBSERVATIONS); 
     168 
    166169                Obs obsGroup = new Obs(); 
    167170                obsGroup.setConcept(defaultObsGroupConcept); 
    168                  
     171 
    169172                for (Obs member : obs) { 
    170               obsGroup.addGroupMember(member); 
    171       } 
    172          
    173       updateObs(obsGroup); 
     173                      obsGroup.addGroupMember(member); 
     174              } 
     175 
     176              updateObs(obsGroup); 
    174177        } 
    175178 
     
    180183                return getObsDAO().getObs(obsId); 
    181184        } 
    182          
     185 
    183186        /** 
    184187         * @see org.openmrs.api.ObsService#getComplexObs(java.lang.Integer) 
    185188         */ 
    186         public Obs getComplexObs(Integer obsId) throws APIException { 
     189        public Obs getComplexObs(Integer obsId, String view) throws APIException { 
    187190                Obs obs = getObsDAO().getObs(obsId); 
    188191                if (obs.isComplex()) { 
    189                         return getHandler(obs).getObs(obs); 
     192                        return getHandler(obs).getObs(obs, view); 
    190193                } 
    191194                return obs; 
    192195        } 
     196 
     197        /** 
     198         * @see org.openmrs.api.ObsService#getAllComplexObs() 
     199         */ 
     200        public List<Obs> getAllComplexObs() throws APIException { 
     201                List<Obs> obs = getObsDAO().getAllComplexObs(); 
     202                return obs; 
     203        } 
     204 
     205        /** 
     206         * @see org.openmrs.api.ObsService#getComplexData(java.lang.Integer) 
     207         */ 
     208        public ComplexData getComplexData(Integer obsId, String view) 
     209                throws APIException { 
     210                return this.getComplexObs(obsId, view).getComplexData(); 
     211        } 
     212 
     213        /** 
     214         * @see org.openmrs.api.ObsService#getComplexData(org.openmrs.Obs) 
     215         */ 
     216        public ComplexData getComplexData(Obs obs, String view) throws APIException { 
     217                return this.getComplexObs(obs.getObsId(), view).getComplexData(); 
     218        } 
    193219         
    194220        /** 
    195          * @see org.openmrs.api.ObsService#getComplexData(java.lang.Integer) 
    196          */ 
    197         public ComplexData getComplexData(Integer obsId) throws APIException { 
    198                 return this.getComplexObs(obsId).getComplexData(); 
    199         } 
    200  
    201         /** 
    202          * @see org.openmrs.api.ObsService#getComplexData(org.openmrs.Obs) 
    203          */ 
    204         public ComplexData getComplexData(Obs obs) throws APIException { 
    205                 return this.getComplexObs(obs.getObsId()).getComplexData(); 
    206         } 
    207                  
     221         * @see org.openmrs.api.ObsService#purgeComplexData(org.openmrs.Obs) 
     222         */ 
     223        public boolean purgeComplexData(Obs obs) throws APIException { 
     224                if (obs.isComplex()) { 
     225                        ComplexObsHandler handler = this.getHandler(obs); 
     226                        if (null != handler) { 
     227                                return handler.purgeComplexData(obs); 
     228                        } 
     229                } 
     230                return false; 
     231        } 
     232         
    208233        /** 
    209234         * @see org.openmrs.api.ObsService#updateObs(org.openmrs.Obs) 
    210235         */ 
    211236        public void updateObs(Obs obs) throws APIException { 
     237                if (obs.isComplex() && null != obs.getComplexData().getData()) { 
     238                        ComplexObsHandler handler = getHandler(obs); 
     239                        if (null != handler) { 
     240                                handler.saveObs(obs); 
     241                        } 
     242                } 
    212243                if (obs.isVoided() && obs.getVoidedBy() == null) 
    213244                        voidObs(obs, obs.getVoidReason()); 
     
    226257         * If the Obs argument is an obsGroup, all group members will be voided. 
    227258         *  
    228          * @see org.openmrs.api.ObsService#voidObs(org.openmrs.Obs, java.lang.String) 
     259         * @see org.openmrs.api.ObsService#voidObs(org.openmrs.Obs, 
     260         *      java.lang.String) 
    229261         * @param Obs obs the Obs to void 
    230262         * @param String reason the void reason 
    231263         * @throws APIException 
    232264         */ 
    233          
     265 
    234266        public void voidObs(Obs obs, String reason) throws APIException { 
    235267                Set<Obs> obsToVoid = new HashSet<Obs>(); 
     
    258290                if (null != handler) { 
    259291                        handler.saveObs(obs); 
    260                 }               
     292                } 
    261293                getObsDAO().updateObs(obs); 
    262294        } 
     
    265297         * Unvoids an Obs 
    266298         *  
    267          * If the Obs argument is an obsGroup, all group members 
    268          * with the same dateVoided will also be unvoided. 
     299         * If the Obs argument is an obsGroup, all group members with the same 
     300         * dateVoided will also be unvoided. 
    269301         *  
    270302         * @see org.openmrs.api.ObsService#unvoidObs(org.openmrs.Obs) 
     
    303335         */ 
    304336        public void deleteObs(Obs obs) throws APIException { 
     337                this.purgeComplexData(obs); 
    305338                getObsDAO().deleteObs(obs); 
    306339        } 
    307          
     340 
    308341        /** 
    309342         * @see org.openmrs.api.ObsService#getMimeTypes() 
     
    321354 
    322355        /** 
    323          * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, boolean includeVoided) 
     356         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, 
     357         *      boolean includeVoided) 
    324358         */ 
    325359        public Set<Obs> getObservations(Person who, boolean includeVoided) { 
     
    328362 
    329363        /** 
    330          * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Concept, org.openmrs.Location, java.lang.String, java.lang.Integer, boolean includeVoided) 
    331          */ 
    332         public List<Obs> getObservations(Concept c, Location loc, String sort, Integer personType, boolean includeVoided) { 
     364         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Concept, 
     365         *      org.openmrs.Location, java.lang.String, java.lang.Integer, boolean 
     366         *      includeVoided) 
     367         */ 
     368        public List<Obs> getObservations(Concept c, Location loc, String sort, 
     369                Integer personType, boolean includeVoided) { 
    333370                return getObsDAO().getObservations(c, loc, sort, personType); 
    334371        } 
    335372 
    336373        /** 
    337          * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, org.openmrs.Concept, boolean includeVoided) 
    338          */ 
    339         public Set<Obs> getObservations(Person who, Concept question, boolean includeVoided) { 
     374         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, 
     375         *      org.openmrs.Concept, boolean includeVoided) 
     376         */ 
     377        public Set<Obs> getObservations(Person who, Concept question, 
     378                boolean includeVoided) { 
    340379                return getObsDAO().getObservations(who, question, includeVoided); 
    341380        } 
    342381 
    343382        /** 
    344          * @see org.openmrs.api.ObsService#getLastNObservations(java.lang.Integer, org.openmrs.Person, org.openmrs.Concept, boolean includeVoided) 
     383         * @see org.openmrs.api.ObsService#getLastNObservations(java.lang.Integer, 
     384         *      org.openmrs.Person, org.openmrs.Concept, boolean includeVoided) 
    345385         */ 
    346386        public List<Obs> getLastNObservations(Integer n, Person who, 
    347                        Concept question, boolean includeVoided) { 
     387                Concept question, boolean includeVoided) { 
    348388                return getObsDAO().getLastNObservations(n, who, question); 
    349389        } 
    350390 
    351391        /** 
    352          * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Concept, java.lang.String, java.lang.Integer, boolean includeVoided) 
    353          */ 
    354         public List<Obs> getObservations(Concept question, String sort, Integer personType, boolean includeVoided) { 
     392         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Concept, 
     393         *      java.lang.String, java.lang.Integer, boolean includeVoided) 
     394         */ 
     395        public List<Obs> getObservations(Concept question, String sort, 
     396                Integer personType, boolean includeVoided) { 
    355397                return getObsDAO().getObservations(question, sort, personType); 
    356398        } 
    357          
    358         /** 
    359          * @see org.openmrs.api.ObsService#getObservationsAnsweredByConcept(org.openmrs.Concept, java.lang.Integer, boolean includeVoided) 
    360          */ 
    361         public List<Obs> getObservationsAnsweredByConcept(Concept answer, Integer personType, boolean includeVoided) { 
     399 
     400        /** 
     401         * @see org.openmrs.api.ObsService#getObservationsAnsweredByConcept(org.openmrs.Concept, 
     402         *      java.lang.Integer, boolean includeVoided) 
     403         */ 
     404        public List<Obs> getObservationsAnsweredByConcept(Concept answer, 
     405                Integer personType, boolean includeVoided) { 
    362406                return getObsDAO().getObservationsAnsweredByConcept(answer, personType); 
    363407        } 
    364          
    365         /** 
    366          * @see org.openmrs.api.ObsService#getNumericAnswersForConcept(org.openmrs.Concept, java.lang.Boolean, java.lang.Integer, boolean includeVoided) 
    367          */ 
    368         public List<Object[]> getNumericAnswersForConcept(Concept answer, Boolean sortByValue, Integer personType, boolean includeVoided) { 
    369                 return getObsDAO().getNumericAnswersForConcept(answer, sortByValue, personType); 
    370         } 
    371          
     408 
     409        /** 
     410         * @see org.openmrs.api.ObsService#getNumericAnswersForConcept(org.openmrs.Concept, 
     411         *      java.lang.Boolean, java.lang.Integer, boolean includeVoided) 
     412         */ 
     413        public List<Object[]> getNumericAnswersForConcept(Concept answer, 
     414                Boolean sortByValue, Integer personType, boolean includeVoided) { 
     415                return getObsDAO().getNumericAnswersForConcept(answer, 
     416                                                               sortByValue, 
     417                                                               personType); 
     418        } 
    372419 
    373420        /** 
     
    386433 
    387434        /** 
    388          * @see org.openmrs.api.ObsService#findObservations(java.lang.String, boolean, java.lang.Integer) 
    389          */ 
    390         public List<Obs> findObservations(String search, boolean includeVoided, Integer personType) { 
     435         * @see org.openmrs.api.ObsService#findObservations(java.lang.String, 
     436         *      boolean, java.lang.Integer) 
     437         */ 
     438        public List<Obs> findObservations(String search, boolean includeVoided, 
     439                Integer personType) { 
    391440                List<Obs> obs = new Vector<Obs>(); 
    392                 for (Person p : Context.getPatientService().getPatientsByIdentifier( 
    393                                search, includeVoided)) { 
     441                for (Person p : Context.getPatientService() 
     442                                       .getPatientsByIdentifier(search, includeVoided)) { 
    394443                        obs.addAll(getObsDAO().findObservations(p.getPersonId(), 
    395                                         includeVoided, personType)); 
     444                                                                includeVoided, 
     445                                                                personType)); 
    396446                } 
    397447                try { 
    398448                        Integer i = Integer.valueOf(search); 
    399449                        if (i != null) 
    400                                 obs.addAll(getObsDAO().findObservations(i, includeVoided, personType)); 
     450                                obs.addAll(getObsDAO().findObservations(i, 
     451                                                                        includeVoided, 
     452                                                                        personType)); 
    401453                } catch (Exception e) { 
    402454                } 
     
    406458 
    407459        /** 
    408          * @see org.openmrs.api.ObsService#getDistinctObservationValues(org.openmrs.Concept, java.lang.Integer) 
    409          */ 
    410         public List<String> getDistinctObservationValues(Concept question, Integer personType) { 
     460         * @see org.openmrs.api.ObsService#getDistinctObservationValues(org.openmrs.Concept, 
     461         *      java.lang.Integer) 
     462         */ 
     463        public List<String> getDistinctObservationValues(Concept question, 
     464                Integer personType) { 
    411465                // todo: make this efficient, and add a sort option 
    412466 
     
    428482 
    429483        /** 
    430          * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, org.openmrs.logic.Aggregation, org.openmrs.Concept, org.openmrs.logic.Constraint) 
     484         * @see org.openmrs.api.ObsService#getObservations(org.openmrs.Person, 
     485         *      org.openmrs.logic.Aggregation, org.openmrs.Concept, 
     486         *      org.openmrs.logic.Constraint) 
    431487         */ 
    432488        public List<Obs> getObservations(Person who, Aggregation aggregation, 
    433                         Concept question, Constraint constraint) { 
    434                 return getObsDAO().getObservations(who, aggregation, question, constraint); 
    435         } 
    436  
    437         /** 
    438          * @see org.openmrs.api.ObsService#getObservations(java.util.List<org.openmrs.Concept>, java.util.Date, java.util.Data, boolean) 
    439          */ 
    440         public List<Obs> getObservations(List<Concept> concepts, Date fromDate, Date toDate, boolean includeVoided) { 
    441                 return getObsDAO().getObservations(concepts, fromDate, toDate, includeVoided); 
    442         } 
    443          
    444         /** 
    445          * @see org.openmrs.api.ObsService#getObservations(java.util.List<org.openmrs.Concept>, java.util.Date, java.util.Data) 
    446          */ 
    447         public List<Obs> getObservations(List<Concept> concepts, Date fromDate, Date toDate) { 
     489                Concept question, Constraint constraint) { 
     490                return getObsDAO().getObservations(who, 
     491                                                   aggregation, 
     492                                                   question, 
     493                                                   constraint); 
     494        } 
     495 
     496        /** 
     497         * @see org.openmrs.api.ObsService#getObservations(java.util.List<org.openmrs.Concept>, 
     498         *      java.util.Date, java.util.Data, boolean) 
     499         */ 
     500        public List<Obs> getObservations(List<Concept> concepts, Date fromDate, 
     501                Date toDate, boolean includeVoided) { 
     502                return getObsDAO().getObservations(concepts, 
     503                                                   fromDate, 
     504                                                   toDate, 
     505                                                   includeVoided); 
     506        } 
     507 
     508        /** 
     509         * @see org.openmrs.api.ObsService#getObservations(java.util.List<org.openmrs.Concept>, 
     510         *      java.util.Date, java.util.Data) 
     511         */ 
     512        public List<Obs> getObservations(List<Concept> concepts, Date fromDate, 
     513                Date toDate) { 
    448514                return this.getObservations(concepts, fromDate, toDate, false); 
    449515        } 
    450          
    451         /** 
    452          * @see org.openmrs.api.ObsService#getObservations(PatientSet patients, List<Concept> concepts, Date fromDate, Date toDate) 
    453          */ 
    454         public List<Obs> getObservations(PatientSet patients, List<Concept> concepts, Date fromDate, Date toDate) { 
     516 
     517        /** 
     518         * @see org.openmrs.api.ObsService#getObservations(PatientSet patients, List<Concept> 
     519         *      concepts, Date fromDate, Date toDate) 
     520         */ 
     521        public List<Obs> getObservations(PatientSet patients, 
     522                List<Concept> concepts, Date fromDate, Date toDate) { 
    455523                return getObsDAO().getObservations(patients, concepts, fromDate, toDate); 
    456524        } 
    457          
    458         /** 
    459          * Convenience method to get the ComplexObsHandler associated with a 
    460          * complex Obs. Returns the ComplexObsHandler. Returns null if the 
     525 
     526        /** 
     527         * Convenience method to get the ComplexObsHandler associated with a complex 
     528         * Obs. Returns the ComplexObsHandler. Returns null if the 
    461529         * Obs.isComplexObs() is false or there is an error instantiating the 
    462          * handler class.  
    463          *  
    464          * TODO: Should ComplexObsHandler be an abstract class and 
    465          * put this method there instead? 
     530         * handler class. 
    466531         *  
    467532         * @param obs A complex Obs. 
     
    470535        public ComplexObsHandler getHandler(Obs obs) { 
    471536                if (obs.getConcept().isComplex()) { 
    472                 //      return getHandler( 
    473                         String key =  ((ConceptComplex)obs.getConcept()).getHandler(); 
    474                         return this.getHandler(key); 
     537                        // Get the ConceptComplex from the ConceptService then return its 
     538                        // handler. 
     539                        return this.getHandler(Context.getConceptService() 
     540                                                      .getConceptComplex(obs.getConcept() 
     541                                                                            .getConceptId()) 
     542                                                      .getHandler()); 
    475543                } 
    476544                return null; 
    477                  
    478                 /* 
    479                 String className = ((ConceptComplex) obs.getConcept()).getHandler(); 
    480                 ComplexObsHandler handler = null; 
    481                 try { 
    482                         Class c = OpenmrsClassLoader.getInstance().loadClass(className); 
    483                         handler = (ComplexObsHandler)c.newInstance(); 
    484                         //Class handlerClass = Class.forName(className); 
    485                         //handler = (ComplexObsHandler)className.getClass().newInstance(); 
    486                         //handler = (ComplexObsHandler) handlerClass.newInstance(); 
    487                 } catch (ClassNotFoundException cnfe) { 
    488                         return null; 
    489                 } catch (InstantiationException ie) { 
    490                         return null; 
    491                 } catch (IllegalAccessException iae) { 
    492                         return null; 
    493                 } 
    494                 return handler; 
    495                 */ 
    496545        } 
    497546 
     
    507556                } 
    508557        } 
    509          
     558 
    510559        public List<ComplexObsHandler> getComplexObsHandlers() { 
    511                 //List handlers = new ArrayList<ComplexObsHandler>(); 
    512                 //handlers.addAll(getHandlers().values()); 
     560                // List handlers = new ArrayList<ComplexObsHandler>(); 
     561                // handlers.addAll(getHandlers().values()); 
    513562                return new ArrayList<ComplexObsHandler>(getHandlers().values()); 
    514                 //return handlers; 
    515         } 
    516          
     563                // return handlers; 
     564        } 
    517565 
    518566        /** 
     
    521569        public ComplexObsHandler getHandler(String key) { 
    522570                try { 
    523                         //System.out.println(this.getHandler(key).getClass().getCanonicalName()); 
    524                         //return handlers.get(OpenmrsClassLoader.getInstance().loadClass(this.getHandler(key).getClass().getCanonicalName())); 
     571                        // System.out.println(this.getHandler(key).getClass().getCanonicalName()); 
     572                        // return 
     573                        // handlers.get(OpenmrsClassLoader.getInstance().loadClass(this.getHandler(key).getClass().getCanonicalName())); 
    525574                        return handlers.get(key); 
    526575                } catch (Exception ex) { 
    527                         log.error("Failed to get ComplexObsHandler for " + this.getHandler(key).getClass().getCanonicalName(), ex); 
     576                        log.error("Failed to get ComplexObsHandler for " 
     577                                + this.getHandler(key).getClass().getCanonicalName(), ex); 
    528578                        return null; 
    529579                } 
    530    
    531          
     580       
     581 
    532582        /** 
    533583         * ADDs handlers...doesn't replace them. 
     584         *  
    534585         * @see org.openmrs.api.ObsService#setHandlers(Map) 
    535586         */ 
    536         public void setHandlers(Map<String, ComplexObsHandler> newHandlers) throws APIException { 
     587        public void setHandlers(Map<String, ComplexObsHandler> newHandlers) 
     588                throws APIException { 
    537589                for (Map.Entry<String, ComplexObsHandler> entry : newHandlers.entrySet()) { 
    538590                        registerHandler(entry.getKey(), entry.getValue()); 
    539591                } 
    540592        } 
    541          
     593 
    542594        /** 
    543595         * @see org.openmrs.api.ObsService#getHandlers() 
     
    546598                if (handlers == null) 
    547599                        handlers = new LinkedHashMap<String, ComplexObsHandler>(); 
    548                  
     600 
    549601                return handlers; 
    550602        } 
    551603 
    552604        /** 
    553          * @see org.openmrs.api.ObsService#registerHandler(java.lang.Class, org.openmrs.obs.ComplexObsHandler) 
    554          */ 
    555         public void registerHandler(String key, ComplexObsHandler handler) throws APIException { 
    556                 /*TODO:   
    557                  * This is a total hack in order to register the ComplexObsHandler by a "key" word instead of the class name. 
    558                  * Spring seems to insist on using the className no matter how you map it in Application-context.xml 
    559                  *  
    560                  */   
    561                 //String[] keys = key.split("."); 
    562                 //String name = (keys.length < 2) ? keys[0] : keys[keys.length-1]; 
    563                 System.out.println(key + " ---> " +  handler.toString()); 
    564                 System.out.println(key.substring(key.lastIndexOf(".")+1, key.length()) + " ---> " +  handler.toString()); 
    565                 getHandlers().put(key.substring(key.lastIndexOf(".")+1, key.length()), handler); 
    566         } 
    567          
     605         * @see org.openmrs.api.ObsService#registerHandler(java.lang.Class, 
     606         *      org.openmrs.obs.ComplexObsHandler) 
     607         */ 
     608        public void registerHandler(String key, ComplexObsHandler handler) 
     609                throws APIException { 
     610                getHandlers().put(key, handler); 
     611        } 
     612 
    568613        /** 
    569614         * @see org.openmrs.api.ObsService#registerHandler(java.lang.String) 
    570615         */ 
    571616        @SuppressWarnings("unchecked") 
    572     public void registerHandler(String key, String handlerClass) throws APIException { 
     617        public void registerHandler(String key, String handlerClass) 
     618                throws APIException { 
    573619                try { 
    574                 Class loadedClass = OpenmrsClassLoader.getInstance().loadClass(handlerClass); 
    575                 registerHandler(key, (ComplexObsHandler)loadedClass.newInstance()); 
    576                  
    577         } catch (Exception e) { 
    578                 throw new APIException("Unable to load and instantiate handler", e); 
    579         } 
    580         } 
    581          
     620                        Class loadedClass = OpenmrsClassLoader.getInstance() 
     621                                                              .loadClass(handlerClass); 
     622                        registerHandler(key, (ComplexObsHandler) loadedClass.newInstance()); 
     623 
     624                } catch (Exception e) { 
     625                        throw new APIException("Unable to load and instantiate handler", e); 
     626                } 
     627        } 
     628 
    582629        /** 
    583630         * @see org.openmrs.api.ObsService#removeHandler(java.lang.Class)