private void viewPatient(final Patients p) {
    Dialog info = new Dialog(getActivity());
    info.setTitle("Patient Details");
    info.setContentView(R.layout.patient_list_item_details_fragment);

    TextView fname = (TextView) info.findViewById(R.id.first_name_info);
    TextView mname = (TextView) info.findViewById(R.id.middle_name_info);
    TextView lname = (TextView) info.findViewById(R.id.last_name_info);
    TextView age = (TextView) info.findViewById(R.id.age);
    TextView status = (TextView) info.findViewById(R.id.status_info);
    TextView address = (TextView) info.findViewById(R.id.address_info);
    TextView hosp_name = (TextView) info.findViewById(R.id.hosp_name_info);
    TextView hosp_room = (TextView) info.findViewById(R.id.hosp_room_info);

    Button see_diag_info = (Button) info.findViewById(R.id.button1);
    see_diag_info.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            Dialog details = new Dialog(getActivity());
            details.setTitle("Medical History");
            TextView history = new TextView(getActivity());
            history.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
            history.setText(p.getMed_history());
            details.setContentView(history);
            details.show();
          }
        });

    fname.setText(p.getFname());
    mname.setText(p.getMi());
    lname.setText(p.getLname());
    age.setText(Integer.toString(p.getAge()));
    if (p.getPat_status() == 1) {
      status.setText("In-Patient");
      hosp_name.setText(p.getHosp_name());
      hosp_room.setText(p.getHosp_room());
    }

    if (p.getPat_status() == 2) {
      status.setText("Out-Patient");
      hosp_name.setText("None..");
      hosp_room.setText("None..");
      hosp_name.setEnabled(false);
      hosp_room.setEnabled(false);
    }

    address.setText(p.getAddr());
    info.show();
  }
  private void updateRounds(final Patients p) {
    final Dialog in_d = new Dialog(getActivity());
    in_d.setTitle("Update Hospital Details");
    in_d.setContentView(R.layout.input_rounds_schedule);

    Calendar c = Calendar.getInstance();
    final EditText h_name = (EditText) in_d.findViewById(R.id.hospital_name_next);
    final EditText h_room = (EditText) in_d.findViewById(R.id.hospital_room_next);
    TimePicker timePicker = (TimePicker) in_d.findViewById(R.id.round_schedule);
    final View amPmView = ((ViewGroup) timePicker.getChildAt(0)).getChildAt(3);
    Button add_rounds_setup = (Button) in_d.findViewById(R.id.save_rounds_setup);
    Button cancel_rounds_setup = (Button) in_d.findViewById(R.id.cancel_rounds_setup);

    c.setTimeInMillis(p.getTime());
    h_name.setText(p.getHosp_name());
    h_room.setText(p.getHosp_room());
    timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(c.get(Calendar.MINUTE));

    mHour = timePicker.getCurrentHour();
    mMin = timePicker.getCurrentMinute();

    timePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {

          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            mHour = hourOfDay;
            mMin = minute;
          }
        });

    add_rounds_setup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            // Temporary Workaround bug on timepicker
            if (amPmView instanceof NumberPicker) {
              if (((NumberPicker) amPmView).getValue() == 1) {
                if (mHour >= 12) mHour = mHour - 12;
                mHour = mHour + 12;
              }

              if (((NumberPicker) amPmView).getValue() == 0) {
                if (mHour >= 12) mHour = mHour - 12;
              }
            }

            // Toast.makeText(getActivity(), "Time of this record is: "+formatTime(timeInMills),
            // Toast.LENGTH_LONG).show();
            Time time = new Time();
            time.hour = mHour;
            time.minute = mMin;
            timeInMills = time.toMillis(false);

            Patients patients = p;

            patients.setHosp_name(h_name.getText().toString());
            patients.setHosp_room(h_room.getText().toString());

            patients.setLocation(h_name.getText().toString() + " - " + h_room.getText().toString());
            patients.setTime(timeInMills);

            Toast.makeText(getActivity(), "Rounds Schedule Updated!", Toast.LENGTH_SHORT).show();
            help.update(patients, Helper.UPDATE_SCHEDULE);
            loadPatientMasterList();
            loadPatientList(1);
            in_d.cancel();
          }
        });

    cancel_rounds_setup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            in_d.cancel();
          }
        });

    in_d.show();
  }
  private void updateRounds(final Patients p) {
    final Dialog in_d = new Dialog(getActivity());
    in_d.setTitle("Update Hospital Details");
    in_d.setContentView(R.layout.input_rounds_schedule);

    Calendar c = Calendar.getInstance();
    final EditText h_name = (EditText) in_d.findViewById(R.id.hospital_name_next);
    final EditText h_room = (EditText) in_d.findViewById(R.id.hospital_room_next);
    TimePicker timePicker = (TimePicker) in_d.findViewById(R.id.round_schedule);
    final View amPmView = ((ViewGroup) timePicker.getChildAt(0)).getChildAt(3);
    save = (Button) in_d.findViewById(R.id.save_rounds_setup);
    Button cancel_rounds_setup = (Button) in_d.findViewById(R.id.cancel_rounds_setup);
    save.setEnabled(false);

    c.setTimeInMillis(p.getTime());
    h_name.setText(p.getHosp_name());
    h_room.setText(p.getHosp_room());
    timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(c.get(Calendar.MINUTE));

    mHour = timePicker.getCurrentHour();
    mMin = timePicker.getCurrentMinute();

    timePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {

          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            mHour = hourOfDay;
            mMin = minute;
            save.setEnabled(true);
          }
        });

    h_name.addTextChangedListener(this);
    h_room.addTextChangedListener(this);

    save.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
            build.setMessage("Are all edits Correct?");
            build.setCancelable(false);
            build.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // Temporary Workaround bug on timepicker
                    if (amPmView instanceof NumberPicker) {
                      if (((NumberPicker) amPmView).getValue() == 1) {
                        if (mHour >= 12) mHour = mHour - 12;
                        mHour = mHour + 12;
                      }

                      if (((NumberPicker) amPmView).getValue() == 0) {
                        if (mHour >= 12) mHour = mHour - 12;
                      }
                    }

                    // Toast.makeText(getActivity(), "Time of this record is:
                    // "+formatTime(timeInMills), Toast.LENGTH_LONG).show();

                    Time time = new Time();
                    time.hour = mHour;
                    time.minute = mMin;
                    time.second = 0;
                    timeInMills = time.toMillis(false);

                    Patients patients = p;

                    patients.setHosp_name(h_name.getText().toString());
                    patients.setHosp_room(h_room.getText().toString());

                    patients.setLocation(
                        h_name.getText().toString() + " - " + h_room.getText().toString());
                    patients.setTime(timeInMills);

                    Toast.makeText(getActivity(), "Rounds Schedule Updated!", Toast.LENGTH_SHORT)
                        .show();
                    help.update(patients, Helper.UPDATE_SCHEDULE);
                    // Helper.scheduleRepeatingAlarm(getActivity(), patients,
                    // patients.getRequestCode(), patients.getTime());
                    loadPatientMasterList();
                    loadPatientList(1);
                    in_d.cancel();
                  }
                });
            build.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                  }
                });

            AlertDialog alert = build.create();
            alert.show();
          }
        });

    cancel_rounds_setup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            in_d.cancel();
          }
        });

    in_d.show();
  }
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Patients patients = (Patients) getListAdapter().getItem(info.position);
    // Toast.makeText(getActivity(), "Full Name of Clicked: "+patients.getId(),
    // Toast.LENGTH_LONG).show();
    // final Patients patients = (Patients) help.getRecord(PATIENTS, id.getText().toString());
    MenuItem edit = menu.add("Edit");
    MenuItem delete = menu.add("Delete");

    if (patients != null && patients.getPat_status() == 1) {
      Log.d("itemCheck", "Patient ID: " + patients.getPatient_id());
      Log.d("itemCheck", "Patient Name: : " + patients.toString());
      help.getPatientSchedule(patients);
      Log.d("itemCheck", "Schedule ID: " + patients.getSchedule_id());
      Log.d("itemCheck", "Location : " + patients.getLocation());
      Log.d("itemCheck", "Hospital Name: " + patients.getHosp_name());
      Log.d("itemCheck", "Hospital Room: " + patients.getHosp_room());
      Log.d("itemCheck", "Time: " + patients.time());
      Log.d("itemCheck", "Request Code: " + patients.getRequestCode());
      Log.d("itemCheck", "Under this Schedule is: Patient Name: " + patients.toString());
      Log.d("itemCheck", "Under this Schedule is: Medical History: " + patients.getMed_history());

      MenuItem update = menu.add("Update Rounds Schedule");
      update.setOnMenuItemClickListener(
          new OnMenuItemClickListener() {

            public boolean onMenuItemClick(MenuItem item) {
              updateRounds(patients);
              return true;
            }
          });
    }

    MenuItem change_status = menu.add("Change Status");

    change_status.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {

          public boolean onMenuItemClick(MenuItem item) {
            changeStatus(patients);
            return true;
          }
        });

    edit.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {

          public boolean onMenuItemClick(MenuItem item) {
            editPatients(patients);
            return true;
          }
        });

    delete.setOnMenuItemClickListener(
        new OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            deletePatients(patients);
            return true;
          }
        });
  }