@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    // reuse views
    if (rowView == null) {
      LayoutInflater inflater = mContext.getLayoutInflater();
      rowView = inflater.inflate(mResourceID, null);
      // configure view holder
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.mRowLayout = (LinearLayout) rowView;
      viewHolder.mIdentifier = (TextView) rowView.findViewById(R.id.patientIdentifier);
      viewHolder.mDisplayName = (TextView) rowView.findViewById(R.id.patientDisplayName);
      viewHolder.mGender = (TextView) rowView.findViewById(R.id.patientGender);
      viewHolder.mAge = (TextView) rowView.findViewById(R.id.patientAge);
      viewHolder.mBirthDate = (TextView) rowView.findViewById(R.id.patientBirthDate);
      viewHolder.mAvailableOfflineCheckbox = (CheckBox) rowView.findViewById(R.id.offlineCheckbox);
      rowView.setTag(viewHolder);
    }

    // fill data
    final ViewHolder holder = (ViewHolder) rowView.getTag();
    final Patient patient = mItems.get(position);

    if (null != patient.getIdentifier()) {
      holder.mIdentifier.setText("#" + patient.getIdentifier());
    }
    if (null != patient.getDisplay()) {
      holder.mDisplayName.setText(patient.getDisplay());
    }
    if (null != patient.getGender()) {
      holder.mGender.setText(patient.getGender());
    }
    if (null != patient.getAge()) {
      holder.mAge.setText(patient.getAge());
    }
    holder.mBirthDate.setText(DateUtils.convertTime(patient.getBirthDate()));
    if (null != holder.mAvailableOfflineCheckbox) {
      setUpCheckBoxLogic(holder, patient);
    }
    holder.mRowLayout.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (new PatientDAO().isUserAlreadySaved(patient.getUuid())) {
              Intent intent = new Intent(mContext, PatientDashboardActivity.class);
              Long patientID = new PatientDAO().findPatientByUUID(patient.getUuid()).getId();
              intent.putExtra(ApplicationConstants.BundleKeys.PATIENT_ID_BUNDLE, patientID);
              mContext.startActivity(intent);
            }
          }
        });

    FontsUtil.setFont((ViewGroup) rowView);
    return rowView;
  }
  public void setUpCheckBoxLogic(final ViewHolder holder, final Patient patient) {
    if (new PatientDAO().userDoesNotExist(patient.getUuid())) {
      holder.mAvailableOfflineCheckbox.setChecked(false);
      holder.mAvailableOfflineCheckbox.setVisibility(View.VISIBLE);
      holder.mAvailableOfflineCheckbox.setText(
          mContext.getString(R.string.find_patients_row_checkbox_download_label));
      holder.mAvailableOfflineCheckbox.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              if (((CheckBox) v).isChecked()) {
                long patientId = new PatientDAO().savePatient(patient);
                ((ACBaseActivity) mContext).showProgressDialog(R.string.save_patient_data_dialog);
                new VisitsManager()
                    .findVisitsByPatientUUID(
                        VisitsHelper.createVisitsByPatientUUIDListener(
                            patient.getUuid(), patientId, (ACBaseActivity) mContext));
                disableCheckBox(holder);

                if (mContext instanceof FindPatientsActivity) {
                  FragmentManager fm =
                      ((FindPatientsActivity) mContext).getSupportFragmentManager();
                  FindPatientInDatabaseFragment fragment =
                      (FindPatientInDatabaseFragment)
                          fm.getFragments().get(FindPatientsActivity.TabHost.DOWNLOADED_TAB_POS);

                  fragment.updatePatientsInDatabaseList();
                }
              }
            }
          });
    } else {
      disableCheckBox(holder);
    }
  }
 private void startCaptureVitals() {
   try {
     Intent intent = new Intent(this, FormEntryActivity.class);
     Uri formURI =
         new FormsDAO(this.getContentResolver())
             .getFormURI(ApplicationConstants.FormNames.VITALS_XFORM);
     intent.setData(formURI);
     intent.putExtra(ApplicationConstants.BundleKeys.PATIENT_UUID_BUNDLE, mPatient.getUuid());
     this.startActivityForResult(intent, CAPTURE_VITALS_REQUEST_CODE);
   } catch (Exception e) {
     ToastUtil.showLongToast(this, ToastUtil.ToastType.ERROR, R.string.failed_to_open_vitals_form);
     OpenMRS.getInstance().getOpenMRSLogger().d(e.toString());
   }
 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   switch (resultCode) {
     case RESULT_OK:
       String path = data.getData().toString();
       String instanceID = path.substring(path.lastIndexOf('/') + 1);
       FormManagerBundle bundle =
           FormsHelper.createBundle(
               new FormsDAO(getContentResolver())
                   .getSurveysSubmissionDataFromFormInstanceId(instanceID)
                   .getFormInstanceFilePath(),
               mPatient.getUuid(),
               mPatient.getId(),
               mVisit.getUuid());
       mFormsManager.uploadXFormWithMultiPartRequest(
           FormsHelper.createUploadXFormWithMultiPartRequestListener(bundle, this));
       break;
     case RESULT_CANCELED:
       finish();
     default:
       break;
   }
 }
 public void endVisit() {
   mVisitsManager.endVisitByUUID(
       VisitsHelper.createEndVisitsByUUIDListener(
           mVisit.getUuid(), mPatient.getId(), mVisit.getId(), this));
 }