public static Visit map(JSONObject jsonObject) throws JSONException {
    Visit visit = new Visit();

    visit.setUuid(getStringFromObject(jsonObject, "uuid"));
    JSONObject locationObject = getJSONObject(jsonObject, "location");
    visit.setVisitPlace(getStringFromObject(locationObject, DISPLAY_KEY));
    JSONObject visitTypeObject = jsonObject.getJSONObject("visitType");
    visit.setVisitType(getStringFromObject(visitTypeObject, DISPLAY_KEY));
    visit.setStartDate(DateUtils.convertTime(getStringFromObject(jsonObject, "startDatetime")));
    visit.setStopDate(DateUtils.convertTime(getStringFromObject(jsonObject, "stopDatetime")));
    List<Encounter> encounterList = new ArrayList<Encounter>();

    if (!jsonObject.isNull("encounters")) {
      JSONArray encountersJSONArray = jsonObject.getJSONArray("encounters");
      for (int i = 0; i < encountersJSONArray.length(); i++) {
        Encounter encounter = new Encounter();
        JSONObject encounterJSONObject = encountersJSONArray.getJSONObject(i);
        List<Observation> observationList = new ArrayList<Observation>();
        encounter.setDisplay(getStringFromObject(encounterJSONObject, DISPLAY_KEY));
        encounter.setUuid(getStringFromObject(encounterJSONObject, "uuid"));
        encounter.setEncounterType(
            Encounter.EncounterType.getType(
                getStringFromObject(
                    getJSONObject(encounterJSONObject, "encounterType"), DISPLAY_KEY)));
        encounter.setEncounterDatetime(
            DateUtils.convertTime(getStringFromObject(encounterJSONObject, "encounterDatetime")));
        JSONArray obsJSONArray = encounterJSONObject.getJSONArray("obs");
        for (int j = 0; j < obsJSONArray.length(); j++) {
          Observation observation = new Observation();
          JSONObject observationJSONObject = obsJSONArray.getJSONObject(j);
          observation.setUuid(getStringFromObject(observationJSONObject, "uuid"));
          if (Encounter.EncounterType.VITALS.equals(encounter.getEncounterType())) {
            String[] labelAndValue =
                getStringFromObject(observationJSONObject, DISPLAY_KEY).split(":");
            observation.setDisplay(labelAndValue[0]);
            observation.setDisplayValue(labelAndValue[1]);
          } else if (Encounter.EncounterType.VISIT_NOTE.equals(encounter.getEncounterType())) {
            observation = ObservationMapper.diagnosisMap(observationJSONObject);
          } else {
            observation.setDisplay(getStringFromObject(observationJSONObject, DISPLAY_KEY));
          }
          observationList.add(observation);
        }
        encounter.setObservations(observationList);
        encounterList.add(encounter);
      }
    }
    visit.setEncounters(encounterList);
    return visit;
  }
  @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 endVisitByUUID(EndVisitByUUIDListener listener) {
    String url = mVisitsByUuidBaseUrl + listener.getVisitUUID();
    mLogger.d(SENDING_REQUEST + url);

    HashMap<String, String> params = new HashMap<String, String>();
    params.put(
        STOP_DATE_TIME,
        DateUtils.convertTime(System.currentTimeMillis(), DateUtils.OPEN_MRS_REQUEST_FORMAT));

    JsonObjectRequestWrapper jsObjRequest =
        new JsonObjectRequestWrapper(
            Request.Method.POST, url, new JSONObject(params), listener, listener, DO_GZIP_REQUEST);
    mOpenMRS.addToRequestQueue(jsObjRequest);
  }
  public void startVisit(StartVisitListener listener) {
    mLogger.d(SENDING_REQUEST + mVisitBaseUrl);

    HashMap<String, String> params = new HashMap<String, String>();
    params.put(PATIENT, listener.getPatientUUID());
    params.put(VISIT_TYPE, OpenMRS.getInstance().getVisitTypeUUID());
    params.put(
        START_DATE_TIME,
        DateUtils.convertTime(System.currentTimeMillis(), DateUtils.OPEN_MRS_REQUEST_FORMAT));
    params.put(
        LOCATION,
        LocationDAO.findLocationByName(OpenMRS.getInstance().getLocation())
            .getParentLocationUuid());

    JsonObjectRequestWrapper jsObjRequest =
        new JsonObjectRequestWrapper(
            Request.Method.POST,
            mVisitBaseUrl,
            new JSONObject(params),
            listener,
            listener,
            DO_GZIP_REQUEST);
    mOpenMRS.addToRequestQueue(jsObjRequest);
  }