Esempio n. 1
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.file_upload, container, false);
    getDialog().setTitle("Upload File");
    capture = (Button) view.findViewById(R.id.capture_image);
    browse = (Button) view.findViewById(R.id.browse_image);
    upload = (Button) view.findViewById(R.id.upload);
    global = (Global) getActivity().getApplicationContext();
    name = (EditText) view.findViewById(R.id.nameValue);
    category = (Spinner) view.findViewById(R.id.categoryValue);
    clinicSpinner = (Spinner) view.findViewById(R.id.clinic);
    medicalReportSpinner = (Spinner) view.findViewById(R.id.medical_report);
    medicalReports = getResources().getStringArray(R.array.medical_report);

    doctorValue = (TextView) view.findViewById(R.id.doctorvalue);
    // doctorValue.setText();

    dateValue = (TextView) view.findViewById(R.id.datevalues);
    dateValue.setText(
        UtilSingleInstance.getDateFormattedInStringFormatUsingLongForMedicinDetails(
            "" + Calendar.getInstance().getTimeInMillis()));
    typespinner = (Spinner) view.findViewById(R.id.typespinner);
    typespinner.setAdapter(
        new MedicalReportSpinner(getActivity(), R.layout.customize_spinner, medicalReports));

    medicalReportSpinner.setAdapter(
        new MedicalReportSpinner(getActivity(), R.layout.customize_spinner, medicalReports));
    document = (Button) view.findViewById(R.id.browse_document);
    categories = getResources().getStringArray(R.array.category_data_list);
    System.out.println("SIze of categories:::::" + categories.length);
    category.setAdapter(new CategorySpinner(getActivity(), R.layout.customize_spinner, categories));
    appointmentDate = global.getAppointmentDate();
    appointmentTime = global.getAppointmentTime();
    name.setText(global.getTestPrescribed());
    session = getActivity().getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
    id = session.getString("sessionID", null);
    type = session.getString("loginType", null);
    appointMentId = session.getString("appointmentId", "");
    doctorId = session.getString("id", "0");

    nameText = (TextView) view.findViewById(R.id.name);
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(5, TimeUnit.MINUTES);
    client.setReadTimeout(5, TimeUnit.MINUTES);
    client.setWriteTimeout(5, TimeUnit.MINUTES);
    RestAdapter restAdapter =
        new RestAdapter.Builder()
            .setEndpoint(getResources().getString(R.string.base_url))
            .setClient(new OkClient(client))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();
    api = restAdapter.create(MyApi.class);

    api.getAllClinics(
        new PersonID(doctorId),
        new Callback<List<Clinic>>() {
          @Override
          public void success(List<Clinic> clinicsList, Response response) {
            clinicDetailVm = clinicsList;
            clinics = new String[clinicsList.size()];
            int count = 0;
            for (Clinic vm : clinicDetailVm) {
              clinics[count] = vm.getClinicName();
              count = count + 1;
            }
            clinicSpinner.setAdapter(
                new ClinicSpinner(getActivity(), R.layout.customize_spinner, clinics));
          }

          @Override
          public void failure(RetrofitError error) {
            Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
            error.printStackTrace();
          }
        });

    category.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            report = (String) category.getSelectedItem();
            if (report.equalsIgnoreCase("Medical Report")) {
              name.setVisibility(View.GONE);
              nameText.setVisibility(View.GONE);
              medicalReportSpinner.setVisibility(View.VISIBLE);

            } else {
              name.setVisibility(View.VISIBLE);
              nameText.setVisibility(View.VISIBLE);
              medicalReportSpinner.setVisibility(View.GONE);
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
    capture.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(
                MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "temp.jpg")));
            startActivityForResult(intent, 0);
          }
        });
    document.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getActivity(), FileChooser.class);
            ArrayList<String> extensions = new ArrayList<String>();
            extensions.add(".pdf");
            extensions.add(".xls");
            extensions.add(".xlsx");
            extensions.add(".txt");
            extensions.add(".doc");
            extensions.add(".docx");
            extensions.add(".jpg");
            intent.putStringArrayListExtra("filterFileExtension", extensions);
            startActivityForResult(intent, FILE_CHOOSER);
          }
        });
    upload.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            progress =
                ProgressDialog.show(
                    getActivity(), "", getResources().getString(R.string.loading_wait));
            String clinicName = (String) clinicSpinner.getSelectedItem();
            System.out.println("Clinic Name:::::::" + clinicName);
            String clinicId =
                clinicDetailVm.get(clinicSpinner.getSelectedItemPosition()).getIdClinic();
            System.out.println("Clinic Id:::::::" + clinicId);
            // String clinicId = "105";
            String nameData;
            /*
            httpPost.addHeader("x-patientId", "102");
             httpPost.addHeader("x-appointmentId", "584");
             httpPost.addHeader("x-clinicId", "101");
             httpPost.addHeader("x-type", "1");
             httpPost.addHeader("x-loggedinUserId", "102");
             httpPost.addHeader("x-fileName", "ANkLE BoNe X-ray.xlsx");
             */

            if (report.equalsIgnoreCase("Medical Report")) {
              nameData = (String) medicalReportSpinner.getSelectedItem();
            } else {
              nameData = name.getText().toString();
            }

            if (type.equalsIgnoreCase("doctor")) {
              doctorId = id;
              patientId = session.getString("patientId", null);
              System.out.println("PatientId::::::" + patientId);
              String categoryData = category.getSelectedItem().toString();
              String documentType = "";
              if (selectedImagePath != null) {
                documentType = selectedImagePath.substring(selectedImagePath.lastIndexOf("."));
              } else {
                documentType = "None";
                typedFile = null;
              }
              System.out.println("Document TYpe::::::" + documentType);

              if (documentType.contains("pdf")) {
                documentType = "1";
              } else {
                documentType = "0";
              }

              // restAdapter..setHea

              // api.uploadFile(typedFile, type, doctorId, patientId, assistantId, documentType,
              // nameData, categoryData, appointmentDate, appointmentTime,clinicId,clinicName,new
              // Callback<FileUpload>() {
              api.addPatientVisitDocument(
                  patientId,
                  appointMentId,
                  clinicId,
                  documentType,
                  doctorId,
                  nameData,
                  typedFile,
                  new Callback<ResponseAddDocuments>() {

                    @Override
                    public void success(
                        ResponseAddDocuments responseAddDocuments, Response response) {
                      {
                        if (responseAddDocuments != null) {
                          // System.out.println("Url::::::::" + responseAddDocuments.getUrl());
                          Toast.makeText(
                                  getActivity(), "File Uploaded Successfully!", Toast.LENGTH_SHORT)
                              .show();
                          progress.dismiss();

                          FileUploadDialog.this.getDialog().cancel();
                        } else {
                          Toast.makeText(getActivity(), "File upload Failed!", Toast.LENGTH_SHORT)
                              .show();
                        }
                      }
                    }

                    @Override
                    public void failure(RetrofitError error) {
                      error.printStackTrace();
                    }
                  });

            } else if (type.equalsIgnoreCase("patient")) {
              patientId = id;
              doctorId = session.getString("patient_doctor_email", null);
              String categoryData = category.getSelectedItem().toString();
              String documentType = "";
              if (selectedImagePath != null) {
                documentType = selectedImagePath.substring(selectedImagePath.lastIndexOf("."));
              } else {
                documentType = "None";
                typedFile = null;
              }
              System.out.println("Document TYpe::::::" + documentType);
              api.uploadFile(
                  typedFile,
                  type,
                  doctorId,
                  patientId,
                  assistantId,
                  documentType,
                  nameData,
                  categoryData,
                  appointmentDate,
                  appointmentTime,
                  clinicId,
                  clinicName,
                  new Callback<FileUpload>() {
                    @Override
                    public void success(FileUpload uploadFile, Response response2) {
                      if (uploadFile != null) {
                        Toast.makeText(getActivity(), "Data Saved Successfully", Toast.LENGTH_SHORT)
                            .show();

                        progress.dismiss();
                        FileUploadDialog.this.getDialog().cancel();
                      } else {
                        Toast.makeText(getActivity(), "Data is not saved", Toast.LENGTH_SHORT)
                            .show();
                      }
                    }

                    @Override
                    public void failure(RetrofitError error) {
                      error.printStackTrace();
                    }
                  });
            }
          }
        });

    browse.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
          }
        });

    return view;
  }
  public void showClinicsList() {
    final String patientId = session.getString("sessionID", null);
    api.getPatientAppointment(
        patientId,
        new Callback<List<Clinic>>() {
          @Override
          public void success(List<Clinic> clinics, Response response) {
            upcomingClinicList = new ArrayList<Clinic>();
            pastClinicList = new ArrayList<Clinic>();
            databaseHandler = new DatabaseHandler(getActivity());
            Global global = (Global) getActivity().getApplicationContext();
            global.setAllClinicsList(clinics);
            ArrayList<AppointmentDB> appointments =
                databaseHandler.getAllPatientAppointment(patientId);
            for (Clinic clinic : clinics) {
              SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
              Date date = null;
              try {
                date = formatter.parse(clinic.appointmentDate);
              } catch (Exception e) {
                e.printStackTrace();
              }
              String[] timeValue;
              Calendar calOne = Calendar.getInstance();
              calOne.setTime(date);
              timeValue = clinic.appointmentTime.split(":");
              int hour1 = Integer.parseInt(timeValue[0].trim());
              int min1 = Integer.parseInt(timeValue[1].trim().split("[a-zA-Z ]+")[0]);
              calOne.set(Calendar.HOUR, hour1);
              calOne.set(Calendar.MINUTE, min1);
              String strAM_PM = timeValue[1].replaceAll("[0-9]", "");
              if (strAM_PM.equals("AM")) {
                calOne.set(Calendar.AM_PM, 0);
              } else {
                calOne.set(Calendar.AM_PM, 1);
              }
              Calendar calTwo = Calendar.getInstance();
              System.out.println(
                  "Condition::::::" + (calOne.getTimeInMillis() < calTwo.getTimeInMillis()));
              System.out.println(
                  "Appoitment Date And Time= "
                      + clinic.appointmentDate
                      + " "
                      + clinic.appointmentTime);
              System.out.println("Appointment in mili= " + calOne.getTimeInMillis());
              System.out.println("Current in mili= " + calTwo.getTimeInMillis());
              for (AppointmentDB appointmentDB : appointments) {
                System.out.println(
                    "Appointment Status DB= " + appointmentDB.getAppointment_status());
                System.out.println("Appointment Date= " + appointmentDB.getAppointment_date());
                System.out.println("Appointment Time= " + appointmentDB.getAppointment_time());

                System.out.println(
                    "Alarm Condition:::::::"
                        + (appointmentDB.getAppointment_time().equals(clinic.appointmentTime)));
                if ((appointmentDB.getAppointment_date().equals(clinic.appointmentDate))) {
                  clinic.alarmFlag = Boolean.parseBoolean(appointmentDB.getAppointment_status());
                  break;
                }
              }
              if (calOne.getTimeInMillis() < calTwo.getTimeInMillis()) {
                clinic.upcomingFlag = false;
                pastClinicList.add(clinic);
              } else {
                clinic.upcomingFlag = true;
                upcomingClinicList.add(clinic);
              }
            }
            if (upcomingClinicList.size() == 0) {
              Clinic clinic = new Clinic();
              clinic.setClinicName("No Appointment Found");
              upcomingClinicList.add(clinic);
            }
            if (pastClinicList.size() == 0) {
              Clinic clinic = new Clinic();
              clinic.setClinicName("No Appointment Found");
              pastClinicList.add(clinic);
            }
            System.out.println("UpcomingList= " + upcomingClinicList.size());
            System.out.println("PastList= " + pastClinicList.size());
            upcomingAdapter = new ClinicAppointmentListAdapter(getActivity(), upcomingClinicList);
            pastAdapter = new ClinicAppointmentListAdapter(getActivity(), pastClinicList);
            upcomingList.setAdapter(upcomingAdapter);
            Utility.setListViewHeightBasedOnChildren(upcomingList);
            pastList.setAdapter(pastAdapter);
            Utility.setListViewHeightBasedOnChildren(pastList);
            progress.dismiss();
          }

          @Override
          public void failure(RetrofitError retrofitError) {
            Toast.makeText(getActivity(), retrofitError.toString(), Toast.LENGTH_LONG).show();
            retrofitError.printStackTrace();
          }
        });
  }