-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsultDoctor.java
496 lines (399 loc) · 19.7 KB
/
ConsultDoctor.java
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
package com.example.shivam.patientapp.bookAnAppointment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.shivam.patientapp.common.Constant;
import com.example.shivam.patientapp.common.Global1;
import com.example.shivam.patientapp.common.ImageUtility;
import com.example.shivam.patientapp.common.PermissionFile;
import com.example.shivam.patientapp.preferences.SharedPreferenceManager;
import com.example.shivam.patientapp.R;
import com.example.shivam.patientapp.tabLayout.TabActivity;
import com.example.shivam.patientapp.apiBase.ApiClient;
import com.example.shivam.patientapp.apiBase.ApiInterface;
import com.example.shivam.patientapp.doctor_schudle.Constants;
import com.example.shivam.patientapp.doctor_schudle.L;
import com.example.shivam.patientapp.doctor_schudle.VolleySingleton;
import com.example.shivam.patientapp.model.SucessModel;
import com.squareup.picasso.Picasso;
import org.json.JSONObject;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import de.hdodenhof.circleimageview.CircleImageView;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
public class ConsultDoctor extends AppCompatActivity implements View.OnClickListener/*,ResponseListener*/{
private EditText message1;
private ImageView video,voice,text,back_icon;
private TextView header_text;
private Intent intent;
private final String TAG=ConsultDoctor.class.getSimpleName();
private VolleySingleton volleySingleton;
private SharedPreferenceManager sharedPreferenceManager;
private Context context=this;
private String mFilePath,mFileEducation;
private String doctorID,startTime,EndTime,consulationDate,amount;
private Button upload_attachment;
private Uri mImageUrl;
private static final int PERMISSION_REQUEST_CODE = 200;
private Button confirm_booking;
private int SELECT_FILE_EDUCATION=103;
private VolleySingleton mVolleySingleton;
String selected_communication_medium1="1";
// Ravinder
String doctorImage="",doctorRating="",mDoctorName="";
PermissionFile permissionFile;
File destination;
Uri outputFileUri;
ImageUtility imageUtility;
String licenseFile = "";
ImageView upload_image;
Call<SucessModel> call;
TextView rating,tvDoctorName,date,time;
CircleImageView ivDoctorImage;
RequestBody imageToUpload;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consult_doctor);
permissionFile = new PermissionFile(this);
imageUtility=new ImageUtility(this);
multiplePermission();
intent=getIntent();
intent.getExtras();
header_text=(TextView)findViewById(R.id.text);
header_text.setText("Book an Appointment");
back_icon=(ImageView)findViewById(R.id.back_icon);
back_icon.setVisibility(View.VISIBLE);
upload_attachment=(Button) findViewById(R.id.upload_attachment);
upload_attachment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setProfileImageEducation();
}
});
upload_attachment.setVisibility(View.GONE );
upload_image=(ImageView)findViewById(R.id.upload_image);
upload_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setProfileImageEducation();
}
});
back_icon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(context,DoctorSchudle.class);
startActivity(intent);
}
});
sharedPreferenceManager=new SharedPreferenceManager(context);
volleySingleton=VolleySingleton.getInstance();
doctorID=intent.getBundleExtra("bundle").getString(Constants.KEY_ID);
consulationDate=intent.getBundleExtra("bundle").getString("consultation_date");
startTime=intent.getBundleExtra("bundle").getString("start_time");
EndTime=intent.getBundleExtra("bundle").getString("end_time");
amount=intent.getBundleExtra("bundle").getString("cost");
Log.e("bundle is",""+intent.getBundleExtra("bundle").getString(Constants.KEY_ID));
initViews();
makeButtonsClickable();
getDoctorDetails();
}
private void makeButtonsClickable() {
confirm_booking.setOnClickListener(this);
video.setOnClickListener(this);
voice.setOnClickListener(this);
text.setOnClickListener(this);
}
private void initViews() {
message1=(EditText)findViewById(R.id.message);
video=(ImageView)findViewById(R.id.video);
text=(ImageView)findViewById(R.id.text_chat);
voice=(ImageView)findViewById(R.id.voice);
confirm_booking=(Button)findViewById(R.id.confirm_booking);
rating=(TextView) findViewById(R.id.rating);
tvDoctorName=(TextView)findViewById(R.id.tvDoctorName);
date=(TextView)findViewById(R.id.date);
time=(TextView)findViewById(R.id.time);
ivDoctorImage=(CircleImageView) findViewById(R.id.ivDoctorImage);
consulationDate=intent.getBundleExtra("bundle").getString("consultation_date");
startTime=intent.getBundleExtra("bundle").getString("start_time");
EndTime=intent.getBundleExtra("bundle").getString("end_time");
amount=intent.getBundleExtra("bundle").getString("cost");
date.setText(consulationDate);
time.setText(startTime+" - "+EndTime);
}
void multiplePermission() {
if (!permissionFile.checkLocStorgePermission(this)) {
permissionFile.checkLocStorgePermission(this);
}
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.confirm_booking:
L.showToast(ConsultDoctor.this,"Test");
if(message1.getText().toString().trim().equals(""))
{
L.showToast(ConsultDoctor.this,"Please Enter Message");
}else
{
bookAppointment(licenseFile);
}
break;
case R.id.text_chat:
video.setImageResource(R.drawable.videodisable_grey);
text.setImageResource(R.drawable.message_enable_blue);
voice.setImageResource(R.drawable.calldisable);
selected_communication_medium1="1";
break;
case R.id.video:
video.setImageResource(R.drawable.video_enable);
text.setImageResource(R.drawable.message_disable_grey);
voice.setImageResource(R.drawable.calldisable);
selected_communication_medium1="3";
break;
case R.id.voice:
video.setImageResource(R.drawable.videodisable_grey);
text.setImageResource(R.drawable.message_disable_grey);
voice.setImageResource(R.drawable.callenable);
selected_communication_medium1="2";
break;
}
}
public void setProfileImageEducation() {
final CharSequence[] items = {"Take Photo","Gallery","Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(ConsultDoctor.this);
builder.setTitle("Patient App");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Take Photo")) {
openCamera();
} if (items[item].equals("Gallery")) {
pickGallery();
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
private void openCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final File root = permissionFile.getFile();
root.mkdirs();
String filename = permissionFile.getUniqueImageFilename();
destination = new File(root, filename);
outputFileUri= FileProvider.getUriForFile(
this,
getApplicationContext()
.getPackageName() + ".provider", destination);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, Global1.CameraPicker);
}
public void pickGallery() {
Intent pickIntent = new Intent(Intent.ACTION_PICK);
pickIntent.setType("image/*");
startActivityForResult(pickIntent, Global1.GalleryPicker);
}
/*this is used to fetch doctor details*/
public void getDoctorDetails() {
L.showProgresssBar(context);
StringRequest myReq = new StringRequest(Request.Method.POST,
Constant.WEB_URL +"get-doctor-profile1",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
L.hideProgressBar(context);
try {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.getBoolean("success") && jsonObject.getString("status_code").equals("200")) {
JSONObject result = jsonObject.getJSONObject("result");
tvDoctorName.setText(result.getString("doctor_name"));
doctorImage= result.getString("profile_image");
Picasso.with(ConsultDoctor.this).load(result.getString("profile_image")).into(ivDoctorImage);
amount=result.getString("amount");
confirm_booking.setText("Pay $ "+amount);
Log.e("amount","amount"+amount);
rating.setText(result.getString("rating"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
L.showToast(getApplicationContext(), "error");
L.hideProgressBar(context);
}
}) {
@Override
protected Map<String, String> getParams() throws com.android.volley.AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("doctor_id", doctorID);
params.put("user_id",sharedPreferenceManager.getValue(SharedPreferenceManager.USER_ID) );
params.put("token", sharedPreferenceManager.getValue(SharedPreferenceManager.TOKEN));
Log.e("params are", "" + params);
return params;
}
};
//add request to volley queue
VolleySingleton.getInstance().addToRequestQueue(myReq, TAG);
}
// end
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && data != null && data.getData() != null) {
if (requestCode == Global1.GalleryPicker) {
onCaptureImageResult(data, "gallery");
}
} else if (resultCode == RESULT_OK && requestCode == Global1.CameraPicker) {
onCaptureImageResult(data, "camera");
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case Global1.REQUEST_CODE_LOCATION:
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// logInApp();
}
break;
case Global1.REQUEST_CODE_STORAGE:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
//sessionManager.selectImage(getActivity(), this, getString(R.string.RegisterScreen));
}
break;
// mapReady();
}
}
private void onCaptureImageResult(Intent data, String imageType) {
Bitmap thumbnail = null;
try {
if (imageType.equals("camera")) {
licenseFile = imageUtility.compressImage(destination.getPath());
} else {
licenseFile = imageUtility.compressImage(imageUtility.getRealPathFromURI(this, data.getData()));
}
Log.e("licenseFile", licenseFile);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(destination.getAbsolutePath(),bmOptions);
// bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
upload_image.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
void bookAppointment( String license_image) {
String splittedAmount[]=amount.split(" ");
Log.e("check","check");
ApiInterface apiService =
ApiClient.getClient().create(ApiInterface.class);
if(license_image.equals(""))
{}
else {
imageToUpload = RequestBody.create(MediaType.parse("image/jpg"), new File(license_image));
}
/* RequestBody user_id = RequestBody.create(MediaType.parse("text/plain"), "27");
RequestBody token = RequestBody.create(MediaType.parse("text/plain"), "2746efe3372f40289099537c00e19b734a30966b6719f6a60a814781f5692e374ac5cdf26659a792");
RequestBody patient_id = RequestBody.create(MediaType.parse("text/plain"), "27");
RequestBody doctor_id = RequestBody.create(MediaType.parse("text/plain"), "5");
RequestBody consultation_date = RequestBody.create(MediaType.parse("text/plain"), "27-07-2017");
RequestBody start_time = RequestBody.create(MediaType.parse("text/plain"), "9:00");
RequestBody end_time = RequestBody.create(MediaType.parse("text/plain"), "9:20");
RequestBody message = RequestBody.create(MediaType.parse("text/plain"), "afd");
RequestBody isPaid = RequestBody.create(MediaType.parse("text/plain"), "1");
RequestBody amount = RequestBody.create(MediaType.parse("text/plain"), "32");
RequestBody payment_method = RequestBody.create(MediaType.parse("text/plain"), "234");
RequestBody selected_communication_medium = RequestBody.create(MediaType.parse("text/plain"), "1");*/
RequestBody user_id = RequestBody.create(MediaType.parse("text/plain"), sharedPreferenceManager.getValue(SharedPreferenceManager.USER_ID));
RequestBody token = RequestBody.create(MediaType.parse("text/plain"),sharedPreferenceManager.getValue(SharedPreferenceManager.TOKEN) );
RequestBody patient_id = RequestBody.create(MediaType.parse("text/plain"), sharedPreferenceManager.getValue(SharedPreferenceManager.USER_ID));
RequestBody doctor_id = RequestBody.create(MediaType.parse("text/plain"), doctorID);
RequestBody consultation_date = RequestBody.create(MediaType.parse("text/plain"), consulationDate);
RequestBody start_time = RequestBody.create(MediaType.parse("text/plain"), startTime);
RequestBody end_time = RequestBody.create(MediaType.parse("text/plain"), EndTime);
RequestBody message = RequestBody.create(MediaType.parse("text/plain"), message1.getText().toString());
RequestBody isPaid = RequestBody.create(MediaType.parse("text/plain"), "1");
RequestBody amount1 = RequestBody.create(MediaType.parse("text/plain"), amount);
RequestBody payment_method = RequestBody.create(MediaType.parse("text/plain"), "1");
RequestBody selected_communication_medium = RequestBody.create(MediaType.parse("text/plain"),selected_communication_medium1);
try {
Log.e("user_id", "user_id" + sharedPreferenceManager.getValue(SharedPreferenceManager.USER_ID));
Log.e("token", "token" + sharedPreferenceManager.getValue(SharedPreferenceManager.TOKEN));
Log.e("patient_id", "patient_id" + sharedPreferenceManager.getValue(SharedPreferenceManager.USER_ID));
Log.e("doctor_id", "doctor_id" + doctorID);
Log.e("consultation_date", "consultation_date" + consulationDate);
Log.e("start_time", "start_time" + startTime);
Log.e("end_time", "end_time" + EndTime);
Log.e("message", "message" + message1.getText().toString());
Log.e("isPaid", "isPaid" + "1");
Log.e("amount", "amount" + amount);
Log.e("payment_method", "payment_method" + "1");
Log.e("selected_commu_medium", "selected_commu_medium" + selected_communication_medium);
}
catch (Exception e)
{
}
if(license_image.equals(""))
{
call = apiService.signup1(user_id, token, patient_id, doctor_id, consultation_date, start_time, end_time,message
,isPaid,amount1,payment_method,selected_communication_medium);
}
else {
call = apiService.signup(imageToUpload, user_id, token, patient_id, doctor_id, consultation_date, start_time, end_time,message
,isPaid,amount1,payment_method,selected_communication_medium);
}
L.showProgresssBar(context);
call.enqueue(new Callback<SucessModel>() {
@Override
public void onResponse(Call<SucessModel> call, retrofit2.Response<SucessModel> response) {
if(response.body().getStatus_code()==200)
{
L.hideProgressBar(context);
L.showToast(getApplicationContext(),"Appointment Created Successfully");
Intent intent=new Intent(context,TabActivity.class);
intent.putExtra("upcoming","upcoming");
startActivity(intent);
finish();
}
else
{
}
}
@Override
public void onFailure(Call<SucessModel> call, Throwable t) {
// Log error here since request failed
Log.e("log", t.toString());
}
});
}
}