- Timestamp:
- 05/09/08 10:53:35 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/trunk/src/api/org/openmrs/api/db/hibernate/HibernatePersonDAO.java
r4095 r4158 49 49 private SessionFactory sessionFactory; 50 50 51 public HibernatePersonDAO() { } 51 public HibernatePersonDAO() { 52 } 52 53 53 54 /** … … 64 65 */ 65 66 @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 { 67 69 if (birthyear == null) 68 70 birthyear = 0; 69 71 70 72 // 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 72 75 73 76 Set<Person> people = new LinkedHashSet<Person>(); … … 86 89 q += " or soundex(pname.familyName) = soundex(:n3) "; 87 90 q += ")"; 88 } 89 else if (names.length == 2) { 91 } else if (names.length == 2) { 90 92 q += "("; 91 93 q += " case"; … … 110 112 q += " end"; 111 113 q += ") between 6 and 7"; 112 } 113 else if (names.length == 3) { 114 } else if (names.length == 3) { 114 115 q += "("; 115 116 q += " case"; … … 137 138 q += " end"; 138 139 q += ") >= 5"; 139 } 140 else 140 } else 141 141 throw new DAOException("Too many names to compare effectively."); 142 142 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) "; 145 145 146 146 String genderMatch = " (p.gender = :gender or p.gender = '') "; … … 148 148 if (birthyear != 0 && gender != null) { 149 149 q += " and (" + birthdayMatch + "and " + genderMatch + ") "; 150 } 151 else if (birthyear != 0) { 150 } else if (birthyear != 0) { 152 151 q += " and " + birthdayMatch; 153 } 154 else if (gender != null) { 152 } else if (gender != null) { 155 153 q += " and " + genderMatch; 156 154 } … … 204 202 205 203 if (includeVoided == false) 206 criteria.add(Expression.eq(" voided", false));204 criteria.add(Expression.eq("personVoided", false)); 207 205 208 206 criteria.addOrder(Order.asc("personId")); … … 219 217 */ 220 218 public Person getPerson(Integer personId) { 221 return (Person) sessionFactory.getCurrentSession().get(Person.class, personId); 219 return (Person) sessionFactory.getCurrentSession().get(Person.class, 220 personId); 222 221 } 223 222 … … 241 240 @SuppressWarnings("unchecked") 242 241 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(); 245 245 } 246 246 … … 256 256 */ 257 257 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); 259 261 } 260 262 261 263 public PersonAttribute getPersonAttribute(Integer id) { 262 return (PersonAttribute)sessionFactory.getCurrentSession().get(PersonAttribute.class, id); 264 return (PersonAttribute) sessionFactory.getCurrentSession() 265 .get(PersonAttribute.class, id); 263 266 } 264 267 … … 276 279 * @see org.openmrs.api.db.PatientService#getRelationship() 277 280 */ 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); 280 286 281 287 return relationship; … … 287 293 @SuppressWarnings("unchecked") 288 294 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(); 290 298 291 299 return relationships; … … 296 304 */ 297 305 @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 { 300 308 Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Relationship.class, "r") 301 309 .add(Expression.or(Expression.eq("personA", person), Expression.eq("personB", person))); … … 311 319 * @see org.openmrs.api.db.PatientService#getRelationshipType(java.lang.Integer) 312 320 */ 313 public RelationshipType getRelationshipType(Integer relationshipTypeId) throws DAOException { 321 public RelationshipType getRelationshipType(Integer relationshipTypeId) 322 throws DAOException { 314 323 RelationshipType relationshipType = new RelationshipType(); 315 relationshipType = (RelationshipType)sessionFactory.getCurrentSession().get(RelationshipType.class, relationshipTypeId); 324 relationshipType = (RelationshipType) sessionFactory.getCurrentSession() 325 .get(RelationshipType.class, 326 relationshipTypeId); 316 327 317 328 return relationshipType; … … 319 330 } 320 331 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) 324 338 .uniqueResult(); 325 339 … … 333 347 public List<RelationshipType> getRelationshipTypes() throws DAOException { 334 348 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(); 336 352 337 353 return relationshipTypes; … … 341 357 * @see org.openmrs.api.db.PersonService#createRelationshipType(org.openmrs.RelationshipType) 342 358 */ 343 public void createRelationshipType(RelationshipType relationshipType) throws DAOException { 359 public void createRelationshipType(RelationshipType relationshipType) 360 throws DAOException { 344 361 relationshipType.setCreator(Context.getAuthenticatedUser()); 345 362 relationshipType.setDateCreated(new Date()); … … 350 367 * @see org.openmrs.api.db.PersonService#updateRelationshipType(org.openmrs.RelationshipType) 351 368 */ 352 public void updateRelationshipType(RelationshipType relationshipType) throws DAOException { 369 public void updateRelationshipType(RelationshipType relationshipType) 370 throws DAOException { 353 371 if (relationshipType.getRelationshipTypeId() == null) 354 372 createRelationshipType(relationshipType); … … 360 378 * @see org.openmrs.api.db.PersonService#deleteRelationshipType(org.openmrs.RelationshipType) 361 379 */ 362 public void deleteRelationshipType(RelationshipType relationshipType) throws DAOException { 380 public void deleteRelationshipType(RelationshipType relationshipType) 381 throws DAOException { 363 382 sessionFactory.getCurrentSession().delete(relationshipType); 364 383 } … … 400 419 * @see org.openmrs.api.db.PersonService#createRelationship(org.openmrs.Relationship) 401 420 */ 402 public void createRelationship(Relationship relationship) throws DAOException { 421 public void createRelationship(Relationship relationship) 422 throws DAOException { 403 423 relationship.setCreator(Context.getAuthenticatedUser()); 404 424 relationship.setDateCreated(new Date()); … … 409 429 * @see org.openmrs.api.db.PersonService#updateRelationship(org.openmrs.Relationship) 410 430 */ 411 public void updateRelationship(Relationship relationship) throws DAOException { 431 public void updateRelationship(Relationship relationship) 432 throws DAOException { 412 433 if (relationship.getRelationshipId() == null) 413 434 createRelationship(relationship); … … 419 440 * @see org.openmrs.api.db.PersonService#deleteRelationship(org.openmrs.Relationship) 420 441 */ 421 public void deleteRelationship(Relationship relationship) throws DAOException { 442 public void deleteRelationship(Relationship relationship) 443 throws DAOException { 422 444 sessionFactory.getCurrentSession().delete(relationship); 423 445 } … … 434 456 * @see org.openmrs.api.db.PersonService#unvoidRelationship(org.openmrs.Relationship) 435 457 */ 436 public void unvoidRelationship(Relationship relationship) throws DAOException { 458 public void unvoidRelationship(Relationship relationship) 459 throws DAOException { 437 460 relationship.setVoided(false); 438 461 relationship.setVoidedBy(null); … … 446 469 * properties of a person before deleting them. 447 470 * 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 449 473 * @param person the person to delete 450 474 */ 451 public static void deletePersonAndAttributes(SessionFactory sessionFactory, Person person) { 475 public static void deletePersonAndAttributes(SessionFactory sessionFactory, 476 Person person) { 452 477 // delete properties and fields so hibernate can't complain 453 478 for (PersonAddress address : person.getAddresses()) { … … 455 480 sessionFactory.getCurrentSession().evict(address); 456 481 address = null; 457 } 458 else 482 } else 459 483 sessionFactory.getCurrentSession().delete(address); 460 484 }