Subversion Repository Public Repository

Aurocare_27_07_2018

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcarecommonutil.daoimpl;

import com.bestray.healthcarecommonutil.exception.DataAccessException;
import com.bestray.healthcarecommonutil.vo.TPatient;
import com.bestray.healthcarecommonutil.dao.PatientDao;
import com.bestray.healthcarecommonutil.vo.DuplicatePatient;
import com.bestray.healthcarecommonutil.vo.TInpatentAdmission;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.transform.AliasToBeanResultTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

// TODO: Auto-generated Javadoc
/**
 * The Class PatientDaoImpl.
 *
 * @author User1
 */
@Repository
public class PatientDaoImpl extends HibernateDaoSupport implements PatientDao{
    
    private SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
    @Autowired
    public void init(SessionFactory sessionfactory) {
        setSessionFactory(sessionfactory);
    }
    
    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Dao.PatientDao#savePatientRegistration(com.bestray.healthcareemr.Vo.TPatient)
     */
    @Override
    public void savePatientRegistration(TPatient patient)throws DataAccessException,ConstraintViolationException,HibernateOptimisticLockingFailureException {
        try{
            getHibernateTemplate().saveOrUpdate(patient);
        }catch(ConstraintViolationException | HibernateOptimisticLockingFailureException  e){
            throw e;
        }
        catch(Exception e){
           throw new DataAccessException();
        }
    }
    
    @Override
    public void savePatientAdmission(TInpatentAdmission admission) throws DataAccessException, ConstraintViolationException, HibernateOptimisticLockingFailureException {
        try{
            System.out.println("########### "+admission.getIpdNo()+"    "+admission.getPatientDisease()+"   "+admission.getPatientNote());
            getHibernateTemplate().saveOrUpdate(admission);
        }catch(ConstraintViolationException | HibernateOptimisticLockingFailureException  e){
            throw e;
        }
        catch(Exception e){
           throw new DataAccessException();
        }
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Dao.PatientDao#getPatientDetails(java.lang.Long)
     */
    @Override
    public TPatient getPatientDetails(Long ID)throws DataAccessException {
        try{
            return getHibernateTemplate().get(TPatient.class, ID);
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Dao.PatientDao#findAllPatientrecords()
     */
    @Override
    public List<TPatient> findAllPatientrecords() throws DataAccessException {
        try{
            return getHibernateTemplate().findByNamedQuery("findAllPatientrecords");
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Dao.PatientDao#findPatientWise(java.lang.String)
     */
    @Override
    public List<TPatient> findPatientWise(String searchCriteria) throws DataAccessException {
        try{
            Query query=getHibernateTemplate().getSessionFactory().openSession().createQuery(searchCriteria);
            List<TPatient> patientList = query.list();
            return patientList;
        }catch(Exception e){
            throw new DataAccessException();
        }
    }
    
    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Dao.PatientDao#getIdToInsert()
     */
    @Transactional(readOnly=true)
    @Override
    public String getIdToInsert() throws DataAccessException {
        try{
            List<TPatient> patientIds = getHibernateTemplate().findByNamedQuery("findMaxId");
            if(patientIds.isEmpty()){
                String date = sdf.format(new Date());
                date = date.substring(0,2)+date.substring(3,5)+date.substring(6);
                return date+"1685";
                //return "A0999";
            }else{
                return (patientIds.get(0)).getPatientId();
            }
        }catch(Exception e){
            throw new DataAccessException();
        }
    }
    @Override
    public boolean isDuplicatePatient(TPatient patient)throws DataAccessException {
        try{
            List<TPatient> patientList = getHibernateTemplate().findByNamedQuery("findDuplicatePatientNameWise",patient.getPatientFName(),patient.getPatientMName(),patient.getPatientLName(),patient.getPatientGender());
            if(!patientList.isEmpty()){
                return true;
            }else{
                return false;
            }
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    @Override
    public List<DuplicatePatient> findDuplicatePatientDetails() throws DataAccessException {
         try{
            SQLQuery query = getHibernateTemplate().getSessionFactory().openSession().createSQLQuery("select patient_f_name as fname,patient_m_name as mname,patient_l_name as lname,patient_gender as gender,count(*) as duplicateNo from t_patient WHERE patient_status = 'ACTIVE' group by patient_f_name,patient_m_name,patient_l_name,patient_gender having count(*)>1 order by 5 desc ;");
            query.addScalar("fname", Hibernate.STRING).addScalar("mname", Hibernate.STRING).addScalar("lname", Hibernate.STRING).addScalar("gender", Hibernate.STRING).addScalar("duplicateNo", Hibernate.INTEGER); 
            query.setResultTransformer(new AliasToBeanResultTransformer(DuplicatePatient.class));
            return query.list();
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    @Override
    public List<TPatient> findDuplicateRecordsByPatient(DuplicatePatient patient) throws DataAccessException {
        try{
             return getHibernateTemplate().findByNamedQuery("findDuplicatePatientNameWise",patient.getFname(),patient.getMname(),patient.getLname(),patient.getGender());
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    @Override
    public void changePatientStatus(String patientids) throws DataAccessException {
        try{
            Session session = getHibernateTemplate().getSessionFactory().openSession();
            Query query = session.getNamedQuery("updatePatient");
            query.setString(0,patientids);
            query.executeUpdate();
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    @Override
    public Long getIdAfterPatientSave(TPatient patient) throws DataAccessException {
        try{
             return (Long)getHibernateTemplate().save(patient);
        }catch(Exception e){
           throw new DataAccessException();
        }
    }
    
    @Override
    public List<TPatient> getPatientByPatientId(String patientID) throws DataAccessException {
        try{
            return getHibernateTemplate().findByNamedQuery("findPatientIdList", patientID);
        }catch(Exception e){
            throw new DataAccessException();
        }
    }

    
}

Commits for Aurocare_27_07_2018/AuroCareCommonUtil/src/main/java/com/bestray/healthcarecommonutil/daoimpl/PatientDaoImpl.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 27 Jul, 2018 07:21:55 +0000