Subversion Repository Public Repository

Satyam

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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcarecommonutil.serviceimpl;

import com.bestray.healthcarecommonutil.exception.DataAccessException;
import com.bestray.healthcarecommonutil.exception.HealthCareException;
import com.bestray.healthcarecommonutil.exception.ProcessingException;
import com.bestray.healthcarecommonutil.vo.TPatient;
import com.bestray.healthcarecommonutil.dao.PatientDao;
import com.bestray.healthcarecommonutil.service.PatientMergeService;
import com.bestray.healthcarecommonutil.service.PatientService;
import com.bestray.healthcarecommonutil.service.RecentPatientService;
import com.bestray.healthcarecommonutil.util.PatientClone;
import com.bestray.healthcarecommonutil.vo.DuplicatePatient;
import com.bestray.healthcarecommonutil.vo.TInpatentAdmission;
import com.bestray.healthcarecommonutil.vo.TPatientMerge;
import com.bestray.healthcarecommonutil.vo.TRecentPatient;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.StaleObjectStateException;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

// TODO: Auto-generated Javadoc
/**
 * The Class PatientServiceImpl.
 *
 * @author User1
 */
@Transactional
@Service
public class PatientServiceImpl implements PatientService{
    
    /** The patient dao. */
    @Autowired
    private PatientDao patientDao;
    
    /** The patient Merge Service. */
    @Autowired
    private PatientMergeService patientMergeService;
    
    @Autowired
    private RecentPatientService recentPatientService;
    
    /** The date. */
    java.util.Date date;
    
    /** The patient full name. */
    private String patientFullName = null;
    
    /** The sdf1. */
    private SimpleDateFormat sdf,sdf1;

    public PatientServiceImpl() {
        sdf = new SimpleDateFormat("dd-MM-yyyy");
        sdf1 = new SimpleDateFormat("yyyy-MM-dd");
    }
 
    /**
     * Instantiates a new patient service impl.
     *
     * @param patientRegistrationDao the patient registration dao
     
    public PatientServiceImpl(PatientDao patientRegistrationDao, PatientMergeService patientMergeService) {
        this.patientMergeService=patientMergeService;
        this.patientDao=patientRegistrationDao;
        sdf = new SimpleDateFormat("dd-MM-yyyy");
        sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        
        
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientService#savePatientRegistration(com.bestray.healthcareemr.Vo.TPatient)
     */
    public void savePatientRegistration(TPatient patient)throws ProcessingException,ConstraintViolationException,HibernateOptimisticLockingFailureException {
        try{
            date= new java.util.Date();
            if(patient.getId()!=null && patient.getId()>0){
                patient.setUpdatedDate(new Timestamp(date.getTime()));
                patientDao.savePatientRegistration(patient);
                TRecentPatient recPatient = PatientClone.getPatient(patient);
                recentPatientService.saveRecentPatient(recPatient);
            }else{
                patient.setCreatedDate(new Timestamp(date.getTime()));
                patient.setPatientStatus("ACTIVE");
                patientDao.savePatientRegistration(patient);
                TRecentPatient recPatient = PatientClone.getPatient(patient);
                recentPatientService.saveRecentPatient(recPatient);
            }
        }catch(StaleObjectStateException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            System.out.println("StateObjectStateException in service");
        }catch(HibernateOptimisticLockingFailureException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw e;
        }catch(ConstraintViolationException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw e;
        }catch(DataAccessException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
     }
    
    @Override
    public void savePatientAdmission(TInpatentAdmission admission) throws ProcessingException,ConstraintViolationException,HibernateOptimisticLockingFailureException {
        try {
            System.out.println("$$$$$$   service"+admission.getIpdNo());
            patientDao.savePatientAdmission(admission);
        } catch (DataAccessException ex) {
            ex.printStackTrace();
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientService#getPatientDetails(java.lang.Long)
     */
    @Transactional(readOnly = true)
    public TPatient getPatientDetails(Long ID)throws ProcessingException {
        try{
            return patientDao.getPatientDetails(ID);
        }catch(DataAccessException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new ProcessingException();
        }
    }
    
    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientService#getAllPatientrecords()
     */
    public Vector<Vector<String>> getAllPatientrecords() throws ProcessingException {
        try {
            Vector<Vector<String>> patients = new Vector<Vector<String>>();
            List<TPatient> patientsList;
            
            patientsList = patientDao.findAllPatientrecords();
            
            for (TPatient patient : patientsList) {
                Vector<String> patientVector = new Vector<String>();
                patientVector.add(String.valueOf(patient.getId()));
                patientVector.add(String.valueOf(patient.getPatientId()));
                if(patient.getPatientMName()!=null){
                    patientFullName = patient.getPatientFName()+" "+patient.getPatientMName()+" "+patient.getPatientLName();
                }else if(patient.getPatientMName()==null){
                    patientFullName = patient.getPatientFName()+" "+patient.getPatientLName();
                }
                patientVector.add(patientFullName);                
                patientVector.add(patient.getPatientGender());
                if(patient.getBirthDate()!=null){
                patientVector.add(String.valueOf(sdf.format(patient.getBirthDate())));
                }else{
                patientVector.add("");
                }
                patientVector.add(String.valueOf(patient.getOpIpStatus()));
                if(patient.getPatientHtNumber()!=null){
                patientVector.add(String.valueOf(patient.getPatientHtNumber()));
                }else{
                patientVector.add("");
                }
                if(patient.getPatientMNumber()!=null){
                patientVector.add(String.valueOf(patient.getPatientMNumber()));
                }else{
                patientVector.add("");
                }
                if(patient.getPatientENumber()!=null){
                patientVector.add(String.valueOf(patient.getPatientENumber()));
                }else{
                patientVector.add("");
                }
                patientVector.add(patient.getPresentAddress1());
                patients.add(patientVector);
            }
            return patients;
        }catch (DataAccessException ex) {
                Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new ProcessingException();
         }catch(Exception e){
             Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
             throw new HealthCareException("Error in Populating Patient List...");
        }
    }
    
    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientService#getPatientWise(java.util.Map)
     */
    @Transactional(readOnly = true)
    public Vector<Vector<String>> getPatientWise(Map searchCriteria)throws ProcessingException {
        try {
            Vector<Vector<String>> patients = new Vector<Vector<String>>();
            List<TPatient> patientsList;
            
            
            StringBuilder sb= new StringBuilder();
            //Search Criteria
            if(searchCriteria.containsKey("patient_id")){
                 String patientId=searchCriteria.get("patient_id").toString();
                 sb.append("from TPatient patient where coalesce(patient.patientId,0) like \'"+patientId+"%\'");
            }else{
                 sb.append("from TPatient patient where coalesce(patient.patientId,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("birth_date"))){
                 Date dob=(Date)(searchCriteria.get("birth_date"));
                 sb.append(" and patient.birthDate = \'"+sdf1.format(dob)+"\'");
            }else{
                 sb.append(" and coalesce(patient.birthDate,0) like \'%\' ");
            }
            if(searchCriteria.containsKey(("patient_f_name"))){
                 String fname=searchCriteria.get("patient_f_name").toString();
                 sb.append(" and coalesce(patient.patientFName,0) like \'%"+fname+"%\'");
            }else{
                 sb.append(" and coalesce(patient.patientFName,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_m_name"))){
                 String mname=searchCriteria.get("patient_m_name").toString();
                 sb.append(" and coalesce(patient.patientMName,0) like \'%"+mname+"%\'");
            }else{
                 sb.append(" and coalesce(patient.patientMName,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_l_name"))){
                 String lname=searchCriteria.get("patient_l_name").toString();
                 sb.append(" and coalesce(patient.patientLName,0) like \'%"+lname+"%\'");
            }else{
                 sb.append(" and coalesce(patient.patientLName,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patientContact"))){
                 Long contact=Long.valueOf(searchCriteria.get("patientContact").toString());
                 sb.append(" and (coalesce(patient.patientHtNumber,0) like \'"+contact+"%\' or coalesce(patient.patientMNumber,0) like \'"+contact+"%\' or coalesce(patient.patientENumber,0) like \'"+contact+"%\' )");
            }else{
                 sb.append(" and (coalesce(patient.patientHtNumber,0) like \'%\' or coalesce(patient.patientMNumber,0) like \'%\' or coalesce(patient.patientENumber,0) like \'%\' )");
            }
            if(searchCriteria.containsKey(("patient_drivinglicense_details"))){
                 String dl=searchCriteria.get("patient_drivinglicense_details").toString();
                 sb.append(" and coalesce(patient.patientDrivingLicenseDetails,0) like \'"+dl+"%\'");
            }else{
                sb.append(" and coalesce(patient.patientDrivingLicenseDetails,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_passport_details"))){
                 String passport=searchCriteria.get("patient_passport_details").toString();
                 sb.append(" and coalesce(patient.patientPassportDetails,0) like \'"+passport+"%\'");
            }else{
                sb.append(" and coalesce(patient.patientPassportDetails,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_votercard_details"))){
                 String voterCard=searchCriteria.get("patient_votercard_details").toString();
                 sb.append(" and coalesce(patient.patientVoterCardDetails,0) like \'"+voterCard+"%\'");
            }else{
                sb.append(" and coalesce(patient.patientVoterCardDetails,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_adharcard_details"))){
                 String adharCard=searchCriteria.get("patient_adharcard_details").toString();
                 sb.append(" and coalesce(patient.patientAdharCardDetails,0) like \'"+adharCard+"%\'");
            }else{
                 sb.append(" and coalesce(patient.patientAdharCardDetails,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_pancard_details"))){
                 String panCard=searchCriteria.get("patient_pancard_details").toString();
                 sb.append(" and coalesce(patient.patientPanCardDetails,0) like \'"+panCard+"%\'");
            }else{
                sb.append(" and coalesce(patient.patientPanCardDetails,0) like \'%\'");
            }
            if(searchCriteria.containsKey(("patient_gender"))){
                 String gender=searchCriteria.get("patient_gender").toString();
                 sb.append(" and coalesce(patient.patientGender,0) = \'"+gender+"\'");
            }else{
                sb.append(" and coalesce(patient.patientGender,0) like \'%\'");
            }
            patientsList = patientDao.findPatientWise(sb.toString());
            
            for (TPatient patient : patientsList) {
                Vector<String> patientVector = new Vector<String>();
                patientVector.add(String.valueOf(patient.getId()));
                patientVector.add(String.valueOf(patient.getPatientId()));
                if(patient.getPatientMName()!=null){
                    patientFullName = patient.getPatientFName()+" "+patient.getPatientMName()+" "+patient.getPatientLName();
                }else if(patient.getPatientMName()==null){
                    patientFullName = patient.getPatientFName()+" "+patient.getPatientLName();
                }
                patientVector.add(patientFullName);                
                patientVector.add(patient.getPatientGender());
                if(patient.getBirthDate()!=null){
                patientVector.add(String.valueOf(sdf.format(patient.getBirthDate())));
                }else{
                patientVector.add("");
                }
                patientVector.add(String.valueOf(patient.getOpIpStatus()));
                if(patient.getPatientHtNumber()!=null){
                patientVector.add(String.valueOf(patient.getPatientHtNumber()));
                }else{
                patientVector.add("");
                }
                if(patient.getPatientMNumber()!=null){
                    patientVector.add(String.valueOf(patient.getPatientMNumber()));
                }else{
                    patientVector.add("");
                }
                if(patient.getPatientENumber()!=null){
                    patientVector.add(String.valueOf(patient.getPatientENumber()));
                }else{
                      patientVector.add("");
                }
                if(patient.getPresentAddress1()!=null){
                    patientVector.add(patient.getPresentAddress1());
                }else{
                    patientVector.add("");
                }
                patients.add(patientVector);
            }
            return patients;
        }catch (DataAccessException ex) {
                Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new ProcessingException();
         }catch(Exception e){
             Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
             throw new HealthCareException("Error in Populating Patient List...");
        }
    }

    @Override
    public Vector<Vector<String>> findDuplicatePatientDetails() throws ProcessingException {
        Vector<Vector<String>> duplicates = new Vector<Vector<String>>();
        try{
            List<DuplicatePatient> duplicateList = patientDao.findDuplicatePatientDetails();
            for(DuplicatePatient dp :duplicateList){
                Vector<String> duplicate = new Vector<String>();
                duplicate.add(dp.getFname());
                duplicate.add(dp.getMname());
                duplicate.add(dp.getLname());
                duplicate.add(dp.getGender());
                duplicate.add(dp.getDuplicateNo().toString());
                duplicates.add(duplicate);
            }
            return duplicates;
            
        }catch (DataAccessException ex) {
                Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new ProcessingException();
         }catch(Exception e){
             Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
             throw new HealthCareException("Error in Populating Duplicate Patient List...");
        }
    }

    @Override
    public List<TPatient> findDuplicateRecordsByPatient(DuplicatePatient patient) throws ProcessingException {
        try{
             return patientDao.findDuplicateRecordsByPatient(patient);
        }catch (DataAccessException ex) {
                Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new ProcessingException();
         }catch(Exception e){
             Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
             throw new HealthCareException("Error in Populating Duplicate Record Of Patient...");
        }
    }

    @Override
    public void mergePatients(String patientids,TPatient patient,String ids) throws ProcessingException {
        try{
              // Create A New Patient
              Long id = patientDao.getIdAfterPatientSave(patient);
              TPatient pat = patientDao.getPatientDetails(id);
              
              //Change the patient status to "InActive" of selected patients to be merged
              String[] splittedids = ids.split(",");
              for(int i=0;i<splittedids.length;i++){
                  patientDao.changePatientStatus(splittedids[i]);
              }
              
              //Inserting the linked record's patient id and newly created patient id in another table.
              TPatientMerge mergepatient = null;
              String[] splittedPatientIds= patientids.split(",");
              for(int i=0;i<splittedPatientIds.length;i++){
                  mergepatient = new TPatientMerge();
                  mergepatient.setNewPatientId(pat.getPatientId());
                  mergepatient.setOldPatientId(splittedPatientIds[i]);
                  patientMergeService.savePatientMerge(mergepatient);
              }
        }catch (DataAccessException ex) {
                Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new ProcessingException();
         }catch(Exception e){
             Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
             throw new HealthCareException("Error in Merging Duplicate Record Of Patient...");
        }
    }

    @Override
    public String getPatientId() throws ProcessingException {
            try{
                String patientId=patientDao.getIdToInsert();
                long idpartnum=Integer.parseInt(patientId.substring(8));
                idpartnum+=1;
                String date = sdf.format(new Date());
                date = date.substring(0,2)+date.substring(3,5)+date.substring(6);
                if(idpartnum<10){
                    return String.valueOf(date+"0"+idpartnum);
                }else{
                    return String.valueOf(date+idpartnum);
                }
            }catch(DataAccessException | NumberFormatException e){
                throw new HealthCareException("Failed To Get The Max Patient Id");
            }
    }

    @Override
    public TPatient getPatientByPatientId(String patientID) throws ProcessingException {
        try{
            List<TPatient> patients = patientDao.getPatientByPatientId(patientID);
            if(patients.isEmpty()){
                return null;
            }else{
                return patients.get(0);
            }
        }catch(DataAccessException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new ProcessingException();
        }
    }

    @Override
    public boolean isDuplicatePatient(TPatient patient) throws ProcessingException {
        try{
            return patientDao.isDuplicatePatient(patient);
        }catch(DataAccessException e){
            Logger.getLogger(PatientServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new ProcessingException();
        }
    }

    

}

Commits for Satyam/AuroCareCommonUtil/src/main/java/com/bestray/healthcarecommonutil/serviceimpl/PatientServiceImpl.java

Diff revisions: vs.
Revision Author Commited Message
1 girijabapi picture girijabapi Fri 20 Jul, 2018 05:59:17 +0000