Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/09/08 10:53:35 (2 months ago)
Author:
bwolfe
Message:

Merging report-api-refactoring to trunk [2696]:[4157]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/trunk/src/api/org/openmrs/api/db/hibernate/HibernatePersonDAO.java

    r4095 r4158  
    4949        private SessionFactory sessionFactory; 
    5050         
    51         public HibernatePersonDAO() { } 
     51        public HibernatePersonDAO() { 
     52        } 
    5253         
    5354        /** 
     
    6465         */ 
    6566        @SuppressWarnings("unchecked") 
    66         public Set<Person> getSimilarPeople(String name, Integer birthyear, String gender) throws DAOException { 
     67        public Set<Person> getSimilarPeople(String name, Integer birthyear, 
     68                String gender) throws DAOException { 
    6769                if (birthyear == null) 
    6870                        birthyear = 0; 
    6971                 
    7072                // TODO return the matched name instead of the primary name 
    71                 //   possible solution: "select new" org.openmrs.PersonListItem and return a list of those 
     73                // possible solution: "select new" org.openmrs.PersonListItem and return 
     74                // a list of those 
    7275                 
    7376                Set<Person> people = new LinkedHashSet<Person>(); 
     
    8689                        q += " or soundex(pname.familyName) = soundex(:n3) "; 
    8790                        q += ")"; 
    88                 } 
    89                 else if (names.length == 2) { 
     91                } else if (names.length == 2) { 
    9092                        q += "("; 
    9193                        q += " case"; 
     
    110112                        q += " end"; 
    111113                        q += ") between 6 and 7"; 
    112                 } 
    113                 else if (names.length == 3) { 
     114                } else if (names.length == 3) { 
    114115                        q += "("; 
    115116                        q += " case"; 
     
    137138                        q += " end"; 
    138139                        q += ") >= 5"; 
    139                 } 
    140                 else 
     140                } else 
    141141                        throw new DAOException("Too many names to compare effectively."); 
    142142                 
    143                 String birthdayMatch = " (year(p.birthdate) between " + (birthyear - 1) + " and " + (birthyear + 1) + 
    144                                                                " or p.birthdate is null) "; 
     143                String birthdayMatch = " (year(p.birthdate) between " + (birthyear - 1) 
     144                        + " and " + (birthyear + 1) + " or p.birthdate is null) "; 
    145145                 
    146146                String genderMatch = " (p.gender = :gender or p.gender = '') "; 
     
    148148                if (birthyear != 0 && gender != null) { 
    149149                        q += " and (" + birthdayMatch + "and " + genderMatch + ") ";  
    150                 } 
    151                 else if (birthyear != 0) { 
     150                } else if (birthyear != 0) { 
    152151                        q += " and " + birthdayMatch; 
    153                 } 
    154                 else if (gender != null) { 
     152                } else if (gender != null) { 
    155153                        q += " and " + genderMatch; 
    156154                } 
     
    204202                                 
    205203                if (includeVoided == false) 
    206                         criteria.add(Expression.eq("voided", false)); 
     204                        criteria.add(Expression.eq("personVoided", false)); 
    207205                 
    208206                criteria.addOrder(Order.asc("personId")); 
     
    219217         */ 
    220218        public Person getPerson(Integer personId) { 
    221                 return (Person) sessionFactory.getCurrentSession().get(Person.class, personId); 
     219                return (Person) sessionFactory.getCurrentSession().get(Person.class, 
     220                                                                       personId); 
    222221        } 
    223222         
     
    241240        @SuppressWarnings("unchecked") 
    242241        public List<PersonAttributeType> getPersonAttributeTypes() { 
    243                 return sessionFactory.getCurrentSession().createQuery( 
    244                 "from PersonAttributeType type order by type.name").list(); 
     242                return sessionFactory.getCurrentSession() 
     243                                     .createQuery("from PersonAttributeType type order by type.name") 
     244                                     .list(); 
    245245        } 
    246246 
     
    256256         */ 
    257257        public PersonAttributeType getPersonAttributeType(Integer typeId) { 
    258                 return (PersonAttributeType) sessionFactory.getCurrentSession().get(PersonAttributeType.class, typeId); 
     258                return (PersonAttributeType) sessionFactory.getCurrentSession() 
     259                                                           .get(PersonAttributeType.class, 
     260                                                                typeId); 
    259261        } 
    260262 
    261263        public PersonAttribute getPersonAttribute(Integer id) { 
    262                 return (PersonAttribute)sessionFactory.getCurrentSession().get(PersonAttribute.class, id); 
     264                return (PersonAttribute) sessionFactory.getCurrentSession() 
     265                                                       .get(PersonAttribute.class, id); 
    263266        } 
    264267 
     
    276279         * @see org.openmrs.api.db.PatientService#getRelationship() 
    277280         */ 
    278         public Relationship getRelationship(Integer relationshipId) throws DAOException { 
    279                 Relationship relationship = (Relationship)sessionFactory.getCurrentSession().get(Relationship.class, relationshipId); 
     281        public Relationship getRelationship(Integer relationshipId) 
     282                throws DAOException { 
     283                Relationship relationship = (Relationship) sessionFactory.getCurrentSession() 
     284                                                                         .get(Relationship.class, 
     285                                                                              relationshipId); 
    280286                 
    281287                return relationship; 
     
    287293        @SuppressWarnings("unchecked") 
    288294        public List<Relationship> getRelationships() throws DAOException { 
    289                 List<Relationship> relationships = sessionFactory.getCurrentSession().createQuery("from Relationship r order by r.relationshipId asc").list(); 
     295                List<Relationship> relationships = sessionFactory.getCurrentSession() 
     296                                                                 .createQuery("from Relationship r order by r.relationshipId asc") 
     297                                                                 .list(); 
    290298                 
    291299                return relationships; 
     
    296304         */ 
    297305        @SuppressWarnings("unchecked") 
    298         public List<Relationship> getRelationships(Person person, boolean showVoided) throws DAOException { 
    299  
     306        public List<Relationship> getRelationships(Person person, boolean showVoided) 
     307                        throws DAOException { 
    300308                Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Relationship.class, "r") 
    301309                .add(Expression.or(Expression.eq("personA", person), Expression.eq("personB", person))); 
     
    311319         * @see org.openmrs.api.db.PatientService#getRelationshipType(java.lang.Integer) 
    312320         */ 
    313         public RelationshipType getRelationshipType(Integer relationshipTypeId) throws DAOException { 
     321        public RelationshipType getRelationshipType(Integer relationshipTypeId) 
     322                throws DAOException { 
    314323                RelationshipType relationshipType = new RelationshipType(); 
    315                 relationshipType = (RelationshipType)sessionFactory.getCurrentSession().get(RelationshipType.class, relationshipTypeId); 
     324                relationshipType = (RelationshipType) sessionFactory.getCurrentSession() 
     325                                                                    .get(RelationshipType.class, 
     326                                                                         relationshipTypeId); 
    316327                 
    317328                return relationshipType; 
     
    319330        } 
    320331         
    321         public RelationshipType findRelationshipType(String relationshipTypeName) throws DAOException { 
    322                 RelationshipType ret = (RelationshipType) sessionFactory.getCurrentSession().createQuery("from RelationshipType t where CONCAT(t.aIsToB, CONCAT('/', t.bIsToA)) = :toString order by weight") 
    323                                         .setString("toString", relationshipTypeName) 
     332        public RelationshipType findRelationshipType(String relationshipTypeName) 
     333                throws DAOException { 
     334                RelationshipType ret = (RelationshipType) sessionFactory.getCurrentSession() 
     335                                                                        .createQuery("from RelationshipType t where CONCAT(t.aIsToB, CONCAT('/', t.bIsToA)) = :toString order by weight") 
     336                                                                        .setString("toString", 
     337                                                                                   relationshipTypeName) 
    324338                                        .uniqueResult(); 
    325339                 
     
    333347        public List<RelationshipType> getRelationshipTypes() throws DAOException { 
    334348                List<RelationshipType> relationshipTypes; 
    335                 relationshipTypes = sessionFactory.getCurrentSession().createQuery("from RelationshipType t order by t.weight").list(); 
     349                relationshipTypes = sessionFactory.getCurrentSession() 
     350                                                  .createQuery("from RelationshipType t order by t.weight") 
     351                                                  .list(); 
    336352                 
    337353                return relationshipTypes; 
     
    341357         * @see org.openmrs.api.db.PersonService#createRelationshipType(org.openmrs.RelationshipType) 
    342358         */ 
    343         public void createRelationshipType(RelationshipType relationshipType) throws DAOException { 
     359        public void createRelationshipType(RelationshipType relationshipType) 
     360                throws DAOException { 
    344361                relationshipType.setCreator(Context.getAuthenticatedUser()); 
    345362                relationshipType.setDateCreated(new Date()); 
     
    350367         * @see org.openmrs.api.db.PersonService#updateRelationshipType(org.openmrs.RelationshipType) 
    351368         */ 
    352         public void updateRelationshipType(RelationshipType relationshipType) throws DAOException { 
     369        public void updateRelationshipType(RelationshipType relationshipType) 
     370                throws DAOException { 
    353371                if (relationshipType.getRelationshipTypeId() == null) 
    354372                        createRelationshipType(relationshipType); 
     
    360378         * @see org.openmrs.api.db.PersonService#deleteRelationshipType(org.openmrs.RelationshipType) 
    361379         */ 
    362         public void deleteRelationshipType(RelationshipType relationshipType) throws DAOException { 
     380        public void deleteRelationshipType(RelationshipType relationshipType) 
     381                throws DAOException { 
    363382                sessionFactory.getCurrentSession().delete(relationshipType); 
    364383        } 
     
    400419         * @see org.openmrs.api.db.PersonService#createRelationship(org.openmrs.Relationship) 
    401420         */ 
    402         public void createRelationship(Relationship relationship) throws DAOException { 
     421        public void createRelationship(Relationship relationship) 
     422                throws DAOException { 
    403423                relationship.setCreator(Context.getAuthenticatedUser()); 
    404424                relationship.setDateCreated(new Date()); 
     
    409429         * @see org.openmrs.api.db.PersonService#updateRelationship(org.openmrs.Relationship) 
    410430         */ 
    411         public void updateRelationship(Relationship relationship) throws DAOException { 
     431        public void updateRelationship(Relationship relationship) 
     432                throws DAOException { 
    412433                if (relationship.getRelationshipId() == null) 
    413434                        createRelationship(relationship); 
     
    419440         * @see org.openmrs.api.db.PersonService#deleteRelationship(org.openmrs.Relationship) 
    420441         */ 
    421         public void deleteRelationship(Relationship relationship) throws DAOException { 
     442        public void deleteRelationship(Relationship relationship) 
     443                throws DAOException { 
    422444                sessionFactory.getCurrentSession().delete(relationship); 
    423445        } 
     
    434456         * @see org.openmrs.api.db.PersonService#unvoidRelationship(org.openmrs.Relationship) 
    435457         */ 
    436         public void unvoidRelationship(Relationship relationship) throws DAOException { 
     458        public void unvoidRelationship(Relationship relationship) 
     459                throws DAOException { 
    437460                relationship.setVoided(false); 
    438461                relationship.setVoidedBy(null); 
     
    446469         * properties of a person before deleting them. 
    447470         *  
    448          * @param sessionFactory the session factory from which to pull the current session 
     471         * @param sessionFactory the session factory from which to pull the current 
     472         *        session 
    449473         * @param person the person to delete 
    450474         */ 
    451         public static void deletePersonAndAttributes(SessionFactory sessionFactory, Person person) { 
     475        public static void deletePersonAndAttributes(SessionFactory sessionFactory, 
     476                Person person) { 
    452477                // delete properties and fields so hibernate can't complain 
    453478                for (PersonAddress address : person.getAddresses()) { 
     
    455480                                sessionFactory.getCurrentSession().evict(address); 
    456481                                address = null; 
    457                         } 
    458                         else 
     482                        } else 
    459483                                sessionFactory.getCurrentSession().delete(address); 
    460484                }