Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/16/08 13:28:28 (4 months ago)
Author:
bwolfe
Message:

api-refactoring: Re-refactoring some of the api services

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/api_refactoring/src/api/org/openmrs/api/impl/AdministrationServiceImpl.java

    r4231 r4240  
    2626import org.openmrs.ConceptDatatype; 
    2727import org.openmrs.ConceptProposal; 
    28 import org.openmrs.ConceptSynonym; 
    2928import org.openmrs.DataEntryStatistic; 
    3029import org.openmrs.EncounterType; 
     
    3332import org.openmrs.Location; 
    3433import org.openmrs.MimeType; 
    35 import org.openmrs.Obs; 
    3634import org.openmrs.PatientIdentifierType; 
    3735import org.openmrs.Privilege; 
     
    4139import org.openmrs.api.APIException; 
    4240import org.openmrs.api.AdministrationService; 
    43 import org.openmrs.api.ConceptService; 
    4441import org.openmrs.api.EventListeners; 
    4542import org.openmrs.api.GlobalPropertyListener; 
     
    5047import org.openmrs.reporting.Report; 
    5148import org.openmrs.util.OpenmrsConstants; 
    52 import org.springframework.util.StringUtils; 
    5349 
    5450/** 
     
    356352 
    357353        /** 
    358          * Create a new ConceptClass 
    359          *  
    360          * @param ConceptClass to create 
    361          * @throws APIException 
    362          * @deprecated moved to ConceptServiceImpl 
     354         * @deprecated moved to ConceptService 
    363355         */ 
    364356        public void createConceptClass(ConceptClass cc) throws APIException { 
    365                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_MANAGE_CONCEPT_CLASSES)) 
    366                         throw new APIAuthenticationException("Privilege required: " 
    367                                 + OpenmrsConstants.PRIV_MANAGE_CONCEPT_CLASSES); 
    368  
    369                 Context.getConceptService().checkIfLocked(); 
    370  
    371                 dao.createConceptClass(cc); 
    372         } 
    373  
    374         /** 
    375          * Update ConceptClass 
    376          *  
    377          * @param ConceptClass to update 
    378          * @throws APIException 
    379          * @deprecated moved to ConceptServiceImpl 
     357                Context.getConceptService().saveConceptClass(cc); 
     358        } 
     359 
     360        /** 
     361         * @deprecated moved to ConceptService 
    380362         */ 
    381363        public void updateConceptClass(ConceptClass cc) throws APIException { 
    382                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_MANAGE_CONCEPT_CLASSES)) 
    383                         throw new APIAuthenticationException("Privilege required: " 
    384                                 + OpenmrsConstants.PRIV_MANAGE_CONCEPT_CLASSES); 
    385  
    386                 Context.getConceptService().checkIfLocked(); 
    387  
    388                 dao.updateConceptClass(cc); 
    389         } 
    390  
    391         /** 
    392          * Delete ConceptClass 
    393          *  
    394          * @param ConceptClass to delete 
    395          * @throws APIException 
    396          * @deprecated moved to ConceptServiceImpl 
     364                Context.getConceptService().saveConceptClass(cc); 
     365        } 
     366 
     367        /** 
     368         * @deprecated moved to ConceptService 
    397369         */ 
    398370        public void deleteConceptClass(ConceptClass cc) throws APIException { 
    399                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_MANAGE_CONCEPT_CLASSES)) 
    400                         throw new APIAuthenticationException("Privilege required: " 
    401                                 + OpenmrsConstants.PRIV_MANAGE_CONCEPT_CLASSES); 
    402  
    403                 Context.getConceptService().checkIfLocked(); 
    404  
    405                 dao.deleteConceptClass(cc); 
    406         } 
    407  
    408         /** 
    409          * Create a new ConceptDatatype 
    410          *  
    411          * @param ConceptDatatype to create 
    412          * @throws APIException 
    413          * @deprecated moved to ConceptServiceImpl 
     371                Context.getConceptService().purgeConceptClass(cc); 
     372        } 
     373 
     374        /** 
     375         * @deprecated moved to ConceptService 
    414376         */ 
    415377        public void createConceptDatatype(ConceptDatatype cd) throws APIException { 
    416                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_MANAGE_CONCEPT_DATATYPES)) 
    417                         throw new APIAuthenticationException("Privilege required: " 
    418                                 + OpenmrsConstants.PRIV_MANAGE_CONCEPT_DATATYPES); 
    419  
    420                 Context.getConceptService().checkIfLocked(); 
    421  
    422                 dao.createConceptDatatype(cd); 
    423         } 
    424  
    425         /** 
    426          * Update ConceptDatatype 
    427          *  
    428          * @param ConceptDatatype to update 
    429          * @throws APIException 
    430          * @deprecated moved to ConceptServiceImpl 
     378                Context.getConceptService().saveConceptDatatype(cd); 
     379        } 
     380 
     381        /** 
     382         * @deprecated moved to ConceptService 
    431383         */ 
    432384        public void updateConceptDatatype(ConceptDatatype cd) throws APIException { 
    433                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_MANAGE_CONCEPT_DATATYPES)) 
    434                         throw new APIAuthenticationException("Privilege required: " 
    435                                 + OpenmrsConstants.PRIV_MANAGE_CONCEPT_DATATYPES); 
    436  
    437                 Context.getConceptService().checkIfLocked(); 
    438  
    439                 dao.updateConceptDatatype(cd); 
    440         } 
    441  
    442         /** 
    443          * Delete ConceptDatatype 
    444          *  
    445          * @param ConceptDatatype to delete 
    446          * @throws APIException 
    447          * @deprecated moved to ConceptServiceImpl 
     385                Context.getConceptService().saveConceptDatatype(cd); 
     386        } 
     387 
     388        /** 
     389         * @deprecated moved to ConceptService 
    448390         */ 
    449391        public void deleteConceptDatatype(ConceptDatatype cd) throws APIException { 
    450                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_MANAGE_CONCEPT_DATATYPES)) 
    451                         throw new APIAuthenticationException("Privilege required: " 
    452                                 + OpenmrsConstants.PRIV_MANAGE_CONCEPT_DATATYPES); 
    453  
    454                 Context.getConceptService().checkIfLocked(); 
    455  
    456                 dao.deleteConceptDatatype(cd); 
     392                Context.getConceptService().purgeConceptDatatype(cd); 
    457393        } 
    458394 
     
    544480 
    545481        /** 
    546          * Iterates over the words in names and synonyms (for each locale) and 
    547          * updates the concept word business table 
    548          *  
    549          * @param concept 
    550          * @throws APIException 
    551482         * @deprecated moved to ConceptServiceImpl 
    552483         */ 
    553484        public void updateConceptWord(Concept concept) throws APIException { 
    554                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_CONCEPTS)) 
    555                         throw new APIAuthenticationException("Privilege required: " 
    556                                 + OpenmrsConstants.PRIV_EDIT_CONCEPTS); 
    557  
    558                 Context.getConceptService().checkIfLocked(); 
    559  
    560                 dao.updateConceptWord(concept); 
    561         } 
    562  
    563         /** 
    564          * Iterates over all concepts calling updateConceptWord(concept) 
    565          *  
    566          * @throws APIException 
     485                Context.getConceptService().updateConceptWord(concept); 
     486        } 
     487 
     488        /** 
    567489         * @deprecated moved to ConceptServiceImpl 
    568490         */ 
    569491        public void updateConceptWords() throws APIException { 
    570                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_CONCEPTS)) 
    571                         throw new APIAuthenticationException("Privilege required: " 
    572                                 + OpenmrsConstants.PRIV_EDIT_CONCEPTS); 
    573  
    574                 Context.getConceptService().checkIfLocked(); 
    575  
    576                 // Run the operation in batches 
    577                 ConceptService cs = Context.getConceptService(); 
    578                 int batchStartId = 0; 
    579                 int endId = cs.getNextAvailableId(); 
    580                 int batchSize = 1000; 
    581                  
    582                 while (batchStartId < endId) 
    583                 { 
    584                         updateConceptWords(batchStartId, batchStartId + batchSize); 
    585                         Context.clearSession(); 
    586                         batchStartId += batchSize; 
    587                 } 
    588  
    589         } 
    590  
    591         /** 
    592          * Iterates over all concepts with conceptIds between 
    593          * <code>conceptIdStart</code> and <code>conceptIdEnd</code> (inclusive) 
    594          * calling updateConceptWord(concept) 
    595          *  
    596          * @throws APIException 
    597          * @deprecated moved to ConceptServiceImpl 
     492                Context.getConceptService().updateConceptWords(); 
     493        } 
     494 
     495        /** 
     496         * @deprecated moved to ConceptService 
    598497         */ 
    599498        public void updateConceptWords(Integer conceptIdStart, Integer conceptIdEnd) 
    600499                throws APIException { 
    601                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_CONCEPTS)) 
    602                         throw new APIAuthenticationException("Privilege required: " 
    603                                 + OpenmrsConstants.PRIV_EDIT_CONCEPTS); 
    604  
    605                 Context.getConceptService().checkIfLocked(); 
    606  
    607                 Integer i = conceptIdStart; 
    608                 ConceptService cs = Context.getConceptService(); 
    609                 while (i++ <= conceptIdEnd) { 
    610                         updateConceptWord(cs.getConcept(i)); 
    611                 } 
    612         } 
    613  
    614         /** 
    615          * Updates the concept set derived business table for this concept (bursting 
    616          * the concept sets) 
    617          *  
    618          * @param concept 
    619          * @throws APIException 
    620          * @deprecated moved to ConceptServiceImpl 
     500                Context.getConceptService().updateConceptWords(conceptIdStart, conceptIdEnd); 
     501        } 
     502 
     503        /** 
     504         * @deprecated moved to ConceptService 
    621505         */ 
    622506        public void updateConceptSetDerived(Concept concept) throws APIException { 
    623                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_CONCEPTS)) 
    624                         throw new APIAuthenticationException("Privilege required: " 
    625                                 + OpenmrsConstants.PRIV_EDIT_CONCEPTS); 
    626  
    627                 Context.getConceptService().checkIfLocked(); 
    628  
    629                 dao.updateConceptSetDerived(concept); 
    630         } 
    631  
    632         /** 
    633          * Iterates over all concepts calling updateConceptSetDerived(concept) 
    634          *  
    635          * @throws APIException 
    636          * @deprecated moved to ConceptServiceImpl 
     507                Context.getConceptService().updateConceptSetDerived(concept); 
     508        } 
     509 
     510        /** 
     511         * @deprecated moved to ConceptService 
    637512         */ 
    638513        public void updateConceptSetDerived() throws APIException { 
    639                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_CONCEPTS)) 
    640                         throw new APIAuthenticationException("Privilege required: " 
    641                                 + OpenmrsConstants.PRIV_EDIT_CONCEPTS); 
    642  
    643                 Context.getConceptService().checkIfLocked(); 
    644  
    645                 dao.updateConceptSetDerived(); 
    646         } 
    647  
    648         /** 
    649          * @see org.openmrs.api.AdministrationService#createConceptProposal(org.openmrs.ConceptProposal) 
    650          * @deprecated moved to ConceptServiceImpl 
     514                Context.getConceptService().updateConceptSetDerived(); 
     515        } 
     516 
     517        /** 
     518         * @deprecated moved to ConceptService 
    651519         */ 
    652520        public void createConceptProposal(ConceptProposal cp) throws APIException { 
    653                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_ADD_CONCEPT_PROPOSAL)) 
    654                         throw new APIAuthenticationException("Privilege required: " 
    655                                 + OpenmrsConstants.PRIV_ADD_CONCEPT_PROPOSAL); 
    656  
    657                 dao.createConceptProposal(cp); 
    658         } 
    659  
    660         /** 
    661          * @deprecated moved to ConceptServiceImpl 
    662          * @see org.openmrs.api.AdministrationService#updateConceptProposal(org.openmrs.ConceptProposal) 
     521                Context.getConceptService().saveConceptProposal(cp); 
     522        } 
     523 
     524        /** 
     525         * @deprecated moved to ConceptService 
    663526         */ 
    664527        public void updateConceptProposal(ConceptProposal cp) throws APIException { 
    665                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_EDIT_CONCEPT_PROPOSAL)) 
    666                         throw new APIAuthenticationException("Privilege required: " 
    667                                 + OpenmrsConstants.PRIV_EDIT_CONCEPT_PROPOSAL); 
    668  
    669                 cp.setChangedBy(Context.getAuthenticatedUser()); 
    670                 cp.setDateChanged(new Date()); 
    671                 dao.updateConceptProposal(cp); 
    672         } 
    673  
    674         /** 
    675          * @deprecated moved to ConceptServiceImpl 
    676          * @see org.openmrs.api.AdministrationService#mapConceptProposalToConcept(org.openmrs.ConceptProposal, org.openmrs.Concept) 
     528                Context.getConceptService().saveConceptProposal(cp); 
     529        } 
     530 
     531        /** 
     532         * @deprecated moved to ConceptService 
    677533         */ 
    678534        public void mapConceptProposalToConcept(ConceptProposal cp, 
    679535                Concept mappedConcept) throws APIException { 
    680  
    681                 if (!Context.hasPrivilege(OpenmrsConstants.PRIV_ADD_CONCEPTS)) 
    682                         throw new APIAuthenticationException("Privilege required: " 
    683                                 + OpenmrsConstants.PRIV_ADD_CONCEPTS); 
    684  
    685                 if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_REJECT)) { 
    686                         rejectConceptProposal(cp); 
    687                         return; 
    688                 } 
    689  
    690                 if (mappedConcept == null) 
    691                         throw new APIException("Illegal Mapped Concept"); 
    692  
    693                 if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT) 
    694                         || !StringUtils.hasText(cp.getFinalText())) { 
    695                         cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT); 
    696                         cp.setFinalText(""); 
    697                 } else if (cp.getState() 
    698                              .equals(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM)) { 
    699  
    700                         Context.getConceptService().checkIfLocked(); 
    701  
    702                         String finalText = cp.getFinalText(); 
    703                         ConceptSynonym syn = new ConceptSynonym(mappedConcept, 
    704                                                                 finalText, 
    705                                                                 Context.getLocale()); 
    706                         syn.setDateCreated(new Date()); 
    707                         syn.setCreator(Context.getAuthenticatedUser()); 
    708  
    709                         mappedConcept.addSynonym(syn); 
    710                         mappedConcept.setChangedBy(Context.getAuthenticatedUser()); 
    711                         mappedConcept.setDateChanged(new Date()); 
    712                         updateConceptWord(mappedConcept); 
    713                 } 
    714  
    715                 cp.setMappedConcept(mappedConcept); 
    716  
    717                 if (cp.getObsConcept() != null) { 
    718                         Obs ob = new Obs(); 
    719                         ob.setEncounter(cp.getEncounter()); 
    720                         ob.setConcept(cp.getObsConcept()); 
    721                         ob.setValueCoded(cp.getMappedConcept()); 
    722                         ob.setCreator(Context.getAuthenticatedUser()); 
    723                         ob.setDateCreated(new Date()); 
    724                         ob.setObsDatetime(cp.getEncounter().getEncounterDatetime()); 
    725                         ob.setLocation(cp.getEncounter().getLocation()); 
    726                         ob.setPerson(cp.getEncounter().getPatient()); 
    727                         cp.setObs(ob); 
    728                 } 
    729  
    730                 updateConceptProposal(cp); 
    731         } 
    732  
    733         /** 
    734          * @deprecated moved to ConceptServiceImpl 
     536                Context.getConceptService().mapConceptProposalToConcept(cp, mappedConcept); 
     537        } 
     538 
     539        /** 
     540         * @deprecated moved to ConceptService 
    735541         * @see org.openmrs.api.AdministrationService#rejectConceptProposal(org.openmrs.ConceptProposal) 
    736542         */ 
    737543        public void rejectConceptProposal(ConceptProposal cp) { 
    738                 cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_REJECT); 
    739                 cp.setFinalText(""); 
    740                 updateConceptProposal(cp); 
     544                Context.getConceptService().rejectConceptProposal(cp); 
    741545        } 
    742546