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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bestray.healthcarecommonutil.util;


 import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.GregorianCalendar;
import java.util.List;

 // TODO: Auto-generated Javadoc
/**
  * The Class TimeRange.
  */
 public class TimeRange {
     
     
    /**
     * Gets the time slot.
     *
     * @param startTime the start time
     * @param endTime the end time
     * @param incr the incr
     * @return the time slot
     */
    public static List<String> getTimeSlot(String startTime,String endTime,int incr) {        
    
        List<String> times = new ArrayList<String>();


        DateFormat sdf1 = new SimpleDateFormat("hh:mm a");
            try {

                Date startDate = sdf1.parse(startTime); 

                Date endDate = sdf1.parse(endTime); 

                SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
                Calendar calendar = GregorianCalendar.getInstance();
                calendar.setTime(startDate);
                int index=0;
                    if (!calendar.getTime().after(endDate)){
                        times.add(sdf.format(calendar.getTime()));
                        while(!calendar.getTime().after(endDate)) {
                             calendar.add(Calendar.MINUTE, incr);
                             times.add(sdf.format(calendar.getTime()));
                             index++;
                        }
                        times.remove(index);
                    }   
            } catch (Exception e) {
                e.printStackTrace();
            }
                return times;
        }
    
    /**
     * Calculate birth date.
     *
     * @param age the age
     * @param agemm the agemm
     * @return the date
     */
    public static Date calculateBirthDate(int age,int agemm){
        
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.YEAR, (-1)*age);
            cal.add(Calendar.MONTH, (-1)*agemm);
            cal.add(Calendar.DAY_OF_MONTH,(-1));
            return new Date(cal.getTimeInMillis());
        
    }
    
    /**
     * Calculate age.
     *
     * @param birthDate the birth date
     * @return the list
     */
    public static List<String> calculateAge(Date birthDate) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(birthDate);
        Calendar today = Calendar.getInstance();
        
        Date d1 = new Date(cal.getTimeInMillis());
        Date d2 = new Date(today.getTimeInMillis());
        int days=(int)( (d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24));
        int year=days/365;
        days=days%365;
        int month=days/30;
        List<String> totalAge = new ArrayList<String>();
        totalAge.add(String.valueOf(year));
        totalAge.add(String.valueOf(month));
        
        return totalAge;
    }
    
    /**
     * Gets the engage time slots.
     *
     * @param startTime the start time
     * @param incr the incr
     * @param count the count
     * @return the engage time slots
     */
    public static List<String> getEngageTimeSlots(String startTime, int incr, int count) {        
    
        List<String> times = new ArrayList<String>();


        DateFormat sdf1 = new SimpleDateFormat("hh:mm a");
            try {

                Date startDate = sdf1.parse(startTime); 

                

                SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");
                Calendar calendar = GregorianCalendar.getInstance();
                calendar.setTime(startDate);
                times.add(sdf.format(calendar.getTime()));
                int i=0;
                for( i=0;i<count;i++){
                
                             calendar.add(Calendar.MINUTE, incr);
                             times.add(sdf.format(calendar.getTime()));
                             
                }
                times.remove(i++);            
            } catch (Exception e) {
                e.printStackTrace();
            }
               return times;
            
        }
    
    /**
     * Check brith date.
     *
     * @param birthDate the birth date
     * @return true, if successful
     */
    public static boolean checkBrithDate(Date birthDate) {
        boolean valid = true;
        Date todayDate = new Date();
        if(todayDate.compareTo(birthDate)<0)
        {
            valid = false;
        }
        return valid;

    }
    
    public static String visitDuration(Date checkout,Date checkin){
        String visitDuration = null;
        Long msdiff= checkout.getTime()-checkin.getTime();
        if(checkout.getTime() >=checkin.getTime()){
            Long minutes = msdiff/60000;
            if(minutes>=60){
                Long hr = minutes/60;
                Long min = minutes%60;
                if((msdiff%60000)>=30000){
                    visitDuration = String.valueOf(hr)+" Hour "+String.valueOf(min+1)+" Min";
                }else{
                    visitDuration = String.valueOf(hr)+" Hour "+String.valueOf(min)+" Min";
                }
            }else{
                if(minutes<1 || (msdiff%60000)>=30000){
                    visitDuration = String.valueOf(minutes+1)+" Min";
                }else{
                    visitDuration = String.valueOf(minutes)+" Min";
                }
            }
        }else{
            visitDuration = "";
        }
        return visitDuration;
    }
    
}

Commits for Pharmacy_09_03_18/Dr Gyana ProjectSpace/DrGyanaCommonUtil/src/main/java/com/bestray/healthcarecommonutil/util/TimeRange.java

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