Subversion Repository Public Repository

Pharmacy_09_03_18

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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcareemr.ServiceImpl;

import com.bestray.healthcarecommonutil.dao.AllergiesMasterDao;
import com.bestray.healthcarecommonutil.dao.DiagnosisMasterDao;
import com.bestray.healthcarecommonutil.dao.MedicationMasterDao;
import com.bestray.healthcarecommonutil.exception.DataAccessException;
import com.bestray.healthcarecommonutil.exception.HealthCareException;
import com.bestray.healthcarecommonutil.exception.ProcessingException;
import com.bestray.healthcarecommonutil.service.OrderResultService;
import com.bestray.healthcarecommonutil.service.OrderSpecimenCollectionService;
import com.bestray.healthcarecommonutil.vo.TAllergiesMaster;
import com.bestray.healthcarecommonutil.vo.TAppointment;
import com.bestray.healthcarecommonutil.vo.TDiagnosisMaster;
import com.bestray.healthcarecommonutil.vo.TEncounterAllergy;
import com.bestray.healthcarecommonutil.vo.TEncounterDiagnosis;
import com.bestray.healthcarecommonutil.vo.TEncounterHistoryVisit;
import com.bestray.healthcarecommonutil.vo.TEncounterMedication;
import com.bestray.healthcarecommonutil.vo.TEncounterProcedure;
import com.bestray.healthcarecommonutil.vo.TEncounterVitalSign;
import com.bestray.healthcarecommonutil.vo.TMedicationMaster;
import com.bestray.healthcarecommonutil.vo.TPatEncOrderResults;
import com.bestray.healthcarecommonutil.vo.TPatient;
import com.bestray.healthcarecommonutil.vo.TPatientEncounter;
import com.bestray.healthcarecommonutil.vo.TProcedureMaster;
import com.bestray.healthcareemr.Dao.PatientEncounterAllergyDao;
import com.bestray.healthcareemr.Dao.PatientEncounterDao;
import com.bestray.healthcareemr.Dao.PatientEncounterDiagnosisDao;
import com.bestray.healthcareemr.Dao.PatientEncounterMedicationDao;
import com.bestray.healthcareemr.Dao.PatientEncounterProcedureDao;
import com.bestray.healthcareemr.Dao.PatientEncounterVisitHistoryDao;
import com.bestray.healthcareemr.Dao.PatientEncounterVitalSignsDao;
import com.bestray.healthcarecommonutil.dao.ProcedureMasterDao;
import com.bestray.healthcarecommonutil.service.RecentPatientService;
import com.bestray.healthcareemr.Service.PatientEncounterService;
import com.bestray.healthcarecommonutil.util.Initcap;
import com.bestray.healthcarecommonutil.util.PatientClone;
import com.bestray.healthcarecommonutil.vo.TDepartmentMaster;
import com.bestray.healthcarecommonutil.vo.TDoctorInformation;
import com.bestray.healthcarecommonutil.vo.TRecentPatient;
import com.bestray.healthcareemr.Dao.AppointmentDao;
import com.bestray.healthcareemr.Dao.XrayImageDao;
import com.bestray.healthcareemr.Vo.XrayImage;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
import org.springframework.stereotype.Service;

// TODO: Auto-generated Javadoc
/**
 * The Class PatientEncounterServiceImpl.
 *
 * @author user3
 */
@Service
public class PatientEncounterServiceImpl implements PatientEncounterService{
    
    /** The out patient dao. */
    @Autowired
    private PatientEncounterDao patientEncounterDao;
    
    /** The allergies master dao. */
    @Autowired
    private AllergiesMasterDao allergiesMasterDao;
    
    /** The medication master dao. */
    @Autowired
    private MedicationMasterDao medicationMasterDao;
    
    /** The procedure master dao. */
    @Autowired
    private ProcedureMasterDao procedureMasterDao;
    
    @Autowired
    private DiagnosisMasterDao diagnosisMasterDao;
    
    @Autowired
    private AppointmentDao appointmentDao;
    
    @Autowired
    private RecentPatientService recentPatientService;
    
    /** The allergy. */
    private TAllergiesMaster allergy;
    
    /** The medication. */
    private TMedicationMaster medication;
    
    /** The procedure. */
    private TProcedureMaster procedure;
    
    private TDiagnosisMaster diagnosis;
    
    /** The enc. */
    private TPatientEncounter enc;
    
    /** The encounter allergy. */
    private TEncounterAllergy encounterAllergy;
    
    /** The encounter medication. */
    private TEncounterMedication encounterMedication;
    
    /** The encounter procedure. */
    private TEncounterProcedure encounterProcedure;
    
    private TEncounterDiagnosis encounterDiagnosis;
    
    /** The sdf. */
    private SimpleDateFormat sdf;
    
    @Autowired
    private PatientEncounterAllergyDao patientEncounterAllergyDao;
    
    @Autowired
    private PatientEncounterDiagnosisDao patientEncounterDiagnosisDao;
    
    @Autowired
    private PatientEncounterMedicationDao patientEncounterMedicationDao;
    
    @Autowired
    private PatientEncounterProcedureDao patientEncounterProcedureDao;
    
    @Autowired
    private PatientEncounterVitalSignsDao patientEncounterVitalSignsDao;
    
    @Autowired
    private XrayImageDao xrayImageDao;
    
    @Autowired
    private PatientEncounterVisitHistoryDao patientEncounterVisitHistoryDao;
    
    @Autowired
    private OrderResultService orderResultService;
    
    @Autowired
    private OrderSpecimenCollectionService orderSpecimenCollectionService;

    public PatientEncounterServiceImpl() {
        allergy = new TAllergiesMaster();
        medication = new TMedicationMaster();
        procedure = new TProcedureMaster();
        enc = new TPatientEncounter();
        diagnosis = new TDiagnosisMaster();
        sdf = new SimpleDateFormat("dd-MM-YYYY");
    }
    
    /**
     * Instantiates a new out patient service impl.
     *
     * @param outPatientDao the out patient dao
     * @param allergiesMasterDao the allergies master dao
     * @param medicationMasterDao the medication master dao
     * @param procedureMasterDao the procedure master dao
     */
    /*public PatientEncounterServiceImpl(PatientEncounterDao patientEncounterDao,AllergiesMasterDao allergiesMasterDao,
            MedicationMasterDao medicationMasterDao,ProcedureMasterDao procedureMasterDao, 
            DiagnosisMasterDao diagnosisMasterDao,
            PatientEncounterAllergyDao patientEncounterAllergyDao, PatientEncounterDiagnosisDao patientEncounterDiagnosisDao,
            PatientEncounterMedicationDao patientEncounterMedicationDao,PatientEncounterProcedureDao patientEncounterProcedureDao,
            PatientEncounterVitalSignsDao patientEncounterVitalSignsDao, PatientEncounterVisitHistoryDao patientEncounterVisitHistoryDao, OrderResultService orderResultService, 
            OrderSpecimenCollectionService orderSpecimenCollectionService) {
        this.patientEncounterDao=patientEncounterDao;
        this.allergiesMasterDao=allergiesMasterDao; 
        this.medicationMasterDao =medicationMasterDao;
        this.procedureMasterDao=procedureMasterDao;
        this.diagnosisMasterDao=diagnosisMasterDao;
        this.patientEncounterAllergyDao=patientEncounterAllergyDao;
        this.patientEncounterDiagnosisDao=patientEncounterDiagnosisDao;
        this.patientEncounterMedicationDao=patientEncounterMedicationDao;
        this.patientEncounterProcedureDao=patientEncounterProcedureDao;
        this.patientEncounterVitalSignsDao=patientEncounterVitalSignsDao;
        this.patientEncounterVisitHistoryDao=patientEncounterVisitHistoryDao;
        this.orderResultService = orderResultService;
        this.orderSpecimenCollectionService = orderSpecimenCollectionService;
        allergy = new TAllergiesMaster();
        medication = new TMedicationMaster();
        procedure = new TProcedureMaster();
        enc = new TPatientEncounter();
        diagnosis = new TDiagnosisMaster();
        sdf = new SimpleDateFormat("dd-MM-YYYY");
    }*/


    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientEncounterService#saveEncounter(com.bestray.healthcareemr.Vo.TPatientEncounter, javax.swing.JTable, javax.swing.JTable, javax.swing.JTable, com.bestray.healthcareemr.Vo.TEncounterVitalSign, com.bestray.healthcareemr.Vo.TEncounterHistoryVisit)
     */
    @Override
    public TPatientEncounter saveEncounter(TPatientEncounter encounter, JTable allergy_table, JTable medication_table,JTable diagnosis_table,JTable procedure_table,TEncounterVitalSign vitalsign,TEncounterHistoryVisit visitHistory,List<Long> removeprocids, List<Long> removediaglist, List<Long> removeallergylist) throws ProcessingException,HibernateOptimisticLockingFailureException,IllegalArgumentException {
        Date d = new Date();
        try {
            encounterAllergy = new TEncounterAllergy();
            encounterMedication = new TEncounterMedication();
            encounterProcedure = new TEncounterProcedure();
            encounterDiagnosis = new TEncounterDiagnosis();
            enc = patientEncounterDao.savePatientEncounterInfo(encounter);
            TRecentPatient recPatient = PatientClone.getPatient(encounter.getPatient());
            recentPatientService.saveRecentPatient(recPatient);
            
            if(removeallergylist.size()>0){
             for(Long ids:removeallergylist){
                patientEncounterAllergyDao.deleteEncounterAllergies(ids);
             }
           }
            for(int i=0;i<allergy_table.getRowCount();i++){
                String allergyname = allergy_table.getValueAt(i, 0).toString();
                TAllergiesMaster allergies = allergiesMasterDao.getAllergy(allergyname);
                if(allergies!=null){
                    allergy = allergies;
                }else{
                    allergy.setAllergiesName(Initcap.toInitCap(allergyname));
                    allergy.setCreatedDate(d);
                    allergy.setAllergiesStatus("ACTIVE");
                    allergiesMasterDao.saveAllergiesMaster(allergy);
                    allergy = allergiesMasterDao.getAllergy(allergyname);
                }
                Object reaction = allergy_table.getValueAt(i, 1);
                Object severity = allergy_table.getValueAt(i, 2);
                Object comments = allergy_table.getValueAt(i, 3);
                if(allergy_table.getValueAt(i, 4)!=null){
                    //encounterAllergy.setId(Long.valueOf(allergy_table.getValueAt(i, 4).toString()));
                    encounterAllergy = patientEncounterAllergyDao.getEncAllergyById(Long.valueOf(allergy_table.getValueAt(i, 4).toString()));
                }else{
                    encounterAllergy.setId(null);
                }
                encounterAllergy.setAllergy(allergy);
                encounterAllergy.setEncounter(enc);
                if(severity!=null){
                    encounterAllergy.setSeverity(String.valueOf(severity));
                }else{
                    encounterAllergy.setSeverity(null);
                }
                if(reaction!=null){
                    encounterAllergy.setReaction(String.valueOf(reaction));
                }else{
                    encounterAllergy.setReaction(null);
                }
                if(comments!=null){
                    encounterAllergy.setComments(String.valueOf(comments));
                }else{
                    encounterAllergy.setComments(null);
                }
                patientEncounterAllergyDao.saveAllergyEncounter(encounterAllergy);
            }
           for(int i=0;i<medication_table.getRowCount();i++){
               String id = medication_table.getValueAt(i, 0).toString();
               String medicationname = medication_table.getValueAt(i, 1).toString();
               TMedicationMaster medications = medicationMasterDao.getMedication(medicationname);
               if(medications!=null){
                    medication = medications;
                }else{
                    medication.setMedicationName(medicationname.toUpperCase());
                    medication.setCreatedDate(d);
                    medication.setMedicationStatus("ACTIVE");
                    medication.setMedicationDose(null);
                    medication.setMedicationFrequency(null);
                    medicationMasterDao.saveMedicationMaster(medication);
                    medication = medicationMasterDao.getMedication(medicationname);
                }
                String dose = medication_table.getValueAt(i, 2).toString();
                String frequency = medication_table.getValueAt(i, 3).toString();
                String route = medication_table.getValueAt(i, 4).toString();
                String comments = medication_table.getValueAt(i, 5).toString();
                String status = medication_table.getValueAt(i, 6).toString();
                String reorderStatus = medication_table.getValueAt(i, 7).toString();
                TPatientEncounter encId = null;
                if(!medication_table.getValueAt(i, 8).toString().equalsIgnoreCase("-")){
                    encId = (TPatientEncounter)medication_table.getValueAt(i, 8);
                }
                if(status.equalsIgnoreCase("Not Taking")){
                    encounterMedication.setStatus(0);
                }else if(status.equalsIgnoreCase("Canceled")){
                    encounterMedication.setStatus(2);
                }else{
                    encounterMedication.setStatus(1);
                }
                encounterMedication.setMedication(medication);
                encounterMedication.setDose(dose);
                encounterMedication.setFrequency(frequency);
                encounterMedication.setRoute(route);
                encounterMedication.setComments(comments);
                if(id.equalsIgnoreCase("-")){
                    encounterMedication.setEncounterMed(enc);
                    patientEncounterMedicationDao.saveMedicationEncounter(encounterMedication);
                }else{
                    if(reorderStatus.equalsIgnoreCase("ReOrdered")){
                        encounterMedication.setEncounterMed(enc);
                        encounterMedication.setStatus(1);
                        patientEncounterMedicationDao.saveMedicationEncounter(encounterMedication);
                        //updating
                        encounterMedication = patientEncounterMedicationDao.getEncMedById(Long.parseLong(id));
                        //encounterMedication.setId(Long.parseLong(id));
                        encounterMedication.setEncounterMed(encId);
                        encounterMedication.setStatus(0);
                        patientEncounterMedicationDao.updateMedicationEncounter(encounterMedication);
                    }else if(status.equalsIgnoreCase("taking") && !reorderStatus.equalsIgnoreCase("ReOrdered")){
                        encounterMedication = patientEncounterMedicationDao.getEncMedById(Long.parseLong(id));
                        //encounterMedication.setId(Long.parseLong(id));
                        encounterMedication.setEncounterMed(encId);
                        encounterMedication.setStatus(1);
                        patientEncounterMedicationDao.updateMedicationEncounter(encounterMedication);
                    }else if(status.equalsIgnoreCase("not taking") && !reorderStatus.equalsIgnoreCase("ReOrdered")){
                        encounterMedication = patientEncounterMedicationDao.getEncMedById(Long.parseLong(id));
                        //encounterMedication.setId(Long.parseLong(id));
                        encounterMedication.setEncounterMed(encId);
                        encounterMedication.setStatus(0);
                        patientEncounterMedicationDao.updateMedicationEncounter(encounterMedication);
                    }else if(status.equalsIgnoreCase("canceled")){
                        encounterMedication = patientEncounterMedicationDao.getEncMedById(Long.parseLong(id));
                        //encounterMedication.setId(Long.parseLong(id));
                        encounterMedication.setEncounterMed(encId);
                        encounterMedication.setStatus(2);
                        patientEncounterMedicationDao.updateMedicationEncounter(encounterMedication);
                    }
                    
                }
                
           }
           
           if(removeprocids.size()>0){
             for(Long ids:removeprocids){
                TEncounterProcedure removeProcedure = patientEncounterProcedureDao.getProcedureEncounterByID(ids);
                orderResultService.deleteOrderResultsEncounter(removeProcedure, enc);
                orderSpecimenCollectionService.deleteSpecimenDetailsEncounter(removeProcedure, enc);
                patientEncounterProcedureDao.deleteEncounterProcedure(ids);
             }
           }
           for(int i=0;i<procedure_table.getRowCount();i++){
               String procedurename = procedure_table.getValueAt(i, 0).toString();
               TProcedureMaster procedures = procedureMasterDao.getProcedure(procedurename);
               if(procedures!=null){
                    procedure = procedures;
                }else{
                    procedure.setProcedureName(Initcap.toInitCap(procedurename));
                    procedure.setCreatedDate(d);
                    procedure.setProcedureStatus("ACTIVE");
                    procedureMasterDao.saveProcedureMaster(procedure);
                    procedure = procedureMasterDao.getProcedure(procedurename);
                }
               
               Object procedurecomments = procedure_table.getValueAt(i, 1);
               Date orderdate = (Date)procedure_table.getValueAt(i, 3);
               String orderby = String.valueOf(procedure_table.getValueAt(i, 4));
               String orderstatus = String.valueOf(procedure_table.getValueAt(i, 5));
               String activeinactive = String.valueOf(procedure_table.getValueAt(i, 6));
               String specimencoll = String.valueOf(procedure_table.getValueAt(i, 7));
               String orderrecived = procedure_table.getValueAt(i, 8).toString();
               Date resultdate = (Date)procedure_table.getValueAt(i, 9);
               
               if(procedure_table.getValueAt(i, 2)!=null){
                    //encounterProcedure.setId(Long.valueOf(procedure_table.getValueAt(i, 2).toString()));
                   encounterProcedure = patientEncounterProcedureDao.getProcedureEncounterByID(Long.valueOf(procedure_table.getValueAt(i, 2).toString()));
                }else{
                   encounterProcedure.setId(null);
                }
               
                encounterProcedure.setProcedure(procedure);
                encounterProcedure.setEncounterProcedure(enc);
                if(procedurecomments!=null){
                    encounterProcedure.setComments(String.valueOf(procedurecomments));
                }else{
                    encounterProcedure.setComments(null);
                }
                encounterProcedure.setOrderDate(orderdate);
                encounterProcedure.setOrderBy(orderby);
                encounterProcedure.setOrderStatus(orderstatus);
                encounterProcedure.setOrderActiveInactiveStatus(activeinactive);
                encounterProcedure.setOrderSpecimenCollectionStatus(specimencoll);
                encounterProcedure.setPatientRecieved(orderrecived);
                encounterProcedure.setOrderResultedDate(resultdate);
                patientEncounterProcedureDao.saveProcedureEncounter(encounterProcedure);
           }
           
           if(removediaglist.size()>0){
             for(Long ids:removediaglist){
                patientEncounterDiagnosisDao.deleteEncounterDiagnosis(ids);
             }
           }           
           for(int i=0;i<diagnosis_table.getRowCount();i++){
               String diagnosisname = diagnosis_table.getValueAt(i, 1).toString();
               TDiagnosisMaster diagnosiss = diagnosisMasterDao.getDiagnosis(diagnosisname);
               if(diagnosiss!=null){
                    diagnosis = diagnosiss;
                }else{
                    diagnosis.setDiagnosisName(Initcap.toInitCap(diagnosisname));
                    diagnosis.setCreatedDate(d);
                    diagnosis.setDiagnosisStatus("ACTIVE");
                    diagnosisMasterDao.saveDiagnosisMaster(diagnosis);
                    diagnosis = diagnosisMasterDao.getDiagnosis(diagnosisname);
                }
               Object diagnosiscomments = diagnosis_table.getValueAt(i, 2);
               if(diagnosis_table.getValueAt(i, 3)!=null){
                    //encounterDiagnosis.setId(Long.valueOf(diagnosis_table.getValueAt(i, 3).toString()));
                   encounterDiagnosis = patientEncounterDiagnosisDao.getEncDiagById(Long.valueOf(diagnosis_table.getValueAt(i, 3).toString()));
                }else{
                    encounterDiagnosis.setId(null);
                }
               
                encounterDiagnosis.setDiagnosis(diagnosis);
                encounterDiagnosis.setEncounterDiagnosis(enc);
                if(diagnosiscomments!=null){
                    encounterDiagnosis.setComments(String.valueOf(diagnosiscomments));
                }else{
                    encounterDiagnosis.setComments(null);
                }
                patientEncounterDiagnosisDao.saveDiagnosisEncounter(encounterDiagnosis);
           }
           
           if(vitalsign.getBloodPressure()==null && vitalsign.getHeight()==null && vitalsign.getPulse()==null && vitalsign.getRespiration()==null && vitalsign.getSource()==null && vitalsign.getTemperature()==null &&vitalsign.getWeight()==null){
           }else{
               vitalsign.setEncounterVitalsign(enc);
               vitalsign.setRecordedDate(d);
               patientEncounterVitalSignsDao.saveVitalSignEncounter(vitalsign);
           }
           if(visitHistory.getWhyVisiting()==null && visitHistory.getVisitNotes()==null && visitHistory.getHistory()==null && visitHistory.getFollowUp()==null && visitHistory.getFollowUpType()==null){            
           }else{
                visitHistory.setEncounterVisitHistory(enc);
                visitHistory.setRecordedDate(d);
                patientEncounterVisitHistoryDao.saveVisitHistoryEncounter(visitHistory);
           }
           return enc;
        }catch(  HibernateOptimisticLockingFailureException | IllegalArgumentException e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw e;
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientEncounterService#getEncounterDates(com.bestray.healthcareemr.Vo.TPatient)
     */
    @Override
    public List<TPatientEncounter> getEncounterDates(TPatient patientinfo) throws ProcessingException {
        try{
            return patientEncounterDao.getEncounterDates(patientinfo);
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
    }

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientEncounterService#countNumberOfVisit(com.bestray.healthcareemr.Vo.TPatient)
     */
    @Override
    public String countNumberOfVisit(TPatient patientinfo) throws ProcessingException {
        try{
            int number = patientEncounterDao.countNumberOfVisit(patientinfo);
            return (number==0)?null:String.valueOf(number);
            
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
    }

    

    /* (non-Javadoc)
     * @see com.bestray.healthcareemr.Service.PatientEncounterService#getEncounter(java.lang.Long)
     */
    @Override
    public TPatientEncounter getEncounterById(Long encid) throws ProcessingException {
        try{
            return patientEncounterDao.getEncounterById(encid);
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in retriving...");
        }
    }

    

    @Override
    public TPatientEncounter getEncounterByAppoitment(TAppointment appointmentinfo) throws ProcessingException {
        try{
            return patientEncounterDao.getEncounterByAppoitment(appointmentinfo);
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in retriving...");
        }
    }

    
    @Override
    public List<TPatEncOrderResults> getLabResultsByProcedureId(TEncounterProcedure encprocedure) throws ProcessingException {
        try{
            return patientEncounterDao.getLabResultsByProcedureId(encprocedure);
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in retriving...");
        }
    }

    @Override
    public List<TAppointment> getOPAppointmentListByDate(Date appointmentDate) throws ProcessingException {
        List<TAppointment> opAppointments = new ArrayList<TAppointment>();
        try {
             List<TAppointment> appointments = appointmentDao.findAppointmentListByDate(appointmentDate);
             for(TAppointment appt:appointments){
                 if(appt.getScheduleType().equalsIgnoreCase("Out Patient")){
                     opAppointments.add(appt);
                 }
             }
             return opAppointments;
        }catch(DataAccessException e){
                Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
                throw new ProcessingException();
        } catch (Exception ex) {
                Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new HealthCareException("Error in populating appointments list");
        }
    }

    @Override
    public List<TAppointment> getOPAppointmentListByDoctor(Date date, TDepartmentMaster departmentValues, TDoctorInformation DoctorDetails) throws ProcessingException{
        List<TAppointment> opAppointments = new ArrayList<TAppointment>();
        try {
             List<TAppointment> appointments = appointmentDao.findAppointmentListByDoctor(date,departmentValues,DoctorDetails);
             for(TAppointment appt:appointments){
                 if(appt.getScheduleType().equalsIgnoreCase("Out Patient")){
                     opAppointments.add(appt);
                 }
             }
             return opAppointments;
        }catch(DataAccessException e){
                Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
                throw new ProcessingException();
        } catch (Exception ex) {
                Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new HealthCareException("Error in populating appointments list");
        }
    }

    @Override
    public List<TAppointment> getOPAppointmentListByDepartment(Date date, TDepartmentMaster departmentValues) throws ProcessingException{
        List<TAppointment> opAppointments = new ArrayList<TAppointment>();
        try {
             List<TAppointment> appointments = appointmentDao.findAppointmentListByDepartment(date,departmentValues);
             for(TAppointment appt:appointments){
                 if(appt.getScheduleType().equalsIgnoreCase("Out Patient")){
                     opAppointments.add(appt);
                 }
             }
             return opAppointments;
        }catch(DataAccessException e){
                Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
                throw new ProcessingException();
        } catch (Exception ex) {
                Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
                throw new HealthCareException("Error in populating appointments list");
        }
    }
    
    
    @Override
    public List<Object>/*TPatientEncounter*/ saveEncounter(TPatientEncounter patientenc,TEncounterHistoryVisit vh,
        List<TEncounterAllergy> encallergy,TEncounterVitalSign vitalsigns,List<Long> removeallergylist,
        List<TEncounterProcedure> encprocedure,List<Long> removeproclist,List<TEncounterMedication> encmedication,
        List<TEncounterDiagnosis> encdiagnosis,List<Long> removediagnosislist)throws ProcessingException {
        
        List<Object> objlist = new ArrayList<Object>();
        List<TEncounterProcedure> encproclist = new ArrayList<TEncounterProcedure>();
        try{
            enc = patientEncounterDao.savePatientEncounterInfo(patientenc);
            
            vh.setEncounterVisitHistory(enc);
            vitalsigns.setEncounterVitalsign(enc);
            patientEncounterVitalSignsDao.saveVitalSignEncounter(vitalsigns);
            patientEncounterVisitHistoryDao.saveVisitHistoryEncounter(vh);
            if(removeallergylist.size()>0){
             for(Long ids:removeallergylist){
                patientEncounterAllergyDao.deleteEncounterAllergies(ids);
             }
            }
            for(TEncounterAllergy al:encallergy){
                al.setEncounter(enc);
                patientEncounterAllergyDao.saveAllergyEncounter(al);
            }
            if(removeproclist.size()>0){
             for(Long ids:removeproclist){
                TEncounterProcedure removeProcedure = patientEncounterProcedureDao.getProcedureEncounterByID(ids);
                orderResultService.deleteOrderResultsEncounter(removeProcedure, enc);
                orderSpecimenCollectionService.deleteSpecimenDetailsEncounter(removeProcedure, enc);
                patientEncounterProcedureDao.deleteEncounterProcedure(ids);
             }
            }
            for(TEncounterProcedure proc:encprocedure){
                proc.setEncounterProcedure(enc);
                patientEncounterProcedureDao.saveProcedureEncounter(proc);
            }
            for(TEncounterMedication medic:encmedication){
                medic.setEncounterMed(enc);
                patientEncounterMedicationDao.saveMedicationEncounter(medic);
            }
            if(removediagnosislist.size()>0){
             for(Long ids:removediagnosislist){
                patientEncounterDiagnosisDao.deleteEncounterDiagnosis(ids);
             }
            }
            for(TEncounterDiagnosis diag:encdiagnosis){
                diag.setEncounterDiagnosis(enc);
                patientEncounterDiagnosisDao.saveDiagnosisEncounter(diag);
            }
            objlist.add(enc);
            objlist.add(encproclist);
            return objlist;
           // return enc;
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in saving...");
        }
    }

    @Override
    public TEncounterHistoryVisit saveVisitHistoryEnc(TEncounterHistoryVisit vh, TPatientEncounter patencbyappoitornew)throws ProcessingException {
        try{
            
                vh.setEncounterVisitHistory(patencbyappoitornew);
                vh.setRecordedDate(new Date());
             
             return patientEncounterVisitHistoryDao.saveVisitHistoryEncounter(vh);
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in saving...");
        }
    }

    @Override 
    public TEncounterAllergy getEncAllergyById(Long id)throws ProcessingException {
        try{
            return patientEncounterAllergyDao.getEncAllergyById(id);
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in saving...");
        }
    }

    @Override
    public void saveProcedureMaster(TProcedureMaster procedure)throws ProcessingException {
        try{
             procedureMasterDao.saveProcedureMaster(procedure);
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in saving...");
        }
    }

    @Override
    public TEncounterMedication getEncMedById(long id)throws ProcessingException {
        try{
             return patientEncounterMedicationDao.getEncMedById(id);
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in saving...");
        }
    }
    
    @Override
    public void savexrayimages(Set<XrayImage> xrayImages)throws ProcessingException {
        try{
             xrayImageDao.savexrayimages(xrayImages);
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in saving...");
        }
    }

@Override
    public List<XrayImage> getXrayImages(TPatientEncounter patientenc) throws ProcessingException {
    try{
           return xrayImageDao.getXrayImages(patientenc);
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in retriving...");
        }
    }

    @Override
    public List<TPatientEncounter> getAllOpenEncounter() throws ProcessingException {
        try{
            return patientEncounterDao.getAllOpenEncounter();
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
    }

    @Override
    public TPatientEncounter createNewEncounter(TPatientEncounter encounter) throws ProcessingException {
        try{
            TRecentPatient recPatient = PatientClone.getPatient(encounter.getPatient());
            recentPatientService.saveRecentPatient(recPatient);
            return patientEncounterDao.savePatientEncounterInfo(encounter);
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new ProcessingException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
    }
    
    @Override
    public void closeEncounter(TPatientEncounter encounter) throws DataAccessException,HibernateOptimisticLockingFailureException {
        try{
            patientEncounterDao.closeEncounter(encounter);
        }catch (DataAccessException ex) {
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
            throw new DataAccessException();
        }catch(Exception e){
            Logger.getLogger(PatientEncounterServiceImpl.class.getName()).log(Level.SEVERE, null, e);
            throw new HealthCareException("Error in Saving...");
        }
    }

   
}

Commits for Pharmacy_09_03_18/Dr Gyana ProjectSpace/DrGyanaEMR/src/main/java/com/bestray/healthcareemr/ServiceImpl/PatientEncounterServiceImpl.java

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